(when url-handler-mode (tramp-register-file-name-handlers))
(eval-after-load 'url-handler
- (progn
- (add-hook 'url-handler-mode-hook 'tramp-register-file-name-handlers)
- (add-hook
- 'tramp-archive-unload-hook
- (lambda ()
- (remove-hook
- 'url-handler-mode-hook 'tramp-register-file-name-handlers)))))
+ '(progn
+ (add-hook 'url-handler-mode-hook 'tramp-register-file-name-handlers)
+ (add-hook
+ 'tramp-archive-unload-hook
+ (lambda ()
+ (remove-hook
+ 'url-handler-mode-hook 'tramp-register-file-name-handlers)))))
\f
;; File name conversions.
(setf (tramp-file-name-localname vec) localname)
vec)))
-;;;###tramp-autoload
(defun tramp-archive-cleanup-hash ()
"Remove local copies of archives, used by GVFS."
(maphash
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 'tramp-archive-unload-hook
(lambda ()
+ (remove-hook 'tramp-cleanup-all-connections-hook
+ 'tramp-archive-cleanup-hash)
(remove-hook 'kill-emacs-hook
'tramp-archive-cleanup-hash)))
(with-current-buffer x (when (tramp-tramp-file-p default-directory) x)))
(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
(defun tramp-cleanup-connection (vec &optional keep-debug keep-password)
"Flush all connection related objects.
(unless keep-password (tramp-clear-passwd vec))
;; Cleanup `tramp-current-connection'. Otherwise, we would be
- ;; suppressed in the test suite. We use `keep-password' as
- ;; indicator; it is not worth to add a new argument.
- (when keep-password (setq tramp-current-connection nil))
+ ;; suppressed.
+ (setq tramp-current-connection nil)
;; Flush file cache.
(tramp-flush-directory-properties vec "")
(tramp-get-connection-property vec "process-buffer" nil)))
(when (bufferp buf) (kill-buffer buf)))
- ;; Remove recentf files.
- (tramp-recentf-cleanup vec)))
+ ;; The end.
+ (run-hook-with-args 'tramp-cleanup-connection-hook vec)))
;;;###tramp-autoload
(defun tramp-cleanup-this-connection ()
(tramp-cleanup-connection
(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
(defun tramp-cleanup-all-connections ()
"Flush all Tramp internal objects.
;; Flush file and connection cache.
(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.
(let ((proxies tramp-default-proxies-alist))
(while proxies
(dolist (name (tramp-list-tramp-buffers))
(when (bufferp (get-buffer name)) (kill-buffer name)))
- ;; Remove recentf files.
- (dolist (v (tramp-list-connections))
- (tramp-recentf-cleanup v)))
+ ;; The end.
+ (run-hooks 'tramp-cleanup-all-connections-hook))
;;;###tramp-autoload
(defun tramp-cleanup-all-buffers ()
(delete a1 (delete a2 file-name-handler-alist)))))
(eval-after-load "ange-ftp"
- '(when (functionp 'tramp-disable-ange-ftp)
- (tramp-disable-ange-ftp)))
+ '(tramp-disable-ange-ftp))
;;;###tramp-autoload
(defun tramp-ftp-enable-ange-ftp ()
'tramp-eshell-directory-change)
(add-hook 'eshell-directory-change-hook
'tramp-eshell-directory-change)
- (add-hook 'tramp-unload-hook
+ (add-hook 'tramp-integration-unload-hook
(lambda ()
(remove-hook 'eshell-mode-hook
'tramp-eshell-directory-change)
(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))))
+
+(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
(lambda () (unload-feature 'tramp-integration 'force)))