emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 72f1c12e58e: Add Tramp option showing ad-hoc multi-hops


From: Michael Albinus
Subject: master 72f1c12e58e: Add Tramp option showing ad-hoc multi-hops
Date: Wed, 21 Jun 2023 12:25:44 -0400 (EDT)

branch: master
commit 72f1c12e58ec2654779506480774e627d46d3693
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Add Tramp option showing ad-hoc multi-hops
    
    * doc/misc/tramp.texi (Ad-hoc multi-hops):
    Describe tramp-show-ad-hoc-proxies.
    
    * lisp/net/tramp.el (tramp-show-ad-hoc-proxies): New defcustom.
    (tramp-make-tramp-file-name): Use it.
    (tramp-make-tramp-hop-name): Don't add hop twice.
    
    * test/lisp/net/tramp-tests.el (tramp-test02-file-name-dissect)
    (tramp-test02-file-name-dissect-simplified)
    (tramp-test02-file-name-dissect-separate): Adapt tests.
---
 doc/misc/tramp.texi          |  18 +-
 lisp/net/tramp.el            |  11 +-
 test/lisp/net/tramp-tests.el | 990 +++++++++++++++++++++++++------------------
 3 files changed, 588 insertions(+), 431 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index a854c15f2b3..eb5c418728e 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -3644,10 +3644,20 @@ Each involved method must be an inline method 
(@pxref{Inline methods}).
 @code{tramp-default-proxies-alist} and is available for re-use during
 that Emacs session.  Subsequent @value{tramp} connections to the same
 remote host can then use the shortcut form:
