emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master c24c5dc: Fix inconsistency expanding "//" in Tramp


From: Michael Albinus
Subject: [Emacs-diffs] master c24c5dc: Fix inconsistency expanding "//" in Tramp
Date: Mon, 5 Feb 2018 08:02:57 -0500 (EST)

branch: master
commit c24c5dc4a4cc18e7f1ec949efcfe1d4bae541d02
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    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.
---
 doc/misc/tramp.texi          |  2 +-
 lisp/net/tramp.el            | 20 +++++++++++---------
 test/lisp/net/tramp-tests.el | 42 +++++++++++++++++++++++++++++++-----------
 3 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 235627c..ae544b0 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 09abd48..b2e2000 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 7a12d14..422e71d 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



reply via email to

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