aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-10-20 13:38:31 +0200
committerMichael Albinus2018-10-20 13:38:31 +0200
commit67d3b40e0cba5f34b1c7aacc4e1ccea6300eae76 (patch)
tree992635f6f00e83aea36a3e2de1ceff1a29c03da8
parentefb214622a0f4e077c09e721d134552dfe76ef70 (diff)
downloademacs-67d3b40e0cba5f34b1c7aacc4e1ccea6300eae76.tar.gz
emacs-67d3b40e0cba5f34b1c7aacc4e1ccea6300eae76.zip
Expand host names in Tramp's ad-hoc multi-hop file names
* doc/misc/tramp.texi (Quick Start Guide): Improve wording. (Change file name syntax): Say, that `tramp-file-name-regexp' is not constant. (Ad-hoc multi-hops): Explain host name expansion. * etc/NEWS: Mention that host names in Tramp ad-hoc multi-hop file names must match the previous hop for methods like "su" or "sudo". Fix typos. * lisp/net/tramp.el (tramp-find-method, tramp-find-user): Adapt docstring. (tramp-find-host): Mark default value. (tramp-dissect-file-name): Expand host name for hops. (tramp-dissect-hop-name, tramp-make-tramp-hop-name): New defuns. (tramp-clear-passwd): Simplify. * test/lisp/net/tramp-tests.el (tramp-test02-file-name-dissect) (tramp-test02-file-name-dissect-simplified) (tramp-test02-file-name-dissect-separate) (tramp-test26-file-name-completion): Extend tests.
-rw-r--r--doc/misc/tramp.texi26
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/net/tramp.el80
-rw-r--r--test/lisp/net/tramp-tests.el131
4 files changed, 188 insertions, 61 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 7c5ebf334ae..128501c3908 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -464,7 +464,7 @@ this case it is written as @code{host#port}.
464@cindex @option{plink} method 464@cindex @option{plink} method
465 465
466If your local host runs an SSH client, and the remote host runs an SSH 466If your local host runs an SSH client, and the remote host runs an SSH
467server, the most simple remote file name is 467server, the simplest remote file name is
468@file{@trampfn{ssh,user@@host,/path/to/file}}. The remote file name 468@file{@trampfn{ssh,user@@host,/path/to/file}}. The remote file name
469@file{@trampfn{ssh,,}} opens a remote connection to yourself on the 469@file{@trampfn{ssh,,}} opens a remote connection to yourself on the
470local host, and is taken often for testing @value{tramp}. 470local host, and is taken often for testing @value{tramp}.
@@ -2459,9 +2459,10 @@ and @code{user@@} parts are optional.
2459 2459
2460@defvar tramp-file-name-regexp 2460@defvar tramp-file-name-regexp
2461This variable keeps a regexp which matches the selected remote file 2461This variable keeps a regexp which matches the selected remote file
2462name syntax. However, it is not recommended to use this variable in 2462name syntax. Its value changes after every call of
2463external packages, a call of @code{file-remote-p} is much more 2463@code{tramp-change-syntax}. However, it is not recommended to use
2464appropriate. 2464this variable in external packages, a call of @code{file-remote-p} is
2465much more appropriate.
2465@ifinfo 2466@ifinfo
2466@pxref{Magic File Names, , , elisp} 2467@pxref{Magic File Names, , , elisp}
2467@end ifinfo 2468@end ifinfo
@@ -2585,9 +2586,9 @@ directory contents.
2585@cindex multi-hop, ad-hoc 2586@cindex multi-hop, ad-hoc
2586@cindex proxy hosts, ad-hoc 2587@cindex proxy hosts, ad-hoc
2587 2588
2588@value{tramp} file name syntax can accommodate ad hoc specification of 2589@value{tramp} file name syntax can accommodate ad-hoc specification of
2589multiple proxies without using @code{tramp-default-proxies-alist} 2590multiple proxies without using @code{tramp-default-proxies-alist}
2590configuration setup(@pxref{Multi-hops}). 2591configuration setup (@pxref{Multi-hops}).
2591 2592
2592Each proxy is specified using the same syntax as the remote host 2593Each proxy is specified using the same syntax as the remote host
2593specification minus the file name part. Each hop is separated by a 2594specification minus the file name part. Each hop is separated by a
@@ -2600,8 +2601,6 @@ proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}:
2600@kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path @key{RET}} 2601@kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path @key{RET}}
2601@end example 2602@end example
2602 2603
2603Proxies can take patterns @code{%h} or @code{%u}.
2604
2605@value{tramp} adds the ad-hoc definitions on the fly to 2604@value{tramp} adds the ad-hoc definitions on the fly to
2606@code{tramp-default-proxies-alist} and is available for re-use 2605@code{tramp-default-proxies-alist} and is available for re-use
2607during that Emacs session. Subsequent @value{tramp} connections to 2606during that Emacs session. Subsequent @value{tramp} connections to
@@ -2618,6 +2617,17 @@ For ad-hoc definitions to be saved automatically in
2618@end lisp 2617@end lisp
2619@end defopt 2618@end defopt
2620 2619
2620Ad-hoc proxies can take patterns @code{%h} or @code{%u} like in
2621@code{tramp-default-proxies-alist}. The following file name expands
2622to user @code{root} on host @code{remotehost}, starting with an
2623@option{ssh} session on host @code{remotehost}:
2624@samp{@value{prefix}ssh@value{postfixhop}%h|su@value{postfixhop}remotehost@value{postfix}}.
2625
2626On the other hand, if a trailing hop does not specifiy a host name,
2627the host name of the previous hop is reused. Therefore, the following
2628file name is equivalent to the previous example:
2629@samp{@value{prefix}ssh@value{postfixhop}remotehost|su@value{postfixhop}@value{postfix}}.
2630
2621 2631
2622@node Remote processes 2632@node Remote processes
2623@section Integration with other Emacs packages 2633@section Integration with other Emacs packages
diff --git a/etc/NEWS b/etc/NEWS
index 09f0362fed7..be6668ed42e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -172,7 +172,7 @@ the data.
172 172
173+++ 173+++
174** The Network Security Manager now allows more fine-grained control 174** The Network Security Manager now allows more fine-grained control
175of what checks to run via the `network-security-protocol-checks' 175of what checks to run via the 'network-security-protocol-checks'
176variable. 176variable.
177 177
178+++ 178+++
@@ -356,7 +356,7 @@ shown in the currently selected window.
356** Comint 356** Comint
357 357
358+++ 358+++
359*** 'send-invisible' is now an obsolete alias for `comint-send-invisible'. 359*** 'send-invisible' is now an obsolete alias for 'comint-send-invisible'.
360Also, 'shell-strip-ctrl-m' is declared obsolete. 360Also, 'shell-strip-ctrl-m' is declared obsolete.
361 361
362+++ 362+++
@@ -391,7 +391,7 @@ facilities to aid more casual SQL developers layout queries and
391complex expressions. 391complex expressions.
392 392
393*** 'sql-use-indent-support' (default t) enables SQL indention support. 393*** 'sql-use-indent-support' (default t) enables SQL indention support.
394The `sql-indent' package from ELPA must be installed to get the 394The 'sql-indent' package from ELPA must be installed to get the
395indentation support in 'sql-mode' and 'sql-interactive-mode'. 395indentation support in 'sql-mode' and 'sql-interactive-mode'.
396 396
397*** 'sql-mode-hook' and 'sql-interactive-mode-hook' changed. 397*** 'sql-mode-hook' and 'sql-interactive-mode-hook' changed.
@@ -420,7 +420,7 @@ This enables more efficient backends. See the docstring of
420 420
421** Package 421** Package
422 422
423*** New function `package-get-version` lets packages query their own version. 423*** New function 'package-get-version' lets packages query their own version.
424Example use in auctex.el: (defconst auctex-version (package-get-version)) 424Example use in auctex.el: (defconst auctex-version (package-get-version))
425 425
426*** New 'package-quickstart' feature. 426*** New 'package-quickstart' feature.
@@ -747,6 +747,10 @@ are obsoleted in GVFS.
747*** The user option 'tramp-ignored-file-name-regexp' allows to disable 747*** The user option 'tramp-ignored-file-name-regexp' allows to disable
748Tramp for some look-alike remote file names. 748Tramp for some look-alike remote file names.
749 749
750+++
751*** For some connection methods, like "su" or "sudo", the host name in
752ad-hoc multi-hop file names must match the previous hop.
753
750** Register 754** Register
751--- 755---
752*** The return value of method 'register-val-describe' includes the 756*** The return value of method 'register-val-describe' includes the
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index e629ce17315..2e6cdf999a5 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1267,7 +1267,7 @@ entry does not exist, return nil."
1267(defun tramp-find-method (method user host) 1267(defun tramp-find-method (method user host)
1268 "Return the right method string to use. 1268 "Return the right method string to use.
1269This is METHOD, if non-nil. Otherwise, do a lookup in 1269This is METHOD, if non-nil. Otherwise, do a lookup in
1270`tramp-default-method-alist'." 1270`tramp-default-method-alist' and `tramp-default-method'."
1271 (when (and method 1271 (when (and method
1272 (or (string-equal method "") 1272 (or (string-equal method "")
1273 (string-equal method tramp-default-method-marker))) 1273 (string-equal method tramp-default-method-marker)))
@@ -1292,7 +1292,7 @@ This is METHOD, if non-nil. Otherwise, do a lookup in
1292(defun tramp-find-user (method user host) 1292(defun tramp-find-user (method user host)
1293 "Return the right user string to use. 1293 "Return the right user string to use.
1294This is USER, if non-nil. Otherwise, do a lookup in 1294This is USER, if non-nil. Otherwise, do a lookup in
1295`tramp-default-user-alist'." 1295`tramp-default-user-alist' and `tramp-default-user'."
1296 (let ((result 1296 (let ((result
1297 (or user 1297 (or user
1298 (let ((choices tramp-default-user-alist) 1298 (let ((choices tramp-default-user-alist)
@@ -1312,18 +1312,24 @@ This is USER, if non-nil. Otherwise, do a lookup in
1312 1312
1313(defun tramp-find-host (method user host) 1313(defun tramp-find-host (method user host)
1314 "Return the right host string to use. 1314 "Return the right host string to use.
1315This is HOST, if non-nil. Otherwise, it is `tramp-default-host'." 1315This is HOST, if non-nil. Otherwise, do a lookup in
1316 (or (and (> (length host) 0) host) 1316`tramp-default-host-alist' and `tramp-default-host'."
1317 (let ((choices tramp-default-host-alist) 1317 (let ((result
1318 lhost item) 1318 (or (and (> (length host) 0) host)
1319 (while choices 1319 (let ((choices tramp-default-host-alist)
1320 (setq item (pop choices)) 1320 lhost item)
1321 (when (and (string-match (or (nth 0 item) "") (or method "")) 1321 (while choices
1322 (string-match (or (nth 1 item) "") (or user ""))) 1322 (setq item (pop choices))
1323 (setq lhost (nth 2 item)) 1323 (when (and (string-match (or (nth 0 item) "") (or method ""))
1324 (setq choices nil))) 1324 (string-match (or (nth 1 item) "") (or user "")))
1325 lhost) 1325 (setq lhost (nth 2 item))
1326 tramp-default-host)) 1326 (setq choices nil)))
1327 lhost)
1328 tramp-default-host)))
1329 ;; We must mark, whether a default value has been used.
1330 (if (or (> (length host) 0) (null result))
1331 result
1332 (propertize result 'tramp-default t))))
1327 1333
1328(defun tramp-dissect-file-name (name &optional nodefault) 1334(defun tramp-dissect-file-name (name &optional nodefault)
1329 "Return a `tramp-file-name' structure of NAME, a remote file name. 1335 "Return a `tramp-file-name' structure of NAME, a remote file name.
@@ -1343,7 +1349,7 @@ default values are used."
1343 (host (match-string (nth 3 tramp-file-name-structure) name)) 1349 (host (match-string (nth 3 tramp-file-name-structure) name))
1344 (localname (match-string (nth 4 tramp-file-name-structure) name)) 1350 (localname (match-string (nth 4 tramp-file-name-structure) name))
1345 (hop (match-string (nth 5 tramp-file-name-structure) name)) 1351 (hop (match-string (nth 5 tramp-file-name-structure) name))
1346 domain port) 1352 domain port v)
1347 (when user 1353 (when user
1348 (when (string-match tramp-user-with-domain-regexp user) 1354 (when (string-match tramp-user-with-domain-regexp user)
1349 (setq domain (match-string 2 user) 1355 (setq domain (match-string 2 user)
@@ -1359,14 +1365,34 @@ default values are used."
1359 (setq host (replace-match "" nil t host)))) 1365 (setq host (replace-match "" nil t host))))
1360 1366
1361 (unless nodefault 1367 (unless nodefault
1362 (setq method (tramp-find-method method user host) 1368 (when hop
1363 user (tramp-find-user method user host) 1369 (setq v (tramp-dissect-hop-name hop)
1364 host (tramp-find-host method user host))) 1370 hop (and hop (tramp-make-tramp-hop-name v))))
1371 (let ((tramp-default-host
1372 (or (and v (not (string-match "%h" (tramp-file-name-host v)))
1373 (tramp-file-name-host v))
1374 tramp-default-host)))
1375 (setq method (tramp-find-method method user host)
1376 user (tramp-find-user method user host)
1377 host (tramp-find-host method user host)
1378 hop
1379 (and hop
1380 (format-spec hop (format-spec-make ?h host ?u user))))))
1365 1381
1366 (make-tramp-file-name 1382 (make-tramp-file-name
1367 :method method :user user :domain domain :host host :port port 1383 :method method :user user :domain domain :host host :port port
1368 :localname localname :hop hop))))) 1384 :localname localname :hop hop)))))
1369 1385
1386(defun tramp-dissect-hop-name (name &optional nodefault)
1387 "Return a `tramp-file-name' structure of `hop' part of NAME.
1388See `tramp-dissect-file-name' for details."
1389 (tramp-dissect-file-name
1390 (concat
1391 tramp-prefix-format
1392 (replace-regexp-in-string
1393 (concat tramp-postfix-hop-regexp "$") tramp-postfix-host-format name))
1394 nodefault))
1395
1370(defun tramp-buffer-name (vec) 1396(defun tramp-buffer-name (vec)
1371 "A name for the connection buffer VEC." 1397 "A name for the connection buffer VEC."
1372 (let ((method (tramp-file-name-method vec)) 1398 (let ((method (tramp-file-name-method vec))
@@ -1433,6 +1459,14 @@ the form (METHOD USER DOMAIN HOST PORT LOCALNAME &optional HOP)."
1433 tramp-postfix-host-format 1459 tramp-postfix-host-format
1434 localname))) 1460 localname)))
1435 1461
1462(defun tramp-make-tramp-hop-name (vec)
1463 "Construct a Tramp hop name from VEC."
1464 (replace-regexp-in-string
1465 tramp-prefix-regexp ""
1466 (replace-regexp-in-string
1467 (concat tramp-postfix-host-regexp "$") tramp-postfix-hop-format
1468 (tramp-make-tramp-file-name vec 'noloc))))
1469
1436(defun tramp-completion-make-tramp-file-name (method user host localname) 1470(defun tramp-completion-make-tramp-file-name (method user host localname)
1437 "Construct a Tramp file name from METHOD, USER, HOST and LOCALNAME. 1471 "Construct a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1438It must not be a complete Tramp file name, but as long as there are 1472It must not be a complete Tramp file name, but as long as there are
@@ -2313,7 +2347,7 @@ Falls back to normal file name handler if no Tramp file name handler exists."
2313 (tramp-message 2347 (tramp-message
2314 v 1 "Interrupt received in operation %s" 2348 v 1 "Interrupt received in operation %s"
2315 (cons operation args))) 2349 (cons operation args)))
2316 ;; Propagate the quit signal. 2350 ;; Propagate the signal.
2317 (signal (car err) (cdr err))) 2351 (signal (car err) (cdr err)))
2318 2352
2319 ;; When we are in completion mode, some failed 2353 ;; When we are in completion mode, some failed
@@ -4508,13 +4542,7 @@ Invokes `password-read' if available, `read-passwd' else."
4508 (hop (tramp-file-name-hop vec))) 4542 (hop (tramp-file-name-hop vec)))
4509 (when hop 4543 (when hop
4510 ;; Clear also the passwords of the hops. 4544 ;; Clear also the passwords of the hops.
4511 (tramp-clear-passwd 4545 (tramp-clear-passwd (tramp-dissect-hop-name hop)))
4512 (tramp-dissect-file-name
4513 (concat
4514 tramp-prefix-format
4515 (replace-regexp-in-string
4516 (concat tramp-postfix-hop-regexp "$")
4517 tramp-postfix-host-format hop)))))
4518 (auth-source-forget 4546 (auth-source-forget
4519 `(:max 1 ,(and user-domain :user) ,user-domain 4547 `(:max 1 ,(and user-domain :user) ,user-domain
4520 :host ,host-port :port ,method)) 4548 :host ,host-port :port ,method))
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 6a08cbb5ab2..ceda70947c8 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -763,8 +763,8 @@ handled properly. BODY shall not contain a timeout."
763 "|-:user2@host2" 763 "|-:user2@host2"
764 "|-:user3@host3:/path/to/file")) 764 "|-:user3@host3:/path/to/file"))
765 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:" 765 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
766 "-" "user1" "host1" 766 "method1" "user1" "host1"
767 "-" "user2" "host2" 767 "method2" "user2" "host2"
768 "method3" "user3" "host3"))) 768 "method3" "user3" "host3")))
769 769
770 ;; Expand `tramp-default-user-alist'. 770 ;; Expand `tramp-default-user-alist'.
@@ -778,9 +778,9 @@ handled properly. BODY shall not contain a timeout."
778 "/method1:host1" 778 "/method1:host1"
779 "|method2:host2" 779 "|method2:host2"
780 "|method3:host3:/path/to/file")) 780 "|method3:host3:/path/to/file"))
781 (format "/%s:%s|%s:%s|%s:%s@%s:" 781 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
782 "method1" "host1" 782 "method1" "user1" "host1"
783 "method2" "host2" 783 "method2" "user2" "host2"
784 "method3" "user3" "host3"))) 784 "method3" "user3" "host3")))
785 785
786 ;; Expand `tramp-default-host-alist'. 786 ;; Expand `tramp-default-host-alist'.
@@ -794,9 +794,36 @@ handled properly. BODY shall not contain a timeout."
794 "/method1:user1@" 794 "/method1:user1@"
795 "|method2:user2@" 795 "|method2:user2@"
796 "|method3:user3@:/path/to/file")) 796 "|method3:user3@:/path/to/file"))
797 (format "/%s:%s@|%s:%s@|%s:%s@%s:" 797 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
798 "method1" "user1" 798 "method1" "user1" "host1"
799 "method2" "user2" 799 "method2" "user2" "host2"
800 "method3" "user3" "host3")))
801
802 ;; Ad-hoc user name and host name expansion.
803 (setq tramp-default-method-alist nil
804 tramp-default-user-alist nil
805 tramp-default-host-alist nil)
806 (should
807 (string-equal
808 (file-remote-p
809 (concat
810 "/method1:user1@host1"
811 "|method2:user2@"
812 "|method3:user3@:/path/to/file"))
813 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
814 "method1" "user1" "host1"
815 "method2" "user2" "host1"
816 "method3" "user3" "host1")))
817 (should
818 (string-equal
819 (file-remote-p
820 (concat
821 "/method1:%u@%h"
822 "|method2:%u@%h"
823 "|method3:user3@host3:/path/to/file"))
824 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
825 "method1" "user3" "host3"
826 "method2" "user3" "host3"
800 "method3" "user3" "host3"))))) 827 "method3" "user3" "host3")))))
801 828
802(ert-deftest tramp-test02-file-name-dissect-simplified () 829(ert-deftest tramp-test02-file-name-dissect-simplified ()
@@ -1067,9 +1094,9 @@ handled properly. BODY shall not contain a timeout."
1067 "/host1" 1094 "/host1"
1068 "|host2" 1095 "|host2"
1069 "|host3:/path/to/file")) 1096 "|host3:/path/to/file"))
1070 (format "/%s|%s|%s@%s:" 1097 (format "/%s@%s|%s@%s|%s@%s:"
1071 "host1" 1098 "user1" "host1"
1072 "host2" 1099 "user2" "host2"
1073 "user3" "host3"))) 1100 "user3" "host3")))
1074 1101
1075 ;; Expand `tramp-default-host-alist'. 1102 ;; Expand `tramp-default-host-alist'.
@@ -1083,9 +1110,35 @@ handled properly. BODY shall not contain a timeout."
1083 "/user1@" 1110 "/user1@"
1084 "|user2@" 1111 "|user2@"
1085 "|user3@:/path/to/file")) 1112 "|user3@:/path/to/file"))
1086 (format "/%s@|%s@|%s@%s:" 1113 (format "/%s@%s|%s@%s|%s@%s:"
1087 "user1" 1114 "user1" "host1"
1088 "user2" 1115 "user2" "host2"
1116 "user3" "host3")))
1117
1118 ;; Ad-hoc user name and host name expansion.
1119 (setq tramp-default-user-alist nil
1120 tramp-default-host-alist nil)
1121 (should
1122 (string-equal
1123 (file-remote-p
1124 (concat
1125 "/user1@host1"
1126 "|user2@"
1127 "|user3@:/path/to/file"))
1128 (format "/%s@%s|%s@%s|%s@%s:"
1129 "user1" "host1"
1130 "user2" "host1"
1131 "user3" "host1")))
1132 (should
1133 (string-equal
1134 (file-remote-p
1135 (concat
1136 "/%u@%h"
1137 "|%u@%h"
1138 "|user3@host3:/path/to/file"))
1139 (format "/%s@%s|%s@%s|%s@%s:"
1140 "user3" "host3"
1141 "user3" "host3"
1089 "user3" "host3")))) 1142 "user3" "host3"))))
1090 1143
1091 ;; Exit. 1144 ;; Exit.
@@ -1670,9 +1723,9 @@ handled properly. BODY shall not contain a timeout."
1670 "/[/user1@host1" 1723 "/[/user1@host1"
1671 "|/user2@host2" 1724 "|/user2@host2"
1672 "|/user3@host3]/path/to/file")) 1725 "|/user3@host3]/path/to/file"))
1673 (format "/[/%s@%s|/%s@%s|%s/%s@%s]" 1726 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1674 "user1" "host1" 1727 "method1" "user1" "host1"
1675 "user2" "host2" 1728 "method2" "user2" "host2"
1676 "method3" "user3" "host3"))) 1729 "method3" "user3" "host3")))
1677 1730
1678 ;; Expand `tramp-default-user-alist'. 1731 ;; Expand `tramp-default-user-alist'.
@@ -1686,9 +1739,9 @@ handled properly. BODY shall not contain a timeout."
1686 "/[method1/host1" 1739 "/[method1/host1"
1687 "|method2/host2" 1740 "|method2/host2"
1688 "|method3/host3]/path/to/file")) 1741 "|method3/host3]/path/to/file"))
1689 (format "/[%s/%s|%s/%s|%s/%s@%s]" 1742 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1690 "method1" "host1" 1743 "method1" "user1" "host1"
1691 "method2" "host2" 1744 "method2" "user2" "host2"
1692 "method3" "user3" "host3"))) 1745 "method3" "user3" "host3")))
1693 1746
1694 ;; Expand `tramp-default-host-alist'. 1747 ;; Expand `tramp-default-host-alist'.
@@ -1702,9 +1755,36 @@ handled properly. BODY shall not contain a timeout."
1702 "/[method1/user1@" 1755 "/[method1/user1@"
1703 "|method2/user2@" 1756 "|method2/user2@"
1704 "|method3/user3@]/path/to/file")) 1757 "|method3/user3@]/path/to/file"))
1705 (format "/[%s/%s@|%s/%s@|%s/%s@%s]" 1758 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1706 "method1" "user1" 1759 "method1" "user1" "host1"
1707 "method2" "user2" 1760 "method2" "user2" "host2"
1761 "method3" "user3" "host3")))
1762
1763 ;; Ad-hoc user name and host name expansion.
1764 (setq tramp-default-method-alist nil
1765 tramp-default-user-alist nil
1766 tramp-default-host-alist nil)
1767 (should
1768 (string-equal
1769 (file-remote-p
1770 (concat
1771 "/[method1/user1@host1"
1772 "|method2/user2@"
1773 "|method3/user3@]/path/to/file"))
1774 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1775 "method1" "user1" "host1"
1776 "method2" "user2" "host1"
1777 "method3" "user3" "host1")))
1778 (should
1779 (string-equal
1780 (file-remote-p
1781 (concat
1782 "/[method1/%u@%h"
1783 "|method2/%u@%h"
1784 "|method3/user3@host3]/path/to/file"))
1785 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1786 "method1" "user3" "host3"
1787 "method2" "user3" "host3"
1708 "method3" "user3" "host3")))) 1788 "method3" "user3" "host3"))))
1709 1789
1710 ;; Exit. 1790 ;; Exit.
@@ -3491,6 +3571,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
3491 (when (not (memq system-type '(cygwin windows-nt))) 3571 (when (not (memq system-type '(cygwin windows-nt)))
3492 (let ((method (file-remote-p tramp-test-temporary-file-directory 'method)) 3572 (let ((method (file-remote-p tramp-test-temporary-file-directory 'method))
3493 (host (file-remote-p tramp-test-temporary-file-directory 'host)) 3573 (host (file-remote-p tramp-test-temporary-file-directory 'host))
3574 (vec (tramp-dissect-file-name tramp-test-temporary-file-directory))
3494 (orig-syntax tramp-syntax)) 3575 (orig-syntax tramp-syntax))
3495 (when (and (stringp host) (string-match tramp-host-with-port-regexp host)) 3576 (when (and (stringp host) (string-match tramp-host-with-port-regexp host))
3496 (setq host (match-string 1 host))) 3577 (setq host (match-string 1 host)))
@@ -3501,6 +3582,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
3501 (if (tramp--test-expensive-test) 3582 (if (tramp--test-expensive-test)
3502 (tramp-syntax-values) `(,orig-syntax))) 3583 (tramp-syntax-values) `(,orig-syntax)))
3503 (tramp-change-syntax syntax) 3584 (tramp-change-syntax syntax)
3585 ;; This has cleaned up all connection data, which are used
3586 ;; for completion. We must refill the cache.
3587 (tramp-set-connection-property vec "property" nil)
3588
3504 (let ;; This is needed for the `simplified' syntax. 3589 (let ;; This is needed for the `simplified' syntax.
3505 ((method-marker 3590 ((method-marker
3506 (if (zerop (length tramp-method-regexp)) 3591 (if (zerop (length tramp-method-regexp))