Subject: Re: bug#40896: 27.0.91; Moving point fails sometimes in shell-command

From: Michael Albinus <[email-masked]>
Date: Sat, 02 May 2020 15:12:17 +0200

Eli Zaretskii <[email-masked]> writes:

Hi Eli,

>> In order to understand the situation better, I have enhanced my test
>> code to cover all different values of shell-command-dont-erase-buffer,
>> and whether the OUTPUT-BUFFER argument of shell-command is the current
>> buffer, or not. Here's the code:
>
> AFAIU, the use case of OUTPUT-BUFFER being different from the current
> buffer is meant for the case where subsequent commands accumulate the
> output in that buffer, which is why the output is appended in that
> case.
>
> Does what you see make more sense now?

Almost. But it is not documented. Maybe we shall apply the appended
patch. And if shell-command-dont-erase-buffer is end-last-out with
output buffer not being the current one, the behavior is simply
wrong, see my previous analysis. At least *this* case must be fixed.

Best regards, Michael.

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 47f195d0b2..ca3d52c36a 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -846,6 +846,9 @@ Single Shell
 shell-command output.
 @end table

+In case the output buffer is not the current buffer, shell command
+output is appended at the end of this buffer.
+
 @node Interactive Shell
 @subsection Interactive Subshell

diff --git a/lisp/simple.el b/lisp/simple.el
index ab277c4e11..2f0626d96e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3606,6 +3606,9 @@ shell-command
 interactively when the prefix argument is given), insert the
 output in current buffer after point leaving mark after it.  This
 cannot be done asynchronously.
+If OUTPUT-BUFFER is a buffer or buffer name different from the
+current buffer, append the output in this buffer instead of
+inserting it at point.

 The user option `shell-command-dont-erase-buffer', which see, controls
 whether the output buffer is erased and where to put point after