unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lin Sun <sunlin7.mail@gmail.com>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 73855@debbugs.gnu.org
Subject: bug#73855: [PATCH] * lisp/autorevert.el: Avoid reverting buffer in short time
Date: Sat, 19 Oct 2024 17:52:35 +0000	[thread overview]
Message-ID: <CABCREdqWQkFsw+BCUMZeYhKrv=9S1qqewGdnP8bQcncJYOvfWA@mail.gmail.com> (raw)
In-Reply-To: <87ldyko40u.fsf@gmx.de>

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

Hi Michael,

On Sat, Oct 19, 2024 at 9:06 AM Michael Albinus <michael.albinus@gmx.de> wrote:
>
> Thanks for explanation, now I understand the scenario.
>
> Your patch makes sense. However, autorevert-tests fail now:
...
> 1 unexpected results:
>    FAILED  auto-revert-test05-global-notify
>
> make[1]: *** [Makefile:185: lisp/autorevert-tests.log] Error 1
...
> Could you pls check what's up?
>
> Best regards, Michael.

Thank you for found the issue, really appreciate it! The issue was
fixed by setting the variable 'auto-revert--lockout-interval' to the
half value of 'auto-revert-interval' (similar to its definition).

Please help review again, thanks.

[-- Attachment #2: 0001-Enhance-the-auto-revert-to-avoid-revert-a-buffer-in-.patch --]
[-- Type: text/x-patch, Size: 3622 bytes --]

From bc22ff0fc60b2ccb071a18fb55e08bb49f78c25a Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
Date: Thu, 17 Oct 2024 06:50:31 +0000
Subject: [PATCH] Enhance the auto-revert to avoid revert a buffer in short
 time

* lisp/autorevert.el: New variable auto-revert--last-time for
  (auto-revert-handler) and (auto-revert-notify-handler).
* test/lisp/autorevert-tests.el: Set the auto-revert--lockout-interval
  correctly in (with-auto-revert-test).
---
 lisp/autorevert.el            | 16 ++++++++++++----
 test/lisp/autorevert-tests.el |  7 +++++--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 0fdab6ffc9f..ef758584c0d 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -370,6 +370,9 @@ auto-revert-notify-modified-p
   "Non-nil when file has been modified on the file system.
 This has been reported by a file notification event.")
 
+(defvar-local auto-revert--last-time nil
+  "The last time of buffer was reverted.")
+
 (defvar auto-revert-debug nil
   "Use for debug messages.")
 
@@ -749,13 +752,17 @@ auto-revert-notify-handler
               ;; Mark buffer modified.
               (setq auto-revert-notify-modified-p t)
 
-              ;; Revert the buffer now if we're not locked out.
+              ;; Lock out the buffer
               (unless auto-revert--lockout-timer
-                (auto-revert-handler)
                 (setq auto-revert--lockout-timer
                       (run-with-timer
                        auto-revert--lockout-interval nil
-                       #'auto-revert--end-lockout buffer))))))))))
+                       #'auto-revert--end-lockout buffer))
+                ;; Revert it when first entry or it was reverted intervals ago
+                (when (or (null auto-revert--last-time)
+                          (> (float-time (time-since auto-revert--last-time))
+                             auto-revert--lockout-interval))
+                  (auto-revert-handler))))))))))
 
 (defun auto-revert--end-lockout (buffer)
   "End the lockout period after a notification.
@@ -801,7 +808,8 @@ auto-revert-handler
                               #'buffer-stale--default-function)
                           t))))
          eob eoblist)
-    (setq auto-revert-notify-modified-p nil)
+    (setq auto-revert-notify-modified-p nil
+          auto-revert--last-time (current-time))
     (when revert
       (when (and auto-revert-verbose
                  (not (eq revert 'fast)))
diff --git a/test/lisp/autorevert-tests.el b/test/lisp/autorevert-tests.el
index 4763994c5d4..7e176df6803 100644
--- a/test/lisp/autorevert-tests.el
+++ b/test/lisp/autorevert-tests.el
@@ -132,12 +132,15 @@ auto-revert--deftest-remote
          (error (message "%s" err) (signal (car err) (cdr err)))))))
 
 (defmacro with-auto-revert-test (&rest body)
-  `(let ((auto-revert-interval-orig auto-revert-interval))
+  `(let ((auto-revert-interval-orig auto-revert-interval)
+         (auto-revert--lockout-interval-orig auto-revert--lockout-interval))
      (unwind-protect
          (progn
            (customize-set-variable 'auto-revert-interval 0.1)
+           (setq auto-revert--lockout-interval 0.05)
            ,@body)
-       (customize-set-variable 'auto-revert-interval auto-revert-interval-orig))))
+       (customize-set-variable 'auto-revert-interval auto-revert-interval-orig)
+       (setq auto-revert--lockout-interval auto-revert--lockout-interval-orig))))
 
 (defun auto-revert-tests--write-file (text file time-delta &optional append)
   (write-region text nil file append 'no-message)
-- 
2.34.1


  reply	other threads:[~2024-10-19 17:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 23:24 bug#73855: [PATCH] * lisp/autorevert.el: Avoid reverting buffer in short time Lin Sun
2024-10-18  7:50 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-19  5:58   ` Lin Sun
2024-10-19  9:06     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-19 17:52       ` Lin Sun [this message]
2024-10-20  9:15         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-20 18:29           ` Lin Sun

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='CABCREdqWQkFsw+BCUMZeYhKrv=9S1qqewGdnP8bQcncJYOvfWA@mail.gmail.com' \
    --to=sunlin7.mail@gmail.com \
    --cc=73855@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    /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).