unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: Eli Zaretskii <eliz@gnu.org>, 71049@debbugs.gnu.org
Subject: bug#71049: async-shell-command ends with "Process *Async Shell Command* finished" when remote "direct-async-process"
Date: Fri, 31 May 2024 03:24:49 +0300	[thread overview]
Message-ID: <9685d486-46fe-4947-8bb2-fb436f09048b@gutov.dev> (raw)
In-Reply-To: <87jzjbr8ek.fsf@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]

Hi Michael,

On 30/05/2024 11:49, Michael Albinus wrote:

>> Thank you. I haven't tested this personally either, but it seems like
>> this is the behavior we will want by default.
>>
>> So the proposed solution should include it, I think.
> In order to not misunderstand: you agree the solution based on
> tramp-histfile-override now, don't you?

Just to be frank: I don't like the approach, but I do think it's better 
than the status quo. In that sense, I agree with it, if none other is 
accepted.

But, well, in the meantime I came up with a couple of new solutions:

1) [first patch] We can add a new major mode, for 'M-&' to use instead 
of the full-blown 'shell-mode' - it could be very simple: just apply 
font-lock keywords and maybe set list-buffers-directory.

Problems? I suppose someone might be using shell-mode-hook to do 
something in the async-shell-command output buffer, and it won't fire 
anymore. Seemingly very minor concern.

