Commit ca2d94ba authored by Michael Albinus's avatar Michael Albinus

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.
parent 709478ea
......@@ -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)
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment