From: Thierry Volpiatto <thievol@posteo.net>
To: Thierry Volpiatto <thievol@posteo.net>
Cc: Jim Porter <jporterbugs@gmail.com>, Eli Zaretskii <eliz@gnu.org>,
71554@debbugs.gnu.org, christopher@librehacker.com
Subject: bug#71554: 29.3; eshell-command async buffer behavior
Date: Thu, 20 Jun 2024 07:30:35 +0000 [thread overview]
Message-ID: <874j9ogjfo.fsf@posteo.net> (raw)
In-Reply-To: <87a5jm94b6.fsf@posteo.net> (Thierry Volpiatto's message of "Sat, 15 Jun 2024 05:13:17 +0000")
[-- Attachment #1.1: Type: text/plain, Size: 2430 bytes --]
Thierry Volpiatto <thievol@posteo.net> writes:
> Jim Porter <jporterbugs@gmail.com> writes:
>
>> On 6/14/2024 1:32 PM, Thierry Volpiatto wrote:
>>> Because IMO what shell-command is doing is annoying, no need to duplicate
>>> this annoyance, after all when running such a command in a terminal
>>> already running a detached process, nothing is asked, so why doing this
>>> in emacs?
>>> Or at least make it optional?
>>
>> 'shell-command' has several possible options for this behavior. See
>> 'async-shell-command-buffer'.
>
> Ah, didn't know this one, thanks.
> What about something like this reusing async-shell-command-buffer (not
> fully tested)?
>
> diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
> index 18e05a371a4..774f25d71b0 100644
> --- a/lisp/eshell/eshell.el
> +++ b/lisp/eshell/eshell.el
> @@ -302,13 +302,25 @@ argument), then insert output into the current buffer at point."
> ,(eshell-parse-command command))
> command))
> intr
> + unique
> (bufname (if (eq (car-safe proc) :eshell-background)
> "*Eshell Async Command Output*"
> (setq intr t)
> "*Eshell Command Output*")))
> - (if (buffer-live-p (get-buffer bufname))
> - (kill-buffer bufname))
> - (rename-buffer bufname)
> + (when (buffer-live-p (get-buffer bufname))
> + (pcase async-shell-command-buffer
> + ('confirm-kill-process
> + (shell-command--same-buffer-confirm "Kill it")
> + (kill-buffer bufname))
> + ('confirm-new-buffer
> + (shell-command--same-buffer-confirm "Use a new buffer")
> + (setq unique t))
> + ('new-buffer (setq unique t))
> + ('confirm-rename-buffer
> + (shell-command--same-buffer-confirm "Rename it")
> + (kill-buffer bufname))
> + ('rename-buffer (kill-buffer bufname))))
> + (rename-buffer bufname unique)
> ;; things get a little coarse here, since the desire is to
> ;; make the output as attractive as possible, with no
> ;; extraneous newlines
This patch doesn't work if user kill for some reason the initial process
buffer, we have to check if other buffers are alive. Also having a new
variable eshell-command-async-buffer instead of reusing
async-shell-command-buffer is better IMO.
Here a patch that fix these issues.
--
Thierry
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Use-async-shell-command-buffer-in-eshell-command-fix.patch --]
[-- Type: text/x-diff, Size: 4962 bytes --]
From 4d9d7b3ce5a5370b733ceac9ebebf40987113810 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thievol@posteo.net>
Date: Wed, 19 Jun 2024 12:02:59 +0200
Subject: [PATCH] Use async-shell-command-buffer in eshell-command fix
bug#71554
* lisp/eshell/eshell.el (eshell-command): Allow using multiple buffers.
(eshell-command-async-buffer): New user var.
---
lisp/eshell/eshell.el | 66 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 60 insertions(+), 6 deletions(-)
diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
index 18e05a371a4..c84b450956a 100644
--- a/lisp/eshell/eshell.el
+++ b/lisp/eshell/eshell.el
@@ -216,6 +216,34 @@ named \"*eshell*<2>\"."
:type 'string
:group 'eshell)
+(defcustom eshell-command-async-buffer 'new-buffer
+ "What to do when the output buffer is used by another shell command.
+This option specifies how to resolve the conflict where a new command
+wants to direct its output to the buffer whose name is stored
+in `eshell-command-buffer-name-async', but that buffer is already
+taken by another running shell command.
+
+The value `confirm-kill-process' is used to ask for confirmation before
+killing the already running process and running a new process
+in the same buffer, `confirm-new-buffer' for confirmation before running
+the command in a new buffer with a name other than the default buffer name,
+`new-buffer' for doing the same without confirmation,
+`confirm-rename-buffer' for confirmation before renaming the existing
+output buffer and running a new command in the default buffer,
+`rename-buffer' for doing the same without confirmation."
+ :type '(choice (const :tag "Confirm killing of running command"
+ confirm-kill-process)
+ (const :tag "Confirm creation of a new buffer"
+ confirm-new-buffer)
+ (const :tag "Create a new buffer"
+ new-buffer)
+ (const :tag "Confirm renaming of existing buffer"
+ confirm-rename-buffer)
+ (const :tag "Rename the existing buffer"
+ rename-buffer))
+ :group 'shell
+ :version "30.1")
+
;;;_* Running Eshell
;;
;; There are only three commands used to invoke Eshell. The first two
@@ -283,11 +311,18 @@ information on Eshell, see Info node `(eshell)Top'."
(eshell-command-mode +1))
(read-from-minibuffer prompt))))
+(defvar eshell-command-buffer-name-async "*Eshell Async Command Output*")
+(defvar eshell-command-buffer-name-sync "*Eshell Command Output*")
;;;###autoload
(defun eshell-command (command &optional to-current-buffer)
"Execute the Eshell command string COMMAND.
If TO-CURRENT-BUFFER is non-nil (interactively, with the prefix
-argument), then insert output into the current buffer at point."
+argument), then insert output into the current buffer at point.
+
+When \"&\" is added at end of command, the command is async and its output
+appears in a specific buffer. You can customize
+`eshell-command-async-buffer' to specify what to do when this output
+buffer is already taken by another running shell command."
(interactive (list (eshell-read-command)
current-prefix-arg))
(save-excursion
@@ -302,13 +337,32 @@ argument), then insert output into the current buffer at point."
,(eshell-parse-command command))
command))
intr
+ unique
(bufname (if (eq (car-safe proc) :eshell-background)
- "*Eshell Async Command Output*"
+ eshell-command-buffer-name-async
(setq intr t)
- "*Eshell Command Output*")))
- (if (buffer-live-p (get-buffer bufname))
- (kill-buffer bufname))
- (rename-buffer bufname)
+ eshell-command-buffer-name-sync)))
+ (when (or (buffer-live-p (get-buffer bufname))
+ (cl-loop for buf in (buffer-list)
+ thereis (and (string-match-p
+ (regexp-quote
+ (substring
+ bufname 0 (1- (length bufname))))
+ (buffer-name buf))
+ (buffer-live-p buf))))
+ (pcase eshell-command-async-buffer
+ ('confirm-kill-process
+ (shell-command--same-buffer-confirm "Kill it")
+ (kill-buffer bufname))
+ ('confirm-new-buffer
+ (shell-command--same-buffer-confirm "Use a new buffer")
+ (setq unique t))
+ ('new-buffer (setq unique t))
+ ('confirm-rename-buffer
+ (shell-command--same-buffer-confirm "Rename it")
+ (kill-buffer bufname))
+ ('rename-buffer (kill-buffer bufname))))
+ (rename-buffer bufname unique)
;; things get a little coarse here, since the desire is to
;; make the output as attractive as possible, with no
;; extraneous newlines
--
2.34.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]
next prev parent reply other threads:[~2024-06-20 7:30 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 13:57 bug#71554: 29.3; eshell-command async buffer behavior Christopher Howard
2024-06-14 18:53 ` Thierry Volpiatto
2024-06-14 18:56 ` Eli Zaretskii
2024-06-14 20:32 ` Thierry Volpiatto
2024-06-14 22:49 ` Jim Porter
2024-06-15 5:13 ` Thierry Volpiatto
2024-06-20 7:30 ` Thierry Volpiatto [this message]
2024-06-24 5:36 ` Jim Porter
2024-06-24 6:23 ` Thierry Volpiatto
2024-06-24 12:33 ` Eli Zaretskii
2024-07-05 4:09 ` Thierry Volpiatto
2024-07-05 5:46 ` Eli Zaretskii
2024-07-05 6:24 ` Thierry Volpiatto
2024-07-05 11:11 ` Eli Zaretskii
2024-07-05 12:21 ` Thierry Volpiatto
2024-07-05 14:34 ` Thierry Volpiatto
2024-07-05 17:41 ` Jim Porter
2024-07-05 18:44 ` Thierry Volpiatto
2024-07-05 20:23 ` Jim Porter
2024-07-06 2:48 ` Jim Porter
2024-07-06 3:34 ` Thierry Volpiatto
2024-07-06 4:12 ` Thierry Volpiatto
2024-07-06 5:28 ` Jim Porter
2024-07-06 6:10 ` Thierry Volpiatto
2024-06-24 14:15 ` Christopher Howard
2024-07-06 15:13 ` Christopher Howard
2024-07-06 17:06 ` Thierry Volpiatto
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874j9ogjfo.fsf@posteo.net \
--to=thievol@posteo.net \
--cc=71554@debbugs.gnu.org \
--cc=christopher@librehacker.com \
--cc=eliz@gnu.org \
--cc=jporterbugs@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.