diff options
| author | Michael Albinus | 2023-02-10 17:48:44 +0100 |
|---|---|---|
| committer | Michael Albinus | 2023-02-10 17:48:44 +0100 |
| commit | ea29622e928f50522e424ee59b0f24bbb5a42eca (patch) | |
| tree | a77189ee0405190966c123a990de96306773923a | |
| parent | ab7c2f809219b0c29e7ee2b5ac66f18b0e657080 (diff) | |
| download | emacs-ea29622e928f50522e424ee59b0f24bbb5a42eca.tar.gz emacs-ea29622e928f50522e424ee59b0f24bbb5a42eca.zip | |
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.
| -rw-r--r-- | lisp/net/tramp.el | 18 | ||||
| -rw-r--r-- | 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." | |||
| 2948 | 2948 | ||
| 2949 | (defun tramp-completion-handle-expand-file-name (filename &optional directory) | 2949 | (defun tramp-completion-handle-expand-file-name (filename &optional directory) |
| 2950 | "Like `expand-file-name' for partial Tramp files." | 2950 | "Like `expand-file-name' for partial Tramp files." |
| 2951 | (if (file-name-absolute-p filename) | 2951 | ;; We need special handling only when a method is needed. Then we |
| 2952 | filename | 2952 | ;; check, whether DIRECTORY is "/method:" or "/[method/". |
| 2953 | (concat (or directory default-directory "/") filename))) | 2953 | (let ((dir (or directory default-directory "/"))) |
| 2954 | (cond | ||
| 2955 | ((file-name-absolute-p filename) filename) | ||
| 2956 | ((and (eq tramp-syntax 'simplified) | ||
| 2957 | (string-match-p (rx (regexp tramp-postfix-host-regexp) eos) dir)) | ||
| 2958 | (concat dir filename)) | ||
| 2959 | ((string-match-p | ||
| 2960 | (rx bos (regexp tramp-prefix-regexp) | ||
| 2961 | (? (regexp tramp-method-regexp) (regexp tramp-postfix-method-regexp)) | ||
| 2962 | eos) | ||
| 2963 | dir) | ||
| 2964 | (concat dir filename)) | ||
| 2965 | (t (tramp-run-real-handler #'expand-file-name (list filename directory)))))) | ||
| 2954 | 2966 | ||
| 2955 | (defun tramp-completion-handle-file-exists-p (filename) | 2967 | (defun tramp-completion-handle-file-exists-p (filename) |
| 2956 | "Like `file-exists-p' for partial Tramp files." | 2968 | "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'." | |||
| 4695 | tramp-prefix-format | 4695 | tramp-prefix-format |
| 4696 | (substring-no-properties method 0 2)) | 4696 | (substring-no-properties method 0 2)) |
| 4697 | unread-command-events | 4697 | unread-command-events |
| 4698 | (mapcar #'identity (concat test "\t\n")) | 4698 | (mapcar #'identity (concat test "\t\t\n")) |
| 4699 | completions nil | 4699 | completions nil |
| 4700 | result (read-file-name "Prompt: ")) | 4700 | result (read-file-name "Prompt: ")) |
| 4701 | (if (not (get-buffer "*Completions*")) | 4701 | (if (not (get-buffer "*Completions*")) |
| @@ -4708,6 +4708,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4708 | (concat tramp-prefix-format method-string) | 4708 | (concat tramp-prefix-format method-string) |
| 4709 | result))) | 4709 | result))) |
| 4710 | (with-current-buffer "*Completions*" | 4710 | (with-current-buffer "*Completions*" |
| 4711 | ;; We must remove leading `default-directory'. | ||
| 4712 | (goto-char (point-min)) | ||
| 4713 | (let ((inhibit-read-only t)) | ||
| 4714 | (while (re-search-forward "//" nil 'noerror) | ||
| 4715 | (delete-region (line-beginning-position) (point)))) | ||
| 4716 | (goto-char (point-min)) | ||
| 4711 | (re-search-forward | 4717 | (re-search-forward |
| 4712 | (rx bol (1+ nonl) "possible completions:" eol)) | 4718 | (rx bol (1+ nonl) "possible completions:" eol)) |
| 4713 | (forward-line 1) | 4719 | (forward-line 1) |
| @@ -4729,7 +4735,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4729 | tramp-prefix-format method-string | 4735 | tramp-prefix-format method-string |
| 4730 | (substring-no-properties host 0 2)) | 4736 | (substring-no-properties host 0 2)) |
| 4731 | unread-command-events | 4737 | unread-command-events |
| 4732 | (mapcar #'identity (concat test "\t\n")) | 4738 | (mapcar #'identity (concat test "\t\t\n")) |
| 4733 | completions nil | 4739 | completions nil |
| 4734 | result (read-file-name "Prompt: ")) | 4740 | result (read-file-name "Prompt: ")) |
| 4735 | (if (not (get-buffer "*Completions*")) | 4741 | (if (not (get-buffer "*Completions*")) |
| @@ -4744,6 +4750,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4744 | ipv6-prefix host ipv6-postfix tramp-postfix-host-format) | 4750 | ipv6-prefix host ipv6-postfix tramp-postfix-host-format) |
| 4745 | result))) | 4751 | result))) |
| 4746 | (with-current-buffer "*Completions*" | 4752 | (with-current-buffer "*Completions*" |
| 4753 | ;; We must remove leading `default-directory'. | ||
| 4754 | (goto-char (point-min)) | ||
| 4755 | (let ((inhibit-read-only t)) | ||
| 4756 | (while (re-search-forward "//" nil 'noerror) | ||
| 4757 | (delete-region (line-beginning-position) (point)))) | ||
| 4758 | (goto-char (point-min)) | ||
| 4747 | (re-search-forward | 4759 | (re-search-forward |
| 4748 | (rx bol (1+ nonl) "possible completions:" eol)) | 4760 | (rx bol (1+ nonl) "possible completions:" eol)) |
| 4749 | (forward-line 1) | 4761 | (forward-line 1) |