-@samp{@trampfn{ssh,you@@remotehost,/path}}.  Ad-hoc definitions are
-removed from @code{tramp-default-proxies-alist} via the command
-@kbd{M-x tramp-cleanup-all-connections @key{RET}} (@pxref{Cleanup
-remote connections}).
+@samp{@trampfn{ssh,you@@remotehost,/path}}.
+
+@defopt tramp-show-ad-hoc-proxies
+If this user option is non-@code{nil}, ad-hoc definitions are kept in
+remote file names instead of showing the shortcuts.
+
+@lisp
+(customize-set-variable 'tramp-show-ad-hoc-proxies t)
+@end lisp
+@end defopt
+
+Ad-hoc definitions are removed from @code{tramp-default-proxies-alist}
+via the command @kbd{M-x tramp-cleanup-all-connections @key{RET}}
+(@pxref{Cleanup remote connections}).
 
 @defopt tramp-save-ad-hoc-proxies
 For ad-hoc definitions to be saved automatically in
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 8c26f533bb8..f7d40cc1de5 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -520,6 +520,11 @@ interpreted as a regular expression which always matches."
   :version "24.3"
   :type 'boolean)
 
+(defcustom tramp-show-ad-hoc-proxies nil
+  "Whether to show ad-hoc proxies in file names."
+  :version "29.2"
+  :type 'boolean)
+
 ;; For some obscure technical reasons, `system-name' on w32 returns
 ;; either lower case or upper case letters.  See
 ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=38079#20>.
@@ -1802,8 +1807,8 @@ the form (METHOD USER DOMAIN HOST PORT LOCALNAME 
&optional HOP)."
       (when (cadr args)
        (setq localname (and (stringp (cadr args)) (cadr args))))
       (when hop
-       ;; Keep hop in file name for completion.
-       (unless minibuffer-completing-file-name
+       ;; Keep hop in file name for completion or when indicated.
+       (unless (or minibuffer-completing-file-name tramp-show-ad-hoc-proxies)
          (setq hop nil))
        ;; Assure that the hops are in `tramp-default-proxies-alist'.
        ;; In tramp-archive.el, the slot `hop' is used for the archive
@@ -1853,7 +1858,7 @@ the form (METHOD USER DOMAIN HOST PORT LOCALNAME 
&optional HOP)."
     (replace-regexp-in-string
      (rx (regexp tramp-postfix-host-regexp) eos)
      tramp-postfix-hop-format
-     (tramp-make-tramp-file-name vec 'noloc)))))
+     (tramp-make-tramp-file-name (tramp-file-name-unify vec))))))
 
 (defun tramp-completion-make-tramp-file-name (method user host localname)
   "Construct a Tramp file name from METHOD, USER, HOST and LOCALNAME.
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 0b01c13470a..a2e57e468c1 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -521,6 +521,7 @@ is greater than 10.
        tramp-default-method-alist
        tramp-default-user-alist
        tramp-default-host-alist
+       tramp-default-proxies-alist
        ;; Suppress method name check.
        (non-essential t)
        ;; Suppress check for multihops.
@@ -847,154 +848,203 @@ is greater than 10.
                   "/path/to/file"))
 
          ;; Multihop.
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file")
-           "/method2:user2@host2:"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
-           "method2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
-           "user2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
-           "host2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file"
-            'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop)
-           (format "%s:%s@%s|"
-                   "method1" "user1" "host1")))
+         (dolist (tramp-show-ad-hoc-proxies '(nil t))
 
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file"))
-           "/method3:user3@host3:"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file")
-            'method)
-           "method3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file")
-            'user)
-           "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file")
-            'host)
-           "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file")
-            'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@host2"
-             "|method3:user3@host3:/path/to/file")
-            'hop)
-           (format "%s:%s@%s|%s:%s@%s|"
-                   "method1" "user1" "host1" "method2" "user2" "host2")))
-
-         ;; Expand `tramp-default-method-alist'.
-         (add-to-list 'tramp-default-method-alist '("host1" "user1" "method1"))
-         (add-to-list 'tramp-default-method-alist '("host2" "user2" "method2"))
-         (add-to-list 'tramp-default-method-alist '("host3" "user3" "method3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/-:user1@host1"
-             "|-:user2@host2"
-             "|-:user3@host3:/path/to/file"))
-           "/method3:user3@host3:"))
-
-         ;; Expand `tramp-default-user-alist'.
-         (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
-         (add-to-list 'tramp-default-user-alist '("method2" "host2" "user2"))
-         (add-to-list 'tramp-default-user-alist '("method3" "host3" "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:host1"
-             "|method2:host2"
-             "|method3:host3:/path/to/file"))
-           "/method3:user3@host3:"))
-
-         ;; Expand `tramp-default-host-alist'.
-         (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
-         (add-to-list 'tramp-default-host-alist '("method2" "user2" "host2"))
-         (add-to-list 'tramp-default-host-alist '("method3" "user3" "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@"
-             "|method2:user2@"
-             "|method3:user3@:/path/to/file"))
-           "/method3:user3@host3:"))
-
-         ;; Ad-hoc user name and host name expansion.
-         (setq tramp-default-method-alist nil
-               tramp-default-user-alist nil
-               tramp-default-host-alist nil)
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:user1@host1"
-             "|method2:user2@"
-             "|method3:user3@:/path/to/file"))
-           "/method3:user3@host1:"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/method1:%u@%h"
-             "|method2:user2@host2"
-             "|method3:%u@%h"
-             "|method4:user4%domain4@host4#1234:/path/to/file"))
-           "/method4:user4%domain4@host4#1234:")))
+           ;; Explicit settings in `tramp-default-proxies-alist'
+           ;; shouldn't show hops.
+           (setq tramp-default-proxies-alist
+                 '(("^host2$" "^user2$" "/method1:user1@host1:")))
+           (should
+            (string-equal
+             (file-remote-p "/method2:user2@host2:/path/to/file")
+             "/method2:user2@host2:"))
+           (setq tramp-default-proxies-alist nil)
+
+           ;; Ad-hoc settings.
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file")
+             (if tramp-show-ad-hoc-proxies
+                 "/method1:user1@host1|method2:user2@host2:"
+               "/method2:user2@host2:")))
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
+             "method2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
+             "user2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
+             "host2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file"
+              'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop)
+             (format "%s:%s@%s|"
+                     "method1" "user1" "host1")))
+
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user1@host1"
+                  "|method2:user2@host2"
+                  "|method3:user3@host3:")
+               "/method3:user3@host3:")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file")
+              'method)
+             "method3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file")
+              'user)
+             "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file")
+              'host)
+             "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file")
+              'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@host2"
+               "|method3:user3@host3:/path/to/file")
+              'hop)
+             (format "%s:%s@%s|%s:%s@%s|"
+                     "method1" "user1" "host1" "method2" "user2" "host2")))
+
+           ;; Expand `tramp-default-method-alist'.
+           (add-to-list
+            'tramp-default-method-alist '("host1" "user1" "method1"))
+           (add-to-list
+            'tramp-default-method-alist '("host2" "user2" "method2"))
+           (add-to-list
+            'tramp-default-method-alist '("host3" "user3" "method3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/-:user1@host1"
+               "|-:user2@host2"
+               "|-:user3@host3:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user1@host1"
+                  "|method2:user2@host2"
+                  "|method3:user3@host3:")
+               "/method3:user3@host3:")))
+
+           ;; Expand `tramp-default-user-alist'.
+           (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
+           (add-to-list 'tramp-default-user-alist '("method2" "host2" "user2"))
+           (add-to-list 'tramp-default-user-alist '("method3" "host3" "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:host1"
+               "|method2:host2"
+               "|method3:host3:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user1@host1"
+                  "|method2:user2@host2"
+                  "|method3:user3@host3:")
+               "/method3:user3@host3:")))
+
+           ;; Expand `tramp-default-host-alist'.
+           (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
+           (add-to-list 'tramp-default-host-alist '("method2" "user2" "host2"))
+           (add-to-list 'tramp-default-host-alist '("method3" "user3" "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@"
+               "|method2:user2@"
+               "|method3:user3@:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user1@host1"
+                  "|method2:user2@host2"
+                  "|method3:user3@host3:")
+               "/method3:user3@host3:")))
+
+           ;; Ad-hoc user name and host name expansion.
+           (setq tramp-default-method-alist nil
+                 tramp-default-user-alist nil
+                 tramp-default-host-alist nil)
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:user1@host1"
+               "|method2:user2@"
+               "|method3:user3@:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user1@host1"
+                  "|method2:user2@host1"
+                  "|method3:user3@host1:")
+               "/method3:user3@host1:")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/method1:%u@%h"
+               "|method2:user2@host2"
+               "|method3:%u@%h"
+               "|method4:user4%domain4@host4#1234:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/method1:user2@host2"
+                  "|method2:user2@host2"
+                  "|method3:user4@host4"
+                  "|method4:user4%domain4@host4#1234:")
+               "/method4:user4%domain4@host4#1234:")))))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -1007,6 +1057,7 @@ is greater than 10.
        (tramp-default-host "default-host")
        tramp-default-user-alist
        tramp-default-host-alist
