From ca2d94ba61dee678f85bfc7299d167e7219e6d8f Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 5 Nov 2017 20:08:05 +0100 Subject: [PATCH] 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. --- lisp/net/tramp.el | 13 ++++++++----- 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." ;;;###autoload (progn (defun tramp-autoload-file-name-handler (operation &rest args) "Load Tramp file name handler, and perform OPERATION." - (let ((default-directory temporary-file-directory)) - (load "tramp" 'noerror 'nomessage)) + (if tramp-mode + (let ((default-directory temporary-file-directory)) + (load "tramp" 'noerror 'nomessage)) + (tramp-unload-file-name-handlers)) (apply operation args))) ;; `tramp-autoload-file-name-handler' must be registered before @@ -2422,12 +2424,13 @@ Add operations defined in `HANDLER-alist' to `tramp-file-name-handler'." (equal (apply operation args) operation)))) ;;;###autoload -(defun tramp-unload-file-name-handlers () +(progn (defun tramp-unload-file-name-handlers () "Unload Tramp file name handlers from `file-name-handler-alist'." (dolist (fnh '(tramp-file-name-handler - tramp-completion-file-name-handler)) + tramp-completion-file-name-handler + tramp-autoload-file-name-handler)) (let ((a1 (rassq fnh file-name-handler-alist))) - (setq file-name-handler-alist (delq a1 file-name-handler-alist))))) + (setq file-name-handler-alist (delq a1 file-name-handler-alist)))))) (add-hook 'tramp-unload-hook 'tramp-unload-file-name-handlers) 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." "Check that Tramp is loaded lazily, only when needed." ;; Tramp is neither loaded at Emacs startup, nor when completing a ;; non-Tramp file name like "/foo". Completing a Tramp-alike file - ;; name like "/foo:" autoloads Tramp. + ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t. (let ((code "(progn \ - (message \"Tramp loaded: %s\" (featurep 'tramp)) \ + (setq tramp-mode %s) \ + (message \"Tramp loaded: %%s\" (featurep 'tramp)) \ (file-name-all-completions \"/foo\" \"/\") \ - (message \"Tramp loaded: %s\" (featurep 'tramp)) \ + (message \"Tramp loaded: %%s\" (featurep 'tramp)) \ (file-name-all-completions \"/foo:\" \"/\") \ - (message \"Tramp loaded: %s\" (featurep 'tramp)))")) - (should - (string-match - "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: t[\n\r]+" - (shell-command-to-string - (format - "%s -batch -Q -L %s --eval %s" - (expand-file-name invocation-name invocation-directory) - (mapconcat 'shell-quote-argument load-path " -L ") - (shell-quote-argument code))))))) + (message \"Tramp loaded: %%s\" (featurep 'tramp)))")) + (dolist (tm '(t nil)) + (should + (string-match + (format + "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+" + tm) + (shell-command-to-string + (format + "%s -batch -Q -L %s --eval %s" + (expand-file-name invocation-name invocation-directory) + (mapconcat 'shell-quote-argument load-path " -L ") + (shell-quote-argument (format code tm))))))))) (ert-deftest tramp-test43-unload () "Check that Tramp and its subpackages unload completely. -- 2.39.5