autorevert

Homepage: https://www.gnu.org/software/emacs

Author: Anders Lindgren

Summary

Revert buffers when files on disk change

Commentary

Introduction:

Whenever a file that Emacs is editing has been changed by another
program the user normally has to execute the command `revert-buffer'
to load the new content of the file into Emacs.

This package contains two minor modes: Global Auto-Revert Mode and
Auto-Revert Mode.  Both modes automatically revert buffers
whenever the corresponding files have been changed on disk and the
buffer contains no unsaved changes.

Auto-Revert Mode can be activated for individual buffers.  Global
Auto-Revert Mode applies to all file buffers.  (If the user option
`global-auto-revert-non-file-buffers' is non-nil, it also applies
to some non-file buffers.  This option is disabled by default.)

Since checking a remote file is slow, these modes check or revert
remote files only if the user option `auto-revert-remote-files' is
non-nil.  It is recommended to disable version control for remote
files.

Both modes operate by checking the time stamp of all files at
intervals of `auto-revert-interval'.  The default is every five
seconds.  The check is aborted whenever the user actually uses
Emacs.  You should never even notice that this package is active
(except that your buffers will be reverted, of course).

If the file exists, Auto-Revert Mode updates the buffer based on
its (possibly empty) contents.  If the file no longer exists, then
there is nothing to revert, so it does not modify the buffer.  Once
a deleted file corresponding to a buffer in Auto-Revert Mode
reappears, Auto-Revert Mode continues to work.

If Emacs is compiled with file notification support, notifications
are used instead of checking the time stamp of the files.  You can
disable this by setting the user option `auto-revert-use-notify' to
nil.  Alternatively, a regular expression of directories to be
excluded from file notifications can be specified by
`auto-revert-notify-exclude-dir-regexp'.

After reverting a file buffer, Auto-Revert Mode normally puts point
at the same position that a regular manual revert would.  However,
there is one exception to this rule.  If point is at the end of the
buffer before reverting, it stays at the end.  Similarly if point
is displayed at the end of a file buffer in any window, it will stay
at the end of the buffer in that window, even if the window is not
selected.  This way, you can use Auto-Revert Mode to `tail' a file.
Just put point at the end of the buffer and it will stay there.
These rules apply to file buffers.  For non-file buffers, the
behavior may be mode dependent.

While you can use Auto-Revert Mode to tail a file, this package
contains a third minor mode, Auto-Revert Tail Mode, which does so
more efficiently, as long as you are sure that the file will only
change by growing at the end.  It only appends the new output,
instead of reverting the entire buffer.  It does so even if the
buffer contains unsaved changes.  (Because they will not be lost.)

Usage:

Go to the appropriate buffer and press either of:
  M-x auto-revert-mode RET
  M-x auto-revert-tail-mode RET

To activate Global Auto-Revert Mode, press:
  M-x global-auto-revert-mode RET

To activate Global Auto-Revert Mode every time Emacs is started
customize the option `global-auto-revert-mode' or the following
line could be added to your ~/.emacs:
  (global-auto-revert-mode 1)

The function `turn-on-auto-revert-mode' could be added to any major
mode hook to activate Auto-Revert Mode for all buffers in that
mode.  For example, the following line will activate Auto-Revert
Mode in all C mode buffers:

(add-hook 'c-mode-hook #'turn-on-auto-revert-mode)

Dependencies

Reverse dependencies