aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-02-05 14:02:49 +0100
committerMichael Albinus2018-02-05 14:02:49 +0100
commitc24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02 (patch)
tree094f175c3e001aab5ec37a18a7db0ae3175bf6a9
parent8fbf28536ee1169f59206523e2af050916befbf6 (diff)
downloademacs-c24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02.tar.gz
emacs-c24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02.zip
Fix inconsistency expanding "//" in Tramp
* doc/misc/tramp.texi (File name completion): Adapt example expanding "//". * lisp/net/tramp.el (tramp-handle-substitute-in-file-name): "//" shall expand the localname only, even when on top of the local part. * test/lisp/net/tramp-tests.el (tramp-test04-substitute-in-file-name): Adapt test.
-rw-r--r--doc/misc/tramp.texi2
-rw-r--r--lisp/net/tramp.el20
-rw-r--r--test/lisp/net/tramp-tests.el42
3 files changed, 43 insertions, 21 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 235627cc0f9..ae544b08712 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -2509,7 +2509,7 @@ Example:
2509 @print{} @trampfn{ssh,melancholia,/etc} 2509 @print{} @trampfn{ssh,melancholia,/etc}
2510 2510
2511@kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}} 2511@kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}}
2512 @print{} /etc 2512 @print{} @trampfn{ssh,melancholia,/etc}
2513 2513
2514@kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}} 2514@kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}}
2515 @print{} /etc 2515 @print{} /etc
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 09abd482260..b2e20000d3f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3554,17 +3554,19 @@ support symbolic links."
3554 ;; First, we must replace environment variables. 3554 ;; First, we must replace environment variables.
3555 (setq filename (tramp-replace-environment-variables filename)) 3555 (setq filename (tramp-replace-environment-variables filename))
3556 (with-parsed-tramp-file-name filename nil 3556 (with-parsed-tramp-file-name filename nil
3557 ;; Ignore in LOCALNAME everything before "//" or "/~".
3558 (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
3559 (setq filename
3560 (concat (file-remote-p filename)
3561 (replace-match "\\1" nil nil localname)))
3562 ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
3563 (when (string-match "~$" filename)
3564 (setq filename (concat filename "/"))))
3565 ;; We do not want to replace environment variables, again. 3557 ;; We do not want to replace environment variables, again.
3566 (let (process-environment) 3558 (let (process-environment)
3567 (tramp-run-real-handler 'substitute-in-file-name (list filename)))))) 3559 ;; Ignore in LOCALNAME everything before "//" or "/~".
3560 (when (stringp localname)
3561 (if (string-match "//\\(/\\|~\\)" localname)
3562 (setq filename (substitute-in-file-name localname))
3563 (setq filename
3564 (concat (file-remote-p filename)
3565 (substitute-in-file-name localname))))))
3566 ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
3567 (if (string-match "~$" filename)
3568 (concat filename "/")
3569 filename))))
3568 3570
3569(defun tramp-handle-set-visited-file-modtime (&optional time-list) 3571(defun tramp-handle-set-visited-file-modtime (&optional time-list)
3570 "Like `set-visited-file-modtime' for Tramp files." 3572 "Like `set-visited-file-modtime' for Tramp files."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 7a12d1468bf..422e71df7c3 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -1712,39 +1712,59 @@ handled properly. BODY shall not contain a timeout."
1712 1712
1713(ert-deftest tramp-test04-substitute-in-file-name () 1713(ert-deftest tramp-test04-substitute-in-file-name ()
1714 "Check `substitute-in-file-name'." 1714 "Check `substitute-in-file-name'."
1715 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo")) 1715 (should (string-equal (substitute-in-file-name "/method:host:///foo") "/foo"))
1716 (should 1716 (should
1717 (string-equal 1717 (string-equal
1718 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo")) 1718 (substitute-in-file-name "/method:host://foo") "/method:host:/foo"))
1719 (should 1719 (should
1720 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo")) 1720 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
1721 (should
1722 (string-equal
1723 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
1721 ;; Quoting local part. 1724 ;; Quoting local part.
1722 (should 1725 (should
1723 (string-equal 1726 (string-equal
1724 (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo")) 1727 (substitute-in-file-name "/method:host:/:///foo") "/method:host:/:///foo"))
1725 (should 1728 (should
1726 (string-equal 1729 (string-equal
1727 (substitute-in-file-name "/method:host:/:/path//foo") 1730 (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
1728 "/method:host:/:/path//foo"))
1729 (should 1731 (should
1730 (string-equal 1732 (string-equal
1731 (substitute-in-file-name "/method:host:/:/path///foo") 1733 (substitute-in-file-name "/method:host:/:/path///foo")
1732 "/method:host:/:/path///foo")) 1734 "/method:host:/:/path///foo"))
1735 (should
1736 (string-equal
1737 (substitute-in-file-name "/method:host:/:/path//foo")
1738 "/method:host:/:/path//foo"))
1733 1739
1734 (should 1740 (should
1741 (string-equal (substitute-in-file-name "/method:host://~foo") "/~foo"))
1742 (should
1735 (string-equal 1743 (string-equal
1736 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo")) 1744 (substitute-in-file-name "/method:host:/~foo") "/method:host:/~foo"))
1737 (should 1745 (should
1738 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo")) 1746 (string-equal (substitute-in-file-name "/method:host:/path//~foo") "/~foo"))
1747 ;; (substitute-in-file-name "/path/~foo") expands only to "/~foo"",
1748 ;; if $LOGNAME or $USER is "foo". Otherwise, it doesn't expand.
1749 (should
1750 (string-equal
1751 (substitute-in-file-name
1752 "/method:host:/path/~foo") "/method:host:/path/~foo"))
1739 ;; Quoting local part. 1753 ;; Quoting local part.
1740 (should 1754 (should
1741 (string-equal 1755 (string-equal
1742 (substitute-in-file-name "/method:host:/:/path/~/foo") 1756 (substitute-in-file-name "/method:host:/://~foo") "/method:host:/://~foo"))
1743 "/method:host:/:/path/~/foo")) 1757 (should
1758 (string-equal
1759 (substitute-in-file-name "/method:host:/:/~foo") "/method:host:/:/~foo"))
1760 (should
1761 (string-equal
1762 (substitute-in-file-name
1763 "/method:host:/:/path//~foo") "/method:host:/:/path//~foo"))
1744 (should 1764 (should
1745 (string-equal 1765 (string-equal
1746 (substitute-in-file-name "/method:host:/:/path//~/foo") 1766 (substitute-in-file-name
1747 "/method:host:/:/path//~/foo")) 1767 "/method:host:/:/path/~foo") "/method:host:/:/path/~foo"))
1748 1768
1749 (let (process-environment) 1769 (let (process-environment)
1750 (should 1770 (should