From: Jim Porter Date: Wed, 25 May 2022 01:56:50 +0000 (-0700) Subject: Reset 'eshell-in-pipeline-p' when interpolating commands X-Git-Tag: emacs-29.0.90~1910^2~432 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0a79e28891ec7394547358207a8213a7c457a592;p=emacs.git Reset 'eshell-in-pipeline-p' when interpolating commands * lisp/eshell/esh-cmd.el (eshell-subcommand-bindings) (eshell-command-to-value): Set 'eshell-in-pipeline-p' to nil. * test/lisp/eshell/eshell-tests.el (eshell-test/subcommand-reset-in-pipeline) (eshell-test/lisp-reset-in-pipeline): New tests (bug#55620). --- diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 73c250632ce..775e4c1057e 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -256,6 +256,7 @@ the command." (defcustom eshell-subcommand-bindings '((eshell-in-subcommand-p t) + (eshell-in-pipeline-p nil) (default-directory default-directory) (process-environment (eshell-copy-environment))) "A list of `let' bindings for subcommand environments." @@ -907,7 +908,8 @@ This avoids the need to use `let*'." (defmacro eshell-command-to-value (object) "Run OBJECT synchronously, returning its result as a string. Returns a string comprising the output from the command." - `(let ((value (make-symbol "eshell-temp"))) + `(let ((value (make-symbol "eshell-temp")) + (eshell-in-pipeline-p nil)) (eshell-do-command-to-value ,object))) ;;;_* Iterative evaluation diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index c0affed80aa..ab5d73d4792 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -130,6 +130,35 @@ e.g. \"{(+ 1 2)} 3\" => 3" (eshell-command-result-p "echo ${*echo hi | *cat} | *cat" "hi"))) +(ert-deftest eshell-test/subcommand-reset-in-pipeline () + "Check that subcommands reset `eshell-in-pipeline-p'." + (skip-unless (executable-find "cat")) + (dolist (template '("echo {%s} | *cat" + "echo ${%s} | *cat" + "*cat $<%s> | *cat")) + (should (equal (eshell-test-command-result + (format template "echo $eshell-in-pipeline-p")) + nil)) + (should (equal (eshell-test-command-result + (format template "echo | echo $eshell-in-pipeline-p")) + "last")) + (should (equal (eshell-test-command-result + (format template "echo $eshell-in-pipeline-p | echo")) + "first")) + (should (equal (eshell-test-command-result + (format template + "echo | echo $eshell-in-pipeline-p | echo")) + "t")))) + +(ert-deftest eshell-test/lisp-reset-in-pipeline () + "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'." + (skip-unless (executable-find "cat")) + (dolist (template '("echo (%s) | *cat" + "echo $(%s) | *cat")) + (should (equal (eshell-test-command-result + (format template "format \"%s\" eshell-in-pipeline-p")) + "nil")))) + (ert-deftest eshell-test/redirect-buffer () "Check that piping to a buffer works" (with-temp-buffer