summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2018-02-05 14:02:49 +0100
committerMichael Albinus <michael.albinus@gmx.de>2018-02-05 14:02:49 +0100
commitc24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02 (patch)
tree094f175c3e001aab5ec37a18a7db0ae3175bf6a9
parent8fbf28536ee1169f59206523e2af050916befbf6 (diff)
downloademacs-c24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02.tar.gz
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:
@print{} @trampfn{ssh,melancholia,/etc}
@kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}}
- @print{} /etc
+ @print{} @trampfn{ssh,melancholia,/etc}
@kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}}
@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."
;; First, we must replace environment variables.
(setq filename (tramp-replace-environment-variables filename))
(with-parsed-tramp-file-name filename nil
- ;; Ignore in LOCALNAME everything before "//" or "/~".
- (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
- (setq filename
- (concat (file-remote-p filename)
- (replace-match "\\1" nil nil localname)))
- ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
- (when (string-match "~$" filename)
- (setq filename (concat filename "/"))))
;; We do not want to replace environment variables, again.
(let (process-environment)
- (tramp-run-real-handler 'substitute-in-file-name (list filename))))))
+ ;; Ignore in LOCALNAME everything before "//" or "/~".
+ (when (stringp localname)
+ (if (string-match "//\\(/\\|~\\)" localname)
+ (setq filename (substitute-in-file-name localname))
+ (setq filename
+ (concat (file-remote-p filename)
+ (substitute-in-file-name localname))))))
+ ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
+ (if (string-match "~$" filename)
+ (concat filename "/")
+ filename))))
(defun tramp-handle-set-visited-file-modtime (&optional time-list)
"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."
(ert-deftest tramp-test04-substitute-in-file-name ()
"Check `substitute-in-file-name'."
- (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
+ (should (string-equal (substitute-in-file-name "/method:host:///foo") "/foo"))
(should
(string-equal
- (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
+ (substitute-in-file-name "/method:host://foo") "/method:host:/foo"))
(should
(string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
+ (should
+ (string-equal
+ (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
;; Quoting local part.
(should
(string-equal
- (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
+ (substitute-in-file-name "/method:host:/:///foo") "/method:host:/:///foo"))
(should
(string-equal
- (substitute-in-file-name "/method:host:/:/path//foo")
- "/method:host:/:/path//foo"))
+ (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
(should
(string-equal
(substitute-in-file-name "/method:host:/:/path///foo")
"/method:host:/:/path///foo"))
+ (should
+ (string-equal
+ (substitute-in-file-name "/method:host:/:/path//foo")
+ "/method:host:/:/path//foo"))
(should
+ (string-equal (substitute-in-file-name "/method:host://~foo") "/~foo"))
+ (should
(string-equal
- (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
+ (substitute-in-file-name "/method:host:/~foo") "/method:host:/~foo"))
(should
- (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
+ (string-equal (substitute-in-file-name "/method:host:/path//~foo") "/~foo"))
+ ;; (substitute-in-file-name "/path/~foo") expands only to "/~foo"",
+ ;; if $LOGNAME or $USER is "foo". Otherwise, it doesn't expand.
+ (should
+ (string-equal
+ (substitute-in-file-name
+ "/method:host:/path/~foo") "/method:host:/path/~foo"))
;; Quoting local part.
(should
(string-equal
- (substitute-in-file-name "/method:host:/:/path/~/foo")
- "/method:host:/:/path/~/foo"))
+ (substitute-in-file-name "/method:host:/://~foo") "/method:host:/://~foo"))
+ (should
+ (string-equal
+ (substitute-in-file-name "/method:host:/:/~foo") "/method:host:/:/~foo"))
+ (should
+ (string-equal
+ (substitute-in-file-name
+ "/method:host:/:/path//~foo") "/method:host:/:/path//~foo"))
(should
(string-equal
- (substitute-in-file-name "/method:host:/:/path//~/foo")
- "/method:host:/:/path//~/foo"))
+ (substitute-in-file-name
+ "/method:host:/:/path/~foo") "/method:host:/:/path/~foo"))
(let (process-environment)
(should