Previous: , Up: Backups and Auto-Saving   [Contents][Index]


36.3 Reverting

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 in The SXEmacs User’s Manual.

Command: revert-buffer &optional check-auto-save noconfirm preserve-modes

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.

If the argument check-auto-save is non-nil, and the latest auto-save file is more recent than the visited file, revert-buffer asks the user whether to use that instead. Otherwise, it always uses the text of the visited file itself. Interactively, check-auto-save is set if there is a numeric prefix argument.

Normally, revert-buffer asks for confirmation before it changes the buffer; but if the argument noconfirm is non-nil, revert-buffer does not ask for confirmation.

Optional third argument preserve-modes non-nil means don’t alter the files modes. Normally we reinitialize them using normal-mode.

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; then 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 these variables—typically, as buffer-local variables.

Variable: revert-buffer-function

The value of this variable is the function to use to revert this buffer. If non-nil, it is called as a function with no arguments to do the work of reverting. If the value is nil, 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, give this variable a buffer-local value that is a function to regenerate the contents.

Variable: revert-buffer-insert-file-contents-function

The value of this variable, if non-nil, is 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, t if the user has asked to read the auto-save file.

Variable: before-revert-hook

This normal hook is run by revert-buffer before actually inserting the modified contents—but only if revert-buffer-function is nil.

Font Lock mode uses this hook to record that the buffer contents are no longer fontified.

Variable: after-revert-hook

This normal hook is run by revert-buffer after actually inserting the modified contents—but only if revert-buffer-function is nil.

Font Lock mode uses this hook to recompute the fonts for the updated buffer contents.


Previous: , Up: Backups and Auto-Saving   [Contents][Index]