2) [second patch] async-shell-command could set shell--start-prog (it's 
permanent-local) to `none', and then shell-mode will check for that 
value, and if set to this value, skip the input ring setup.

Downsides? Pretty ad-hoc approach. And any external code looking up this 
(private) variable could be surprised by the new value.

[-- Attachment #2: shell-command-mode.diff --]
[-- Type: text/x-patch, Size: 2105 bytes --]

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 9385b023392..f0c64a7a90f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -5247,8 +5247,8 @@ tramp-handle-shell-command
 	      ;; Display output.
 	      (with-current-buffer output-buffer
 		(setq mode-line-process '(":%s"))
-		(unless (eq major-mode 'shell-mode)
-		  (shell-mode))
+		(unless (eq major-mode 'shell-command-mode)
+		  (shell-command-mode))
 		(set-process-filter p #'comint-output-filter)
 		(set-process-sentinel p #'shell-command-sentinel)
 		(when error-file
diff --git a/lisp/shell.el b/lisp/shell.el
index e6b315ee5c0..7fa84a37e83 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -838,6 +838,13 @@ shell-write-history-on-exit
       (with-current-buffer buf
         (insert (format "\nProcess %s %s\n" process event))))))
 
+(define-derived-mode shell-command-mode comint-mode "Shell"
+  "Major mode for the output of `async-shell-command'."
+  (setq-local font-lock-defaults '(shell-font-lock-keywords t))
+  ;; See comments in `shell-mode'.
+  (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
+  (setq list-buffers-directory (expand-file-name default-directory)))
+
 ;;;###autoload
 (defun shell (&optional buffer file-name)
   "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*').
diff --git a/lisp/simple.el b/lisp/simple.el
index ae8a824cb54..8618427f5c0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -31,7 +31,7 @@
 (eval-when-compile (require 'cl-lib))
 
 (declare-function widget-convert "wid-edit" (type &rest args))
-(declare-function shell-mode "shell" ())
+(declare-function shell-command-mode "shell" ())
 
 ;;; From compile.el
 (defvar compilation-current-error)
@@ -4721,7 +4721,7 @@ shell-command
 		  (setq proc
 			(start-process-shell-command "Shell" buffer command)))
 		(setq mode-line-process '(":%s"))
-                (shell-mode)
+                (shell-command-mode)
                 (setq-local revert-buffer-function
                             (lambda (&rest _)
                               (async-shell-command command buffer)))

[-- Attachment #3: shell-start-prog-none.diff --]
[-- Type: text/x-patch, Size: 1763 bytes --]

diff --git a/lisp/shell.el b/lisp/shell.el
index e6b315ee5c0..07038832437 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -702,7 +702,7 @@ shell-mode
   (add-hook 'comint-indirect-setup-hook
             #'shell-indirect-setup-hook 'append t)
   (setq comint-indirect-setup-function
-        (let ((shell shell--start-prog))
+        (let ((shell (and (stringp shell--start-prog) shell--start-prog)))
           (lambda ()
             (require 'sh-script)
             (cl-letf
@@ -720,7 +720,8 @@ shell-mode
   ;; edit this directory.  But it is useful in the buffer list and menus.
   (setq list-buffers-directory (expand-file-name default-directory))
   ;; shell-dependent assignments.
-  (when (ring-empty-p comint-input-ring)
+  (when (and (ring-empty-p comint-input-ring)
+             (not (eq shell--start-prog 'none)))
     (let ((remote (file-remote-p default-directory))
           (shell (or shell--start-prog ""))
           (hsize (getenv "HISTSIZE"))
diff --git a/lisp/simple.el b/lisp/simple.el
index ae8a824cb54..9074f564ca1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -4621,6 +4621,7 @@ shell-command
 			  (and filename (file-relative-name filename))))
     current-prefix-arg
     shell-command-default-error-buffer))
+  (defvar shell--start-prog)
   ;; Look for a handler in case default-directory is a remote file name.
   (let ((handler
 	 (find-file-name-handler (directory-file-name default-directory)
@@ -4721,6 +4722,7 @@ shell-command
 		  (setq proc
 			(start-process-shell-command "Shell" buffer command)))
 		(setq mode-line-process '(":%s"))
+                (setq shell--start-prog 'none)
                 (shell-mode)
                 (setq-local revert-buffer-function
                             (lambda (&rest _)

  reply	other threads:[~2024-05-31  0:24 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-19  0:19 bug#71049: async-shell-command ends with "Process *Async Shell Command* finished" when remote "direct-async-process" Dmitry Gutov
2024-05-19  6:17 ` Eli Zaretskii
2024-05-19 12:40   ` Dmitry Gutov
2024-05-24 11:15 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 14:06   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 14:50     ` Eli Zaretskii
2024-05-24 16:39       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 18:55         ` Eli Zaretskii
2024-05-24 19:20           ` Dmitry Gutov
2024-05-25 10:49             ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-25 13:54               ` Dmitry Gutov
2024-05-25 15:51                 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-25 16:17                   ` Dmitry Gutov
2024-05-25 17:00                     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-25 17:31                       ` Dmitry Gutov
2024-05-25 17:44                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-26 14:18                           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29  1:59                             ` Dmitry Gutov
2024-05-29  7:41                               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29 11:55                                 ` Dmitry Gutov
2024-05-29 15:19                                   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29 11:53                               ` Eli Zaretskii
2024-05-29 11:57                                 ` Dmitry Gutov
2024-05-29 12:46                                   ` Eli Zaretskii
2024-05-29 17:26                                     ` Dmitry Gutov
2024-05-29 17:42                                       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29 18:15                                         ` Dmitry Gutov
2024-05-29 18:38                                           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29 20:40                                             ` Dmitry Gutov
2024-05-30  8:49                                               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-31  0:24                                                 ` Dmitry Gutov [this message]
2024-05-31  5:53                                                   ` Eli Zaretskii
2024-05-31 16:24                                                     ` Dmitry Gutov
2024-05-31 18:05                                                       ` Eli Zaretskii
2024-06-01  1:21                                                         ` Dmitry Gutov
2024-06-01  6:07                                                           ` Eli Zaretskii
2024-06-01 15:33                                                             ` Dmitry Gutov
2024-06-01 15:47                                                               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02  1:39                                                                 ` Dmitry Gutov
2024-06-02  8:36                                                                   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02 14:10                                                                     ` Dmitry Gutov
2024-06-02 14:46                                                                       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02 15:01                                                                         ` Dmitry Gutov
2024-06-02 17:31                                                                           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-31  7:27                                                   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-31 12:13                                                     ` Dmitry Gutov
2024-05-29 18:11                                       ` Eli Zaretskii
2024-05-25 17:10                   ` Eli Zaretskii
2024-05-25  7:23           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 17:17     ` Dmitry Gutov
2024-05-24 17:41       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 17:50         ` Dmitry Gutov
2024-05-24 18:09           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-25 13:03 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-25 14:40   ` Dmitry Gutov
2024-05-25 15:26     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9685d486-46fe-4947-8bb2-fb436f09048b@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=71049@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=michael.albinus@gmx.de \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).