mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-17 10:06:13 +00:00
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.
This commit is contained in:
parent
67ed6ee733
commit
b02f0ae995
@ -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
|
||||
|
4
etc/NEWS
4
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.
|
||||
|
143
lisp/files.el
143
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.
|
||||
|
Loading…
Reference in New Issue
Block a user