Reverting In Emacs

One of the things about Emacs is that buffers tend to hang around for a long time. This is especially true if you’re using desktop-save-mode. Most of the time this isn’t a problem but every once in a while the file underneath a buffer changes. Most of the time Emacs will notice this and can run 【Meta+xrevert-buffer to sync things up again. Of course, you can also use revert-buffer to erase all changes to the buffer since the last save.

Sometimes, though, there is another process making frequent changes to the visited file and you’d like to keep the buffer current. For this, there is auto-revert-mode. With a positive argument, auto-revert-mode will track the visited file and automatically update the corresponding Emacs buffer. This mode affects only the current buffer but you can, if necessary, track all open buffers with global-auto-revert-mode. You’ll probably take a performance hit (although I haven’t verified this) if you have a lot of buffers open and turn on global-auto-revert-mode so be careful out there.

A related mode is auto-revert-tail-mode. This mode tracks appends to the file in the manner of tail -f. It needs only check if the size of the file has changed so it’s more efficient when you’re just worried about additions to the file.

This entry was posted in General and tagged . Bookmark the permalink.