(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)
;; 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")
(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.