]> git.eshelyaron.com Git - emacs.git/commitdiff
Reset 'eshell-in-pipeline-p' when interpolating commands
authorJim Porter <jporterbugs@gmail.com>
Wed, 25 May 2022 01:56:50 +0000 (18:56 -0700)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 25 May 2022 12:13:07 +0000 (14:13 +0200)
* 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).

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

index 73c250632ce4799fb8f1279cedecb2116b0c71cf..775e4c1057ee7d755429e78de3dfa136432de8af 100644 (file)
@@ -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
index c0affed80aa7f3f2ea09ef8d9c3d9beb0e03c642..ab5d73d4792f569d43ca204d06b6f816680d2bc7 100644 (file)
@@ -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