GNU bug report logs - #79067
31.0.50; Cannot async-shell-command anymore

Previous Next

Package: emacs;

Reported by: Manuel Giraud <manuel <at> ledu-giraud.fr>

Date: Mon, 21 Jul 2025 08:32:01 UTC

Severity: normal

Found in version 31.0.50

Full log


Message #11 received at 79067 <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Manuel Giraud <manuel <at> ledu-giraud.fr>
Cc: 79067 <at> debbugs.gnu.org
Subject: Re: bug#79067: 31.0.50; Cannot async-shell-command anymore
Date: Mon, 21 Jul 2025 12:27:38 +0200
[Message part 1 (text/plain, inline)]
On Mon, 21 Jul 2025 11:51:38 +0200 Manuel Giraud <manuel <at> ledu-giraud.fr> wrote:

> Manuel Giraud <manuel <at> ledu-giraud.fr> writes:
>
>> Hi,
>>
>>From a current build, I can't call `async-shell-command' anymore.  Here
>> is my recipe:
>>
>>   - emacs -Q
>>   - M-& ls <RET>
>>
>> I get the following error:
>>
>> shell-command: Asynchronous shell commands cannot output to current
>> buffer
>
> I'm not quite sure about the logic at play here but the following patch
> fixes my issue:
>
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 88886de05c4..f7f059793ca 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -4715,7 +4715,8 @@ shell-command
>  	;; Output goes in a separate buffer.
>  	(if (string-match "[ \t]*&[ \t]*\\'" command)
>  	    ;; Command ending with ampersand means asynchronous.
> -            (let* ((_ (or (bufferp output-buffer)
> +            (let* ((_ (or (null output-buffer)
> +                          (bufferp output-buffer)
>                            (stringp output-buffer)
>                            (error "Asynchronous shell commands cannot output to current buffer")))
>                     (buffer (get-buffer-create

The commit message of 852009b4f1c9, which added the bufferp and stringp
checks and the error message, says 'Improve error message for "C-u M-!
something &"'.  An alternative is to ignore the prefix argument when the
command is asynchronous, just like `async-shell-command' ignores the
prefix argument:

[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/simple.el b/lisp/simple.el
index 88886de05c4..c64d3e5285b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -4715,9 +4715,12 @@ shell-command
 	;; Output goes in a separate buffer.
 	(if (string-match "[ \t]*&[ \t]*\\'" command)
 	    ;; Command ending with ampersand means asynchronous.
-            (let* ((_ (or (bufferp output-buffer)
-                          (stringp output-buffer)
-                          (error "Asynchronous shell commands cannot output to current buffer")))
+            (let* ((output-buffer (unless (consp output-buffer)
+                                    ;; Output of asynchronous commands
+                                    ;; cannot be inserted into current
+                                    ;; buffer, so if OUTPUT-BUFFER is a
+                                    ;; prefix argument, ignore it.
+                                    output-buffer))
                    (buffer (get-buffer-create
                             (or output-buffer shell-command-buffer-name-async)))
                    (bname (buffer-name buffer))
[Message part 3 (text/plain, inline)]
Steve Berman

This bug report was last modified 6 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.