summaryrefslogtreecommitdiff
path: root/lisp/eshell/em-extpipe.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/eshell/em-extpipe.el')
-rw-r--r--lisp/eshell/em-extpipe.el22
1 files changed, 18 insertions, 4 deletions
diff --git a/lisp/eshell/em-extpipe.el b/lisp/eshell/em-extpipe.el
index eb5b3bfe1df..3db1dea5955 100644
--- a/lisp/eshell/em-extpipe.el
+++ b/lisp/eshell/em-extpipe.el
@@ -49,6 +49,19 @@
(add-hook 'eshell-pre-rewrite-command-hook
#'eshell-rewrite-external-pipeline -20 t))
+(defmacro em-extpipe--or-with-catch (&rest disjuncts)
+ "Evaluate DISJUNCTS like `or' but catch `eshell-incomplete'.
+
+If `eshell-incomplete' is thrown during the evaluation of a
+disjunct, that disjunct yields nil."
+ (let ((result (gensym)))
+ `(let (,result)
+ (or ,@(cl-loop for disjunct in disjuncts collect
+ `(if (catch 'eshell-incomplete
+ (ignore (setq ,result ,disjunct)))
+ nil
+ ,result))))))
+
(defun eshell-parse-external-pipeline ()
"Parse a pipeline intended for execution by the external shell.
@@ -105,10 +118,11 @@ as though it were Eshell syntax."
(if (re-search-forward pat next t)
(throw 'found (match-beginning 1))
(goto-char next)
- (while (or (eshell-parse-lisp-argument)
- (eshell-parse-backslash)
- (eshell-parse-double-quote)
- (eshell-parse-literal-quote)))
+ (while (em-extpipe--or-with-catch
+ (eshell-parse-lisp-argument)
+ (eshell-parse-backslash)
+ (eshell-parse-double-quote)
+ (eshell-parse-literal-quote)))
;; Guard against an infinite loop if none of
;; the parsers moved us forward.
(unless (or (> (point) next) (eobp))