summaryrefslogtreecommitdiff
path: root/lisp/eshell/em-pred.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2022-06-25 20:05:57 -0700
committerLars Ingebrigtsen <larsi@gnus.org>2022-06-26 16:51:21 +0200
commit598d7c5d1c10bfb161cb53aa76d480864414487c (patch)
tree42d650e0476b281145c650dbe095e8e651b60a18 /lisp/eshell/em-pred.el
parentb637d9c0750fde8810058a153d964b6c70e0f577 (diff)
downloademacs-598d7c5d1c10bfb161cb53aa76d480864414487c.tar.gz
Optionally signal an error if an Eshell predicate fails to match anything
* lisp/eshell/em-pred.el (eshell-error-if-no-glob): Declare it. (eshell-apply-modifiers): Add STRING-DESC argument and signal an error if there are no matches and 'eshell-error-if-no-glob' is set. (eshell-parse-arg-modifier): Pass modifier string to 'eshell-apply-modifiers'. * test/lisp/eshell/em-pred-tests.el (eshell-eval-predicate): Simplify. (em-pred-test/no-matches): New test. * doc/misc/eshell.texi (Bugs and ideas): Remove todo entry about this change.
Diffstat (limited to 'lisp/eshell/em-pred.el')
-rw-r--r--lisp/eshell/em-pred.el18
1 files changed, 13 insertions, 5 deletions
diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el
index d73976d3464..b4ef154f8c3 100644
--- a/lisp/eshell/em-pred.el
+++ b/lisp/eshell/em-pred.el
@@ -233,6 +233,8 @@ Each element is of the form (OPEN . CLOSE), where OPEN and CLOSE
are characters representing the opening and closing delimiter,
respectively.")
+(defvar eshell-error-if-no-glob) ; Defined in em-glob.el.
+
(defvar-keymap eshell-pred-mode-map
"C-c M-q" #'eshell-display-predicate-help
"C-c M-m" #'eshell-display-modifier-help)
@@ -263,14 +265,19 @@ respectively.")
#'eshell-parse-arg-modifier t t)
(eshell-pred-mode))
-(defun eshell-apply-modifiers (lst predicates modifiers)
- "Apply to list LST a series of PREDICATES and MODIFIERS."
+(defun eshell-apply-modifiers (lst predicates modifiers string-desc)
+ "Apply to list LST a series of PREDICATES and MODIFIERS.
+STRING-DESC is the original string defining these predicates and
+modifiers."
(let (stringified)
(if (stringp lst)
(setq lst (list lst)
stringified t))
(when (listp lst)
- (setq lst (eshell-winnow-list lst nil predicates))
+ (when lst
+ (setq lst (or (eshell-winnow-list lst nil predicates)
+ (when eshell-error-if-no-glob
+ (error "No matches found: (%s)" string-desc)))))
(while modifiers
(setq lst (funcall (car modifiers) lst)
modifiers (cdr modifiers)))
@@ -290,7 +297,8 @@ This function is specially for adding onto `eshell-parse-argument-hook'."
(when (eshell-arg-delimiter (1+ end))
(save-restriction
(narrow-to-region (point) end)
- (let* ((modifiers (eshell-parse-modifiers))
+ (let* ((modifier-string (buffer-string))
+ (modifiers (eshell-parse-modifiers))
(preds (car modifiers))
(mods (cdr modifiers)))
(if (or preds mods)
@@ -302,7 +310,7 @@ This function is specially for adding onto `eshell-parse-argument-hook'."
(list
(lambda (lst)
(eshell-apply-modifiers
- lst preds mods))))))))
+ lst preds mods modifier-string))))))))
(goto-char (1+ end))
(eshell-finish-arg))))))