diff options
author | Jim Porter <jporterbugs@gmail.com> | 2023-02-01 17:48:47 -0800 |
---|---|---|
committer | Jim Porter <jporterbugs@gmail.com> | 2023-02-23 14:09:36 -0800 |
commit | 9d48c9844bf6b27fede6fe8f864e6dfb6909586b (patch) | |
tree | 2ac879c460333cda9da624bbf8595ed0621cb5ca /lisp/eshell | |
parent | 4b364a990a06cd73b553fdc9e9a65bc7398dbea6 (diff) | |
download | emacs-9d48c9844bf6b27fede6fe8f864e6dfb6909586b.tar.gz |
Don't add a space after the trailing slash when completing ~USER in Eshell
This provides a programmed completion function that works similarly to
~USER completion in 'completion-file-name-table'.
* lisp/eshell/em-dirs.el (eshell-complete-user-reference): Throw a
programmed completion function.
* test/lisp/eshell/em-cmpl-tests.el
(em-cmpl-test/user-ref-completion): Update test.
Diffstat (limited to 'lisp/eshell')
-rw-r--r-- | lisp/eshell/em-dirs.el | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el index 0d02b64b084..62d37e8f9fe 100644 --- a/lisp/eshell/em-dirs.el +++ b/lisp/eshell/em-dirs.el @@ -281,15 +281,34 @@ Thus, this does not include the current directory.") (let ((arg (pcomplete-actual-arg))) (when (string-match "\\`~[a-z]*\\'" arg) (setq pcomplete-stub (substring arg 1) - pcomplete-last-completion-raw t) - (throw 'pcomplete-completions - (progn - (eshell-read-user-names) - (pcomplete-uniquify-list - (mapcar - (lambda (user) - (file-name-as-directory (cdr user))) - eshell-user-names))))))) + pcomplete-last-completion-raw t) + ;; pcomplete-exit-function #'eshell-complete-user-ref--exit) + (eshell-read-user-names) + (let ((names (pcomplete-uniquify-list + (mapcar (lambda (user) + (file-name-as-directory (cdr user))) + eshell-user-names)))) + (throw 'pcomplete-completions + ;; Provide a programmed completion table. This works + ;; just like completing over the list of names, except + ;; it always returns the completed string, never `t'. + ;; That's because this is only completing a directory + ;; name, and so the completion isn't actually finished + ;; yet. + (lambda (string pred action) + (pcase action + ('nil ; try-completion + (let ((result (try-completion string names pred))) + (if (eq result t) string result))) + ('t ; all-completions + (all-completions string names pred)) + ('lambda ; test-completion + (let ((result (test-completion string names pred))) + (if (eq result t) string result))) + ('metadata + '(metadata (category . file))) + (`(boundaries . ,suffix) + `(boundaries 0 . ,(string-search "/" suffix)))))))))) (defun eshell/pwd (&rest _args) "Change output from `pwd' to be cleaner." |