aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2020-04-18 12:01:26 +0300
committerEli Zaretskii2020-04-18 12:01:26 +0300
commit175c61c18bfaa1d75aa087ba4bd4de3ebfe1a1d6 (patch)
treedfbb644b07477429f7958c7a8c01998aa6e68cf6
parent6b297519b580df27d8721943f55629689b4c83e0 (diff)
downloademacs-175c61c18bfaa1d75aa087ba4bd4de3ebfe1a1d6.tar.gz
emacs-175c61c18bfaa1d75aa087ba4bd4de3ebfe1a1d6.zip
Fix "C-u M-!" when 'shell-command-dont-erase-buffer' is non-nil
* lisp/simple.el (shell-command-dont-erase-buffer): Clarify the effect of the various values in the doc string. (shell-command-save-pos-or-erase, shell-command): Don't move or push point if the output will go to the current buffer. (Bug#40690) (shell-command): Mention 'shell-command-dont-erase-buffer' in the doc string. * test/lisp/simple-tests.el (with-shell-command-dont-erase-buffer): Don't is shell quoting 'like this', as it doesn't work on MS-Windows; quote "like this" instead. (simple-tests-shell-command-dont-erase-buffer): Adapt the test to the new modus operandi. * doc/emacs/misc.texi (Single Shell): Document the effect of the various values of 'shell-command-dont-erase-buffer'. * etc/NEWS: Expand and reword the entry regarding changes in 'shell-command-dont-erase-buffer'.
-rw-r--r--doc/emacs/misc.texi27
-rw-r--r--etc/NEWS11
-rw-r--r--lisp/simple.el35
-rw-r--r--test/lisp/simple-tests.el4
4 files changed, 51 insertions, 26 deletions
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index d097f4ee7d8..294430aa183 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -740,10 +740,11 @@ creates the file @file{foo} and produces no terminal output.
740 740
741 A numeric argument to @code{shell-command}, e.g., @kbd{M-1 M-!}, 741 A numeric argument to @code{shell-command}, e.g., @kbd{M-1 M-!},
742causes it to insert terminal output into the current buffer instead of 742causes it to insert terminal output into the current buffer instead of
743a separate buffer. It puts point before the output, and sets the mark 743a separate buffer. By default, it puts point before the output, and
744after the output. For instance, @kbd{M-1 M-! gunzip < foo.gz 744sets the mark after the output (but a non-default value of
745@key{RET}} would insert the uncompressed form of the file 745@code{shell-command-dont-erase-buffer} can change that, see below).
746@file{foo.gz} into the current buffer. 746For instance, @kbd{M-1 M-! gunzip < foo.gz @key{RET}} would insert the
747uncompressed form of the file @file{foo.gz} into the current buffer.
747 748
748 Provided the specified shell command does not end with @samp{&}, it 749 Provided the specified shell command does not end with @samp{&}, it
749runs @dfn{synchronously}, and you must wait for it to exit before 750runs @dfn{synchronously}, and you must wait for it to exit before
@@ -829,11 +830,21 @@ inserted into a buffer of that name.
829 By default, the output buffer is erased between shell commands, except 830 By default, the output buffer is erased between shell commands, except
830when the output goes to the current buffer. If you change the value 831when the output goes to the current buffer. If you change the value
831of the option @code{shell-command-dont-erase-buffer} to @code{erase}, 832of the option @code{shell-command-dont-erase-buffer} to @code{erase},
832then the output buffer is always erased. Any other non-@code{nil} 833then the output buffer is always erased. Other non-@code{nil} values
833value prevents to erase the output buffer. 834prevent erasing of the output buffer, and---if the output buffer is
835not the current buffer---also control where to put point after
836inserting the output of the shell command:
834 837
835This option also controls where to set the point in the output buffer 838@table @code
836after the command completes; see the documentation of the option for details. 839@item beg-last-out
840Puts point at the beginning of the last shell-command output.
841@item end-last-out
842Puts point at the end of the last shell-command output, i.e.@: at the
843end of the output buffer.
844@item save-point
845Restores the position of point as it was before inserting the
846shell-command output.
847@end table
837 848
838@node Interactive Shell 849@node Interactive Shell
839@subsection Interactive Subshell 850@subsection Interactive Subshell
diff --git a/etc/NEWS b/etc/NEWS
index aba3028184b..4485bf91650 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2084,12 +2084,17 @@ variable for remote shells. It still defaults to "/bin/sh".
2084** Single shell commands 2084** Single shell commands
2085 2085
2086+++ 2086+++
2087*** 'shell-command-dont-erase-buffer' accepts the value 'erase' to 2087*** New values of 'shell-command-dont-erase-buffer'.
2088force to erase the output buffer before execution of the command. 2088This option can now have the value 'erase' to force to erase the
2089output buffer before execution of the command, even if the output goes
2090to the current buffer. Additional values 'beg-last-out',
2091'end-last-out', and 'save-point' control where to put point in the
2092output buffer after inserting the shell-command output.
2089 2093
2094---
2090*** The new functions 'shell-command-save-pos-or-erase' and 2095*** The new functions 'shell-command-save-pos-or-erase' and
2091'shell-command-set-point-after-cmd' control how point is handled 2096'shell-command-set-point-after-cmd' control how point is handled
2092between two consecutive shell commands in the same buffer. 2097between two consecutive shell commands in the same output buffer.
2093 2098
2094+++ 2099+++
2095*** 'async-shell-command-width' defines the number of display columns 2100*** 'async-shell-command-width' defines the number of display columns
diff --git a/lisp/simple.el b/lisp/simple.el
index ea16d1400cc..e3169e523b9 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3437,20 +3437,22 @@ This affects `shell-command' and `async-shell-command'."
3437 :version "27.1") 3437 :version "27.1")
3438 3438
3439(defcustom shell-command-dont-erase-buffer nil 3439(defcustom shell-command-dont-erase-buffer nil
3440 "Control if the output buffer is erased before the command. 3440 "Whether to erase the output buffer before executing shell command.
3441 3441
3442A nil value erases the output buffer before execution of the 3442A nil value erases the output buffer before execution of the
3443shell command, except when the output buffer is the current one. 3443shell command, except when the output buffer is the current one.
3444 3444
3445The value `erase' ensures the output buffer is erased before 3445The value `erase' ensures the output buffer is erased before
3446execution of the shell command. 3446execution of the shell command even if it is the current buffer.
3447 3447
3448Other non-nil values prevent the output buffer from being erased and 3448Other non-nil values prevent the output buffer from being erased; they
3449set the point after execution of the shell command. 3449also reposition point in the shell output buffer after execution of the
3450shell command, except when the output buffer is the current buffer.
3450 3451
3451The value `beg-last-out' sets point at the beginning of the output, 3452The value `beg-last-out' sets point at the beginning of the last
3452`end-last-out' sets point at the end of the buffer, `save-point' 3453output, `end-last-out' sets point at the end of the last output,
3453restores the buffer position before the command." 3454and `save-point' restores the buffer position as it was before the
3455shell command."
3454 :type '(choice 3456 :type '(choice
3455 (const :tag "Erase output buffer if not the current one" nil) 3457 (const :tag "Erase output buffer if not the current one" nil)
3456 (const :tag "Always erase output buffer" erase) 3458 (const :tag "Always erase output buffer" erase)
@@ -3480,9 +3482,12 @@ See `shell-command-dont-erase-buffer'."
3480 ;; if some text has a non-nil read-only property, 3482 ;; if some text has a non-nil read-only property,
3481 ;; which comint sometimes adds for prompts. 3483 ;; which comint sometimes adds for prompts.
3482 (setq pos 3484 (setq pos
3483 (cond ((eq sym 'save-point) (point)) 3485 (cond ((eq sym 'save-point)
3484 ((eq sym 'beg-last-out) (point-max)) 3486 (if (not output-to-current-buffer)
3485 ;;((not sym) 3487 (point)))
3488 ((eq sym 'beg-last-out)
3489 (if (not output-to-current-buffer)
3490 (point-max)))
3486 ((or (eq sym 'erase) 3491 ((or (eq sym 'erase)
3487 (and (null sym) (not output-to-current-buffer))) 3492 (and (null sym) (not output-to-current-buffer)))
3488 (let ((inhibit-read-only t)) 3493 (let ((inhibit-read-only t))
@@ -3597,10 +3602,15 @@ says to put the output in some other buffer.
3597If OUTPUT-BUFFER is a buffer or buffer name, erase that buffer 3602If OUTPUT-BUFFER is a buffer or buffer name, erase that buffer
3598and insert the output there; a non-nil value of 3603and insert the output there; a non-nil value of
3599`shell-command-dont-erase-buffer' prevents the buffer from being 3604`shell-command-dont-erase-buffer' prevents the buffer from being
3600erased. If OUTPUT-BUFFER is not a buffer and not nil, insert the 3605erased. If OUTPUT-BUFFER is not a buffer and not nil (which happens
3606interactively when the prefix argument is given), insert the
3601output in current buffer after point leaving mark after it. This 3607output in current buffer after point leaving mark after it. This
3602cannot be done asynchronously. 3608cannot be done asynchronously.
3603 3609
3610The user option `shell-command-dont-erase-buffer', which see, controls
3611whether the output buffer is erased and where to put point after
3612the shell command.
3613
3604If the command terminates without error, but generates output, 3614If the command terminates without error, but generates output,
3605and you did not specify \"insert it in the current buffer\", 3615and you did not specify \"insert it in the current buffer\",
3606the output can be displayed in the echo area or in its buffer. 3616the output can be displayed in the echo area or in its buffer.
@@ -3688,8 +3698,7 @@ impose the use of a shell (with its need to quote arguments)."
3688 ;; because we inserted text. 3698 ;; because we inserted text.
3689 (goto-char (prog1 (mark t) 3699 (goto-char (prog1 (mark t)
3690 (set-marker (mark-marker) (point) 3700 (set-marker (mark-marker) (point)
3691 (current-buffer)))) 3701 (current-buffer)))))
3692 (shell-command-set-point-after-cmd))
3693 ;; Output goes in a separate buffer. 3702 ;; Output goes in a separate buffer.
3694 ;; Preserve the match data in case called from a program. 3703 ;; Preserve the match data in case called from a program.
3695 ;; FIXME: It'd be ridiculous for an Elisp function to call 3704 ;; FIXME: It'd be ridiculous for an Elisp function to call
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 276df795fca..8c477165a4f 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -724,7 +724,7 @@ See Bug#21722."
724 (,output-buf (if ,output-buffer-is-current ,caller-buf 724 (,output-buf (if ,output-buffer-is-current ,caller-buf
725 (generate-new-buffer "output-buf"))) 725 (generate-new-buffer "output-buf")))
726 (emacs (expand-file-name invocation-name invocation-directory)) 726 (emacs (expand-file-name invocation-name invocation-directory))
727 (,command (format "%s -Q --batch --eval '(princ \"%s\")'" 727 (,command (format "%s -Q --batch --eval \"(princ \\\"%s\\\")\""
728 emacs ,str)) 728 emacs ,str))
729 (inhibit-message t)) 729 (inhibit-message t))
730 (unwind-protect 730 (unwind-protect
@@ -761,7 +761,7 @@ See Bug#21722."
761 (expected-point `((beg-last-out . ,(1+ (length str))) 761 (expected-point `((beg-last-out . ,(1+ (length str)))
762 (end-last-out . ,(1+ (* 2 (length str)))) 762 (end-last-out . ,(1+ (* 2 (length str))))
763 (save-point . 1)))) 763 (save-point . 1))))
764 (dolist (output-buffer-is-current '(t ni)) 764 (dolist (output-buffer-is-current '(nil))
765 (with-shell-command-dont-erase-buffer str output-buffer-is-current 765 (with-shell-command-dont-erase-buffer str output-buffer-is-current
766 (when (memq shell-command-dont-erase-buffer '(beg-last-out end-last-out save-point)) 766 (when (memq shell-command-dont-erase-buffer '(beg-last-out end-last-out save-point))
767 (should (= (point) (alist-get shell-command-dont-erase-buffer expected-point)))))))) 767 (should (= (point) (alist-get shell-command-dont-erase-buffer expected-point))))))))