unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Boruch Baum <boruch_baum@gmx.com>
To: 43412@debbugs.gnu.org
Subject: bug#43412: [FEATURE] autorevert-only-if-visible [PATCH]
Date: Tue, 15 Sep 2020 00:07:28 -0400	[thread overview]
Message-ID: <20200915040728.77ufv7g6bekvrzqa@E15-2016.optimum.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

The attached proposed patch adds a defcustom and makes a change to two
existing functions in order to allow a user the option to only have
autorevert mode operate on visible buffers. The change to function
'after-find-files' may also fix a bug (or change behavior) in that
sometimes when being prompted to manually revert a buffer that had been
in auto-revert-mode, the auto-revert-mode status would be lost, ie. set
to nil.

Use of this feature:

1) Reduces CPU workload when using autorevert

2) Reduces messages when using `auto-revert-verbose'

Possible disadvantage:

1) When making a buffer visible, it might take as long as
   'auto-revert-interval' seconds for any accumulated changes to
   auto-revert. The default for that value is five seconds.

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0

[-- Attachment #2: autorevert.patch --]
[-- Type: text/x-diff, Size: 1273 bytes --]

diff --git a/autorevert.el b/autorevert.el
index 7b83026..ace010e 100644
--- a/autorevert.el
+++ b/autorevert.el
@@ -302,6 +302,12 @@ You should set this variable through Custom."
   :type 'regexp
   :version "24.4")

+(defcustom auto-revert-only-if-visible nil
+  "If non-nil, suppress Auto-Revert Mode when a buffer isn't visible."
+  :group 'auto-revert
+  :type 'boolean
+  :version "28")
+
 ;; Internal variables:

 (defvar auto-revert-buffer-list ()
@@ -686,8 +692,14 @@ This is an internal function used by Auto-Revert Mode."
                               #'buffer-stale--default-function)
                           t))))
          eob eoblist)
-    (setq auto-revert-notify-modified-p nil)
-    (when revert
+    (when (and revert
+               (or (not auto-revert-only-if-visible)
+                   (member buffer
+                     (mapcar 'window-buffer
+                       (get-buffer-window-list
+                         nil nil
+                         (if (display-graphic-p) 'visible (window-normalize-frame nil)))))))
+      (setq auto-revert-notify-modified-p nil)
       (when (and auto-revert-verbose
                  (not (eq revert 'fast)))
         (message "Reverting buffer `%s'." (buffer-name)))

[-- Attachment #3: files.patch --]
[-- Type: text/x-diff, Size: 522 bytes --]

diff --git a/files.el b/files.el
index e6629d2..2cdf451 100644
--- a/files.el
+++ b/files.el
@@ -2570,7 +2570,10 @@ unless NOMODES is non-nil."
   (unless nomodes
     (when (and view-read-only view-mode)
       (view-mode -1))
-    (normal-mode t)
+    (let ((auto-revert auto-revert-mode))
+      (normal-mode t)
+      (when auto-revert
+        (auto-revert-mode 1)))
     ;; If requested, add a newline at the end of the file.
     (and (memq require-final-newline '(visit visit-save))
 	 (> (point-max) (point-min))

[-- Attachment #4: NEWS.patch --]
[-- Type: text/x-diff, Size: 543 bytes --]

diff --git a/NEWS b/NEWS
index 4076630..579f1f9 100644
--- a/NEWS
+++ b/NEWS
@@ -1157,6 +1157,12 @@ type symbols.
 messages, contain the error name of that message now.  They can be
 made visible by setting user variable 'dbus-show-dbus-errors' to
 non-nil, even if protected by 'dbus-ignore-errors' otherwise.
+** Autorevert
+
++++
+*** autorevert can be restricted to act only when a buffer is visible
+
+Enable the feature using defcustom variable 'auto-revert-only-if-visible'.

 \f
 * New Modes and Packages in Emacs 28.1

             reply	other threads:[~2020-09-15  4:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-15  4:07 Boruch Baum [this message]
2020-09-15 14:30 ` bug#43412: [FEATURE] autorevert-only-if-visible [PATCH] Eli Zaretskii
2020-09-15 15:39   ` Boruch Baum
2020-09-15 15:49     ` Eli Zaretskii
2020-09-15 16:12       ` Boruch Baum
2020-09-15 17:24         ` Eli Zaretskii
2020-09-16 20:11           ` Boruch Baum
2020-09-17 13:13             ` Eli Zaretskii
2020-09-17 20:10               ` Boruch Baum
2020-09-18  6:35                 ` Eli Zaretskii
2020-09-18  7:49               ` martin rudalics
2020-09-29 13:05                 ` Boruch Baum
2020-09-29 14:34                   ` martin rudalics
2020-09-29 14:45                   ` Eli Zaretskii
2020-09-15 18:47 ` Michael Albinus
2020-09-15 19:31   ` Boruch Baum
2020-09-17 11:07     ` Michael Albinus
2020-09-17 20:03       ` Boruch Baum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200915040728.77ufv7g6bekvrzqa@E15-2016.optimum.net \
    --to=boruch_baum@gmx.com \
    --cc=43412@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).