From b41a763d9a7d83571779c6dae210bd4d5965f17c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 27 Jul 2019 13:04:33 +0200 Subject: [PATCH] Allow global-auto-revert-ignore-buffer to be a predicate function * lisp/autorevert.el (global-auto-revert-ignore-buffer): Allow this to be a predicate function (bug#25277). (auto-revert--global-add-current-buffer): Use it. --- etc/NEWS | 5 +++++ lisp/autorevert.el | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 021e84c9a43..2146fcd02b5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1691,6 +1691,11 @@ the new variable 'buffer-auto-revert-by-notification' to a non-nil value. Auto Revert mode can use this information to avoid polling the buffer periodically when 'auto-revert-avoid-polling' is non-nil. +--- +*** `global-auto-revert-ignore-buffer' can now also be a predicate +function that can be used for more fine-grained control of which +buffers to auto-revert. + ** auth-source-pass +++ diff --git a/lisp/autorevert.el b/lisp/autorevert.el index 5c79a7e7955..6cdc1d3a297 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el @@ -266,7 +266,10 @@ buffers. CPU usage depends on the version control system." (defvar-local global-auto-revert-ignore-buffer nil "When non-nil, Global Auto-Revert Mode will not revert this buffer. -This variable becomes buffer local when set in any fashion.") +This variable can also be a predicate function, in which case +it'll be called with one parameter (the buffer in question), and +it should return non-nil to make Global Auto-Revert Mode not +revert this buffer.") (defcustom auto-revert-remote-files nil "If non-nil remote files are also reverted." @@ -541,7 +544,11 @@ specifies in the mode line." (not (eq buffer-stale-function #'buffer-stale--default-function)))) (not (memq 'major-mode global-auto-revert-ignore-modes)) - (not global-auto-revert-ignore-buffer)) + (or (null global-auto-revert-ignore-buffer) + (if (functionp global-auto-revert-ignore-buffer) + (not (funcall global-auto-revert-ignore-buffer + (current-buffer))) + nil))) (setq auto-revert--global-mode t))) (defun auto-revert--global-adopt-current-buffer () -- 2.39.2