From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#71554: 29.3; eshell-command async buffer behavior Date: Thu, 20 Jun 2024 07:30:35 +0000 Message-ID: <874j9ogjfo.fsf@posteo.net> References: <87frtfpqyn.fsf@librehacker.com> <87ikyb8igc.fsf@posteo.net> <86tthvwdxp.fsf@gnu.org> <87ed8z8duo.fsf@posteo.net> <87a5jm94b6.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39745"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jim Porter , Eli Zaretskii , 71554@debbugs.gnu.org, christopher@librehacker.com To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 20 09:29:21 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sKCER-000A47-AC for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Jun 2024 09:29:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKCE8-0000lo-DH; Thu, 20 Jun 2024 03:29:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKCE7-0000jz-6h for bug-gnu-emacs@gnu.org; Thu, 20 Jun 2024 03:28:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKCE6-00030P-Ug for bug-gnu-emacs@gnu.org; Thu, 20 Jun 2024 03:28:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sKCE9-0008CV-Nh for bug-gnu-emacs@gnu.org; Thu, 20 Jun 2024 03:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Jun 2024 07:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71554 X-GNU-PR-Package: emacs Original-Received: via spool by 71554-submit@debbugs.gnu.org id=B71554.171886848831427 (code B ref 71554); Thu, 20 Jun 2024 07:29:01 +0000 Original-Received: (at 71554) by debbugs.gnu.org; 20 Jun 2024 07:28:08 +0000 Original-Received: from localhost ([127.0.0.1]:46809 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sKCDH-0008Ao-VY for submit@debbugs.gnu.org; Thu, 20 Jun 2024 03:28:08 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:41595) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sKCDG-0008AP-Ei for 71554@debbugs.gnu.org; Thu, 20 Jun 2024 03:28:07 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 1EF70240101 for <71554@debbugs.gnu.org>; Thu, 20 Jun 2024 09:27:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1718868477; bh=tsfSqlqo7glD8Zb8jKKHM7X8dTQI0ib45edZiykpzhU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: Autocrypt:OpenPGP:From; b=QAFWR8qciHHRx1HQjEGy9+HpvkDqeIXTSkqOvuKxBpWOyz+vZf8qR5vpqUzV7POx2 P/yYll6fvy6XIpJPPAURFNGcsk//KXazjdLCk8EDWyx1l0QAS5aoBO2SXyXFhcCUx3 SK/me9qMg9w9ibSjTnJG/bxGzh68k5gNbKOVc36UWem//B7CG2TrI0MzzKinuSRXXK Gf2jDnzlF+og7gSN679UEbQGx/kAKhWbabkEHxMsn9WBkDeiAcv1MrOBjHxyNZ+oGH mMNFCU83UPDSFb7zHV8PdWFfBRBzNQrggnis0DW1sMuoy9MNBXtS5owsrsHs0omGuz cHQD0oqjy02DQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4W4XBt1WNnz9rxF; Thu, 20 Jun 2024 09:27:49 +0200 (CEST) In-Reply-To: <87a5jm94b6.fsf@posteo.net> (Thierry Volpiatto's message of "Sat, 15 Jun 2024 05:13:17 +0000") Autocrypt: addr=thievol@posteo.net; prefer-encrypt=mutual; keydata=xsDNBF8ylcIBDADG+hy+zR6L4/vbdDDZuSaMmSrU3A5QZJpeBCvxTr7MpzzruZbhLPW1K3R6N2MA edi8Y+C8o27FVRIjpdbaKMGu9je7JV/TbUQYo3SOwCK1vM4LUn4V6ZLzSYkuiEt4eyMoiDdyvN0p kcK6P9x9DCetcEVszXzQg+yzCVrQ2hXWDXWT4M18EC3wtO7RHPouMqGiwBFhBAYErCqFWFxQHkfb tG/4yGyJ58rglb65O3qijjMWvYwcWZun9/7qm8Z4/4mHopmo2zgU+OrptnLSZfkZGz3Y7Uf452xQ GVq0Fv75NPvQru7y+DYVhuVXXyAmGxt+vf4rIiixMBbhKEPjcxEPAa2LTzex2IsTZR+QVG9uDnqC WcgaOEQ58fzXNvNhtwwF/Rgio2XWAJVdmFWS59/k9W58CIUSNKBMZh2XeGdEmtHvDtCxW3z6FJha 36RzOM3fMNNiAGdFZJA84gcdloJR+sHCDTTPT3784fjr+V8An7sI581NGFzkRQqPvEQCZbUAEQEA Ac0SdGhpZXZvbEBwb3N0ZW8ubmV0wsEOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA FiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmL3HCoACgkQDsVtFB0W75OVEAv/f6XxmtIFz08fUb8h Bp/zJP6IC4/rhhh+0GMRIRzLN8DK0jV8JCzYdFHiRJOy2lNIOpmrrCmjRRxferc2G42+ePFIsslx hU46VSz1Z83NwIG3mpdYNV5WUTUdgzxExHTNTFCd7NKv0nlHKQaA OpenPGP: url=https://posteo.de/keys/thievol@posteo.net.asc; preference=encrypt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287533 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Thierry Volpiatto writes: > Jim Porter writes: > >> On 6/14/2024 1:32 PM, Thierry Volpiatto wrote: >>> Because IMO what shell-command is doing is annoying, no need to duplica= te >>> 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 buff= er 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. =2D-=20 Thierry --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Use-async-shell-command-buffer-in-eshell-command-fix.patch Content-Transfer-Encoding: quoted-printable From=204d9d7b3ce5a5370b733ceac9ebebf40987113810 Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto 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. =2D-- 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 =2D-- a/lisp/eshell/eshell.el +++ b/lisp/eshell/eshell.el @@ -216,6 +216,34 @@ named \"*eshell*<2>\"." :type 'string :group 'eshell) =20 +(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)))) =20 +(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 =2Dargument), 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) =2D "*Eshell Async Command Output*" + eshell-command-buffer-name-async (setq intr t) =2D "*Eshell Command Output*"))) =2D (if (buffer-live-p (get-buffer bufname)) =2D (kill-buffer bufname)) =2D (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 =2D-=20 2.34.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHHBAEBCgAxFiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmZz2pwTHHRoaWV2b2xA cG9zdGVvLm5ldAAKCRAOxW0UHRbvk51jC/9lczk1tG7X8qb/fgJowbgGU7v2+8Kn aqe+xmsLjDLhH8L2AfKLHsRxDkDJwZ2HcplRLsWnL3uhR5DbDAZD05Pqk2mFQENj 2nckBvcXfgqwBr1RbqJhKAP7x1wJBFkbXdkbxEQFJC+YSRoxQhgDdTn7+YeQxOC3 0hsM4n0xt+FToGBF5XeYmebTUHND4FdJ1SDdn7r/qscjV7Znb7nSK3/qQyQyMNCJ LKWkRMG4rK3bouGmpySMCvtC1ktft4s/cMrWhxzpUjcZZScDGwWbdD5YIABy8L78 o0DPseEc7Dy+Yzq3fZhq2PzADj5jsbN3c8xEBmPSPVDRup4DlYMnSGTx0ybH+gp9 90w21h7Y0bzgndgO3GNBi0+C49o2U74Q7Px37k6Ve6Ze8bKmm01uuBEQAMDP6hif M0k1qZob9/Lcm7wQtp02FavaUu6WPW/SJSYkKpgGg5RpMPhKKLY9AQCgo7phce4R uXeEWspK+0G9prnDDAfXizeo4qa316gsWuA= =xMcj -----END PGP SIGNATURE----- --==-=-=--