Function: global-auto-revert-mode

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

Signature

(global-auto-revert-mode &optional ARG)

Documentation

Toggle Global Auto-Revert Mode.

Global Auto-Revert Mode is a global minor mode that reverts any buffer associated with a file when the file changes on disk. Use auto-revert-mode(var)/auto-revert-mode(fun) to revert a particular buffer.

If global-auto-revert-non-file-buffers is non-nil, this mode may also revert some non-file buffers, as described in the documentation of that variable. It ignores buffers with modes matching global-auto-revert-ignore-modes, and buffers with a non-nil value of global-auto-revert-ignore-buffer.

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

This function calls the hook global-auto-revert-mode-hook. It displays the text that global-auto-revert-mode-text specifies in the mode line.

This is a global minor mode. If called interactively, toggle the Global 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 (default-value \=global-auto-revert-mode)'.

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

View in manual

Probably introduced at or before Emacs version 25.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/autorevert.el.gz
;;;###autoload
(define-minor-mode global-auto-revert-mode
  "Toggle Global Auto-Revert Mode.

Global Auto-Revert Mode is a global minor mode that reverts any
buffer associated with a file when the file changes on disk.  Use
`auto-revert-mode' to revert a particular buffer.

If `global-auto-revert-non-file-buffers' is non-nil, this mode
may also revert some non-file buffers, as described in the
documentation of that variable.  It ignores buffers with modes
matching `global-auto-revert-ignore-modes', and buffers with a
non-nil value of `global-auto-revert-ignore-buffer'.

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

This function calls the hook `global-auto-revert-mode-hook'.
It displays the text that `global-auto-revert-mode-text'
specifies in the mode line."
  :global t :group 'auto-revert :lighter global-auto-revert-mode-text
  (auto-revert-set-timer)
  (if global-auto-revert-mode
      ;; Turn global-auto-revert-mode ON.
      (progn
        (dolist (buf (buffer-list))
          (with-current-buffer buf
            (auto-revert--global-add-current-buffer)))
        ;; Make sure future buffers are added as well.
        (add-hook 'find-file-hook #'auto-revert--global-adopt-current-buffer)
        ;; To track non-file buffers, we need to listen in to buffer
        ;; creation in general.  Listening to major-mode changes is
        ;; suitable, since we then know whether it's a mode that is tracked.
        (add-hook 'after-change-major-mode-hook
                  #'auto-revert--global-possibly-adopt-current-buffer)
        (auto-revert-buffers))
    ;; Turn global-auto-revert-mode OFF.
    (remove-hook 'after-change-major-mode-hook
                 #'auto-revert--global-possibly-adopt-current-buffer)
    (remove-hook 'find-file-hook #'auto-revert--global-adopt-current-buffer)
    (dolist (buf (buffer-list))
      (with-current-buffer buf
        (when auto-revert--global-mode
          (setq auto-revert--global-mode nil)
          (when (and auto-revert-notify-watch-descriptor
                     (not (or auto-revert-mode auto-revert-tail-mode)))
	    (auto-revert-notify-rm-watch)))))))