]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure that tailproc is set for the last process in an Eshell pipeline
authorJim Porter <jporterbugs@gmail.com>
Fri, 28 Jan 2022 07:13:36 +0000 (23:13 -0800)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 3 Feb 2022 19:02:20 +0000 (20:02 +0100)
In particular, this used to fail for pipelines where the last process
in the pipeline came from the first element of the pipeline. This
could happen when a process was piped to an ordinary Lisp function,
like in '*echo hi | echo bye'.

* lisp/eshell/esh-cmd.el (eshell-do-pipelines): Set the tailproc even
for the first process in the pipeline.

* test/lisp/eshell/eshell-tests.el (eshell-test/pipe-tailproc): New
test.

lisp/eshell/esh-cmd.el
test/lisp/eshell/eshell-tests.el

index 04d65df4f331593593cae8aa1b48d85e30c39662..14139896dd453247a32df12735ed6fd5241419bb 100644 (file)
@@ -764,8 +764,7 @@ This macro calls itself recursively, with NOTFIRST non-nil."
               (eshell-set-output-handle ,eshell-output-handle
                                         'append nextproc)
               (eshell-set-output-handle ,eshell-error-handle
-                                        'append nextproc)
-              (setq tailproc (or tailproc nextproc))))
+                                        'append nextproc)))
        ,(let ((head (car pipeline)))
           (if (memq (car head) '(let progn))
               (setq head (car (last head))))
@@ -781,7 +780,9 @@ This macro calls itself recursively, with NOTFIRST non-nil."
               ,(cond ((not notfirst) (quote 'first))
                      ((cdr pipeline) t)
                      (t (quote 'last)))))
-         ,(car pipeline))))))
+          (let ((proc ,(car pipeline)))
+            (setq tailproc (or tailproc proc))
+            proc))))))
 
 (defmacro eshell-do-pipelines-synchronously (pipeline)
   "Execute the commands in PIPELINE in sequence synchronously.
index 542815df80963546c964441551e56c26dfd315b0..7658d5f5517e8a6a5595c69b8349df2c5964cba6 100644 (file)
@@ -129,6 +129,13 @@ e.g. \"{(+ 1 2)} 3\" => 3"
    (eshell-command-result-p "echo ${echo hi}-${*echo there}"
                             "hi-there\n")))
 
+(ert-deftest eshell-test/pipe-tailproc ()
+  "Check that piping a process to a non-process command waits for the process"
+  (skip-unless (executable-find "echo"))
+  (with-temp-eshell
+   (eshell-command-result-p "*echo hi | echo bye"
+                            "bye\nhi\n")))
+
 (ert-deftest eshell-test/window-height ()
   "$LINES should equal (window-height)"
   (should (eshell-test-command-result "= $LINES (window-height)")))