From 8a8319140c5f5e981e61f20854f836874aa9dd5e Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 21 Sep 2021 23:09:34 +0200 Subject: [PATCH] Make global-auto-revert-non-file-buffers work better * lisp/autorevert.el (global-auto-revert-mode): Always switch on the non-file tracking. (auto-revert--global-possibly-adopt-current-buffer): New function to respect dynamically changing `global-auto-revert-non-file-buffers'. --- lisp/autorevert.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/autorevert.el b/lisp/autorevert.el index c8fe205946c..5b1cd322471 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el @@ -521,13 +521,12 @@ specifies in the mode line." ;; To track non-file buffers, we need to listen in to buffer ;; creation in general. Listening to major-mode changes is ;; suitable, since we then know whether it's a mode that is tracked. - (when global-auto-revert-non-file-buffers - (add-hook 'after-change-major-mode-hook - #'auto-revert--global-adopt-current-buffer)) + (add-hook 'after-change-major-mode-hook + #'auto-revert--global-possibly-adopt-current-buffer) (auto-revert-buffers)) ;; Turn global-auto-revert-mode OFF. (remove-hook 'after-change-major-mode-hook - #'auto-revert--global-adopt-current-buffer) + #'auto-revert--global-possibly-adopt-current-buffer) (remove-hook 'find-file-hook #'auto-revert--global-adopt-current-buffer) (dolist (buf (buffer-list)) (with-current-buffer buf @@ -556,6 +555,12 @@ specifies in the mode line." nil))) (setq auto-revert--global-mode t))) +(defun auto-revert--global-possibly-adopt-current-buffer () + "Consider tracking current buffer in a running Global Auto-Revert mode. +This tracks buffers if `global-auto-revert-non-file-buffers' is non-nil." + (when global-auto-revert-non-file-buffers + (auto-revert--global-adopt-current-buffer))) + (defun auto-revert--global-adopt-current-buffer () "Consider tracking current buffer in a running Global Auto-Revert mode." (auto-revert--global-add-current-buffer)