Implement lazy auto-revert

Instead of using auto-revert-mode or global-auto-revert-mode, we employ
lazy auto reverting on focus-in-hook, doom-switch-buffer-hook and
after-save-hook.

We do this because autorevert abuses inotify handles, which can grind
Emacs to a halt if you have hundreds of buffers open and something
performs expensive mtime or attribute-altering IO on their files outside
of Emacs. We only really need revert checks when we switch to or save a
buffer, or when we focus the Emacs frame.
This commit is contained in:
Henrik Lissner 2019-05-19 13:25:56 -04:00
parent 41de07177b
commit d6aea001c5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -73,11 +73,27 @@ detected.")
;;; Built-in plugins
(def-package! autorevert
;; revert buffers for changed files
:after-call after-find-file
;; revert buffers when their files/state have changed
:hook (focus-in . doom|auto-revert-buffers)
:hook (doom-switch-buffer . auto-revert-handler)
:hook (after-save . doom|auto-revert-buffers)
:config
(setq auto-revert-verbose nil)
(global-auto-revert-mode +1))
(setq auto-revert-verbose t ; let us know when it happens
auto-revert-use-notify nil
auto-revert-stop-on-user-input nil)
;; Instead of using `auto-revert-mode' or `global-auto-revert-mode', we employ
;; lazy auto reverting on `focus-in-hook' and `doom-switch-buffer-hook'.
;;
;; This is because autorevert abuses the heck out of inotify handles which can
;; grind Emacs to a halt if you do expensive IO (outside of Emacs) on the
;; files you have open (like compression). We only really need revert changes
;; when we switch to a buffer or when we focus the Emacs frame.
(defun doom|auto-revert-buffers ()
"Auto revert's stale buffers (that are visible)."
(dolist (buf (doom-visible-buffers))
(with-current-buffer buf
(auto-revert-handler)))))
(def-package! recentf
;; Keep track of recently opened files