]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a new action in save-some-buffers to view the buffer
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 13 Oct 2019 19:36:57 +0000 (21:36 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 13 Oct 2019 19:42:03 +0000 (21:42 +0200)
* 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.

doc/emacs/files.texi
etc/NEWS
lisp/files.el

index 9fe1b564a829a7d71a7320cb86d2142fe5ffc125..c3ede1833b51811fbac7377b2fbf36577e6b7101 100644 (file)
@@ -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
index eeb02b7066cf04d01a1214e13c03ffd83c5cad55..5b3dabe22ac1d17bc83b72b8c7edc9399b570df3 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -453,6 +453,10 @@ Note that this key binding will not work on MS-Windows systems if
 \f
 * 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.
index a1c7e3c8144fd2ea89b6fb8d9fb5a9242855e2df..007195d22a87fe0eff60e95ca7d36afa52520bba 100644 (file)
@@ -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)))))
 \f
 (defun clear-visited-file-modtime ()
   "Clear out records of last mod time of visited file.