]> git.eshelyaron.com Git - emacs.git/commitdiff
Adapt hooks in Tramp
authorMichael Albinus <michael.albinus@gmx.de>
Mon, 25 Feb 2019 10:59:52 +0000 (11:59 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Mon, 25 Feb 2019 10:59:52 +0000 (11:59 +0100)
* 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'.

lisp/net/tramp-archive.el
lisp/net/tramp-cmds.el
lisp/net/tramp-ftp.el
lisp/net/tramp-integration.el

index db9aec05c203c0562a0077252ec2f92263668b90..dcddb0ec67dfa23964810a288d2af5de1dd1463b 100644 (file)
@@ -369,13 +369,13 @@ pass to the OPERATION."
 (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.
@@ -467,7 +467,6 @@ name is kept in slot `hop'"
       (setf (tramp-file-name-localname vec) localname)
       vec)))
 
-;;;###tramp-autoload
 (defun tramp-archive-cleanup-hash ()
   "Remove local copies of archives, used by GVFS."
   (maphash
@@ -482,9 +481,12 @@ name is kept in slot `hop'"
    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)))
 
index 38e440e09300934ecf28acdcd278d8943181badf..cf4f74174755b893383601b55722c2e5a707a93d 100644 (file)
@@ -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)))
     (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.
@@ -99,9 +104,8 @@ When called interactively, a Tramp connection has to be selected."
     (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 "")
@@ -120,8 +124,8 @@ When called interactively, a Tramp connection has to be selected."
                   (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 ()
@@ -131,6 +135,10 @@ When called interactively, a Tramp connection has to be selected."
        (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.
@@ -146,10 +154,6 @@ This includes password cache, file cache, connection cache, buffers."
   ;; 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
@@ -167,9 +171,8 @@ This includes password cache, file cache, connection cache, buffers."
   (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 ()
index 4807fe0701c02856bbecefadad1405ca9dd0ab85..8735d13f9dd81486e89ee8cc15ed08cec9e247ed 100644 (file)
@@ -54,8 +54,7 @@ present for backward compatibility."
          (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 ()
index f3f95f1b69c79e2f27bfbe9630683ca778710cc0..e2a0d6b206fcce3e3d4af27aeb90e3225bcb1bef 100644 (file)
@@ -128,7 +128,7 @@ been set up by `rfn-eshadow-setup-minibuffer'."
               '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)
@@ -151,6 +151,25 @@ NAME must be equal to `tramp-current-connection'."
          (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)))