+       tramp-default-proxies-alist
        ;; Suppress method name check.
        (non-essential t)
        ;; Suppress check for multihops.
@@ -1178,137 +1229,178 @@ is greater than 10.
                   "/path/to/file"))
 
          ;; Multihop.
-         (should
-          (string-equal
-           (file-remote-p "/user1@host1|user2@host2:/path/to/file")
-           "/user2@host2:"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/user1@host1|user2@host2:/path/to/file" 'method)
-           "default-method"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/user1@host1|user2@host2:/path/to/file" 'user)
-           "user2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/user1@host1|user2@host2:/path/to/file" 'host)
-           "host2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/user1@host1|user2@host2:/path/to/file" 'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/user1@host1|user2@host2:/path/to/file" 'hop)
-           (format "%s@%s|" "user1" "host1")))
+         (dolist (tramp-show-ad-hoc-proxies '(nil t))
 
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file"))
-           "/user3@host3:"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file")
-            'method)
-           "default-method"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file")
-            'user)
-           "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file")
-            'host)
-           "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file")
-            'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@host2"
-             "|user3@host3:/path/to/file")
-            'hop)
-           (format "%s@%s|%s@%s|"
-                   "user1" "host1" "user2" "host2")))
-
-         ;; Expand `tramp-default-user-alist'.
-         (add-to-list 'tramp-default-user-alist '(nil "host1" "user1"))
-         (add-to-list 'tramp-default-user-alist '(nil "host2" "user2"))
-         (add-to-list 'tramp-default-user-alist '(nil "host3" "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/host1"
-             "|host2"
-             "|host3:/path/to/file"))
-           "/user3@host3:"))
-
-         ;; Expand `tramp-default-host-alist'.
-         (add-to-list 'tramp-default-host-alist '(nil "user1" "host1"))
-         (add-to-list 'tramp-default-host-alist '(nil "user2" "host2"))
-         (add-to-list 'tramp-default-host-alist '(nil "user3" "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@"
-             "|user2@"
-             "|user3@:/path/to/file"))
-           "/user3@host3:"))
-
-         ;; Ad-hoc user name and host name expansion.
-         (setq tramp-default-user-alist nil
-               tramp-default-host-alist nil)
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/user1@host1"
-             "|user2@"
-             "|user3@:/path/to/file"))
-           "/user3@host1:"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/%u@%h"
-             "|user2@host2"
-             "|%u@%h"
-             "|user4%domain4@host4#1234:/path/to/file"))
-           "/user4%domain4@host4#1234:")))
+           ;; Explicit settings in `tramp-default-proxies-alist'
+           ;; shouldn't show hops.
+           (setq tramp-default-proxies-alist
+                 '(("^host2$" "^user2$" "/user1@host1:")))
+           (should
+            (string-equal
+             (file-remote-p "/user2@host2:/path/to/file")
+             "/user2@host2:"))
+           (setq tramp-default-proxies-alist nil)
+
+           ;; Ad-hoc settings.
+           (should
+            (string-equal
+             (file-remote-p "/user1@host1|user2@host2:/path/to/file")
+             (if tramp-show-ad-hoc-proxies
+                 "/user1@host1|user2@host2:"
+               "/user2@host2:")))
+           (should
+            (string-equal
+             (file-remote-p
+              "/user1@host1|user2@host2:/path/to/file" 'method)
+             "default-method"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/user1@host1|user2@host2:/path/to/file" 'user)
+             "user2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/user1@host1|user2@host2:/path/to/file" 'host)
+             "host2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/user1@host1|user2@host2:/path/to/file" 'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/user1@host1|user2@host2:/path/to/file" 'hop)
+             (format "%s@%s|" "user1" "host1")))
+
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/user1@host1"
+                  "|user2@host2"
+                  "|user3@host3:")
+               "/user3@host3:")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file")
+              'method)
+             "default-method"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file")
+              'user)
+             "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file")
+              'host)
+             "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file")
+              'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@host2"
+               "|user3@host3:/path/to/file")
+              'hop)
+             (format "%s@%s|%s@%s|"
+                     "user1" "host1" "user2" "host2")))
+
+           ;; Expand `tramp-default-user-alist'.
+           (add-to-list 'tramp-default-user-alist '(nil "host1" "user1"))
+           (add-to-list 'tramp-default-user-alist '(nil "host2" "user2"))
+           (add-to-list 'tramp-default-user-alist '(nil "host3" "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/host1"
+               "|host2"
+               "|host3:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/user1@host1"
+                  "|user2@host2"
+                  "|user3@host3:")
+               "/user3@host3:")))
+
+           ;; Expand `tramp-default-host-alist'.
+           (add-to-list 'tramp-default-host-alist '(nil "user1" "host1"))
+           (add-to-list 'tramp-default-host-alist '(nil "user2" "host2"))
+           (add-to-list 'tramp-default-host-alist '(nil "user3" "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@"
+               "|user2@"
+               "|user3@:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/user1@host1"
+                  "|user2@host2"
+                  "|user3@host3:")
+               "/user3@host3:")))
+
+           ;; Ad-hoc user name and host name expansion.
+           (setq tramp-default-user-alist nil
+                 tramp-default-host-alist nil)
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/user1@host1"
+               "|user2@"
+               "|user3@:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/user1@host1"
+                  "|user2@host1"
+                  "|user3@host1:")
+               "/user3@host1:")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/%u@%h"
+               "|user2@host2"
+               "|%u@%h"
+               "|user4%domain4@host4#1234:/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/user2@host2"
+                  "|user2@host2"
+                  "|user4@host4"
+                  "|user4%domain4@host4#1234:")
+               "/user4%domain4@host4#1234:")))))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -1322,6 +1414,7 @@ is greater than 10.
        tramp-default-method-alist
        tramp-default-user-alist
        tramp-default-host-alist
+       tramp-default-proxies-alist
        ;; Suppress method name check.
        (non-essential t)
        ;; Suppress check for multihops.
@@ -1794,154 +1887,203 @@ is greater than 10.
                   "/path/to/file"))
 
          ;; Multihop.
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file")
-           "/[method2/user2@host2]"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'method)
-           "method2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user)
-           "user2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host)
-           "host2"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file"
-            'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop)
-           (format "%s/%s@%s|"
-                   "method1" "user1" "host1")))
+         (dolist (tramp-show-ad-hoc-proxies '(nil t))
 
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file"))
-           "/[method3/user3@host3]"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file")
-            'method)
-           "method3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file")
-            'user)
-           "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file")
-            'host)
-           "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file")
-            'localname)
-           "/path/to/file"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@host2"
-             "|method3/user3@host3]/path/to/file")
-            'hop)
-           (format "%s/%s@%s|%s/%s@%s|"
-                   "method1" "user1" "host1" "method2" "user2" "host2")))
-
-         ;; Expand `tramp-default-method-alist'.
-         (add-to-list 'tramp-default-method-alist '("host1" "user1" "method1"))
-         (add-to-list 'tramp-default-method-alist '("host2" "user2" "method2"))
-         (add-to-list 'tramp-default-method-alist '("host3" "user3" "method3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[/user1@host1"
-             "|/user2@host2"
-             "|/user3@host3]/path/to/file"))
-           "/[method3/user3@host3]"))
-
-         ;; Expand `tramp-default-user-alist'.
-         (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
-         (add-to-list 'tramp-default-user-alist '("method2" "host2" "user2"))
-         (add-to-list 'tramp-default-user-alist '("method3" "host3" "user3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/host1"
-             "|method2/host2"
-             "|method3/host3]/path/to/file"))
-           "/[method3/user3@host3]"))
-
-         ;; Expand `tramp-default-host-alist'.
-         (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
-         (add-to-list 'tramp-default-host-alist '("method2" "user2" "host2"))
-         (add-to-list 'tramp-default-host-alist '("method3" "user3" "host3"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@"
-             "|method2/user2@"
-             "|method3/user3@]/path/to/file"))
-           "/[method3/user3@host3]"))
-
-         ;; Ad-hoc user name and host name expansion.
-         (setq tramp-default-method-alist nil
-               tramp-default-user-alist nil
-               tramp-default-host-alist nil)
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/user1@host1"
-             "|method2/user2@"
-             "|method3/user3@]/path/to/file"))
-           "/[method3/user3@host1]"))
-         (should
-          (string-equal
-           (file-remote-p
-            (concat
-             "/[method1/%u@%h"
-             "|method2/user2@host2"
-             "|method3/%u@%h"
-             "|method4/user4%domain4@host4#1234]/path/to/file"))
-           "/[method4/user4%domain4@host4#1234]")))
+           ;; Explicit settings in `tramp-default-proxies-alist'
+           ;; shouldn't show hops.
+           (setq tramp-default-proxies-alist
+                 '(("^host2$" "^user2$" "/[method1/user1@host1]")))
+           (should
+            (string-equal
+             (file-remote-p "/[method2/user2@host2]/path/to/file")
+             "/[method2/user2@host2]"))
+           (setq tramp-default-proxies-alist nil)
+
+           ;; Ad-hoc settings.
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file")
+             (if tramp-show-ad-hoc-proxies
+                 "/[method1/user1@host1|method2/user2@host2]"
+               "/[method2/user2@host2]")))
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file" 
'method)
+             "method2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user)
+             "user2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host)
+             "host2"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file"
+              'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop)
+             (format "%s/%s@%s|"
+                     "method1" "user1" "host1")))
+
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user1@host1"
+                  "|method2/user2@host2"
+                  "|method3/user3@host3]")
+               "/[method3/user3@host3]")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file")
+              'method)
+             "method3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file")
+              'user)
+             "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file")
+              'host)
+             "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file")
+              'localname)
+             "/path/to/file"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@host2"
+               "|method3/user3@host3]/path/to/file")
+              'hop)
+             (format "%s/%s@%s|%s/%s@%s|"
+                     "method1" "user1" "host1" "method2" "user2" "host2")))
+
+           ;; Expand `tramp-default-method-alist'.
+           (add-to-list
+            'tramp-default-method-alist '("host1" "user1" "method1"))
+           (add-to-list
+            'tramp-default-method-alist '("host2" "user2" "method2"))
+           (add-to-list
+            'tramp-default-method-alist '("host3" "user3" "method3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[/user1@host1"
+               "|/user2@host2"
+               "|/user3@host3]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user1@host1"
+                  "|method2/user2@host2"
+                  "|method3/user3@host3]")
+               "/[method3/user3@host3]")))
+
+           ;; Expand `tramp-default-user-alist'.
+           (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
+           (add-to-list 'tramp-default-user-alist '("method2" "host2" "user2"))
+           (add-to-list 'tramp-default-user-alist '("method3" "host3" "user3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/host1"
+               "|method2/host2"
+               "|method3/host3]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user1@host1"
+                  "|method2/user2@host2"
+                  "|method3/user3@host3]")
+               "/[method3/user3@host3]")))
+
+           ;; Expand `tramp-default-host-alist'.
+           (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
+           (add-to-list 'tramp-default-host-alist '("method2" "user2" "host2"))
+           (add-to-list 'tramp-default-host-alist '("method3" "user3" "host3"))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@"
+               "|method2/user2@"
+               "|method3/user3@]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user1@host1"
+                  "|method2/user2@host2"
+                  "|method3/user3@host3]")
+               "/[method3/user3@host3]")))
+
+           ;; Ad-hoc user name and host name expansion.
+           (setq tramp-default-method-alist nil
+                 tramp-default-user-alist nil
+                 tramp-default-host-alist nil)
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/user1@host1"
+               "|method2/user2@"
+               "|method3/user3@]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user1@host1"
+                  "|method2/user2@host1"
+                  "|method3/user3@host1]")
+               "/[method3/user3@host1]")))
+           (should
+            (string-equal
+             (file-remote-p
+              (concat
+               "/[method1/%u@%h"
+               "|method2/user2@host2"
+               "|method3/%u@%h"
+               "|method4/user4%domain4@host4#1234]/path/to/file"))
+             (if tramp-show-ad-hoc-proxies
+                 (concat
+                  "/[method1/user2@host2"
+                  "|method2/user2@host2"
+                  "|method3/user4@host4"
+                  "|method4/user4%domain4@host4#1234]")
+               "/[method4/user4%domain4@host4#1234]")))))
 
       ;; Exit.
       (tramp-change-syntax syntax))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]