How to have Emacs auto-refresh all buffers when files have changed on disk?

EmacsElispDot Emacs

Emacs Problem Overview


I have a non-emacs global search and replace function that causes my disk files to become more up-to-date than my emacs buffers (en masse). Is there any way to tell emacs to refresh all the buffers from disk in one fell swoop, instead of having to do each one individually by reloading the file?

Thanks! D

Emacs Solutions


Solution 1 - Emacs

(global-auto-revert-mode t) in your .emacs.

Solution 2 - Emacs

Here is an alternative if you are using Emacs GUI (Mine is GNU Emacs 25.1.1 on Windows 7):

  1. Click "Options" in menubar
  2. Select "Customize Emacs"
  3. Select "Saved Options"
  4. Then you should see a search field where you enter "global-auto-revert-mode" and press "Search" button
  5. Click "Toggle" button and make sure it reads "on" to the right of the button
  6. Press "Apply and Save" button right below the search field

If you already have a few files opened, you should see this taken effect instantly. Good luck!

Solution 3 - Emacs

Thanks to @Ashwin for pointing out (global-auto-revert-mode t). I found that Emacs won't automatically update buffers whose files have changed on disk with this change alone. From https://www.gnu.org/software/emacs/manual/html_node/emacs/Reverting.html:

> By default, Auto-Revert mode works using file notifications, whereby changes in the filesystem are reported to Emacs by the OS. You can disable use of file notifications by customizing the variable auto-revert-use-notify to a nil value, then Emacs will check for file changes by polling every five seconds. You can change the polling interval through the variable auto-revert-interval.

After I set (setq auto-revert-use-notify nil), Emacs did indeed refresh all buffers every 5 seconds.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaveView Question on Stackoverflow
Solution 1 - EmacsAshwinView Answer on Stackoverflow
Solution 2 - EmacsbenjaminzView Answer on Stackoverflow
Solution 3 - EmacsjdcView Answer on Stackoverflow