<!-- language-all: lang-el --> ## Original Here is my slightly improved version of the snippet in the question. Reviewing my VC history, I confirm that the below snippet started out as the snippet posted by the OP. So I do pay attribute to that. Here's the code that has been stable for me: (defun modi/revert-all-file-buffers () "Refresh all open buffers from their respective files." (interactive) (let* ((list (buffer-list)) (buffer (car list))) (while buffer (let ((filename (buffer-file-name buffer))) ;; 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 buffer))) (if (file-exists-p filename) ;; If the file exists, revert the buffer. (with-current-buffer buffer (revert-buffer :ignore-auto :noconfirm :preserve-modes)) ;; If the file doesn't exist, kill the buffer. (let (kill-buffer-query-functions) ; No query done when killing buffer (kill-buffer buffer) (message "Killed non-existing file buffer: %s" filename))))) (setq buffer (pop list))) (message "Finished reverting buffers containing unmodified files."))) --- ## 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/d139c218d62c11994dbbe35d742f78b15ca84f90/setup-files/setup-windows-buffers.el#L210-L235 [2]: https://emacs.stackexchange.com/a/24464/115