Commit 1943220d authored by Mattias Engdegård's avatar Mattias Engdegård

Don't use file notification on non-file buffers

Allow non-file buffers to declare that notification on their
default-directory is sufficient to know when auto-revert updates are
required by setting the new variable `buffer-auto-revert-by-notification'
to non-nil.  If nil, the default, then auto-revert will poll
those buffers instead. (bug#35418).
Currently, only Dired sets that variable.

* lisp/autorevert.el (auto-revert-buffers):
Modify condition for using notification.
* lisp/files.el (buffer-auto-revert-by-notification): New variable.
* lisp/dired.el (dired-mode): Set buffer-auto-revert-by-notification.
* doc/emacs/arevert-xtra.texi (Non-File Buffers): Document new variable.
* etc/NEWS (Changes in Specialized Modes and Packages): Describe new variable.
parent 4bf447bb
Pipeline #1716 passed with stage
in 54 minutes and 41 seconds
......@@ -35,6 +35,14 @@ the Buffer Menu.) In this case, Auto Revert does not print any
messages while reverting, even when @code{auto-revert-verbose} is
non-@code{nil}.
@vindex buffer-auto-revert-by-notification
Some non-file buffers can be updated reliably by file notification on
their default directory; Dired buffers is an example. The major mode
can indicate this by setting @code{buffer-auto-revert-by-notification}
to a non-@code{nil} value in that buffer, allowing Auto Revert to
avoid periodic polling. Such notification does not include changes to
files in that directory, only to the directory itself.
The details depend on the particular types of buffers and are
explained in the corresponding sections.
......
......@@ -1446,6 +1446,13 @@ of an idle Emacs, but may fail on some network file systems; set
notification is not supported. The new variable currently has no
effect in 'global-auto-revert-mode'. The default value is nil.
*** New variable 'buffer-auto-revert-by-notification'
A major mode can declare that notification on the buffer's default
directory is sufficient to know when updates are required, by setting
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.
* New Modes and Packages in Emacs 27.1
......
......@@ -858,8 +858,12 @@ the timer when no buffers need to be checked."
(auto-revert-remove-current-buffer))
(when (auto-revert-active-p)
;; Enable file notification.
;; Don't bother creating a notifier for non-file buffers
;; unless it explicitly indicates that this works.
(when (and auto-revert-use-notify
(not auto-revert-notify-watch-descriptor))
(not auto-revert-notify-watch-descriptor)
(or buffer-file-name
buffer-auto-revert-by-notification))
(auto-revert-notify-add-watch))
(auto-revert-handler)))))
(setq bufs (cdr bufs)))
......
......@@ -2148,6 +2148,7 @@ Keybindings:
(setq buffer-invisibility-spec (list t)))
(setq-local revert-buffer-function #'dired-revert)
(setq-local buffer-stale-function #'dired-buffer-stale-p)
(setq-local buffer-auto-revert-by-notification t)
(setq-local page-delimiter "\n\n")
(setq-local dired-directory (or dirname default-directory))
;; list-buffers uses this to display the dir being edited in this buffer.
......
......@@ -5890,6 +5890,16 @@ This should not be relied upon.
For more information on how this variable is used by Auto Revert mode,
see Info node `(emacs)Supporting additional buffers'.")
(defvar-local buffer-auto-revert-by-notification nil
"Whether a buffer can rely on notification in Auto-Revert mode.
If non-nil, monitoring changes to the directory of the current
buffer is sufficient for knowing when that buffer needs to be
updated in Auto Revert Mode. Such notification does not include
changes to files in that directory, only to the directory itself.
This variable only applies to buffers where `buffer-file-name' is
nil; other buffers are tracked by their files.")
(defvar before-revert-hook nil
"Normal hook for `revert-buffer' to run before reverting.
The function `revert-buffer--default' runs this.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment