Skip to main content
Commonmark migration
Source Link

Here's an improved and a better documented version of above after looking at @Drew's [solution][2]solution.

[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/115Reference

Here's an improved and a better documented version of above after looking at @Drew's [solution][2].

[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

Here's an improved and a better documented version of above after looking at @Drew's solution.

Reference

replaced http://emacs.stackexchange.com/ with https://emacs.stackexchange.com/
Source Link

[Reference][1] [1]: https://github.com/kaushalmodi/.emacs.d/blob/d139c218d62c11994dbbe35d742f78b15ca84f90/setup-files/setup-windows-buffers.el#L210-L235 [2]: httphttps://emacs.stackexchange.com/a/24464/115

[Reference][1] [1]: https://github.com/kaushalmodi/.emacs.d/blob/d139c218d62c11994dbbe35d742f78b15ca84f90/setup-files/setup-windows-buffers.el#L210-L235 [2]: http://emacs.stackexchange.com/a/24464/115

[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

Add a better documentation version of the same function; use dolist instead of car and pop, use file-readable-p instead of file-exists-p
Source Link
Kaushal Modi
  • 26.4k
  • 4
  • 84
  • 193

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

[Reference][1] [1]: https://github.com/kaushalmodi/.emacs.d/blob/60739a16fe76081ab3ea37eafa5ef1578cdc5d99/setup-files/setup-windows-buffers.el#L210-L234

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/d139c218d62c11994dbbe35d742f78b15ca84f90/setup-files/setup-windows-buffers.el#L210-L235 [2]: http://emacs.stackexchange.com/a/24464/115

Source Link
Kaushal Modi
  • 26.4k
  • 4
  • 84
  • 193
Loading