emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 8884baf: Fix Bug#26258


From: Michael Albinus
Subject: [Emacs-diffs] master 8884baf: Fix Bug#26258
Date: Sun, 26 Mar 2017 11:37:18 -0400 (EDT)

branch: master
commit 8884baf3c8919abd67071296ed4784739bf94c00
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    Fix Bug#26258
    
    * lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
    * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
    * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
    * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
    Autoload.  Call `tramp-register-foreign-file-name-handler'.  (Bug#26258)
    
    * lisp/net/tramp.el (tramp-autoload-file-name-handler): Remove.
    (tramp-register-autoload-file-name-handlers)
    (tramp-register-file-name-handlers): Do not handle
    `tramp-autoload-file-name-handler' anymore.  Mark `operations'
    the handlers are responsible for.
    (tramp-register-foreign-file-name-handler): New defun.
---
 lisp/net/tramp-adb.el  |  7 ++---
 lisp/net/tramp-gvfs.el |  7 +++--
 lisp/net/tramp-sh.el   | 11 ++++----
 lisp/net/tramp-smb.el  |  6 ++---
 lisp/net/tramp.el      | 72 ++++++++++++++++++++++++++++----------------------
 5 files changed, 57 insertions(+), 46 deletions(-)

diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 4191c3e..240e017 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -94,9 +94,6 @@ It is used for TCP/IP devices."
     tramp-adb-method '((tramp-adb-parse-device-names ""))))
 
 ;;;###tramp-autoload
-(add-to-list 'tramp-foreign-file-name-handler-alist
-            (cons 'tramp-adb-file-name-p 'tramp-adb-file-name-handler))
-
 (defconst tramp-adb-file-name-handler-alist
   '((access-file . ignore)
     (add-name-to-file . tramp-adb-handle-copy-file)
@@ -190,6 +187,10 @@ pass to the OPERATION."
       (tramp-run-real-handler operation args))))
 
 ;;;###tramp-autoload
+(tramp-register-foreign-file-name-handler
+ 'tramp-adb-file-name-p 'tramp-adb-file-name-handler)
+
+;;;###tramp-autoload
 (defun tramp-adb-parse-device-names (_ignore)
   "Return a list of (nil host) tuples allowed to access."
   (with-timeout (10)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 561f6c8..59d8771 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -452,6 +452,7 @@ Every entry is a list (NAME ADDRESS).")
 
 
 ;; New handlers should be added here.
+;;;###tramp-autoload
 (defconst tramp-gvfs-file-name-handler-alist
   '((access-file . ignore)
     (add-name-to-file . tramp-gvfs-handle-copy-file)
@@ -548,12 +549,10 @@ pass to the OPERATION."
        (save-match-data (apply (cdr fn) args))
       (tramp-run-real-handler operation args))))
 
