Automatically revert buffers

If you want Emacs to automatically update a buffer if a file changes on disk, then add the following to your emacs config file

;; auto revert mode
(global-auto-revert-mode 1)

Of course, if your buffer has unsaved changes when the file changes on disk, then Emacs will prompt you and your changes won’t be lost.

This mode only applies to buffers associated with files on the disk, but I like to have my dired view updated if the contents of a directory change. This is accomplished with the following code:

;; auto refresh dired when file changes
(add-hook 'dired-mode-hook 'auto-revert-mode)
  • Leszek Wroński

    Thank you 😉

  • Brad

    I’ve always wanted Emacs to do this, this is awesome – until I opened a log file from a network drive. It it gets written to every few seconds takes about 10 seconds to open, which resulted in Emacs effectively completely freezing up.

    Any idea on how to handle this? The documentation says that “These minor modes do not check or revert remote
    files”, but apparently Emacs doesn’t consider this file “remote” (I’m on Windows, opening this file with a UNC path, not a mapped drive). Is it possible to tell Emacs to not auto-revert files over a few MB?

  • You can also use this for dired and other non-file modes:

    (setq global-auto-revert-non-file-buffers t)