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-descriptorAn association list mapping notification descriptors to buffers.
auto-revert--global-modeNon-nil if buffer is handled by Global Auto-Revert mode.
auto-revert--lockout-intervalDuration, in seconds, of the Auto-Revert Mode notification lockout.
auto-revert--lockout-timerTimer awaiting the end of the notification lockout interval, or nil.
auto-revert-avoid-pollingNon-nil to avoid polling files when notification is available.
auto-revert-buffer-listList of buffers in Auto-Revert Mode.
auto-revert-check-vc-infoIf non-nil Auto-Revert Mode reliably updates version control info.
auto-revert-debugUse for debug messages.
auto-revert-intervalTime, in seconds, between Auto-Revert Mode file checks.
auto-revert-load-hookFunctions to run when Auto-Revert Mode is first loaded.
auto-revert-modeNon-nil if Auto-Revert mode is enabled.
auto-revert-mode-hookFunctions to run when Auto-Revert Mode is activated.
auto-revert-mode-textString to display in the mode line when Auto-Revert Mode is active.
auto-revert-notify-exclude-dir-regexpRegular expression of directories to be excluded from file notifications.
auto-revert-notify-modified-pNon-nil when file has been modified on the file system.
auto-revert-notify-watch-descriptorThe file watch descriptor active for the current buffer.
auto-revert-remaining-buffersBuffers not checked when user input stopped execution.
auto-revert-remote-filesIf nil remote files are not reverted in Auto Revert modes.
auto-revert-stop-on-user-inputWhen non-nil, user input temporarily interrupts Auto-Revert Mode.
auto-revert-tail-modeNon-nil if Auto-Revert-Tail mode is enabled.
auto-revert-tail-mode-hookHook run after entering or leaving ‘auto-revert-tail-mode’.
auto-revert-tail-mode-textString to display in the mode line when Auto-Revert Tail Mode is active.
auto-revert-tail-posPosition of last known end of file.
auto-revert-timerTimer used by Auto-Revert Mode.
auto-revert-use-notifyIf non-nil Auto-Revert Mode uses file notification functions.
auto-revert-verboseWhen nil, Auto-Revert Mode does not generate any messages.
global-auto-revert-ignore-bufferWhen non-nil, Global Auto-Revert Mode will not revert this buffer.
global-auto-revert-ignore-modesList of major modes Global Auto-Revert Mode should not check.
global-auto-revert-modeNon-nil if Global Auto-Revert mode is enabled.
global-auto-revert-mode-hookHook called when Global Auto-Revert Mode is activated.
global-auto-revert-mode-textString to display when Global Auto-Revert Mode is active.
global-auto-revert-non-file-buffersWhen nil, Global Auto-Revert Mode operates only on file-visiting buffers.

Defined functions (23)

auto-revert--buffer-candidates()
auto-revert--end-lockout(BUFFER)
auto-revert--global-add-current-buffer()
auto-revert--global-adopt-current-buffer()
auto-revert--global-possibly-adopt-current-buffer()
auto-revert--need-polling-p()
auto-revert--polled-buffers()
auto-revert-active-p()
auto-revert-buffer(BUF)
auto-revert-buffers()
auto-revert-handler()
auto-revert-mode(&optional ARG)
auto-revert-notify-add-watch()
auto-revert-notify-handler(EVENT)
auto-revert-notify-rm-watch()
auto-revert-remove-current-buffer(&optional BUFFER)
auto-revert-set-timer()
auto-revert-set-visited-file-name()
auto-revert-tail-handler(SIZE)
auto-revert-tail-mode(&optional ARG)
global-auto-revert-mode(&optional ARG)
turn-on-auto-revert-mode()
turn-on-auto-revert-tail-mode()

Defined faces (0)