From: Dmitry Gutov <dmitry@gutov.dev>
To: Eli Zaretskii <eliz@gnu.org>
Cc: michael.albinus@gmx.de, 71049@debbugs.gnu.org
Subject: bug#71049: async-shell-command ends with "Process *Async Shell Command* finished" when remote "direct-async-process"
Date: Sat, 1 Jun 2024 04:21:46 +0300 [thread overview]
Message-ID: <fe3323d2-0a44-4653-873f-3c6fea1c37bf@gutov.dev> (raw)
In-Reply-To: <86h6edq2kz.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]
On 31/05/2024 21:05, Eli Zaretskii wrote:
>> Date: Fri, 31 May 2024 19:24:10 +0300
>> Cc:michael.albinus@gmx.de,71049@debbugs.gnu.org
>> From: Dmitry Gutov<dmitry@gutov.dev>
>>
>> On 31/05/2024 08:53, Eli Zaretskii wrote:
>>
>>>> 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.
>>> I think I'm okay with this. (It needs to be prominently documented,
>>> of course.)
>> In NEWS?
> There, but also in the doc string of M-&, and maybe also in the doc
> string of shell-mode-hook.
>
>>> But we need a documented way for people to get previous
>>> behavior if they want that. How would that work?
>> If we really needed the capability to rollback the change, I suppose we
>> could add a defvar pointing to the major mode to use. I.e.
>>
>> (defvar async-shell-command-major-mode #'shell-command-mode)
> That could work, yes.
How about this?
[-- Attachment #2: shell-command-mode.diff --]
[-- Type: text/x-patch, Size: 4686 bytes --]
diff --git a/etc/NEWS b/etc/NEWS
index d058acc3572..40407edf4e3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1881,6 +1881,10 @@ than regular expressions, but less complexity than context-free
grammars. The Info manual "(elisp) Parsing Expression Grammars" has
documentation and examples.
+** New major mode 'shell-command-mode'.
+This mode is used by default for the output of 'async-shell-command'.
+To revert to the previous behavior, set 'async-shell-command-mode' to
+'shell-mode'.
\f
* Incompatible Lisp Changes in Emacs 30.1
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 9385b023392..795a9e667c7 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -5247,8 +5247,13 @@ tramp-handle-shell-command
;; Display output.
(with-current-buffer output-buffer
(setq mode-line-process '(":%s"))
- (unless (eq major-mode 'shell-mode)
- (shell-mode))
+ (cond
+ ((boundp 'async-shell-command-mode)
+ ;; Emacs 30+
+ (unless (eq major-mode async-shell-command-mode)
+ (funcall async-shell-command-mode)))
+ ((not (eq major-mode 'shell-mode))
+ (shell-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..edee46cdb4d 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 asynchronous `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..fa745f10148 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -31,7 +31,6 @@
(eval-when-compile (require 'cl-lib))
(declare-function widget-convert "wid-edit" (type &rest args))
-(declare-function shell-mode "shell" ())
;;; From compile.el
(defvar compilation-current-error)
@@ -4487,9 +4486,10 @@ async-shell-command
The output appears in OUTPUT-BUFFER, which could be a buffer or
the name of a buffer, and defaults to `shell-command-buffer-name-async'
-if nil or omitted. That buffer is in shell mode. Note that, unlike
-with `shell-command', OUTPUT-BUFFER can only be a buffer, a buffer's
-name (a string), or nil.
+if nil or omitted. That buffer is in major mode specified by the
+variable `async-shell-command-mode'. Note that, unlike with
+`shell-command', OUTPUT-BUFFER can only be a buffer, a buffer's name
+(a string), or nil.
You can customize `async-shell-command-buffer' to specify what to do
when the buffer specified by `shell-command-buffer-name-async' is
@@ -4533,6 +4533,9 @@ async-shell-command
(declare-function comint-output-filter "comint" (process string))
(declare-function comint-term-environment "comint" ())
+(defvar async-shell-command-mode 'shell-command-mode
+ "Major mode to use for the output of asynchronous `shell-command'.")
+
(defun shell-command (command &optional output-buffer error-buffer)
"Execute string COMMAND in inferior shell; display output, if any.
With prefix argument, insert the COMMAND's output at point.
@@ -4543,9 +4546,9 @@ shell-command
If COMMAND ends in `&', execute it asynchronously.
The output appears in the buffer whose name is specified
-by `shell-command-buffer-name-async'. That buffer is in shell
-mode. You can also use `async-shell-command' that automatically
-adds `&'.
+by `shell-command-buffer-name-async'. That buffer is in major mode
+specified by the variable `async-shell-command-mode'. You can also use
+`async-shell-command' that automatically adds `&'.
Otherwise, COMMAND is executed synchronously. The output appears in
the buffer named by `shell-command-buffer-name'. If the output is
@@ -4721,7 +4724,7 @@ shell-command
(setq proc
(start-process-shell-command "Shell" buffer command)))
(setq mode-line-process '(":%s"))
- (shell-mode)
+ (funcall async-shell-command-mode)
(setq-local revert-buffer-function
(lambda (&rest _)
(async-shell-command command buffer)))
next prev parent reply other threads:[~2024-06-01 1:21 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
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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe3323d2-0a44-4653-873f-3c6fea1c37bf@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 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.