
* doc/misc/tramp.texi (Remote programs, Remote processes) (Frequently Asked Questions): Adapt Emacs versions. * doc/misc/trampver.texi: * lisp/net/trampver.el: Change version to "2.6.0-pre". * lisp/net/tramp-adb.el (top): Don't use `tramp-compat-funcall' for connection-local functions. * lisp/net/tramp-compat.el (tramp-unload-file-name-handlers) (tramp-handle-temporary-file-directory) (tramp-compat-temporary-file-directory-function) (tramp-compat-file-attribute-type) (tramp-compat-file-attribute-link-number) (tramp-compat-file-attribute-user-id) (tramp-compat-file-attribute-group-id) (tramp-compat-file-attribute-access-time) (tramp-compat-file-attribute-modification-time) (tramp-compat-file-attribute-status-change-time) (tramp-compat-file-attribute-size) (tramp-compat-file-attribute-modes, tramp-file-missing) (tramp-compat-file-missing, tramp-compat-file-local-name): Remove. (tramp-compat-file-name-quoted-p, tramp-compat-file-name-quote) (tramp-compat-file-name-unquote) (tramp-compat-progress-reporter-update) (tramp-compat-file-modes, tramp-compat-set-file-modes) (tramp-compat-set-file-times, tramp-compat-directory-files) (tramp-compat-directory-files-and-attributes): Adapt implementation. * lisp/net/tramp.el: * lisp/net/tramp-adb.el: * lisp/net/tramp-archive.el: * lisp/net/tramp-crypt.el: * lisp/net/tramp-fuse.el: * lisp/net/tramp-gvfs.el: * lisp/net/tramp-rclone.el: * lisp/net/tramp-sh.el: * lisp/net/tramp-smb.el: * lisp/net/tramp-sudoedit.el: Adapt callees. * lisp/net/tramp-crypt.el (tramp-crypt-config-file-name): Expand file name. * lisp/net/tramp-fuse.el (tramp-fuse-handle-file-readable-p): Remove. * lisp/net/tramp-gvfs.el (tramp-gvfs-enabled): Don't check Emacs version. (tramp-gvfs-handler-mounted-unmounted): Use `make-tramp-file-name'. * lisp/net/tramp-integration.el (rfn-eshadow-overlay): Remove declaration. (top): Don't use `tramp-compat-funcall' for connection-local functions. * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): Use `tramp-rclone-handle-file-readable-p'. (tramp-rclone-handle-file-readable-p): New defun. * lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist): Use `tramp-handle-file-readable-p'. * lisp/net/tramp.el (tramp-temp-name-prefix, tramp-lookup-syntax): Adapt docstring. (tramp-set-connection-local-variables) (tramp-set-connection-local-variables-for-buffer): Don't use `tramp-compat-funcall' for connection-local functions. (tramp-file-name-for-operation): Reorder list. (tramp-handle-make-symbolic-link): Don't handle TARGET and OK-IF-ALREADY-EXISTS. (tramp-read-passwd): Don't use `read-passwd' any longer. (top): Don't check for `interrupt-process-functions'. * test/lisp/net/tramp-archive-tests.el (tramp-archive--test-emacs26-p): Remove. (tramp-archive-test02-file-name-dissect): Use `make-tramp-file-name'. (all): Replace Emacs 26 compatibility functions with their original name. (tramp-archive-test46-auto-load) (tramp-archive-test46-delay-load): Rename. * test/lisp/net/tramp-tests.el (dired-aux, seq): Require them. (dired-compress, connection-local-criteria-alist) (connection-local-profile-alist, async-shell-command-width): Don't declare. (all): Replace Emacs 26 compatibility functions with their original name. (tramp-test04-substitute-in-file-name) (tramp-test10-write-region, tramp-test11-copy-file) (tramp-test12-rename-file, tramp-test15-copy-directory) (tramp-test17-insert-directory) (tramp-test17-dired-with-wildcards, tramp-test21-file-links) (tramp-test31-interrupt-process) (tramp-test34-connection-local-variables) (tramp-test34-explicit-shell-file-name) (tramp-test40-make-nearby-temp-file) (tramp-test41-special-characters, tramp-test42-utf8) (tramp-test46-delay-load, tramp-test46-remote-load-path) (tramp-test47-unload): Don't check for Emacs 26 special features. (tramp--test-emacs26-p): Remove. (tramp--test-emacs29-p): New defun. (tramp-test45-dired-compress-file) (tramp-test45-dired-compress-dir): Use it. (tramp-test44-asynchronous-requests): Use `seq-random-elt'.
311 lines
11 KiB
EmacsLisp
311 lines
11 KiB
EmacsLisp
;;; tramp-integration.el --- Tramp integration into other packages -*- lexical-binding:t -*-
|
||
|
||
;; Copyright (C) 2019-2021 Free Software Foundation, Inc.
|
||
|
||
;; Author: Michael Albinus <michael.albinus@gmx.de>
|
||
;; Keywords: comm, processes
|
||
;; Package: tramp
|
||
|
||
;; This file is part of GNU Emacs.
|
||
|
||
;; GNU Emacs is free software: you can redistribute it and/or modify
|
||
;; it under the terms of the GNU General Public License as published by
|
||
;; the Free Software Foundation, either version 3 of the License, or
|
||
;; (at your option) any later version.
|
||
|
||
;; GNU Emacs is distributed in the hope that it will be useful,
|
||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;; GNU General Public License for more details.
|
||
|
||
;; You should have received a copy of the GNU General Public License
|
||
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
;;; Commentary:
|
||
|
||
;; This assembles all integration of Tramp with other packages.
|
||
|
||
;;; Code:
|
||
|
||
(require 'tramp-compat)
|
||
|
||
;; Pacify byte-compiler.
|
||
(require 'cl-lib)
|
||
(declare-function info-lookup->cache "info-look")
|
||
(declare-function info-lookup->mode-cache "info-look")
|
||
(declare-function info-lookup->mode-value "info-look")
|
||
(declare-function info-lookup->other-modes "info-look")
|
||
(declare-function info-lookup->topic-cache "info-look")
|
||
(declare-function info-lookup->topic-value "info-look")
|
||
(declare-function info-lookup-maybe-add-help "info-look")
|
||
(declare-function recentf-cleanup "recentf")
|
||
(declare-function tramp-dissect-file-name "tramp")
|
||
(declare-function tramp-file-name-equal-p "tramp")
|
||
(declare-function tramp-tramp-file-p "tramp")
|
||
(declare-function tramp-rename-files "tramp-cmds")
|
||
(declare-function tramp-rename-these-files "tramp-cmds")
|
||
(defvar eshell-path-env)
|
||
(defvar ido-read-file-name-non-ido)
|
||
(defvar info-lookup-alist)
|
||
(defvar ivy-completing-read-handlers-alist)
|
||
(defvar recentf-exclude)
|
||
(defvar tramp-current-connection)
|
||
(defvar tramp-postfix-host-format)
|
||
(defvar tramp-use-ssh-controlmaster-options)
|
||
|
||
;;; Fontification of `read-file-name':
|
||
|
||
(defvar tramp-rfn-eshadow-overlay)
|
||
(make-variable-buffer-local 'tramp-rfn-eshadow-overlay)
|
||
|
||
(defun tramp-rfn-eshadow-setup-minibuffer ()
|
||
"Set up a minibuffer for `file-name-shadow-mode'.
|
||
Adds another overlay hiding filename parts according to Tramp's
|
||
special handling of `substitute-in-file-name'."
|
||
(when minibuffer-completing-file-name
|
||
(setq tramp-rfn-eshadow-overlay
|
||
(make-overlay (minibuffer-prompt-end) (minibuffer-prompt-end)))
|
||
;; Copy rfn-eshadow-overlay properties.
|
||
(let ((props (overlay-properties rfn-eshadow-overlay)))
|
||
(while props
|
||
;; The `field' property prevents correct minibuffer
|
||
;; completion; we exclude it.
|
||
(if (not (eq (car props) 'field))
|
||
(overlay-put tramp-rfn-eshadow-overlay (pop props) (pop props))
|
||
(pop props) (pop props))))))
|
||
|
||
(add-hook 'rfn-eshadow-setup-minibuffer-hook
|
||
#'tramp-rfn-eshadow-setup-minibuffer)
|
||
(add-hook 'tramp-unload-hook
|
||
(lambda ()
|
||
(remove-hook 'rfn-eshadow-setup-minibuffer-hook
|
||
#'tramp-rfn-eshadow-setup-minibuffer)))
|
||
|
||
(defun tramp-rfn-eshadow-update-overlay-regexp ()
|
||
"An overlay covering the shadowed part of the filename."
|
||
(format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format))
|
||
|
||
(defun tramp-rfn-eshadow-update-overlay ()
|
||
"Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
|
||
This is intended to be used as a minibuffer `post-command-hook' for
|
||
`file-name-shadow-mode'; the minibuffer should have already
|
||
been set up by `rfn-eshadow-setup-minibuffer'."
|
||
;; In remote files name, there is a shadowing just for the local part.
|
||
(ignore-errors
|
||
(let ((end (or (overlay-end rfn-eshadow-overlay)
|
||
(minibuffer-prompt-end)))
|
||
;; We do not want to send any remote command.
|
||
(non-essential t))
|
||
(when (tramp-tramp-file-p (buffer-substring end (point-max)))
|
||
(save-excursion
|
||
(save-restriction
|
||
(narrow-to-region
|
||
(1+ (or (string-match-p
|
||
(tramp-rfn-eshadow-update-overlay-regexp)
|
||
(buffer-string) end)
|
||
end))
|
||
(point-max))
|
||
(let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay)
|
||
(rfn-eshadow-update-overlay-hook nil)
|
||
file-name-handler-alist)
|
||
(move-overlay rfn-eshadow-overlay (point-max) (point-max))
|
||
(rfn-eshadow-update-overlay))))))))
|
||
|
||
(add-hook 'rfn-eshadow-update-overlay-hook
|
||
#'tramp-rfn-eshadow-update-overlay)
|
||
(add-hook 'tramp-unload-hook
|
||
(lambda ()
|
||
(remove-hook 'rfn-eshadow-update-overlay-hook
|
||
#'tramp-rfn-eshadow-update-overlay)))
|
||
|
||
;;; Integration of eshell.el:
|
||
|
||
;; eshell.el keeps the path in `eshell-path-env'. We must change it
|
||
;; when `default-directory' points to another host.
|
||
(defun tramp-eshell-directory-change ()
|
||
"Set `eshell-path-env' to $PATH of the host related to `default-directory'."
|
||
;; Remove last element of `(exec-path)', which is `exec-directory'.
|
||
;; Use `path-separator' as it does eshell.
|
||
(setq eshell-path-env
|
||
(mapconcat
|
||
#'identity (butlast (tramp-compat-exec-path)) path-separator)))
|
||
|
||
(with-eval-after-load 'esh-util
|
||
(add-hook 'eshell-mode-hook
|
||
#'tramp-eshell-directory-change)
|
||
(add-hook 'eshell-directory-change-hook
|
||
#'tramp-eshell-directory-change)
|
||
(add-hook 'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(remove-hook 'eshell-mode-hook
|
||
#'tramp-eshell-directory-change)
|
||
(remove-hook 'eshell-directory-change-hook
|
||
#'tramp-eshell-directory-change))))
|
||
|
||
;;; Integration of recentf.el:
|
||
|
||
(defun tramp-recentf-exclude-predicate (name)
|
||
"Predicate to exclude a remote file name from recentf.
|
||
NAME must be equal to `tramp-current-connection'."
|
||
(when (file-remote-p name)
|
||
(tramp-file-name-equal-p
|
||
(tramp-dissect-file-name name) (car tramp-current-connection))))
|
||
|
||
(defun tramp-recentf-cleanup (vec)
|
||
"Remove all file names related to VEC from recentf."
|
||
(when (bound-and-true-p recentf-list)
|
||
(let ((tramp-current-connection `(,vec))
|
||
(recentf-exclude '(tramp-recentf-exclude-predicate)))
|
||
(recentf-cleanup))))
|
||
|
||
(defun tramp-recentf-cleanup-all ()
|
||
"Remove all remote file names from recentf."
|
||
(when (bound-and-true-p recentf-list)
|
||
(let ((recentf-exclude '(file-remote-p)))
|
||
(recentf-cleanup))))
|
||
|
||
(with-eval-after-load 'recentf
|
||
(add-hook 'tramp-cleanup-connection-hook
|
||
#'tramp-recentf-cleanup)
|
||
(add-hook 'tramp-cleanup-all-connections-hook
|
||
#'tramp-recentf-cleanup-all)
|
||
(add-hook 'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(remove-hook 'tramp-cleanup-connection-hook
|
||
#'tramp-recentf-cleanup)
|
||
(remove-hook 'tramp-cleanup-all-connections-hook
|
||
#'tramp-recentf-cleanup-all))))
|
||
|
||
;;; Integration of ido.el:
|
||
|
||
(with-eval-after-load 'ido
|
||
(add-to-list 'ido-read-file-name-non-ido #'tramp-rename-files)
|
||
(add-to-list 'ido-read-file-name-non-ido #'tramp-rename-these-files)
|
||
(add-hook 'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(setq ido-read-file-name-non-ido
|
||
(delq #'tramp-rename-these-files ido-read-file-name-non-ido)
|
||
ido-read-file-name-non-ido
|
||
(delq #'tramp-rename-files ido-read-file-name-non-ido)))))
|
||
|
||
;;; Integration of ivy.el:
|
||
|
||
(with-eval-after-load 'ivy
|
||
(add-to-list 'ivy-completing-read-handlers-alist
|
||
'(tramp-rename-files . completing-read-default))
|
||
(add-to-list 'ivy-completing-read-handlers-alist
|
||
'(tramp-rename-these-files . completing-read-default))
|
||
(add-hook
|
||
'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(setq ivy-completing-read-handlers-alist
|
||
(delete
|
||
(assq #'tramp-rename-these-files ivy-completing-read-handlers-alist)
|
||
ivy-completing-read-handlers-alist)
|
||
ivy-completing-read-handlers-alist
|
||
(delete
|
||
(assq #'tramp-rename-files ivy-completing-read-handlers-alist)
|
||
ivy-completing-read-handlers-alist)))))
|
||
|
||
;;; Integration of info-look.el:
|
||
|
||
(with-eval-after-load 'info-look
|
||
;; Create a pseudo mode `tramp-info-lookup-mode' for Tramp symbol lookup.
|
||
(info-lookup-maybe-add-help
|
||
:mode 'tramp-info-lookup-mode :topic 'symbol
|
||
:regexp "[^][()`'‘’,\" \t\n]+"
|
||
:doc-spec '(("(tramp)Function Index" nil "^ -+ .*: " "\\( \\|$\\)")
|
||
("(tramp)Variable Index" nil "^ -+ .*: " "\\( \\|$\\)")))
|
||
|
||
(add-hook
|
||
'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(setcdr (assq 'symbol info-lookup-alist)
|
||
(delete (info-lookup->mode-value 'symbol 'tramp-info-lookup-mode)
|
||
(info-lookup->topic-value 'symbol)))
|
||
(setcdr (info-lookup->cache 'symbol)
|
||
(delete (info-lookup->mode-cache 'symbol 'tramp-info-lookup-mode)
|
||
(info-lookup->topic-cache 'symbol)))))
|
||
|
||
(dolist (mode (mapcar #'car (info-lookup->topic-value 'symbol)))
|
||
;; Add `tramp-info-lookup-mode' to `other-modes' for either
|
||
;; `emacs-lisp-mode' itself, or to modes which use
|
||
;; `emacs-lisp-mode' as `other-modes'. Reset `info-lookup-cache'.
|
||
(when (and (or (equal mode 'emacs-lisp-mode)
|
||
(memq
|
||
'emacs-lisp-mode (info-lookup->other-modes 'symbol mode)))
|
||
(not (memq 'tramp-info-lookup-mode
|
||
(info-lookup->other-modes 'symbol mode))))
|
||
(setcdr (info-lookup->mode-value 'symbol mode)
|
||
(append (butlast (cdr (info-lookup->mode-value 'symbol mode)))
|
||
`((tramp-info-lookup-mode
|
||
. ,(info-lookup->other-modes 'symbol mode)))))
|
||
(setcdr (info-lookup->cache 'symbol)
|
||
(delete (info-lookup->mode-cache 'symbol mode)
|
||
(info-lookup->topic-cache 'symbol)))
|
||
|
||
(add-hook
|
||
'tramp-integration-unload-hook
|
||
`(lambda ()
|
||
(setcdr (info-lookup->mode-value 'symbol ',mode)
|
||
(append (butlast
|
||
(cdr (info-lookup->mode-value 'symbol ',mode)))
|
||
(list
|
||
(delq 'tramp-info-lookup-mode
|
||
(info-lookup->other-modes 'symbol ',mode)))))
|
||
(setcdr (info-lookup->cache 'symbol)
|
||
(delete (info-lookup->mode-cache 'symbol ',mode)
|
||
(info-lookup->topic-cache 'symbol))))))))
|
||
|
||
;;; Integration of compile.el:
|
||
|
||
;; Compilation processes use `accept-process-output' such a way that
|
||
;; Tramp's parallel `accept-process-output' blocks. See last part of
|
||
;; Bug#45518. So we don't use ssh ControlMaster options.
|
||
(defun tramp-compile-disable-ssh-controlmaster-options ()
|
||
"Don't allow ssh ControlMaster while compiling."
|
||
(setq-local tramp-use-ssh-controlmaster-options nil))
|
||
|
||
(with-eval-after-load 'compile
|
||
(add-hook 'compilation-mode-hook
|
||
#'tramp-compile-disable-ssh-controlmaster-options)
|
||
(add-hook 'tramp-integration-unload-hook
|
||
(lambda ()
|
||
(remove-hook 'compilation-start-hook
|
||
#'tramp-compile-disable-ssh-controlmaster-options))))
|
||
|
||
;;; Default connection-local variables for Tramp.
|
||
|
||
(defconst tramp-connection-local-default-system-variables
|
||
'((path-separator . ":")
|
||
(null-device . "/dev/null"))
|
||
"Default connection-local system variables for remote connections.")
|
||
|
||
(connection-local-set-profile-variables
|
||
'tramp-connection-local-default-system-profile
|
||
tramp-connection-local-default-system-variables)
|
||
|
||
(connection-local-set-profiles
|
||
'(:application tramp)
|
||
'tramp-connection-local-default-system-profile)
|
||
|
||
(defconst tramp-connection-local-default-shell-variables
|
||
'((shell-file-name . "/bin/sh")
|
||
(shell-command-switch . "-c"))
|
||
"Default connection-local shell variables for remote connections.")
|
||
|
||
(connection-local-set-profile-variables
|
||
'tramp-connection-local-default-shell-profile
|
||
tramp-connection-local-default-shell-variables)
|
||
|
||
(with-eval-after-load 'shell
|
||
(connection-local-set-profiles
|
||
'(:application tramp)
|
||
'tramp-connection-local-default-shell-profile))
|
||
|
||
(add-hook 'tramp-unload-hook
|
||
(lambda () (unload-feature 'tramp-integration 'force)))
|
||
|
||
(provide 'tramp-integration)
|
||
|
||
;;; tramp-integration.el ends here
|