# Automatically refreshing files in Emacs

I like my editor to auto-refresh the file I'm visiting if it has changed on disc. To give a simple example, I tend to run the pessimize command after installing dependencies for a project. This adds version numbers to the project's Gemfile. But I usually do this right after adding or removing a gem from the file, which means it's almost a fact that the file will be opened in a buffer on Emacs.

When that happens, I like the changes to be visible on my buffer right away. If not, there's a high probability tht I'll make a change right away and save and all the changes made by pessimize will be lost.

Emacs calls this process of refreshing the file revert. Here's how I have my config do it for me.

The first line enables the auto-revert feature for all files. Then, the second line takes care of updating dired buffers. Finally, the last line tells Emacs to make the changes to the buffer without all the fuzz, no question asked, no messages raised.

  ;; Auto revert files when they change
(global-auto-revert-mode t)

;; Also auto refresh dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)

It's a simple feature, but one I cann't live without.

I hope you find it useful.

Saluti.