diff options
| author | Michael Albinus | 2017-11-05 20:08:05 +0100 |
|---|---|---|
| committer | Michael Albinus | 2017-11-05 20:08:05 +0100 |
| commit | ca2d94ba61dee678f85bfc7299d167e7219e6d8f (patch) | |
| tree | 10dd2860d7fc05945d738c8a2b26eaaa96caca7b | |
| parent | 709478eaa866e10a4600f8d8829ab8c79200d45e (diff) | |
| download | emacs-ca2d94ba61dee678f85bfc7299d167e7219e6d8f.tar.gz emacs-ca2d94ba61dee678f85bfc7299d167e7219e6d8f.zip | |
Do not load Tramp unless `tramp-mode' is non-nil
* lisp/net/tramp.el (tramp-autoload-file-name-handler): Load Tramp only if
`tramp-mode' is non-nil.
(tramp-unload-file-name-handlers): Unload also
`tramp-autoload-file-name-handler'.
* test/lisp/net/tramp-tests.el (tramp-test42-delay-load): Extend test.
| -rw-r--r-- | lisp/net/tramp.el | 13 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 30 |
2 files changed, 25 insertions, 18 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 67192e32401..3d5dcbdbb14 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -2305,8 +2305,10 @@ Falls back to normal file name handler if no Tramp file name handler exists." | |||
| 2305 | ;;;###autoload | 2305 | ;;;###autoload |
| 2306 | (progn (defun tramp-autoload-file-name-handler (operation &rest args) | 2306 | (progn (defun tramp-autoload-file-name-handler (operation &rest args) |
| 2307 | "Load Tramp file name handler, and perform OPERATION." | 2307 | "Load Tramp file name handler, and perform OPERATION." |
| 2308 | (let ((default-directory temporary-file-directory)) | 2308 | (if tramp-mode |
| 2309 | (load "tramp" 'noerror 'nomessage)) | 2309 | (let ((default-directory temporary-file-directory)) |
| 2310 | (load "tramp" 'noerror 'nomessage)) | ||
| 2311 | (tramp-unload-file-name-handlers)) | ||
| 2310 | (apply operation args))) | 2312 | (apply operation args))) |
| 2311 | 2313 | ||
| 2312 | ;; `tramp-autoload-file-name-handler' must be registered before | 2314 | ;; `tramp-autoload-file-name-handler' must be registered before |
| @@ -2422,12 +2424,13 @@ Add operations defined in `HANDLER-alist' to `tramp-file-name-handler'." | |||
| 2422 | (equal (apply operation args) operation)))) | 2424 | (equal (apply operation args) operation)))) |
| 2423 | 2425 | ||
| 2424 | ;;;###autoload | 2426 | ;;;###autoload |
| 2425 | (defun tramp-unload-file-name-handlers () | 2427 | (progn (defun tramp-unload-file-name-handlers () |
| 2426 | "Unload Tramp file name handlers from `file-name-handler-alist'." | 2428 | "Unload Tramp file name handlers from `file-name-handler-alist'." |
| 2427 | (dolist (fnh '(tramp-file-name-handler | 2429 | (dolist (fnh '(tramp-file-name-handler |
| 2428 | tramp-completion-file-name-handler)) | 2430 | tramp-completion-file-name-handler |
| 2431 | tramp-autoload-file-name-handler)) | ||
| 2429 | (let ((a1 (rassq fnh file-name-handler-alist))) | 2432 | (let ((a1 (rassq fnh file-name-handler-alist))) |
| 2430 | (setq file-name-handler-alist (delq a1 file-name-handler-alist))))) | 2433 | (setq file-name-handler-alist (delq a1 file-name-handler-alist)))))) |
| 2431 | 2434 | ||
| 2432 | (add-hook 'tramp-unload-hook 'tramp-unload-file-name-handlers) | 2435 | (add-hook 'tramp-unload-hook 'tramp-unload-file-name-handlers) |
| 2433 | 2436 | ||
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index af707f85007..8eedfd72094 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -4432,23 +4432,27 @@ process sentinels. They shall not disturb each other." | |||
| 4432 | "Check that Tramp is loaded lazily, only when needed." | 4432 | "Check that Tramp is loaded lazily, only when needed." |
| 4433 | ;; Tramp is neither loaded at Emacs startup, nor when completing a | 4433 | ;; Tramp is neither loaded at Emacs startup, nor when completing a |
| 4434 | ;; non-Tramp file name like "/foo". Completing a Tramp-alike file | 4434 | ;; non-Tramp file name like "/foo". Completing a Tramp-alike file |
| 4435 | ;; name like "/foo:" autoloads Tramp. | 4435 | ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t. |
| 4436 | (let ((code | 4436 | (let ((code |
| 4437 | "(progn \ | 4437 | "(progn \ |
| 4438 | (message \"Tramp loaded: %s\" (featurep 'tramp)) \ | 4438 | (setq tramp-mode %s) \ |
| 4439 | (message \"Tramp loaded: %%s\" (featurep 'tramp)) \ | ||
| 4439 | (file-name-all-completions \"/foo\" \"/\") \ | 4440 | (file-name-all-completions \"/foo\" \"/\") \ |
| 4440 | (message \"Tramp loaded: %s\" (featurep 'tramp)) \ | 4441 | (message \"Tramp loaded: %%s\" (featurep 'tramp)) \ |
| 4441 | (file-name-all-completions \"/foo:\" \"/\") \ | 4442 | (file-name-all-completions \"/foo:\" \"/\") \ |
| 4442 | (message \"Tramp loaded: %s\" (featurep 'tramp)))")) | 4443 | (message \"Tramp loaded: %%s\" (featurep 'tramp)))")) |
| 4443 | (should | 4444 | (dolist (tm '(t nil)) |
| 4444 | (string-match | 4445 | (should |
| 4445 | "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: t[\n\r]+" | 4446 | (string-match |
| 4446 | (shell-command-to-string | 4447 | (format |
| 4447 | (format | 4448 | "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+" |
| 4448 | "%s -batch -Q -L %s --eval %s" | 4449 | tm) |
| 4449 | (expand-file-name invocation-name invocation-directory) | 4450 | (shell-command-to-string |
| 4450 | (mapconcat 'shell-quote-argument load-path " -L ") | 4451 | (format |
| 4451 | (shell-quote-argument code))))))) | 4452 | "%s -batch -Q -L %s --eval %s" |
| 4453 | (expand-file-name invocation-name invocation-directory) | ||
| 4454 | (mapconcat 'shell-quote-argument load-path " -L ") | ||
| 4455 | (shell-quote-argument (format code tm))))))))) | ||
| 4452 | 4456 | ||
| 4453 | (ert-deftest tramp-test43-unload () | 4457 | (ert-deftest tramp-test43-unload () |
| 4454 | "Check that Tramp and its subpackages unload completely. | 4458 | "Check that Tramp and its subpackages unload completely. |