From 31c07d873b8055e4749bcc097dfb81dc4c29fd5c Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Mon, 19 Jan 2026 12:28:18 +0100 Subject: [PATCH] ; Minor Tramp cleanup * lisp/net/tramp-adb.el: * lisp/net/tramp-androidsu.el: * lisp/net/tramp-integration.el: * lisp/net/tramp-smb.el: Do not delay `connection-local-set-profiles' until after loading `shell'. * lisp/net/tramp-integration.el: Add the local profile for all hosts listed in `tramp-local-host-names'. * lisp/net/tramp.el (tramp-local-host-names): New defvar. (tramp-local-host-regexp): Use it. * test/lisp/net/tramp-tests.el (tramp-test03-file-name-defaults): Adapt test. --- lisp/net/tramp-adb.el | 9 ++++----- lisp/net/tramp-androidsu.el | 10 +++------- lisp/net/tramp-integration.el | 22 ++++++++-------------- lisp/net/tramp-smb.el | 24 +++++++++++------------- lisp/net/tramp.el | 24 +++++++++++++----------- test/lisp/net/tramp-tests.el | 5 ++--- 6 files changed, 41 insertions(+), 53 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index a745633c24b..1def3aa3791 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -1227,11 +1227,10 @@ connection if a previous connection has died for some reason." 'tramp-adb-connection-local-default-ps-profile tramp-adb-connection-local-default-ps-variables) -(with-eval-after-load 'shell - (connection-local-set-profiles - `(:application tramp :protocol ,tramp-adb-method) - 'tramp-adb-connection-local-default-shell-profile - 'tramp-adb-connection-local-default-ps-profile)) +(connection-local-set-profiles + `(:application tramp :protocol ,tramp-adb-method) + 'tramp-adb-connection-local-default-shell-profile + 'tramp-adb-connection-local-default-ps-profile) ;; `shell-mode' tries to open remote files like "/adb::~/.history". ;; This fails, because the tilde cannot be expanded. Tell diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index d3e528e8ce7..f15c5587651 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el @@ -529,13 +529,9 @@ arguments to pass to the OPERATION." (connection-local-set-profiles `(:application tramp :protocol ,tramp-androidsu-method) - 'tramp-androidsu-connection-local-default-profile) - -(with-eval-after-load 'shell - (connection-local-set-profiles - `(:application tramp :protocol ,tramp-androidsu-method) - 'tramp-adb-connection-local-default-shell-profile - 'tramp-adb-connection-local-default-ps-profile)) + 'tramp-androidsu-connection-local-default-profile + 'tramp-adb-connection-local-default-shell-profile + 'tramp-adb-connection-local-default-ps-profile) (add-hook 'tramp-unload-hook (lambda () diff --git a/lisp/net/tramp-integration.el b/lisp/net/tramp-integration.el index 0183960d7f4..83351952c6c 100644 --- a/lisp/net/tramp-integration.el +++ b/lisp/net/tramp-integration.el @@ -367,10 +367,6 @@ It's value must be a Tramp user option, indexed in the Tramp manual via 'tramp-connection-local-default-system-profile tramp-connection-local-default-system-variables) -(connection-local-set-profiles - '(:application tramp) - 'tramp-connection-local-default-system-profile) - (defconst tramp-connection-local-default-shell-variables '((shell-file-name . "/bin/sh") (shell-command-switch . "-c")) @@ -380,10 +376,10 @@ It's value must be a Tramp user option, indexed in the Tramp manual via 'tramp-connection-local-default-shell-profile tramp-connection-local-default-shell-variables) -(with-eval-after-load 'shell - (connection-local-set-profiles - '(:application tramp) - 'tramp-connection-local-default-shell-profile)) +(connection-local-set-profiles + '(:application tramp) + 'tramp-connection-local-default-system-profile + 'tramp-connection-local-default-shell-profile) ;; Tested with FreeBSD 12.2. (defconst tramp-bsd-process-attributes-ps-args @@ -586,12 +582,10 @@ See `tramp-process-attributes-ps-format'.") 'tramp-connection-local-darwin-ps-profile) ;; ... Add other system types here. ))) - (connection-local-set-profiles - `(:application tramp :machine ,(system-name)) - local-profile) - (connection-local-set-profiles - '(:application tramp :machine "localhost") - local-profile)) + (dolist (local-host tramp-local-host-names) + (connection-local-set-profiles + `(:application tramp :machine ,local-host) + local-profile))) ;; Set connection-local variables for buffers visiting a file. diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 10ab64929eb..b87eee0fcce 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -2230,10 +2230,6 @@ SHARE will be passed to the call of `tramp-smb-get-localname'." 'tramp-smb-connection-local-default-system-profile tramp-smb-connection-local-default-system-variables) -(connection-local-set-profiles - `(:application tramp :protocol ,tramp-smb-method) - 'tramp-smb-connection-local-default-system-profile) - ;; (defconst tramp-smb-connection-local-bash-variables ;; '((explicit-shell-file-name . "bash") ;; (explicit-bash-args . ("--norc" "--noediting" "-i")) @@ -2257,12 +2253,6 @@ SHARE will be passed to the call of `tramp-smb-get-localname'." 'tramp-smb-connection-local-powershell-profile tramp-smb-connection-local-powershell-variables) -(defun tramp-smb-shell-prompt () - "Set `comint-prompt-regexp' to a proper value." - ;; Used for remote `shell-mode' buffers. - (when (tramp-smb-file-name-p default-directory) - (setq-local comint-prompt-regexp tramp-smb-prompt))) - ;; (defconst tramp-smb-connection-local-cmd-variables ;; '((explicit-shell-file-name . "cmd") ;; (explicit-cmd-args . ("/Q")) @@ -2274,10 +2264,18 @@ SHARE will be passed to the call of `tramp-smb-get-localname'." ;; 'tramp-smb-connection-local-cmd-profile ;; tramp-smb-connection-local-cmd-variables) +(connection-local-set-profiles + `(:application tramp :protocol ,tramp-smb-method) + 'tramp-smb-connection-local-default-system-profile + 'tramp-smb-connection-local-powershell-profile) + +(defun tramp-smb-shell-prompt () + "Set `comint-prompt-regexp' to a proper value." + ;; Used for remote `shell-mode' buffers. + (when (tramp-smb-file-name-p default-directory) + (setq-local comint-prompt-regexp tramp-smb-prompt))) + (with-eval-after-load 'shell - (connection-local-set-profiles - `(:application tramp :protocol ,tramp-smb-method) - 'tramp-smb-connection-local-powershell-profile) (add-hook 'shell-mode-hook #'tramp-smb-shell-prompt) (add-hook 'tramp-smb-unload-hook diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 1614fe5f7a3..f57b572532a 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -583,19 +583,21 @@ host runs a restricted shell, it shall be added to this list, too." :type '(repeat (regexp :tag "Host regexp")) :link '(info-link :tag "Tramp manual" "(tramp) Multi-hops")) +;;;###tramp-autoload +(defvar tramp-local-host-names + (list tramp-system-name "localhost" "127.0.0.1" "::1" + ;; Fedora. + "localhost4" "localhost6" + ;; Ubuntu. + "ip6-localhost" "ip6-loopback" + ;; OpenSUSE. + "ipv6-localhost" "ipv6-loopback") + "List of host names which are regarded as local host.") + ;;;###tramp-autoload (defcustom tramp-local-host-regexp - (rx bos - (| (literal tramp-system-name) - (| "localhost" "127.0.0.1" "::1" - ;; Fedora. - "localhost4" "localhost6" - ;; Ubuntu. - "ip6-localhost" "ip6-loopback" - ;; OpenSUSE. - "ipv6-localhost" "ipv6-loopback")) - eos) - "Host names which are regarded as local host. + (rx-to-string `(: bos (| . ,tramp-local-host-names) eos)) + "Regexp of host names which are regarded as local host. If the local host runs a chrooted environment, set this to nil." :version "30.1" :type '(choice (const :tag "Chrooted environment" nil) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cb8253e66f6..37923cf2a19 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2158,9 +2158,8 @@ being the result.") (string-equal (file-remote-p (format "/-:%s@:" u) 'method) "ftp")))) ;; Default values in tramp-sh.el and tramp-sudoedit.el. (when (assoc "su" tramp-methods) - (dolist - (h `("127.0.0.1" "[::1]" "localhost" "localhost4" "localhost6" - "ip6-localhost" "ip6-loopback" ,(system-name))) + ;; "::1" is used as "[::1]" in remote file names. + (dolist (h (cons "[::1]" (delete "::1" tramp-local-host-names))) (should (string-equal (file-remote-p (format "/-:root@%s:" h) 'method) "su")))) (dolist (m '("su" "sudo" "ksu" "doas" "sudoedit"))