Fix Eshell incompatibility with "[" command when eshell-pred is disabled

* lisp/eshell/em-pred.el (eshell-pred-initialize): Ensure that
'eshell-parse-arg-modifier' is called before 'eshell-parse-glob-chars'.

* lisp/eshell/em-glob.el (eshell-glob-initialize): Use a number for hook
depth to be clearer.
(eshell-parse-glob-chars): Simplify; since eshell-pred's hook now runs
first, the extra code is no longer necessary.

* test/lisp/eshell/em-glob-tests.el
(em-glob-test/test-command-without-pred): New test.
This commit is contained in:
Jim Porter 2024-10-20 21:37:55 -07:00
parent d6fe32e531
commit 523aade3ea
3 changed files with 15 additions and 19 deletions

View file

@ -141,7 +141,7 @@ This mimics the behavior of zsh if non-nil, but bash if nil."
(when (boundp 'eshell-special-chars-outside-quoting)
(setq-local eshell-special-chars-outside-quoting
(append eshell-glob-chars-list eshell-special-chars-outside-quoting)))
(add-hook 'eshell-parse-argument-hook 'eshell-parse-glob-chars t t)
(add-hook 'eshell-parse-argument-hook 'eshell-parse-glob-chars 90 t)
(add-hook 'eshell-pre-rewrite-command-hook
'eshell-no-command-globbing nil t))
@ -165,22 +165,7 @@ The character is not advanced for ordinary globbing characters, so
that other function may have a chance to override the globbing
interpretation."
(when (memq (char-after) eshell-glob-chars-list)
(if (not (memq (char-after) '(?\( ?\[)))
(ignore (eshell-add-glob-modifier))
(let ((here (point)))
(forward-char)
(let* ((delim (char-before))
(end (eshell-find-delimiter
delim (if (eq delim ?\[) ?\] ?\)))))
(if (not end)
(throw 'eshell-incomplete (char-to-string delim))
(if (and (eshell-using-module 'eshell-pred)
(eshell-arg-delimiter (1+ end)))
(ignore (goto-char here))
(eshell-add-glob-modifier)
(prog1
(buffer-substring-no-properties (1- (point)) (1+ end))
(goto-char (1+ end))))))))))
(ignore (eshell-add-glob-modifier))))
(defvar eshell-glob-matches)
(defvar message-shown)

View file

@ -261,8 +261,8 @@ respectively.")
(defun eshell-pred-initialize () ;Called from `eshell-mode' via intern-soft!
"Initialize the predicate/modifier code."
(add-hook 'eshell-parse-argument-hook
#'eshell-parse-arg-modifier t t)
;; Make sure this function runs before `eshell-parse-glob-chars'.
(add-hook 'eshell-parse-argument-hook #'eshell-parse-arg-modifier 50 t)
(eshell-pred-mode))
(defun eshell-apply-modifiers (lst predicates modifiers string-desc)

View file

@ -317,4 +317,15 @@ value of `eshell-glob-splice-results'."
(should (equal (eshell-extended-glob (format "%s~/file.txt" remote))
(format "%s~/file.txt" remote)))))
;; Compatibility tests
(ert-deftest em-glob-test/test-command-without-pred ()
"Test that the \"[\" command works when `eshell-pred' is disabled."
(skip-unless (executable-find "["))
(let ((eshell-modules-list (remq 'eshell-pred eshell-modules-list)))
(with-temp-eshell
(eshell-match-command-output "[ foo = foo ]" "\\`\\'")
(should (= eshell-last-command-status 0)))))
;; em-glob-tests.el ends here