commit b39c0b31f0328da8b1a87226d5cfd7d46af62c0f (HEAD, refs/remotes/origin/master) Author: Tino Calancha Date: Fri Aug 26 15:27:37 2016 +0900 Rename option to shell-command-dont-erase-buffer Suggested by Clément Pit--Claudel in: http://lists.gnu.org/archive/html/emacs-devel/2016-08/msg00487.html * lisp/simple.el (shell-command-dont-erase-buffer): (shell-command--save-pos-or-erase): (shell-command--set-point-after-cmd): (shell-command-on-region): * doc/emacs/misc.texi (shell-command-dont-erase-buffer): * etc/NEWS (Changes in Emacs 25.2): Rename from shell-command-not-erase-buffer. diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index acddb7a..502ccad 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -771,10 +771,10 @@ the output buffer. But if you change the value of the variable @code{shell-command-default-error-buffer} to a string, error output is inserted into a buffer of that name. -@vindex shell-command-not-erase-buffer +@vindex shell-command-dont-erase-buffer By default, the output buffer is erased between shell commands. If you change the value of the variable -@code{shell-command-not-erase-buffer} to a non-@code{nil} value, +@code{shell-command-dont-erase-buffer} to a non-@code{nil} value, the output buffer is not erased. This variable also controls where to set the point in the output buffer after the command completes; see the documentation of the variable for details. diff --git a/etc/NEWS b/etc/NEWS index d30d1fa..1290fa4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -60,12 +60,12 @@ affected by this, as SGI stopped supporting IRIX in December 2013. inferior shell with the buffer region as input. +++ -** The new user option 'shell-command-not-erase-buffer' controls +** The new user option 'shell-command-dont-erase-buffer' controls if the output buffer is erased between shell commands; if non-nil, the output buffer is not erased; this variable also controls where to set the point in the output buffer: beginning of the output, end of the buffer or save the point. -When 'shell-command-not-erase-buffer' is nil, the default value, +When 'shell-command-dont-erase-buffer' is nil, the default value, the behaviour of 'shell-command', 'shell-command-on-region' and 'async-shell-command' is as usual. diff --git a/lisp/simple.el b/lisp/simple.el index de8883a..04a525c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -37,7 +37,7 @@ (defvar compilation-current-error) (defvar compilation-context-lines) -(defcustom shell-command-not-erase-buffer nil +(defcustom shell-command-dont-erase-buffer nil "If non-nil, output buffer is not erased between shell commands. Also, a non-nil value set the point in the output buffer once the command complete. @@ -56,7 +56,7 @@ restore the buffer position before the command." "Point position in the output buffer after command complete. It is an alist (BUFFER . POS), where BUFFER is the output buffer, and POS is the point position in BUFFER once the command finish. -This variable is used when `shell-command-not-erase-buffer' is non-nil.") +This variable is used when `shell-command-dont-erase-buffer' is non-nil.") (defcustom idle-update-delay 0.5 "Idle time delay before updating various things on the screen. @@ -3233,8 +3233,8 @@ output buffer and running a new command in the default buffer, (defun shell-command--save-pos-or-erase () "Store a buffer position or erase the buffer. -See `shell-command-not-erase-buffer'." - (let ((sym shell-command-not-erase-buffer) +See `shell-command-dont-erase-buffer'." + (let ((sym shell-command-dont-erase-buffer) pos) (setq buffer-read-only nil) ;; Setting buffer-read-only to nil doesn't suffice @@ -3257,8 +3257,8 @@ BUFFER is the output buffer of the command; if nil, then defaults to the current BUFFER. Set point to the `cdr' of the element in `shell-command-saved-pos' whose `car' is BUFFER." - (when shell-command-not-erase-buffer - (let* ((sym shell-command-not-erase-buffer) + (when shell-command-dont-erase-buffer + (let* ((sym shell-command-dont-erase-buffer) (buf (or buffer (current-buffer))) (pos (alist-get buf shell-command-saved-pos))) (setq shell-command-saved-pos @@ -3340,7 +3340,7 @@ The optional second argument OUTPUT-BUFFER, if non-nil, says to put the output in some other buffer. If OUTPUT-BUFFER is a buffer or buffer name, erase that buffer and insert the output there; a non-nil value of -`shell-command-not-erase-buffer' prevent to erase the buffer. +`shell-command-dont-erase-buffer' prevent to erase the buffer. If OUTPUT-BUFFER is not a buffer and not nil, insert the output in current buffer after point leaving mark after it. This cannot be done asynchronously. @@ -3562,7 +3562,7 @@ and are only used if a pop-up buffer is displayed." ;; We have a sentinel to prevent insertion of a termination message ;; in the buffer itself, and to set the point in the buffer when -;; `shell-command-not-erase-buffer' is non-nil. +;; `shell-command-dont-erase-buffer' is non-nil. (defun shell-command-sentinel (process signal) (when (memq (process-status process) '(exit signal)) (shell-command--set-point-after-cmd (process-buffer process)) @@ -3603,7 +3603,7 @@ appears at the end of the output. Optional fourth arg OUTPUT-BUFFER specifies where to put the command's output. If the value is a buffer or buffer name, erase that buffer and insert the output there; a non-nil value of -`shell-command-not-erase-buffer' prevent to erase the buffer. +`shell-command-dont-erase-buffer' prevent to erase the buffer. If the value is nil, use the buffer `*Shell Command Output*'. Any other non-nil value means to insert the output in the current buffer after START. @@ -3683,7 +3683,7 @@ interactively, this is t." (or output-buffer "*Shell Command Output*")))) (unwind-protect (if (and (eq buffer (current-buffer)) - (or (not shell-command-not-erase-buffer) + (or (not shell-command-dont-erase-buffer) (and (not (eq buffer (get-buffer "*Shell Command Output*"))) (not (region-active-p))))) ;; If the input is the same buffer as the output, commit 93c67f6b2c98ab69e25d2ca7417bcf6c15a165db Author: Alan Mackenzie Date: Thu Aug 25 16:21:55 2016 +0000 Fix an infinite loop in C++ Mode when we have "{ .... [ .... }" * lisp/progmodes/cc-fonts.el (c-font-lock-c++-lambda-captures): In the inner `while' form's condition, check for "\\s)" rather than merely "\\]", so that the loop won't hang at a "terminating" paren of a different type (due to the c-syntactic-re-search-forward at the end of the loop stopping at such characters). diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 60b8b6d..bf8b857 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1654,8 +1654,13 @@ casts and declarations are fontified. Used on level 2 and higher." (c-forward-syntactic-ws))) (c-backward-token-2))) - ;; Go round the following loop once per captured item. - (while (and (not (eq (char-after) ?\])) + ;; Go round the following loop once per captured item. We use "\\s)" + ;; rather than "\\]" here to avoid infinite looping in this situation: + ;; "unsigned items [] { [ }". The second "[" triggers this function, + ;; but if we don't match the "}" with an "\\s)", the + ;; `c-syntactic-re-search-forward' at the end of the loop fails to + ;; move forward over it, leaving point stuck at the "}". + (while (and (not (looking-at "\\s)")) (< (point) limit)) (if (eq (char-after) ?&) (progn (setq mode ?&) @@ -1704,7 +1709,8 @@ casts and declarations are fontified. Used on level 2 and higher." (c-forward-syntactic-ws))) (setq capture-default nil) - (forward-char)))) ; over the terminating "]". + (if (< (point) limit) + (forward-char))))) ; over the terminating "]" or other close paren. nil) commit 5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135 Author: Tino Calancha Date: Thu Aug 25 22:17:56 2016 +0900 call-shell-region: New defun Suggested by Stefan Monnier in Bug#22679. * lisp/subr.el (call-shell-region): New defun; execute a command in an inferior shell with the buffer region as input. * lisp/simple.el (shell-command-on-region): Use it. * lisp/gnus/message.el (message-do-fcc): Idem. * doc/lispref/processes.texi: Document call-shell-region in the manual. ;* etc/NEWS: Add entry for this new function. diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index cd12012..e043578 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -492,20 +492,17 @@ inputinput@point{} @end smallexample For example, the @code{shell-command-on-region} command uses -@code{call-process-region} in a manner similar to this: +@code{call-shell-region} in a manner similar to this: @smallexample @group -(call-process-region +(call-shell-region start end - shell-file-name ; @r{name of program} + command ; @r{shell command} nil ; @r{do not delete region} - buffer ; @r{send output to @code{buffer}} - nil ; @r{no redisplay during output} - "-c" command) ; @r{arguments for the shell} + buffer) ; @r{send output to @code{buffer}} @end group @end smallexample -@c It actually uses shell-command-switch, but no need to mention that here. @end defun @defun call-process-shell-command command &optional infile destination display @@ -525,6 +522,15 @@ convention allowed passing any number of additional arguments after supported, but strongly discouraged. @end defun +@defun call-shell-region start end command &optional delete destination +This function sends the text from @var{start} to @var{end} as +standard input to an inferior shell running @var{command}. This function +is similar than @code{call-process-region}, with process being a shell. +The arguments @code{delete}, @code{destination} and the return value +are like in @code{call-process-region}. +Note that this funtion doesn't accept additional arguments. +@end defun + @defun shell-command-to-string command This function executes @var{command} (a string) as a shell command, then returns the command's output as a string. diff --git a/etc/NEWS b/etc/NEWS index 494a091..d30d1fa 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -56,6 +56,10 @@ affected by this, as SGI stopped supporting IRIX in December 2013. * Changes in Emacs 25.2 +++ +** The new funtion 'call-shell-region' executes a command in an +inferior shell with the buffer region as input. + ++++ ** The new user option 'shell-command-not-erase-buffer' controls if the output buffer is erased between shell commands; if non-nil, the output buffer is not erased; this variable also controls where diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index cb4843e..e4e42df 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -5409,9 +5409,7 @@ Otherwise, generate and save a value for `canlock-password' first." (setq file (pop list)) (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file) ;; Pipe the article to the program in question. - (call-process-region (point-min) (point-max) shell-file-name - nil nil nil shell-command-switch - (match-string 1 file)) + (call-shell-region (point-min) (point-max) (match-string 1 file)) ;; Save the article. (setq file (expand-file-name file)) (unless (file-exists-p (file-name-directory file)) diff --git a/lisp/simple.el b/lisp/simple.el index 6105f01..de8883a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3667,11 +3667,10 @@ interactively, this is t." (goto-char start) (and replace (push-mark (point) 'nomsg)) (setq exit-status - (call-process-region start end shell-file-name replace + (call-shell-region start end command replace (if error-file (list t error-file) - t) - nil shell-command-switch command)) + t))) ;; It is rude to delete a buffer which the command is not using. ;; (let ((shell-buffer (get-buffer "*Shell Command Output*"))) ;; (and shell-buffer (not (eq shell-buffer (current-buffer))) @@ -3709,11 +3708,10 @@ interactively, this is t." (setq default-directory directory)) (shell-command--save-pos-or-erase))) (setq exit-status - (call-process-region start end shell-file-name nil + (call-shell-region start end command nil (if error-file (list buffer error-file) - buffer) - nil shell-command-switch command))) + buffer)))) ;; Report the output. (with-current-buffer buffer (setq mode-line-process diff --git a/lisp/subr.el b/lisp/subr.el index 8ab1178..96917b9 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3078,6 +3078,28 @@ Similar to `call-process-shell-command', but calls `process-file'." infile buffer display (if (file-remote-p default-directory) "-c" shell-command-switch) (mapconcat 'identity (cons command args) " "))) + +(defun call-shell-region (start end command &optional delete buffer) + "Send text from START to END as input to an inferior shell running COMMAND. +Delete the text if fourth arg DELETE is non-nil. + +Insert output in BUFFER before point; t means current buffer; nil for + BUFFER means discard it; 0 means discard and don't wait; and `(:file + FILE)', where FILE is a file name string, means that it should be + written to that file (if the file already exists it is overwritten). +BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, +REAL-BUFFER says what to do with standard output, as above, +while STDERR-FILE says what to do with standard error in the child. +STDERR-FILE may be nil (discard standard error output), +t (mix it with ordinary output), or a file name string. + +If BUFFER is 0, `call-shell-region' returns immediately with value nil. +Otherwise it waits for COMMAND to terminate +and returns a numeric exit status or a signal description string. +If you quit, the process is killed with SIGINT, or SIGKILL if you quit again." + (call-process-region start end + shell-file-name delete buffer nil + shell-command-switch command)) ;;;; Lisp macros to do various things temporarily. commit 95c82efdb141029de89d9136a9ce4fe907de7c5e Author: Martin Rudalics Date: Thu Aug 25 11:04:46 2016 +0200 In ‘clone-indirect-buffer’ fix argument mixup (Bug#24306) * lisp/simple.el (clone-indirect-buffer): Add value for ACTION argument in `pop-to-buffer' call (Bug#24306). diff --git a/lisp/simple.el b/lisp/simple.el index 51b24bb..6105f01 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8419,7 +8419,7 @@ Returns the newly created indirect buffer." (with-current-buffer buffer (run-hooks 'clone-indirect-buffer-hook)) (when display-flag - (pop-to-buffer buffer norecord)) + (pop-to-buffer buffer nil norecord)) buffer)) commit 63415a53c7ad31d51295c25423a9151b6737d6be Author: Martin Rudalics Date: Thu Aug 25 10:53:27 2016 +0200 Some fixes around `delete-other-frames' and `next-frame' * src/frame.c (Fdelete_frame): Clarify doc-string. * lisp/frame.el (delete-other-frames): Delete other frames on FRAME's terminal instead of the current terminal. Delete non-minibuffer-only surrogate frames too. See http://lists.gnu.org/archive/html/emacs-devel/2016-08/msg00467.html * doc/lispref/frames.texi (Deleting Frames): Minor fixes for docs of `delete-frame' and `frame-live-p'. Add entry for `delete-other-frames'. (Finding All Frames): Fix doc of `next-frame'. diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index 15a9bd9..53406d1 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -1904,10 +1904,11 @@ to it. @deffn Command delete-frame &optional frame force @vindex delete-frame-functions -This function deletes the frame @var{frame}. Unless @var{frame} is a -tooltip, it first runs the hook @code{delete-frame-functions} (each -function gets one argument, @var{frame}). By default, @var{frame} is -the selected frame. +This function deletes the frame @var{frame}. The argument @var{frame} +must specify a live frame (see below) and defaults to the selected +frame. Unless @var{frame} specifies a tooltip, this function first runs +the hook @code{delete-frame-functions} (each function getting one +argument, @var{frame}). A frame cannot be deleted as long as its minibuffer serves as surrogate minibuffer for another frame (@pxref{Minibuffers and Frames}). @@ -1916,9 +1917,9 @@ but if @var{force} is non-@code{nil}, then you are allowed to do so. @end deffn @defun frame-live-p frame -The function @code{frame-live-p} returns non-@code{nil} if the frame -@var{frame} has not been deleted. The possible non-@code{nil} return -values are like those of @code{framep}. @xref{Frames}. +This function returns non-@code{nil} if the frame @var{frame} has not +been deleted. The possible non-@code{nil} return values are like those +of @code{framep}. @xref{Frames}. @end defun Some window managers provide a command to delete a window. These work @@ -1927,6 +1928,15 @@ When Emacs gets one of these commands, it generates a @code{delete-frame} event, whose normal definition is a command that calls the function @code{delete-frame}. @xref{Misc Events}. +@deffn Command delete-other-frames &optional frame +This command deletes all frames on @var{frame}'s terminal, except +@var{frame}. If @var{frame} uses another frame's minibuffer, that +minibuffer frame is left untouched. The argument @var{frame} must +specify a live frame and defaults to the selected frame. Internally, +this command works by calling @code{delete-frame} with @var{force} +@code{nil} for all frames that shall be deleted. +@end deffn + @node Finding All Frames @section Finding All Frames @cindex frames, scanning all @@ -1946,11 +1956,11 @@ visible, even though only the selected one is actually displayed. @end defun @defun next-frame &optional frame minibuf -This function lets you cycle conveniently through all the frames on -the current display from an arbitrary starting point. It returns the -next frame after @var{frame} in the cycle. If @var{frame} is -omitted or @code{nil}, it defaults to the selected frame (@pxref{Input -Focus}). +This function lets you cycle conveniently through all the frames on a +specific terminal from an arbitrary starting point. It returns the +frame following @var{frame}, in the list of all live frames, on +@var{frame}'s terminal. The argument @var{frame} must specify a live +frame and defaults to the selected frame. The second argument, @var{minibuf}, says which frames to consider: diff --git a/lisp/frame.el b/lisp/frame.el index 09738d1..cfd40bf 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1874,30 +1874,29 @@ In the 3rd, 4th, and 6th examples, the returned value is relative to the opposite frame edge from the edge indicated in the input spec." (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame))) - (defun delete-other-frames (&optional frame) - "Delete all frames on the current terminal, except FRAME. + "Delete all frames on FRAME's terminal, except FRAME. If FRAME uses another frame's minibuffer, the minibuffer frame is -left untouched. FRAME nil or omitted means use the selected frame." +left untouched. FRAME must be a live frame and defaults to the +selected one." (interactive) - (unless frame - (setq frame (selected-frame))) - (let* ((mini-frame (window-frame (minibuffer-window frame))) - (frames (delq mini-frame (delq frame (frame-list))))) - ;; Only consider frames on the same terminal. - (dolist (frame (prog1 frames (setq frames nil))) - (if (eq (frame-terminal) (frame-terminal frame)) - (push frame frames))) - ;; Delete mon-minibuffer-only frames first, because `delete-frame' - ;; signals an error when trying to delete a mini-frame that's - ;; still in use by another frame. - (dolist (frame frames) - (unless (eq (frame-parameter frame 'minibuffer) 'only) - (delete-frame frame))) - ;; Delete minibuffer-only frames. - (dolist (frame frames) - (when (eq (frame-parameter frame 'minibuffer) 'only) - (delete-frame frame))))) + (setq frame (window-normalize-frame frame)) + (let ((minibuffer-frame (window-frame (minibuffer-window frame))) + (this (next-frame frame t)) + next) + ;; In a first round consider minibuffer-less frames only. + (while (not (eq this frame)) + (setq next (next-frame this t)) + (unless (eq (window-frame (minibuffer-window this)) this) + (delete-frame this)) + (setq this next)) + ;; In a second round consider all remaining frames. + (setq this (next-frame frame t)) + (while (not (eq this frame)) + (setq next (next-frame this t)) + (unless (eq this minibuffer-frame) + (delete-frame this)) + (setq this next)))) ;; miscellaneous obsolescence declarations (define-obsolete-variable-alias 'delete-frame-hook diff --git a/src/frame.c b/src/frame.c index 2b7ee3b..6de55e4 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1826,7 +1826,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force) DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", doc: /* Delete FRAME, permanently eliminating it from use. -FRAME defaults to the selected frame. +FRAME must be a live frame and defaults to the selected one. A frame may not be deleted if its minibuffer serves as surrogate minibuffer for another frame. Normally, you may not delete a frame if