Function: auto-revert-mode

auto-revert-mode is an autoloaded, interactive and byte-compiled function defined in autorevert.el.gz.

Signature

(auto-revert-mode &optional ARG)

Documentation

Toggle reverting buffer when the file changes (Auto-Revert Mode).

Auto-Revert Mode is a minor mode that affects only the current buffer. When enabled, it reverts the buffer when the file on disk changes.

When a buffer is reverted, a message is generated. This can be suppressed by setting auto-revert-verbose to nil.

Reverting can sometimes fail to preserve all the markers in the buffer. To avoid that, set revert-buffer-insert-file-contents-function to the slower function revert-buffer-insert-file-contents-delicately.

Use global-auto-revert-mode(var)/global-auto-revert-mode(fun) to automatically revert all buffers. Use auto-revert-tail-mode(var)/auto-revert-tail-mode(fun) if you know that the file will only grow without being changed in the part that is already in the buffer.

This is a minor mode. If called interactively, toggle the Auto-Revert mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable auto-revert-mode(var)/auto-revert-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/autorevert.el.gz
;;;###autoload
(define-minor-mode auto-revert-mode
  "Toggle reverting buffer when the file changes (Auto-Revert Mode).

Auto-Revert Mode is a minor mode that affects only the current
buffer.  When enabled, it reverts the buffer when the file on
disk changes.

When a buffer is reverted, a message is generated.  This can be
suppressed by setting `auto-revert-verbose' to nil.

Reverting can sometimes fail to preserve all the markers in the buffer.
To avoid that, set `revert-buffer-insert-file-contents-function' to
the slower function `revert-buffer-insert-file-contents-delicately'.

Use `global-auto-revert-mode' to automatically revert all buffers.
Use `auto-revert-tail-mode' if you know that the file will only grow
without being changed in the part that is already in the buffer."
  :group 'auto-revert :lighter auto-revert-mode-text
  (if auto-revert-mode
      (when (and (not (buffer-base-buffer (current-buffer)))
                 (not (memq (current-buffer) auto-revert-buffer-list)))
        (push (current-buffer) auto-revert-buffer-list)
        (add-hook
         'kill-buffer-hook
         #'auto-revert-remove-current-buffer
         nil t))
    (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch))
    (auto-revert-remove-current-buffer))
  (auto-revert-set-timer)
  (when auto-revert-mode
    (auto-revert-buffer (current-buffer))
    (setq auto-revert-tail-mode nil)))