; 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.
This commit is contained in:
Michael Albinus 2026-01-19 12:28:18 +01:00
parent caeebd6a6d
commit 31c07d873b
6 changed files with 41 additions and 53 deletions

View file

@ -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

View file

@ -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 ()

View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -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"))