-;; This might be moved to tramp.el.  It shall be the first file name
-;; handler.
 ;;;###tramp-autoload
 (when (featurep 'dbusbind)
-  (add-to-list 'tramp-foreign-file-name-handler-alist
-              (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
+  (tramp-register-foreign-file-name-handler
+   'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler))
 
 
 ;; D-Bus helper function.
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 486e002..e0f8d71 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -981,6 +981,7 @@ here-document, otherwise the command could exceed maximum 
length
 of command line.")
 
 ;; New handlers should be added here.
+;;;###tramp-autoload
 (defconst tramp-sh-file-name-handler-alist
   '(;; `access-file' performed by default handler.
     (add-name-to-file . tramp-sh-handle-add-name-to-file)
@@ -1054,11 +1055,6 @@ of command line.")
   "Alist of handler functions.
 Operations not mentioned here will be handled by the normal Emacs functions.")
 
-;; This must be the last entry, because `identity' always matches.
-;;;###tramp-autoload
-(add-to-list 'tramp-foreign-file-name-handler-alist
-            '(identity . tramp-sh-file-name-handler) 'append)
-
 ;;; File Name Handler Functions:
 
 (defun tramp-sh-handle-make-symbolic-link
@@ -3536,6 +3532,11 @@ Fall back to normal file name handler if no Tramp 
handler exists."
                (tramp-run-real-handler operation args)))))
       (setq tramp-locked tl))))
 
+;; This must be the last entry, because `identity' always matches.
+;;;###tramp-autoload
+(tramp-register-foreign-file-name-handler
+ 'identity 'tramp-sh-file-name-handler 'append)
+
 (defun tramp-vc-file-name-handler (operation &rest args)
   "Invoke special file name handler, which collects files to be handled."
   (save-match-data
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index eaa8ac6..b91a726 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -217,6 +217,7 @@ This list is used for smbcacls actions.
 See `tramp-actions-before-shell' for more info.")
 
 ;; New handlers should be added here.
+;;;###tramp-autoload
 (defconst tramp-smb-file-name-handler-alist
   '(;; `access-file' performed by default handler.
     (add-name-to-file . tramp-smb-handle-add-name-to-file)
@@ -340,9 +341,8 @@ pass to the OPERATION."
 
 ;;;###tramp-autoload
 (unless (memq system-type '(cygwin windows-nt))
-  (add-to-list 'tramp-foreign-file-name-handler-alist
-              (cons 'tramp-smb-file-name-p 'tramp-smb-file-name-handler)))
-
+  (tramp-register-foreign-file-name-handler
+   'tramp-smb-file-name-p 'tramp-smb-file-name-handler))
 
 ;; File name primitives.
 
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index a7c36c0..41406d8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2121,41 +2121,26 @@ Falls back to normal file name handler if no Tramp file 
name handler exists."
        (save-match-data (apply (cdr fn) args))
       (tramp-run-real-handler operation args))))
 
-;; Mark `operations' the handler is responsible for.
-;;;###autoload
-(put 'tramp-completion-file-name-handler 'operations
-     (mapcar 'car tramp-completion-file-name-handler-alist))
-
-;;;###autoload
-(progn (defun tramp-autoload-file-name-handler (operation &rest args)
-  "Load Tramp file name handler, and perform OPERATION."
-  (if (and
-       ;; Do not load tramp.el just for "/".
-       (not (and (stringp (car args)) (string-equal (car args) "/")))
-       ;; Avoid recursive loading of tramp.el.
-       (let ((default-directory temporary-file-directory))
-        (and (null load-in-progress) (load "tramp" 'noerror 'nomessage))))
-      (apply operation args)
-    ;; tramp.el not needed or not available for loading, fall back.
-    (tramp-run-real-handler operation args))))
-
-;; `tramp-autoload-file-name-handler' must be registered before
-;; evaluation of site-start and init files, because there might exist
-;; remote files already, f.e. files kept via recentf-mode.  We cannot
-;; autoload `tramp-file-name-handler', because it would result in
-;; recursive loading of tramp.el when `default-directory' is set to
-;; remote.
+;; `tramp-file-name-handler' must be registered before evaluation of
+;; site-start and init files, because there might exist remote files
+;; already, f.e. files kept via recentf-mode.
 ;;;###autoload
 (progn (defun tramp-register-autoload-file-name-handlers ()
   "Add Tramp file name handlers to `file-name-handler-alist' during autoload."
   (add-to-list 'file-name-handler-alist
-              (cons tramp-file-name-regexp
-                    'tramp-autoload-file-name-handler))
-  (put 'tramp-autoload-file-name-handler 'safe-magic t)
+              (cons tramp-file-name-regexp 'tramp-file-name-handler))
+  (put 'tramp-file-name-handler 'safe-magic t)
+  ;; Mark `operations' the handler is responsible for.  It's a short list ...
+  (put 'tramp-file-name-handler 'operations
+       '(file-name-all-completions file-name-completion file-remote-p))
+
   (add-to-list 'file-name-handler-alist
               (cons tramp-completion-file-name-regexp
                     'tramp-completion-file-name-handler))
-  (put 'tramp-completion-file-name-handler 'safe-magic t)))
+  (put 'tramp-completion-file-name-handler 'safe-magic t)
+  ;; Mark `operations' the handler is responsible for.
+  (put 'tramp-completion-file-name-handler 'operations
+       (mapcar 'car tramp-completion-file-name-handler-alist))))
 
 ;;;###autoload
 (tramp-register-autoload-file-name-handlers)
@@ -2165,22 +2150,29 @@ Falls back to normal file name handler if no Tramp file 
name handler exists."
   ;; Remove autoloaded handlers from file name handler alist.  Useful,
   ;; if `tramp-syntax' has been changed.
   (dolist (fnh '(tramp-file-name-handler
-                tramp-completion-file-name-handler
-                tramp-autoload-file-name-handler))
+                tramp-completion-file-name-handler))
     (let ((a1 (rassq fnh file-name-handler-alist)))
       (setq file-name-handler-alist (delq a1 file-name-handler-alist))))
+
   ;; The initial value of `tramp-file-name-regexp' is too simple
   ;; minded, but we cannot give it the real value in the autoload
   ;; pattern.  See Bug#24889.
   (setq tramp-file-name-regexp (car tramp-file-name-structure))
-  ;; Add the handlers.
+  ;; Add the handlers.  We do not add anything to the `operations'
+  ;; property of `tramp-file-name-handler', this shall be done by the
+  ;; respective foreign handlers.
   (add-to-list 'file-name-handler-alist
               (cons tramp-file-name-regexp 'tramp-file-name-handler))
   (put 'tramp-file-name-handler 'safe-magic t)
+
   (add-to-list 'file-name-handler-alist
               (cons tramp-completion-file-name-regexp
                     'tramp-completion-file-name-handler))
   (put 'tramp-completion-file-name-handler 'safe-magic t)
+  ;; Mark `operations' the handler is responsible for.
+  (put 'tramp-completion-file-name-handler 'operations
+       (mapcar 'car tramp-completion-file-name-handler-alist))
+
   ;; If jka-compr or epa-file are already loaded, move them to the
   ;; front of `file-name-handler-alist'.
   (dolist (fnh '(epa-file-handler jka-compr-handler))
@@ -2191,6 +2183,24 @@ Falls back to normal file name handler if no Tramp file 
name handler exists."
 
 (eval-after-load 'tramp (tramp-register-file-name-handlers))
 
+;;;###tramp-autoload
+(progn (defun tramp-register-foreign-file-name-handler
+    (func handler &optional append)
+  "Register (FUNC . HANDLER) in `tramp-foreign-file-name-handler-alist'.
+FUNC is the function, which determines whether HANDLER is to be called.
+Add operations defined in `HANDLER-alist' to `tramp-file-name-handler'."
+  (add-to-list
+   'tramp-foreign-file-name-handler-alist `(,func . ,handler) append)
+  ;; Mark `operations' the handler is responsible for.
+  (put 'tramp-file-name-handler
+       'operations
+       (cl-delete-duplicates
+        (append
+         (get 'tramp-file-name-handler 'operations)
+         (mapcar
+          'car
+          (symbol-value (intern (concat (symbol-name handler) "-alist")))))))))
+
 (defun tramp-exists-file-name-handler (operation &rest args)
   "Check, whether OPERATION runs a file name handler."
   ;; The file name handler is determined on base of either an



reply via email to

[Prev in Thread] Current Thread [Next in Thread]