From: Lars Ingebrigtsen Date: Sun, 13 Oct 2019 19:36:57 +0000 (+0200) Subject: Add a new action in save-some-buffers to view the buffer X-Git-Tag: emacs-27.0.90~1100 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b02f0ae995110393f7a8136d01933fb80960fc54;p=emacs.git Add a new action in save-some-buffers to view the buffer * doc/emacs/files.texi (Save Commands): Document it. * lisp/files.el (save-some-buffers-action-alist): Offer to pop to the buffer and then quit (bug#3625). (save-some-buffers): Implement it. (save-some-buffers--switch-window-callback): New variable. --- diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 9fe1b564a82..c3ede1833b5 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -419,6 +419,9 @@ about other buffers. View the buffer that you are currently being asked about. When you exit View mode, you get back to @code{save-some-buffers}, which asks the question again. +@item C-f +Exit @code{save-some-buffers} and visit the buffer that you are +currently being asked about. @item d Diff the buffer against its corresponding file, so you can see what changes you would be saving. This calls the command diff --git a/etc/NEWS b/etc/NEWS index eeb02b7066c..5b3dabe22ac 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -453,6 +453,10 @@ Note that this key binding will not work on MS-Windows systems if * Editing Changes in Emacs 27.1 ++++ +** 'save-some-buffers' now has a new action in the prompt: 'C-f' will +exit the command and switch to the buffer currently being asked about. + +++ ** The new 'amalgamating-undo-limit' variable can be used to control how many changes should be amalgamated when using the 'undo' command. diff --git a/lisp/files.el b/lisp/files.el index a1c7e3c8144..007195d22a8 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5390,6 +5390,8 @@ Before and after saving the buffer, this function runs (declare-function diff-no-select "diff" (old new &optional switches no-async buf)) +(defvar save-some-buffers--switch-window-callback nil) + (defvar save-some-buffers-action-alist `((?\C-r ,(lambda (buf) @@ -5401,6 +5403,11 @@ Before and after saving the buffer, this function runs ;; Return nil to ask about BUF again. nil) ,(purecopy "view this buffer")) + (?\C-f + ,(lambda (buf) + (funcall save-some-buffers--switch-window-callback buf) + (setq quit-flag t)) + ,(purecopy "view this buffer and quit")) (?d ,(lambda (buf) (if (null (buffer-file-name buf)) (message "Not applicable: no file") @@ -5464,69 +5471,79 @@ change the additional actions you can take on files." (interactive "P") (unless pred (setq pred save-some-buffers-default-predicate)) - (save-window-excursion - (let* (queried autosaved-buffers - files-done abbrevs-done) - (dolist (buffer (buffer-list)) - ;; First save any buffers that we're supposed to save unconditionally. - ;; That way the following code won't ask about them. - (with-current-buffer buffer - (when (and buffer-save-without-query (buffer-modified-p)) - (push (buffer-name) autosaved-buffers) - (save-buffer)))) - ;; Ask about those buffers that merit it, - ;; and record the number thus saved. - (setq files-done - (map-y-or-n-p - (lambda (buffer) - ;; Note that killing some buffers may kill others via - ;; hooks (e.g. Rmail and its viewing buffer). - (and (buffer-live-p buffer) - (buffer-modified-p buffer) - (not (buffer-base-buffer buffer)) - (or - (buffer-file-name buffer) - (with-current-buffer buffer - (or (eq buffer-offer-save 'always) - (and pred buffer-offer-save (> (buffer-size) 0))))) - (or (not (functionp pred)) - (with-current-buffer buffer (funcall pred))) - (if arg - t - (setq queried t) - (if (buffer-file-name buffer) - (format "Save file %s? " - (buffer-file-name buffer)) - (format "Save buffer %s? " - (buffer-name buffer)))))) - (lambda (buffer) - (with-current-buffer buffer - (save-buffer))) - (buffer-list) - '("buffer" "buffers" "save") - save-some-buffers-action-alist)) - ;; Maybe to save abbrevs, and record whether - ;; we either saved them or asked to. - (and save-abbrevs abbrevs-changed - (progn - (if (or arg - (eq save-abbrevs 'silently) - (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) - (write-abbrev-file nil)) - ;; Don't keep bothering user if he says no. - (setq abbrevs-changed nil) - (setq abbrevs-done t))) - (or queried (> files-done 0) abbrevs-done - (cond - ((null autosaved-buffers) - (when (called-interactively-p 'any) - (files--message "(No files need saving)"))) - ((= (length autosaved-buffers) 1) - (files--message "(Saved %s)" (car autosaved-buffers))) - (t - (files--message "(Saved %d files: %s)" - (length autosaved-buffers) - (mapconcat 'identity autosaved-buffers ", ")))))))) + (let* ((switched-buffer nil) + (save-some-buffers--switch-window-callback + (lambda (buffer) + (setq switched-buffer buffer))) + queried autosaved-buffers + files-done abbrevs-done) + (unwind-protect + (save-window-excursion + (dolist (buffer (buffer-list)) + ;; First save any buffers that we're supposed to save + ;; unconditionally. That way the following code won't ask + ;; about them. + (with-current-buffer buffer + (when (and buffer-save-without-query (buffer-modified-p)) + (push (buffer-name) autosaved-buffers) + (save-buffer)))) + ;; Ask about those buffers that merit it, + ;; and record the number thus saved. + (setq files-done + (map-y-or-n-p + (lambda (buffer) + ;; Note that killing some buffers may kill others via + ;; hooks (e.g. Rmail and its viewing buffer). + (and (buffer-live-p buffer) + (buffer-modified-p buffer) + (not (buffer-base-buffer buffer)) + (or + (buffer-file-name buffer) + (with-current-buffer buffer + (or (eq buffer-offer-save 'always) + (and pred buffer-offer-save + (> (buffer-size) 0))))) + (or (not (functionp pred)) + (with-current-buffer buffer (funcall pred))) + (if arg + t + (setq queried t) + (if (buffer-file-name buffer) + (format "Save file %s? " + (buffer-file-name buffer)) + (format "Save buffer %s? " + (buffer-name buffer)))))) + (lambda (buffer) + (with-current-buffer buffer + (save-buffer))) + (buffer-list) + '("buffer" "buffers" "save") + save-some-buffers-action-alist)) + ;; Maybe to save abbrevs, and record whether + ;; we either saved them or asked to. + (and save-abbrevs abbrevs-changed + (progn + (if (or arg + (eq save-abbrevs 'silently) + (y-or-n-p (format "Save abbrevs in %s? " + abbrev-file-name))) + (write-abbrev-file nil)) + ;; Don't keep bothering user if he says no. + (setq abbrevs-changed nil) + (setq abbrevs-done t))) + (or queried (> files-done 0) abbrevs-done + (cond + ((null autosaved-buffers) + (when (called-interactively-p 'any) + (files--message "(No files need saving)"))) + ((= (length autosaved-buffers) 1) + (files--message "(Saved %s)" (car autosaved-buffers))) + (t + (files--message + "(Saved %d files: %s)" (length autosaved-buffers) + (mapconcat 'identity autosaved-buffers ", ")))))) + (when switched-buffer + (pop-to-buffer-same-window switched-buffer))))) (defun clear-visited-file-modtime () "Clear out records of last mod time of visited file.