aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2024-06-01 18:03:42 +0300
committerDmitry Gutov2024-06-01 18:03:42 +0300
commita154f0aa73bceeaaeefcd243e7db9d09e3f450d7 (patch)
tree4708f1f9e80eaff35cddb7bdc09d18948d014166
parentd91ad9be5a72974784e0552069020c3ae0bc830e (diff)
downloademacs-a154f0aa73bceeaaeefcd243e7db9d09e3f450d7.tar.gz
emacs-a154f0aa73bceeaaeefcd243e7db9d09e3f450d7.zip
shell-command-mode: New major mode for async-shell-command
* etc/NEWS: Mention the additions. * lisp/shell.el (shell-command-mode): New major mode (bug#71049). * lisp/simple.el (async-shell-command-mode): New variable, with default value pointing to that mode. (shell-command): Refer to it here. (async-shell-command): Update docstring. * lisp/net/tramp.el (tramp-handle-shell-command): Use the new variable when available.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/net/tramp.el9
-rw-r--r--lisp/shell.el7
-rw-r--r--lisp/simple.el19
4 files changed, 30 insertions, 10 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 2cae3730602..e5a63cc8a67 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1902,6 +1902,11 @@ than regular expressions, but less complexity than context-free
1902grammars. The Info manual "(elisp) Parsing Expression Grammars" has 1902grammars. The Info manual "(elisp) Parsing Expression Grammars" has
1903documentation and examples. 1903documentation and examples.
1904 1904
1905** New major mode 'shell-command-mode'.
1906This mode is used by default for the output of 'async-shell-command'.
1907To revert to the previous behavior, set the (also new) variable
1908'async-shell-command-mode' to 'shell-mode'. Any hooks or mode-specific
1909variables used should be adapted appropriately.
1905 1910
1906* Incompatible Lisp Changes in Emacs 30.1 1911* Incompatible Lisp Changes in Emacs 30.1
1907 1912
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index b2442f4538c..3dffe7544ab 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -5259,8 +5259,13 @@ support symbolic links."
5259 ;; Display output. 5259 ;; Display output.
5260 (with-current-buffer output-buffer 5260 (with-current-buffer output-buffer
5261 (setq mode-line-process '(":%s")) 5261 (setq mode-line-process '(":%s"))
5262 (unless (eq major-mode 'shell-mode) 5262 (cond
5263 (shell-mode)) 5263 ((boundp 'async-shell-command-mode)
5264 ;; Emacs 30+
5265 (unless (eq major-mode async-shell-command-mode)
5266 (funcall async-shell-command-mode)))
5267 ((not (eq major-mode 'shell-mode))
5268 (shell-mode)))
5264 (set-process-filter p #'comint-output-filter) 5269 (set-process-filter p #'comint-output-filter)
5265 (set-process-sentinel p #'shell-command-sentinel) 5270 (set-process-sentinel p #'shell-command-sentinel)
5266 (when error-file 5271 (when error-file
diff --git a/lisp/shell.el b/lisp/shell.el
index b3201726762..4352811912a 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -838,6 +838,13 @@ Sentinels will always get the two parameters PROCESS and EVENT."
838 (with-current-buffer buf 838 (with-current-buffer buf
839 (insert (format "\nProcess %s %s\n" process event)))))) 839 (insert (format "\nProcess %s %s\n" process event))))))
840 840
841(define-derived-mode shell-command-mode comint-mode "Shell"
842 "Major mode for the output of asynchronous `shell-command'."
843 (setq-local font-lock-defaults '(shell-font-lock-keywords t))
844 ;; See comments in `shell-mode'.
845 (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
846 (setq list-buffers-directory (expand-file-name default-directory)))
847
841;;;###autoload 848;;;###autoload
842(defun shell (&optional buffer file-name) 849(defun shell (&optional buffer file-name)
843 "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*'). 850 "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*').
diff --git a/lisp/simple.el b/lisp/simple.el
index cb7a54409a6..68209eadc41 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -31,7 +31,6 @@
31(eval-when-compile (require 'cl-lib)) 31(eval-when-compile (require 'cl-lib))
32 32
33(declare-function widget-convert "wid-edit" (type &rest args)) 33(declare-function widget-convert "wid-edit" (type &rest args))
34(declare-function shell-mode "shell" ())
35 34
36;;; From compile.el 35;;; From compile.el
37(defvar compilation-current-error) 36(defvar compilation-current-error)
@@ -4488,9 +4487,10 @@ to execute it asynchronously.
4488 4487
4489The output appears in OUTPUT-BUFFER, which could be a buffer or 4488The output appears in OUTPUT-BUFFER, which could be a buffer or
4490the name of a buffer, and defaults to `shell-command-buffer-name-async' 4489the name of a buffer, and defaults to `shell-command-buffer-name-async'
4491if nil or omitted. That buffer is in shell mode. Note that, unlike 4490if nil or omitted. That buffer is in major mode specified by the
4492with `shell-command', OUTPUT-BUFFER can only be a buffer, a buffer's 4491variable `async-shell-command-mode'. Note that, unlike with
4493name (a string), or nil. 4492`shell-command', OUTPUT-BUFFER can only be a buffer, a buffer's name
4493(a string), or nil.
4494 4494
4495You can customize `async-shell-command-buffer' to specify what to do 4495You can customize `async-shell-command-buffer' to specify what to do
4496when the buffer specified by `shell-command-buffer-name-async' is 4496when the buffer specified by `shell-command-buffer-name-async' is
@@ -4534,6 +4534,9 @@ a shell (with its need to quote arguments)."
4534(declare-function comint-output-filter "comint" (process string)) 4534(declare-function comint-output-filter "comint" (process string))
4535(declare-function comint-term-environment "comint" ()) 4535(declare-function comint-term-environment "comint" ())
4536 4536
4537(defvar async-shell-command-mode 'shell-command-mode
4538 "Major mode to use for the output of asynchronous `shell-command'.")
4539
4537(defun shell-command (command &optional output-buffer error-buffer) 4540(defun shell-command (command &optional output-buffer error-buffer)
4538 "Execute string COMMAND in inferior shell; display output, if any. 4541 "Execute string COMMAND in inferior shell; display output, if any.
4539With prefix argument, insert the COMMAND's output at point. 4542With prefix argument, insert the COMMAND's output at point.
@@ -4544,9 +4547,9 @@ directory in the prompt.
4544 4547
4545If COMMAND ends in `&', execute it asynchronously. 4548If COMMAND ends in `&', execute it asynchronously.
4546The output appears in the buffer whose name is specified 4549The output appears in the buffer whose name is specified
4547by `shell-command-buffer-name-async'. That buffer is in shell 4550by `shell-command-buffer-name-async'. That buffer is in major mode
4548mode. You can also use `async-shell-command' that automatically 4551specified by the variable `async-shell-command-mode'. You can also use
4549adds `&'. 4552`async-shell-command' that automatically adds `&'.
4550 4553
4551Otherwise, COMMAND is executed synchronously. The output appears in 4554Otherwise, COMMAND is executed synchronously. The output appears in
4552the buffer named by `shell-command-buffer-name'. If the output is 4555the buffer named by `shell-command-buffer-name'. If the output is
@@ -4722,7 +4725,7 @@ impose the use of a shell (with its need to quote arguments)."
4722 (setq proc 4725 (setq proc
4723 (start-process-shell-command "Shell" buffer command))) 4726 (start-process-shell-command "Shell" buffer command)))
4724 (setq mode-line-process '(":%s")) 4727 (setq mode-line-process '(":%s"))
4725 (shell-mode) 4728 (funcall async-shell-command-mode)
4726 (setq-local revert-buffer-function 4729 (setq-local revert-buffer-function
4727 (lambda (&rest _) 4730 (lambda (&rest _)
4728 (async-shell-command command buffer))) 4731 (async-shell-command command buffer)))