unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Milan Zimmermann <milan.zimmermann@gmail.com>, emacs-devel@gnu.org
Subject: Re: Checking if this is a Eshell bug in emacs 29: Should eshell redirect all output in esh script to stdout
Date: Wed, 23 Nov 2022 12:30:45 -0800	[thread overview]
Message-ID: <82bcaf3d-29a6-c7be-46e9-edafc9c33de1@gmail.com> (raw)
In-Reply-To: <CAEc2VK0h=B6JtcZKC2Smdnn4NBPXMQ=DeHPc_WHM8sefdWB1AQ@mail.gmail.com>

On 11/23/2022 10:56 AM, Milan Zimmermann wrote:
> I would like to check here before reporting an Eshell bug.
> 
> A script named 'redirect-echo.esh' with two echo commands.
> 
> Emacs 29: Sourcing it and redirecting output to a file, results in the 
> first echo string ('hello') showing in eshell, only the second 
> ('there')(presumably because it is last) showing in the output file:
[snip]
>   I believe this is a bug but I am not sure about Eshell's intended 
> features, so I wanted to check first.

This is definitely a bug. I think the best way to fix it though would be 
to first replace 'eshell-do-eval', since it's a bit limited in what Lisp 
forms it can manage correctly.

(Warning: the following is based on my memory of looking at this a few 
months ago, so I might have misremembered some details. If so, sorry 
about that.)

Currently, Eshell manages output handles in a fairly tricky way: many 
internal Eshell forms automatically try to close the handles, so to get 
around this, other Eshell forms increment the handles' refcount so that 
closing just decrements that count instead of actually closing it. 
That's a fine strategy in general, but the increment-refcount 
('eshell-protect') and decrement-refcount-and-close 
('eshell-close-handles') are called very far from each other in the 
code, so the logic gets pretty hard to follow, leading to bugs like this.

I think the best way to fix this would be to put the increment and 
decrement code in the same spot, so that you'd do something like so:

   (unwind-protect
       (progn
         (eshell-protect)
         (do-stuff))
     (eshell-close-handles))

Unfortunately, if 'do-stuff' calls a deferred command[1], Eshell ends up 
evaluating 'eshell-close-handles' immediately, instead of when 
'do-stuff' actually finishes. That means that either a) we'd need to fix 
this without using 'unwind-protect', which would be painful to get 
right, or b) we'd need to make 'unwind-protect' work as expected. (b) is 
effectively bug#57635[2], I think. (That bug suggests using 
generator.el's internals to drive Eshell's iterative evaluation.)

Bug#57635 is a pretty big change too, but I think it would greatly help 
with the overall reliability of Eshell.

[1] Basically, a command that should yield execution back to the rest of 
Emacs while waiting on some background task (e.g. a subprocess).

[2] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57635



  reply	other threads:[~2022-11-23 20:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 18:56 Checking if this is a Eshell bug in emacs 29: Should eshell redirect all output in esh script to stdout Milan Zimmermann
2022-11-23 20:30 ` Jim Porter [this message]
2022-11-23 20:46   ` Milan Zimmermann
2022-11-24  6:20   ` Eli Zaretskii
2022-11-24  6:32     ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82bcaf3d-29a6-c7be-46e9-edafc9c33de1@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=milan.zimmermann@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).