Commit cedc3410 authored by Michael Albinus's avatar Michael Albinus

Adapt hooks in Tramp

* lisp/net/tramp-archive.el (tramp-archive-cleanup-hash):
Remove autoload cookie.
(tramp-cleanup-all-connections-hook): Add `tramp-archive-cleanup-hash'.

* lisp/net/tramp-cmds.el (tramp-cleanup-connection-hook)
(tramp-cleanup-all-connections-hook): New hook variables.
(tramp-cleanup-connection): Set `tramp-current-connection' always
to nil.
(tramp-cleanup-connection): Do not call `tramp-recentf-cleanup'.
Run ´tramp-cleanup-connection-hook`.
(tramp-cleanup-all-connections): Do not call
`tramp-archive-cleanup-hash' and ´tramp-recentf-cleanup'.  Run
`tramp-cleanup-all-connections-hook'.

* lisp/net/tramp-ftp.el (top): Simply call `tramp-disable-ange-ftp'.

* lisp/net/tramp-integration.el (tramp-recentf-cleanup-all): New defun.
(top): Adapt `tramp-integration-unload-hook',
`tramp-cleanup-connection-hook' and
`tramp-cleanup-all-connections-hook'.
parent 6a3b1aaa
Pipeline #855 passed with stage
in 50 minutes and 32 seconds
...@@ -369,13 +369,13 @@ pass to the OPERATION." ...@@ -369,13 +369,13 @@ pass to the OPERATION."
(when url-handler-mode (tramp-register-file-name-handlers)) (when url-handler-mode (tramp-register-file-name-handlers))
(eval-after-load 'url-handler (eval-after-load 'url-handler
(progn '(progn
(add-hook 'url-handler-mode-hook 'tramp-register-file-name-handlers) (add-hook 'url-handler-mode-hook 'tramp-register-file-name-handlers)
(add-hook (add-hook
'tramp-archive-unload-hook 'tramp-archive-unload-hook
(lambda () (lambda ()
(remove-hook (remove-hook
'url-handler-mode-hook 'tramp-register-file-name-handlers))))) 'url-handler-mode-hook 'tramp-register-file-name-handlers)))))
;; File name conversions. ;; File name conversions.
...@@ -467,7 +467,6 @@ name is kept in slot `hop'" ...@@ -467,7 +467,6 @@ name is kept in slot `hop'"
(setf (tramp-file-name-localname vec) localname) (setf (tramp-file-name-localname vec) localname)
vec))) vec)))
;;;###tramp-autoload
(defun tramp-archive-cleanup-hash () (defun tramp-archive-cleanup-hash ()
"Remove local copies of archives, used by GVFS." "Remove local copies of archives, used by GVFS."
(maphash (maphash
...@@ -482,9 +481,12 @@ name is kept in slot `hop'" ...@@ -482,9 +481,12 @@ name is kept in slot `hop'"
tramp-archive-hash) tramp-archive-hash)
(clrhash tramp-archive-hash)) (clrhash tramp-archive-hash))
(add-hook 'tramp-cleanup-all-connections-hook 'tramp-archive-cleanup-hash)
(add-hook 'kill-emacs-hook 'tramp-archive-cleanup-hash) (add-hook 'kill-emacs-hook 'tramp-archive-cleanup-hash)
(add-hook 'tramp-archive-unload-hook (add-hook 'tramp-archive-unload-hook
(lambda () (lambda ()
(remove-hook 'tramp-cleanup-all-connections-hook
'tramp-archive-cleanup-hash)
(remove-hook 'kill-emacs-hook (remove-hook 'kill-emacs-hook
'tramp-archive-cleanup-hash))) 'tramp-archive-cleanup-hash)))
......
...@@ -68,6 +68,11 @@ SYNTAX can be one of the symbols `default' (default), ...@@ -68,6 +68,11 @@ SYNTAX can be one of the symbols `default' (default),
(with-current-buffer x (when (tramp-tramp-file-p default-directory) x))) (with-current-buffer x (when (tramp-tramp-file-p default-directory) x)))
(buffer-list)))) (buffer-list))))
;;;###tramp-autoload
(defvar tramp-cleanup-connection-hook nil
"List of functions to be called after Tramp connection is cleaned up.
Each function is called with the current vector as argument.")
;;;###tramp-autoload ;;;###tramp-autoload
(defun tramp-cleanup-connection (vec &optional keep-debug keep-password) (defun tramp-cleanup-connection (vec &optional keep-debug keep-password)
"Flush all connection related objects. "Flush all connection related objects.
...@@ -99,9 +104,8 @@ When called interactively, a Tramp connection has to be selected." ...@@ -99,9 +104,8 @@ When called interactively, a Tramp connection has to be selected."
(unless keep-password (tramp-clear-passwd vec)) (unless keep-password (tramp-clear-passwd vec))
;; Cleanup `tramp-current-connection'. Otherwise, we would be ;; Cleanup `tramp-current-connection'. Otherwise, we would be
;; suppressed in the test suite. We use `keep-password' as ;; suppressed.
;; indicator; it is not worth to add a new argument. (setq tramp-current-connection nil)
(when keep-password (setq tramp-current-connection nil))
;; Flush file cache. ;; Flush file cache.
(tramp-flush-directory-properties vec "") (tramp-flush-directory-properties vec "")
...@@ -120,8 +124,8 @@ When called interactively, a Tramp connection has to be selected." ...@@ -120,8 +124,8 @@ When called interactively, a Tramp connection has to be selected."
(tramp-get-connection-property vec "process-buffer" nil))) (tramp-get-connection-property vec "process-buffer" nil)))
(when (bufferp buf) (kill-buffer buf))) (when (bufferp buf) (kill-buffer buf)))
;; Remove recentf files. ;; The end.
(tramp-recentf-cleanup vec))) (run-hook-with-args 'tramp-cleanup-connection-hook vec)))
;;;###tramp-autoload ;;;###tramp-autoload
(defun tramp-cleanup-this-connection () (defun tramp-cleanup-this-connection ()
...@@ -131,6 +135,10 @@ When called interactively, a Tramp connection has to be selected." ...@@ -131,6 +135,10 @@ When called interactively, a Tramp connection has to be selected."
(tramp-cleanup-connection (tramp-cleanup-connection
(tramp-dissect-file-name default-directory 'noexpand)))) (tramp-dissect-file-name default-directory 'noexpand))))
;;;###tramp-autoload
(defvar tramp-cleanup-all-connections-hook nil
"List of functions to be called after all Tramp connections are cleaned up.")
;;;###tramp-autoload ;;;###tramp-autoload
(defun tramp-cleanup-all-connections () (defun tramp-cleanup-all-connections ()
"Flush all Tramp internal objects. "Flush all Tramp internal objects.
...@@ -146,10 +154,6 @@ This includes password cache, file cache, connection cache, buffers." ...@@ -146,10 +154,6 @@ This includes password cache, file cache, connection cache, buffers."
;; Flush file and connection cache. ;; Flush file and connection cache.
(clrhash tramp-cache-data) (clrhash tramp-cache-data)
;; Cleanup local copies of archives.
(when (bound-and-true-p tramp-archive-enabled)
(tramp-archive-cleanup-hash))
;; Remove ad-hoc proxies. ;; Remove ad-hoc proxies.
(let ((proxies tramp-default-proxies-alist)) (let ((proxies tramp-default-proxies-alist))
(while proxies (while proxies
...@@ -167,9 +171,8 @@ This includes password cache, file cache, connection cache, buffers." ...@@ -167,9 +171,8 @@ This includes password cache, file cache, connection cache, buffers."
(dolist (name (tramp-list-tramp-buffers)) (dolist (name (tramp-list-tramp-buffers))
(when (bufferp (get-buffer name)) (kill-buffer name))) (when (bufferp (get-buffer name)) (kill-buffer name)))
;; Remove recentf files. ;; The end.
(dolist (v (tramp-list-connections)) (run-hooks 'tramp-cleanup-all-connections-hook))
(tramp-recentf-cleanup v)))
;;;###tramp-autoload ;;;###tramp-autoload
(defun tramp-cleanup-all-buffers () (defun tramp-cleanup-all-buffers ()
......
...@@ -54,8 +54,7 @@ present for backward compatibility." ...@@ -54,8 +54,7 @@ present for backward compatibility."
(delete a1 (delete a2 file-name-handler-alist))))) (delete a1 (delete a2 file-name-handler-alist)))))
(eval-after-load "ange-ftp" (eval-after-load "ange-ftp"
'(when (functionp 'tramp-disable-ange-ftp) '(tramp-disable-ange-ftp))
(tramp-disable-ange-ftp)))
;;;###tramp-autoload ;;;###tramp-autoload
(defun tramp-ftp-enable-ange-ftp () (defun tramp-ftp-enable-ange-ftp ()
......
...@@ -128,7 +128,7 @@ been set up by `rfn-eshadow-setup-minibuffer'." ...@@ -128,7 +128,7 @@ been set up by `rfn-eshadow-setup-minibuffer'."
'tramp-eshell-directory-change) 'tramp-eshell-directory-change)
(add-hook 'eshell-directory-change-hook (add-hook 'eshell-directory-change-hook
'tramp-eshell-directory-change) 'tramp-eshell-directory-change)
(add-hook 'tramp-unload-hook (add-hook 'tramp-integration-unload-hook
(lambda () (lambda ()
(remove-hook 'eshell-mode-hook (remove-hook 'eshell-mode-hook
'tramp-eshell-directory-change) 'tramp-eshell-directory-change)
...@@ -151,6 +151,25 @@ NAME must be equal to `tramp-current-connection'." ...@@ -151,6 +151,25 @@ NAME must be equal to `tramp-current-connection'."
(recentf-exclude '(tramp-recentf-exclude-predicate))) (recentf-exclude '(tramp-recentf-exclude-predicate)))
(recentf-cleanup)))) (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))))
(eval-after-load "recentf"
'(progn
(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)))))
(add-hook 'tramp-unload-hook (add-hook 'tramp-unload-hook
(lambda () (unload-feature 'tramp-integration 'force))) (lambda () (unload-feature 'tramp-integration 'force)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment