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.
This commit is contained in:
Michael Albinus 2023-02-10 17:48:44 +01:00
parent ab7c2f8092
commit ea29622e92
2 changed files with 29 additions and 5 deletions

View file

@ -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."

View file

@ -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)