Subject: bug#63432: closed (Re: bug#63432: 30.0.50; Handle current-prefix-arg in async-shell-command)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 14 May 2023 06:29:02 +0000

Your bug report

#63432: 30.0.50; Handle current-prefix-arg in async-shell-command

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
63432: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63432
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#63432: 30.0.50; Handle current-prefix-arg in async-shell-command
From: Eli Zaretskii <[email-masked]>
To: Gabriel <[email-masked]>
Cc: [email-masked]
Date: Sun, 14 May 2023 09:28:34 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Gabriel <[email-masked]>
> Date: Sat, 13 May 2023 20:35:51 -0300
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Thanks, but I don't understand why we need the error message.  Isn't
> > it enough to pass nil as 2nd argument to shell-command?
> 
> The error message is just for noninteractive cases where a caller passes
> a numeric argument as the second argument of `async-shell-command'.

I think the error signaled by shell-command is sufficient in the
non-interactive case.  We don't usually try detecting
wrong-type-argument errors in non-interactive use, we leave it to the
underlying primitives to detect and report.

> Example:
>     Before patch:
>         (async-shell-command "ls" 1) => error: (wrong-type-argument stringp 1)
>     After patch:
>         (async-shell-command "ls" 1) => error: (error "Invalid output buffer")

I see nothing wrong with the "before" version, it gives an accurate
description of the problem for that case.

> Here is a patch without the error message, in case it's preferable:

Thanks, installed on the emacs-29 branch, and closing the bug.

Subject: 30.0.50; Handle current-prefix-arg in async-shell-command
From: Gabriel <[email-masked]>
To: [email-masked]
Date: Wed, 10 May 2023 20:04:24 -0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Severity: bug

Steps:
1) emacs -Q from master branch (3adc1e7f379)
2) C-u M-& "ls"
   Error: shell-command: Wrong type argument: stringp, (4)

Cause:
When called interactively, `async-shell-command' pass argument
OUTPUT-BUFFER as `current-prefix-arg' to `shell-command'.  As per
docstring of `shell-command':

  "If OUTPUT-BUFFER is not a buffer and not nil (which happens
  interactively when the prefix argument is given), insert the output in
  current buffer after point leaving mark after it.  This cannot be done
  asynchronously."

Patch:
>From 8016742cfd1d59cf3082afeb1cf77b9a12b9b251 Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <[email-masked]>
Date: Wed, 10 May 2023 19:41:05 -0300
Subject: [PATCH 1/1] Handle current-prefix-arg in async-shell-command.

* lisp/simple.el (async-shell-command): Properly handle
  current-prefix-arg.  When called interactively, defaults to nil,
  otherwise, check if it's not a number before passing to
  `shell-command'.
---
 lisp/simple.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 58517dd81f9..ba832581955 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -4499,10 +4499,12 @@ async-shell-command
 				((eq major-mode 'dired-mode)
 				 (dired-get-filename nil t)))))
 			  (and filename (file-relative-name filename))))
-    current-prefix-arg
+    nil
     shell-command-default-error-buffer))
   (unless (string-match "&[ \t]*\\'" command)
     (setq command (concat command " &")))
+  (when (and output-buffer (numberp output-buffer))
+    (error "Invalid output buffer"))
   (shell-command command output-buffer error-buffer))
 
 (declare-function comint-output-filter "comint" (process string))
-- 
2.34.1

---
Gabriel