emacs-diffs
[Top][All Lists]
Advanced

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

master ea29622e928: Fix Tramp file name completion


From: Michael Albinus
Subject: master ea29622e928: Fix Tramp file name completion
Date: Fri, 10 Feb 2023 11:49:31 -0500 (EST)

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

    Fix Tramp file name completion
    
    * lisp/net/tramp.el (tramp-completion-handle-expand-file-name):
    Reimplement.  It must also work for the non-Tramp case.
    
    * test/lisp/net/tramp-tests.el
    (tramp-test26-interactive-file-name-completion): Fix test.
---
 lisp/net/tramp.el            | 18 +++++++++++++++---
 test/lisp/net/tramp-tests.el | 16 ++++++++++++++--
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index b75a1816fdb..36305dda496 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2948,9 +2948,21 @@ not in completion mode."
 
 (defun tramp-completion-handle-expand-file-name (filename &optional directory)
   "Like `expand-file-name' for partial Tramp files."
-  (if (file-name-absolute-p filename)
-      filename
-    (concat (or directory default-directory "/") filename)))
+  ;; We need special handling only when a method is needed.  Then we
+  ;; check, whether DIRECTORY is "/method:" or "/[method/".
+  (let ((dir (or directory default-directory "/")))
+    (cond
+     ((file-name-absolute-p filename) filename)
+     ((and (eq tramp-syntax 'simplified)
+           (string-match-p (rx (regexp tramp-postfix-host-regexp) eos) dir))
+      (concat dir filename))
+     ((string-match-p
+       (rx bos (regexp tramp-prefix-regexp)
+          (? (regexp tramp-method-regexp) (regexp tramp-postfix-method-regexp))
+          eos)
+       dir)
+      (concat dir filename))
+     (t (tramp-run-real-handler #'expand-file-name (list filename 
directory))))))
 
 (defun tramp-completion-handle-file-exists-p (filename)
   "Like `file-exists-p' for partial Tramp files."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index eea59843d47..a9f22369231 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4695,7 +4695,7 @@ This tests also `make-symbolic-link', `file-truename' and 
`add-name-to-file'."
                               tramp-prefix-format
                               (substring-no-properties method 0 2))
                         unread-command-events
-                        (mapcar #'identity (concat test "\t\n"))
+                        (mapcar #'identity (concat test "\t\t\n"))
                         completions nil
                         result (read-file-name "Prompt: "))
                   (if (not (get-buffer "*Completions*"))
@@ -4708,6 +4708,12 @@ This tests also `make-symbolic-link', `file-truename' 
and `add-name-to-file'."
                           (concat tramp-prefix-format method-string)
                           result)))
                     (with-current-buffer "*Completions*"
+                     ;; We must remove leading `default-directory'.
+                     (goto-char (point-min))
+                     (let ((inhibit-read-only t))
+                       (while (re-search-forward "//" nil 'noerror)
+                         (delete-region (line-beginning-position) (point))))
+                     (goto-char (point-min))
                      (re-search-forward
                        (rx bol (1+ nonl) "possible completions:" eol))
                      (forward-line 1)
@@ -4729,7 +4735,7 @@ This tests also `make-symbolic-link', `file-truename' and 
`add-name-to-file'."
                               tramp-prefix-format method-string
                               (substring-no-properties host 0 2))
                         unread-command-events
-                        (mapcar #'identity (concat test "\t\n"))
+                        (mapcar #'identity (concat test "\t\t\n"))
                         completions nil
                         result (read-file-name "Prompt: "))
                   (if (not (get-buffer "*Completions*"))
@@ -4744,6 +4750,12 @@ This tests also `make-symbolic-link', `file-truename' 
and `add-name-to-file'."
                           ipv6-prefix host ipv6-postfix 
tramp-postfix-host-format)
                           result)))
                     (with-current-buffer "*Completions*"
+                     ;; We must remove leading `default-directory'.
+                     (goto-char (point-min))
+                     (let ((inhibit-read-only t))
+                       (while (re-search-forward "//" nil 'noerror)
+                         (delete-region (line-beginning-position) (point))))
+                     (goto-char (point-min))
                      (re-search-forward
                        (rx bol (1+ nonl) "possible completions:" eol))
                      (forward-line 1)



reply via email to

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