Previous: Auto-Saving, Up: Backups and Auto-Saving
If you have made extensive changes to a file and then change your mind
about them, you can get rid of them by reading in the previous version
of the file with the revert-buffer command. See Reverting a Buffer↗.
This command replaces the buffer text with the text of the visited file on disk. This action undoes all changes since the file was visited or saved.
By default, if the latest auto-save file is more recent than the visited file, and the argument ignore-auto is
nil,revert-bufferasks the user whether to use that auto-save instead. When you invoke this command interactively, ignore-auto istif there is no numeric prefix argument; thus, the interactive default is not to check the auto-save file.Normally,
revert-bufferasks for confirmation before it changes the buffer; but if the argument noconfirm is non-nil,revert-bufferdoes not ask for confirmation.Normally, this command reinitializes the file's major and minor modes using
normal-mode. But if preserve-modes is non-nil, the modes remain unchanged.Reverting tries to preserve marker positions in the buffer by using the replacement feature of
insert-file-contents. If the buffer contents and the file contents are identical before the revert operation, reverting preserves all the markers. If they are not identical, reverting does change the buffer; in that case, it preserves the markers in the unchanged text (if any) at the beginning and end of the buffer. Preserving any additional markers would be problematical.
You can customize how revert-buffer does its work by setting
the variables described in the rest of this section.
This variable holds a list of files that should be reverted without query. The value is a list of regular expressions. If the visited file name matches one of these regular expressions, and the file has changed on disk but the buffer is not modified, then
revert-bufferreverts the file without asking the user for confirmation.
Some major modes customize revert-buffer by making
buffer-local bindings for these variables:
The value of this variable is the function to use to revert this buffer. If non-
nil, it should be a function with two optional arguments to do the work of reverting. The two optional arguments, ignore-auto and noconfirm, are the arguments thatrevert-bufferreceived. If the value isnil, reverting works the usual way.Modes such as Dired mode, in which the text being edited does not consist of a file's contents but can be regenerated in some other fashion, can give this variable a buffer-local value that is a function to regenerate the contents.
The value of this variable, if non-
nil, specifies the function to use to insert the updated contents when reverting this buffer. The function receives two arguments: first the file name to use; second,tif the user has asked to read the auto-save file.The reason for a mode to set this variable instead of
revert-buffer-functionis to avoid duplicating or replacing the rest of whatrevert-bufferdoes: asking for confirmation, clearing the undo list, deciding the proper major mode, and running the hooks listed below.
This normal hook is run by
revert-bufferbefore inserting the modified contents—but only ifrevert-buffer-functionisnil.
This normal hook is run by
revert-bufferafter inserting the modified contents—but only ifrevert-buffer-functionisnil.
