Based on @Drew's answer, with progress reporting since it can be slow with many files open.
(defun revert-all-buffers () "Refresh all open buffers from their respective files." (interactive) (message "Begin reverting all buffers...") (let* ( ;; pairs of (filename, buf) (ls (mapcar (lambda (buf) (list (buffer-file-name buf) buf)) (seq-filter 'buffer-file-name (buffer-list)))) (count (length ls)) (count-closed 0) ;; Keep text at a fixed width when redrawing. (format-count (format "%%%dd" (length (number-to-string count)))) (format-text (concat "Reverting [" format-count " of " format-count "] %3d%%: %s")) (index 1) ) (while ls (cl-destructuring-bind (filename buf) (pop ls) ;; Revert only buffers containing files, which are not modified; ;; do not try to revert non-file buffers like *Messages*. (message format-text index count (round (* 100 (/ (float index) count))) filename) (if (file-exists-p filename) ;; If the file exists, revert the buffer. (with-demoted-errors "Error: %S" (with-current-buffer buf (revert-buffer :ignore-auto :noconfirm)) ) ;; If the file doesn't exist, kill the buffer. (let (kill-buffer-query-functions) ; No query done when killing buffer. (kill-buffer buf) (message "Closed non-existing file buffer: %s" buf) (setq count-closed (1+ count-closed)) ) ) (setq index (1+ index)) ) ) (message "Finished reverting %d file buffer(s), closed (%d)." count count-closed) ) )