Original
Update
Here's an improved and a better documented version of above after looking at @Drew's [solution][2].
(defun modi/revert-all-file-buffers () "Refresh all open file buffers without confirmation. Buffers in modified (not yet saved) state in emacs will not be reverted. They will be reverted though if they were modified outside emacs. Buffers visiting files which do not exist any more or are no longer readable will be killed." (interactive) (dolist (buf (buffer-list)) (let ((filename (buffer-file-name buf))) ;; Revert only buffers containing files, which are not modified; ;; do not try to revert non-file buffers like *Messages*. (when (and filename (not (buffer-modified-p buf))) (if (file-readable-p filename) ;; If the file exists and is readable, revert the buffer. (with-current-buffer buf (revert-buffer :ignore-auto :noconfirm :preserve-modes)) ;; Otherwise, kill the buffer. (let (kill-buffer-query-functions) ; No query done when killing buffer (kill-buffer buf) (message "Killed non-existing/unreadable file buffer: %s" filename)))))) (message "Finished reverting buffers containing unmodified files."))
[Reference][1] [1]: https://github.com/kaushalmodi/.emacs.d/blob/60739a16fe76081ab3ea37eafa5ef1578cdc5d99d139c218d62c11994dbbe35d742f78b15ca84f90/setup-files/setup-windows-buffers.el#L210-L234L235 [2]: http://emacs.stackexchange.com/a/24464/115