File: autorevert.el.html
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(var)/global-auto-revert-mode(fun) 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)
Defined variables (32)
auto-revert--buffer-by-watch-descriptor | An association list mapping notification descriptors to buffers. |
auto-revert--global-mode | Non-nil if buffer is handled by Global Auto-Revert mode. |
auto-revert--lockout-interval | Duration, in seconds, of the Auto-Revert Mode notification lockout. |
auto-revert--lockout-timer | Timer awaiting the end of the notification lockout interval, or nil. |
auto-revert-avoid-polling | Non-nil to avoid polling files when notification is available. |
auto-revert-buffer-list | List of buffers in Auto-Revert Mode. |
auto-revert-check-vc-info | If non-nil Auto-Revert Mode reliably updates version control info. |
auto-revert-debug | Use for debug messages. |
auto-revert-interval | Time, in seconds, between Auto-Revert Mode file checks. |
auto-revert-load-hook | Functions to run when Auto-Revert Mode is first loaded. |
auto-revert-mode | Non-nil if Auto-Revert mode is enabled. |
auto-revert-mode-hook | Functions to run when Auto-Revert Mode is activated. |
auto-revert-mode-text | String to display in the mode line when Auto-Revert Mode is active. |
auto-revert-notify-exclude-dir-regexp | Regular expression of directories to be excluded from file notifications. |
auto-revert-notify-modified-p | Non-nil when file has been modified on the file system. |
auto-revert-notify-watch-descriptor | The file watch descriptor active for the current buffer. |
auto-revert-remaining-buffers | Buffers not checked when user input stopped execution. |
auto-revert-remote-files | If non-nil remote files are also reverted. |
auto-revert-stop-on-user-input | When non-nil, user input temporarily interrupts Auto-Revert Mode. |
auto-revert-tail-mode | Non-nil if Auto-Revert-Tail mode is enabled. |
auto-revert-tail-mode-hook | Hook run after entering or leaving ‘auto-revert-tail-mode’. |
auto-revert-tail-mode-text | String to display in the mode line when Auto-Revert Tail Mode is active. |
auto-revert-tail-pos | Position of last known end of file. |
auto-revert-timer | Timer used by Auto-Revert Mode. |
auto-revert-use-notify | If non-nil Auto-Revert Mode uses file notification functions. |
auto-revert-verbose | When nil, Auto-Revert Mode does not generate any messages. |
global-auto-revert-ignore-buffer | When non-nil, Global Auto-Revert Mode will not revert this buffer. |
global-auto-revert-ignore-modes | List of major modes Global Auto-Revert Mode should not check. |
global-auto-revert-mode | Non-nil if Global Auto-Revert mode is enabled. |
global-auto-revert-mode-hook | Hook called when Global Auto-Revert Mode is activated. |
global-auto-revert-mode-text | String to display when Global Auto-Revert Mode is active. |
global-auto-revert-non-file-buffers | When nil, Global Auto-Revert Mode operates only on file-visiting buffers. |