Subject: bug#54136: 29.0.50; Eshell emits extra prompts when killing processes in some cases

From: Jim Porter <[email-masked]>
Date: Wed, 23 Feb 2022 21:11:41 -0800

(Patch forthcoming; I'm just getting a bug number first...)

Sometimes, when killing processes in Eshell (especially in pipelines), 
Eshell will emit *two* prompts instead of one. Starting with "emacs -Q 
--eval '(eshell)'...

Problem #1: Killing pipelines
-----------------------------

   ~ $ sh -c 'while true; do echo y; sleep 1; done' | sh -c 'while true; 
do read NAME; done'
   C-c C-c  ; or C-c C-k

The result is ("|" is the point):

   interrupted
   ~ $
   ~ $ |

What's happening here is one prompt is being emitted per process in the 
pipeline. It should only emit one prompt total.

Problem #2: Killing the head of a pipeline
------------------------------------------

   ~ $ sh -c 'while true; do sleep 1; done' | sh -c 'while read NAME; do 
echo =${NAME}=; done'
   M-: (kill-process (eshell-head-process)) RET

The result is:

   ~ $ =killed=
   |

In this case, Eshell writes the head process's exit status message to 
its stdout handle (i.e. to the tail process's stdin). It should either 
write directly to the terminal, or not write at all. I went with the 
latter, since the former would mean that we write "interrupted" N times 
in problem #1 above.

Problem #3: Killing a background process
----------------------------------------

    ~ $ sh -c 'while true; do sleep 1; done' &

This outputs, as expected:

   [sh] 12345
   ~ $

Now call `(kill-process (caar eshell-process-list))'. The result is:

   ~ $ killed
   ~ $ |

Here, Eshell writes the exit status to the terminal, but does so in an 
awkward spot, and then emits a new prompt. I think it should just avoid 
printing anything here. Information about the killed process is also 
shown in the minibuffer, so the user already has a place (and a better 
one at that!) to see what happened.