]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Eshell incompatibility with "[" command when eshell-pred is disabled
authorJim Porter <jporterbugs@gmail.com>
Mon, 21 Oct 2024 04:37:55 +0000 (21:37 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Oct 2024 09:52:30 +0000 (10:52 +0100)
* 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.

(cherry picked from commit 523aade3ea11c188e30e3889f031d1848129cf82)

lisp/eshell/em-glob.el
lisp/eshell/em-pred.el
test/lisp/eshell/em-glob-tests.el

index 56b6cd3fae75e34bd0579c36519250bdee34a87c..40f08cb875ae48e8a1cc07a50f1cf285e41b07fa 100644 (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)
index 0fa1cfb256b234e54b90578b08810c48c8259c95..9618df055e26095e08d20eb03786e9c0e0748dc4 100644 (file)
@@ -166,8 +166,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)
index 88e9cc73bbd5499e591bf42c3cf01b9384496582..239968917abc070014db2c36b836d4cfb66f8ddc 100644 (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
+\f
+
+(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