From ad7dbf7e455dc6ed926b51a4b936a34d52eb3500 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 1 Feb 2023 17:48:47 -0800 Subject: [PATCH 3/3] Don't add a space after the trailing slash when completing ~FOO in Eshell * lisp/eshell/em-dirs.el (eshell-complete-user-reference): Set exit function. (eshell-complete-user-ref--exit): New function. * test/lisp/eshell/em-cmpl-tests.el (em-cmpl-test/user-ref-completion): Update test. --- lisp/eshell/em-dirs.el | 16 +++++++++++----- test/lisp/eshell/em-cmpl-tests.el | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el index 0d02b64b084..c6e384be374 100644 --- a/lisp/eshell/em-dirs.el +++ b/lisp/eshell/em-dirs.el @@ -281,15 +281,21 @@ eshell-complete-user-reference (let ((arg (pcomplete-actual-arg))) (when (string-match "\\`~[a-z]*\\'" arg) (setq pcomplete-stub (substring arg 1) - pcomplete-last-completion-raw t) + pcomplete-last-completion-raw t + pcomplete-exit-function #'eshell-complete-user-ref--exit) (throw 'pcomplete-completions (progn (eshell-read-user-names) (pcomplete-uniquify-list - (mapcar - (lambda (user) - (file-name-as-directory (cdr user))) - eshell-user-names))))))) + (mapcar #'cdr eshell-user-names))))))) + +(defun eshell-complete-user-ref--exit (_ status) + "An exit function for completing Eshell user references. +STATUS is a symbol representing the state of the completion." + (when (eq status 'finished) + (insert "/") + ;; Tell Pcomplete not to insert its own termination string. + t)) (defun eshell/pwd (&rest _args) "Change output from `pwd' to be cleaner." diff --git a/test/lisp/eshell/em-cmpl-tests.el b/test/lisp/eshell/em-cmpl-tests.el index 1f8c571c44c..ecab7332822 100644 --- a/test/lisp/eshell/em-cmpl-tests.el +++ b/test/lisp/eshell/em-cmpl-tests.el @@ -218,15 +218,14 @@ em-cmpl-test/variable-assign-completion "VAR=file.txt "))))) (ert-deftest em-cmpl-test/user-ref-completion () - "Test completeion of user references like \"~user\". + "Test completion of user references like \"~user\". See ." (unwind-protect (with-temp-eshell (cl-letf (((symbol-function 'eshell-read-user-names) (lambda () (setq eshell-user-names '((1234 . "user")))))) - ;; FIXME: Should this really add a space at the end? (should (equal (eshell-insert-and-complete "echo ~us") - "echo ~user/ ")))) + "echo ~user/")))) ;; Clear the cached user names we set above. (setq eshell-user-names nil))) -- 2.25.1