Add a new command `revert-buffer-quick'

* doc/emacs/files.texi (Reverting): Document it.
* lisp/bindings.el (ctl-x-x-map): Bind `C-x x g' to
`revert-buffer-quick' instead.

* lisp/files.el (revert-buffer-quick-short-answers): New user option.
(revert-buffer-quick): New command (bug#49869).
This commit is contained in:
Lars Ingebrigtsen
2021-08-10 16:40:58 +02:00
parent 2656ecff96
commit ebaae4480e
4 changed files with 55 additions and 3 deletions

View File

@@ -948,7 +948,7 @@ Manual}). For customizations, see the Custom group @code{time-stamp}.
then change your mind, you can @dfn{revert} the changes and go back to
the saved version of the file. To do this, type @kbd{C-x x g}. Since
reverting unintentionally could lose a lot of work, Emacs asks for
confirmation first.
confirmation first if the buffer is modified.
The @code{revert-buffer} command tries to position point in such a
way that, if the file was edited only slightly, you will be at
@@ -991,6 +991,17 @@ revert it automatically if it has changed---provided the buffer itself
is not modified. (If you have edited the text, it would be wrong to
discard your changes.)
@vindex revert-buffer-quick-short-answers
@findex revert-buffer-quick
The @kbd{C-x x g} keystroke is bound to the
@code{revert-buffer-quick} command. This is like the
@code{revert-buffer} command, but prompts less. Unlike
@code{revert-buffer}, it will not prompt if the current buffer visits
a file, and the buffer is not modified. It also respects the
@code{revert-buffer-quick-short-answers} user option. If this option
is non-@code{nil}, use a shorter @kbd{y/n} query instead of a longer
@kbd{yes/no} query.
You can also tell Emacs to revert buffers automatically when their
visited files change on disk; @pxref{Auto Revert}.

View File

@@ -310,7 +310,7 @@ search buffer due to too many matches being highlighted.
+++
** A new keymap for buffer actions has been added.
The 'C-x x' keymap now holds keystrokes for various buffer-oriented
commands. The new keystrokes are 'C-x x g' ('revert-buffer'),
commands. The new keystrokes are 'C-x x g' ('revert-buffer-quick'),
'C-x x r' ('rename-buffer'), 'C-x x u' ('rename-uniquely'), 'C-x x n'
('clone-buffer'), 'C-x x i' ('insert-buffer'), 'C-x x t'
('toggle-truncate-lines') and 'C-x x f' ('font-lock-update').
@@ -2394,6 +2394,16 @@ This command, called interactively, toggles the local value of
** Miscellaneous
+++
*** New command 'revert-buffer-quick'.
This is bound to 'C-x x g' and is like `revert-buffer', but prompts
less.
+++
*** New user option 'revert-buffer-quick-short-answers'. This
controls how the new 'revert-buffer-quick' (`C-x x g') command
prompts.
---
*** fileloop will now skip missing files instead of signalling an error.

View File

@@ -1469,7 +1469,7 @@ if `inhibit-field-text-motion' is non-nil."
(defvar ctl-x-x-map
(let ((map (make-sparse-keymap)))
(define-key map "f" #'font-lock-update)
(define-key map "g" #'revert-buffer)
(define-key map "g" #'revert-buffer-quick)
(define-key map "r" #'rename-buffer)
(define-key map "u" #'rename-uniquely)
(define-key map "n" #'clone-buffer)

View File

@@ -6561,6 +6561,37 @@ details on the arguments, see `revert-buffer'."
(revert-buffer-with-fine-grain-success-p)
(fmakunbound 'revert-buffer-with-fine-grain-success-p)))))
(defcustom revert-buffer-quick-short-answers nil
"How much confirmation to be done by the `revert-buffer-quit' command.
If non-nil, use `y-or-n-p' instead of `yes-or-no-p'."
:version "28.1"
:type 'boolean)
(defun revert-buffer-quick (&optional auto-save)
"Like `revert-buffer', but asks for less confirmation.
If the current buffer is visiting a file, and the buffer is not
modified, no confirmation is required.
This command heeds the `revert-buffer-quick-short-answers' user option.
If AUTO-SAVE (the prefix argument), offer to revert from latest
auto-save file, if that is more recent than the visited file."
(interactive "P")
(cond
;; If we've visiting a file, and we have no changes, don't ask for
;; confirmation.
((and buffer-file-name
(not (buffer-modified-p)))
(revert-buffer (not auto-save) t)
(message "Reverted buffer"))
;; Heed `revert-buffer-quick-short-answers'.
(revert-buffer-quick-short-answers
(let ((use-short-answers t))
(revert-buffer (not auto-save))))
;; Call `revert-buffer' normally.
(t
(revert-buffer (not auto-save)))))
(defun recover-this-file ()
"Recover the visited file--get contents from its last auto-save file."
(interactive)