diff options
| author | Michael Albinus | 2017-05-16 15:55:06 +0200 |
|---|---|---|
| committer | Michael Albinus | 2017-05-16 15:55:06 +0200 |
| commit | 138c8256f41f242341c7d146c99f4e6fa267a638 (patch) | |
| tree | 32979ab3e1a88ee17d5b4b5c518be88e8bc6c9ff | |
| parent | 712a5faa2c95596db2d4d94dada575ad16b317c5 (diff) | |
| download | emacs-138c8256f41f242341c7d146c99f4e6fa267a638.tar.gz emacs-138c8256f41f242341c7d146c99f4e6fa267a638.zip | |
Make autoloading Tramp more robust
* lisp/net/tramp.el (tramp-file-name-for-operation):
Use `default-directory' where appropriate.
(tramp-file-name-handler): Do not autoload.
(tramp-autoload-file-name-handler): Reintroduce function.
(tramp-register-autoload-file-name-handlers): Use it.
| -rw-r--r-- | lisp/net/tramp.el | 99 |
1 files changed, 57 insertions, 42 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 99cb7d19b0b..5b1e478db04 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -1996,7 +1996,7 @@ ARGS are the arguments OPERATION has been called with." | |||
| 1996 | file-name-case-insensitive-p)) | 1996 | file-name-case-insensitive-p)) |
| 1997 | (if (file-name-absolute-p (nth 0 args)) | 1997 | (if (file-name-absolute-p (nth 0 args)) |
| 1998 | (nth 0 args) | 1998 | (nth 0 args) |
| 1999 | (expand-file-name (nth 0 args)))) | 1999 | default-directory)) |
| 2000 | ;; FILE DIRECTORY resp FILE1 FILE2. | 2000 | ;; FILE DIRECTORY resp FILE1 FILE2. |
| 2001 | ((member operation | 2001 | ((member operation |
| 2002 | '(add-name-to-file copy-directory copy-file expand-file-name | 2002 | '(add-name-to-file copy-directory copy-file expand-file-name |
| @@ -2008,10 +2008,12 @@ ARGS are the arguments OPERATION has been called with." | |||
| 2008 | (cond | 2008 | (cond |
| 2009 | ((tramp-tramp-file-p (nth 0 args)) (nth 0 args)) | 2009 | ((tramp-tramp-file-p (nth 0 args)) (nth 0 args)) |
| 2010 | ((tramp-tramp-file-p (nth 1 args)) (nth 1 args)) | 2010 | ((tramp-tramp-file-p (nth 1 args)) (nth 1 args)) |
| 2011 | (t (buffer-file-name (current-buffer)))))) | 2011 | (t default-directory)))) |
| 2012 | ;; START END FILE. | 2012 | ;; START END FILE. |
| 2013 | ((eq operation 'write-region) | 2013 | ((eq operation 'write-region) |
| 2014 | (nth 2 args)) | 2014 | (if (file-name-absolute-p (nth 2 args)) |
| 2015 | (nth 2 args) | ||
| 2016 | default-directory)) | ||
| 2015 | ;; BUFFER. | 2017 | ;; BUFFER. |
| 2016 | ((member operation | 2018 | ((member operation |
| 2017 | '(make-auto-save-file-name | 2019 | '(make-auto-save-file-name |
| @@ -2058,13 +2060,6 @@ ARGS are the arguments OPERATION has been called with." | |||
| 2058 | `(let ((debug-on-error tramp-debug-on-error)) | 2060 | `(let ((debug-on-error tramp-debug-on-error)) |
| 2059 | (tramp-compat-condition-case-unless-debug ,var ,bodyform ,@handlers))) | 2061 | (tramp-compat-condition-case-unless-debug ,var ,bodyform ,@handlers))) |
| 2060 | 2062 | ||
| 2061 | ;; This is to avoid recursive load. | ||
| 2062 | ;;;###autoload(defun tramp-file-name-handler (operation &rest args) | ||
| 2063 | ;;;###autoload "Load Tramp file name handler, and perform OPERATION." | ||
| 2064 | ;;;###autoload (let ((default-directory temporary-file-directory)) | ||
| 2065 | ;;;###autoload (load "tramp" nil t)) | ||
| 2066 | ;;;###autoload (apply operation args)) | ||
| 2067 | |||
| 2068 | ;; Main function. | 2063 | ;; Main function. |
| 2069 | (defun tramp-file-name-handler (operation &rest args) | 2064 | (defun tramp-file-name-handler (operation &rest args) |
| 2070 | "Invoke Tramp file name handler. | 2065 | "Invoke Tramp file name handler. |
| @@ -2193,15 +2188,23 @@ Falls back to normal file name handler if no Tramp file name handler exists." | |||
| 2193 | (save-match-data (apply (cdr fn) args)) | 2188 | (save-match-data (apply (cdr fn) args)) |
| 2194 | (tramp-run-real-handler operation args)))) | 2189 | (tramp-run-real-handler operation args)))) |
| 2195 | 2190 | ||
| 2196 | ;; `tramp-file-name-handler' must be registered before evaluation of | 2191 | ;;;###autoload |
| 2197 | ;; site-start and init files, because there might exist remote files | 2192 | (progn (defun tramp-autoload-file-name-handler (operation &rest args) |
| 2198 | ;; already, f.e. files kept via recentf-mode. | 2193 | "Load Tramp file name handler, and perform OPERATION." |
| 2194 | (let ((default-directory temporary-file-directory)) | ||
| 2195 | (load "tramp" 'noerror 'nomessage)) | ||
| 2196 | (apply operation args))) | ||
| 2197 | |||
| 2198 | ;; `tramp-autoload-file-name-handler' must be registered before | ||
| 2199 | ;; evaluation of site-start and init files, because there might exist | ||
| 2200 | ;; remote files already, f.e. files kept via recentf-mode. | ||
| 2199 | ;;;###autoload | 2201 | ;;;###autoload |
| 2200 | (progn (defun tramp-register-autoload-file-name-handlers () | 2202 | (progn (defun tramp-register-autoload-file-name-handlers () |
| 2201 | "Add Tramp file name handlers to `file-name-handler-alist' during autoload." | 2203 | "Add Tramp file name handlers to `file-name-handler-alist' during autoload." |
| 2202 | (add-to-list 'file-name-handler-alist | 2204 | (add-to-list 'file-name-handler-alist |
| 2203 | (cons tramp-initial-file-name-regexp 'tramp-file-name-handler)) | 2205 | (cons tramp-initial-file-name-regexp |
| 2204 | (put 'tramp-file-name-handler 'safe-magic t) | 2206 | 'tramp-autoload-file-name-handler)) |
| 2207 | (put 'tramp-autoload-file-name-handler 'safe-magic t) | ||
| 2205 | 2208 | ||
| 2206 | (add-to-list 'file-name-handler-alist | 2209 | (add-to-list 'file-name-handler-alist |
| 2207 | (cons tramp-initial-completion-file-name-regexp | 2210 | (cons tramp-initial-completion-file-name-regexp |
| @@ -2220,7 +2223,6 @@ Falls back to normal file name handler if no Tramp file name handler exists." | |||
| 2220 | ;; if `tramp-syntax' has been changed. | 2223 | ;; if `tramp-syntax' has been changed. |
| 2221 | (dolist (fnh '(tramp-file-name-handler | 2224 | (dolist (fnh '(tramp-file-name-handler |
| 2222 | tramp-completion-file-name-handler | 2225 | tramp-completion-file-name-handler |
| 2223 | ;; This is autoloaded in Emacs 24 & 25. | ||
| 2224 | tramp-autoload-file-name-handler)) | 2226 | tramp-autoload-file-name-handler)) |
| 2225 | (let ((a1 (rassq fnh file-name-handler-alist))) | 2227 | (let ((a1 (rassq fnh file-name-handler-alist))) |
| 2226 | (setq file-name-handler-alist (delq a1 file-name-handler-alist)))) | 2228 | (setq file-name-handler-alist (delq a1 file-name-handler-alist)))) |
| @@ -2438,42 +2440,55 @@ They are collected by `tramp-completion-dissect-file-name1'." | |||
| 2438 | (tramp-postfix-ipv6-format)))) | 2440 | (tramp-postfix-ipv6-format)))) |
| 2439 | ;; "/method" "/[method" | 2441 | ;; "/method" "/[method" |
| 2440 | (tramp-completion-file-name-structure1 | 2442 | (tramp-completion-file-name-structure1 |
| 2441 | (list (concat (tramp-prefix-regexp) "\\(" (tramp-method-regexp) x-nil "\\)$") | 2443 | (list |
| 2442 | 1 nil nil nil)) | 2444 | (concat |
| 2445 | (tramp-prefix-regexp) | ||
| 2446 | "\\(" (tramp-method-regexp) x-nil "\\)$") | ||
| 2447 | 1 nil nil nil)) | ||
| 2443 | ;; "/method:user" "/[method/user" | 2448 | ;; "/method:user" "/[method/user" |
| 2444 | (tramp-completion-file-name-structure2 | 2449 | (tramp-completion-file-name-structure2 |
| 2445 | (list (concat (tramp-prefix-regexp) | 2450 | (list |
| 2446 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) | 2451 | (concat |
| 2447 | "\\(" tramp-user-regexp x-nil "\\)$") | 2452 | (tramp-prefix-regexp) |
| 2448 | 1 2 nil nil)) | 2453 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) |
| 2454 | "\\(" tramp-user-regexp x-nil "\\)$") | ||
| 2455 | 1 2 nil nil)) | ||
| 2449 | ;; "/method:host" "/[method/host" | 2456 | ;; "/method:host" "/[method/host" |
| 2450 | (tramp-completion-file-name-structure3 | 2457 | (tramp-completion-file-name-structure3 |
| 2451 | (list (concat (tramp-prefix-regexp) | 2458 | (list |
| 2452 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) | 2459 | (concat |
| 2453 | "\\(" tramp-host-regexp x-nil "\\)$") | 2460 | (tramp-prefix-regexp) |
| 2454 | 1 nil 2 nil)) | 2461 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) |
| 2462 | "\\(" tramp-host-regexp x-nil "\\)$") | ||
| 2463 | 1 nil 2 nil)) | ||
| 2455 | ;; "/method:[ipv6" "/[method/ipv6" | 2464 | ;; "/method:[ipv6" "/[method/ipv6" |
| 2456 | (tramp-completion-file-name-structure4 | 2465 | (tramp-completion-file-name-structure4 |
| 2457 | (list (concat (tramp-prefix-regexp) | 2466 | (list |
| 2458 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) | 2467 | (concat |
| 2459 | (tramp-prefix-ipv6-regexp) | 2468 | (tramp-prefix-regexp) |
| 2460 | "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") | 2469 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) |
| 2461 | 1 nil 2 nil)) | 2470 | (tramp-prefix-ipv6-regexp) |
| 2471 | "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") | ||
| 2472 | 1 nil 2 nil)) | ||
| 2462 | ;; "/method:user@host" "/[method/user@host" | 2473 | ;; "/method:user@host" "/[method/user@host" |
| 2463 | (tramp-completion-file-name-structure5 | 2474 | (tramp-completion-file-name-structure5 |
| 2464 | (list (concat (tramp-prefix-regexp) | 2475 | (list |
| 2465 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) | 2476 | (concat |
| 2466 | "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp | 2477 | (tramp-prefix-regexp) |
| 2467 | "\\(" tramp-host-regexp x-nil "\\)$") | 2478 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) |
| 2468 | 1 2 3 nil)) | 2479 | "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp |
| 2480 | "\\(" tramp-host-regexp x-nil "\\)$") | ||
| 2481 | 1 2 3 nil)) | ||
| 2469 | ;; "/method:user@[ipv6" "/[method/user@ipv6" | 2482 | ;; "/method:user@[ipv6" "/[method/user@ipv6" |
| 2470 | (tramp-completion-file-name-structure6 | 2483 | (tramp-completion-file-name-structure6 |
| 2471 | (list (concat (tramp-prefix-regexp) | 2484 | (list |
| 2472 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) | 2485 | (concat |
| 2473 | "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp | 2486 | (tramp-prefix-regexp) |
| 2474 | (tramp-prefix-ipv6-regexp) | 2487 | "\\(" (tramp-method-regexp) "\\)" (tramp-postfix-method-regexp) |
| 2475 | "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") | 2488 | "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp |
| 2476 | 1 2 3 nil))) | 2489 | (tramp-prefix-ipv6-regexp) |
| 2490 | "\\(" tramp-completion-ipv6-regexp x-nil "\\)$") | ||
| 2491 | 1 2 3 nil))) | ||
| 2477 | (delq | 2492 | (delq |
| 2478 | nil | 2493 | nil |
| 2479 | (mapcar | 2494 | (mapcar |