aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2023-02-24 21:49:54 -0800
committerJim Porter2023-02-25 20:38:55 -0800
commit9565e34762af6e0db51e9ae01683eb5d4c97ff3d (patch)
tree9f9a1a3a3d0e0d3ddc86adc8bf4d8831283e35b4
parent2baf08683fcf4b6b1ad65a6dc239b889d78a74b2 (diff)
downloademacs-9565e34762af6e0db51e9ae01683eb5d4c97ff3d.tar.gz
emacs-9565e34762af6e0db51e9ae01683eb5d4c97ff3d.zip
Be more cautious in completing Eshell variable assignments
Previously, Eshell treated cases like the second argument in "tar --directory=dir" as a variable assignment, but that prevented 'pcomplete/tar' from implementing its own completion for that argument (bug#61778). * lisp/eshell/esh-var.el (eshell-complete-variable-assignment): Only handle completion when all initial arguments are variable assignments. * test/lisp/eshell/em-cmpl-tests.el (em-cmpl-test/variable-assign-completion/non-assignment): New test.
-rw-r--r--lisp/eshell/esh-var.el18
-rw-r--r--test/lisp/eshell/em-cmpl-tests.el14
2 files changed, 27 insertions, 5 deletions
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 0031324b537..5d6299af564 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -862,11 +862,19 @@ START and END."
862 862
863(defun eshell-complete-variable-assignment () 863(defun eshell-complete-variable-assignment ()
864 "If there is a variable assignment, allow completion of entries." 864 "If there is a variable assignment, allow completion of entries."
865 (let ((arg (pcomplete-actual-arg)) pos) 865 (catch 'not-assignment
866 (when (string-match (concat "\\`" eshell-variable-name-regexp "=") arg) 866 ;; The current argument can only be a variable assignment if all
867 (setq pos (match-end 0)) 867 ;; arguments leading up to it are also variable assignments. See
868 (if (string-match "\\(:\\)[^:]*\\'" arg) 868 ;; `eshell-handle-local-variables'.
869 (setq pos (match-end 1))) 869 (dotimes (offset (1+ pcomplete-index))
870 (unless (string-match (concat "\\`" eshell-variable-name-regexp "=")
871 (pcomplete-actual-arg 'first offset))
872 (throw 'not-assignment nil)))
873 ;; We have a variable assignment. Handle it.
874 (let ((arg (pcomplete-actual-arg))
875 (pos (match-end 0)))
876 (when (string-match "\\(:\\)[^:]*\\'" arg)
877 (setq pos (match-end 1)))
870 (setq pcomplete-stub (substring arg pos)) 878 (setq pcomplete-stub (substring arg pos))
871 (throw 'pcomplete-completions (pcomplete-entries))))) 879 (throw 'pcomplete-completions (pcomplete-entries)))))
872 880
diff --git a/test/lisp/eshell/em-cmpl-tests.el b/test/lisp/eshell/em-cmpl-tests.el
index ecab7332822..be2199c0464 100644
--- a/test/lisp/eshell/em-cmpl-tests.el
+++ b/test/lisp/eshell/em-cmpl-tests.el
@@ -217,6 +217,20 @@ See <lisp/eshell/esh-var.el>."
217 (should (equal (eshell-insert-and-complete "VAR=f") 217 (should (equal (eshell-insert-and-complete "VAR=f")
218 "VAR=file.txt "))))) 218 "VAR=file.txt ")))))
219 219
220(ert-deftest em-cmpl-test/variable-assign-completion/non-assignment ()
221 "Test completion of things that look like variable assignment, but aren't.
222For example, the second argument in \"tar --directory=dir\" looks
223like it could be a variable assignment, but it's not. We should
224let `pcomplete-tar' handle it instead.
225
226See <lisp/eshell/esh-var.el>."
227 (with-temp-eshell
228 (ert-with-temp-directory default-directory
229 (write-region nil nil (expand-file-name "file.txt"))
230 (make-directory "dir")
231 (should (equal (eshell-insert-and-complete "tar --directory=")
232 "tar --directory=dir/")))))
233
220(ert-deftest em-cmpl-test/user-ref-completion () 234(ert-deftest em-cmpl-test/user-ref-completion ()
221 "Test completion of user references like \"~user\". 235 "Test completion of user references like \"~user\".
222See <lisp/eshell/em-dirs.el>." 236See <lisp/eshell/em-dirs.el>."