From d6aea001c5976517f5f7d70dbba421406cedd9b5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 19 May 2019 13:25:56 -0400 Subject: [PATCH] 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. --- core/core-editor.el | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/core/core-editor.el b/core/core-editor.el index 091ad443b..a56ee8b27 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -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