unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55620: 29.0.50; Eshell doesn't reset `eshell-in-pipeline-p' in subcommands
@ 2022-05-25  2:20 Jim Porter
  2022-05-25  3:37 ` bug#55620: [PATCH] " Jim Porter
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Porter @ 2022-05-25  2:20 UTC (permalink / raw)
  To: 55620

 From `emacs -Q -f eshell':

   ~ $ echo $eshell-in-pipeline-p
   ;; no output
   ~ $ echo ${echo $eshell-in-pipeline-p}
   ;; no output
   ~ $ echo ${echo $eshell-in-pipeline-p} | cat
   first

(Note: in the first two cases, `eshell-in-pipeline-p' is nil, so there's 
no output.) The last case is surprising: it's true that the inner `echo' 
invocation is in a pipeline, but the pipeline is a level above it 
(`first' means that when `eshell-in-pipeline-p' was evaluated, it was 
the first command in a pipeline). Since the inner `echo' is effectively 
in a subshell, it makes more sense for the value of 
`eshell-in-pipeline-p' to be nil for the last case.

While this is a seemingly-obscure issue, there is one practical effect 
that might bite users: currently, the Eshell implementation of `cat' 
only works when *not* in a pipeline. Usually, it'll just fall back to 
using the real system `cat' program if the Eshell version doesn't work, 
but on systems without `cat' (e.g. MS Windows), you get the following error:

   ~ $ echo ${cat file.txt} | echo
   Eshell’s ‘cat’ does not work in pipelines

Patch forthcoming momentarily; just getting a bug number...





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#55620: [PATCH] 29.0.50; Eshell doesn't reset `eshell-in-pipeline-p' in subcommands
  2022-05-25  2:20 bug#55620: 29.0.50; Eshell doesn't reset `eshell-in-pipeline-p' in subcommands Jim Porter
@ 2022-05-25  3:37 ` Jim Porter
  2022-05-25 12:13   ` bug#55620: " Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Porter @ 2022-05-25  3:37 UTC (permalink / raw)
  To: 55620

[-- Attachment #1: Type: text/plain, Size: 721 bytes --]

(Originally mis-sent with the wrong email address.)

Attached is a patch with tests to fix this. Note that I reset 
`eshell-in-pipeline-p' in two places:

1. `eshell-subcommand-bindings': This handles any case where a 
subcommand is invoked. This can happen with the following syntaxes: 
{CMD}, ${CMD}, and $<CMD>.

2. `eshell-command-to-value': This handles cases where a command is run 
synchronously. This can happen with some of the syntaxes mentioned 
above: {CMD} and ${CMD}. However, it can also happen for Lisp forms like 
(LISP) and $(LISP). (Most Lisp forms aren't likely to consult 
`eshell-in-pipeline-p', but if you were calling an Eshell built-in 
command using Lisp syntax, you might run into this issue.)

[-- Attachment #2: 0001-Reset-eshell-in-pipeline-p-when-interpolating-comman.patch --]
[-- Type: text/plain, Size: 3340 bytes --]

From 3a18199fcc8919220892c25c64970c7343c9e63f Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Tue, 24 May 2022 18:56:50 -0700
Subject: [PATCH] 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).
---
 lisp/eshell/esh-cmd.el           |  4 +++-
 test/lisp/eshell/eshell-tests.el | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 73c250632c..775e4c1057 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -256,6 +256,7 @@ eshell-deferrable-commands
 
 (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 @@ eshell-do-command-to-value
 (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 c0affed80a..ab5d73d479 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -130,6 +130,35 @@ eshell-test/pipe-subcommand-with-pipe
    (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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#55620: 29.0.50; Eshell doesn't reset `eshell-in-pipeline-p' in subcommands
  2022-05-25  3:37 ` bug#55620: [PATCH] " Jim Porter
@ 2022-05-25 12:13   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-25 12:13 UTC (permalink / raw)
  To: Jim Porter; +Cc: 55620

Jim Porter <jporterbugs@gmail.com> writes:

> Attached is a patch with tests to fix this. Note that I reset
> `eshell-in-pipeline-p' in two places:

Thanks; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-25 12:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25  2:20 bug#55620: 29.0.50; Eshell doesn't reset `eshell-in-pipeline-p' in subcommands Jim Porter
2022-05-25  3:37 ` bug#55620: [PATCH] " Jim Porter
2022-05-25 12:13   ` bug#55620: " Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).