all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#43714: 28.1: auto-revert code improvements [PATCH]
@ 2020-09-30  6:26 Boruch Baum
  2020-09-30 13:48 ` Lars Ingebrigtsen
  2020-09-30 16:51 ` bug#43714: [boruch_baum@gmx.com: Re: bug#43714: 28.1: auto-revert code improvements [PATCH]] Boruch Baum
  0 siblings, 2 replies; 18+ messages in thread
From: Boruch Baum @ 2020-09-30  6:26 UTC (permalink / raw)
  To: 43714

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

In pursuing a 'best' solution for bug-report#43412, I've taken the
plunge and gotten an emacs 28 snapshot installed locally, and in
examining the code, saw things that didn't make sense to me or were
unnecessary or could just do with better readability. My testing
indicates no harm done by the changes, but they should be peer-reviewed
and undergo further testing. Nothing in the attached patch is aimed at
changing functionality, so you may want to reject it on the basis of "if
it ain't broke, don't fix it", but it does improve the code.

Just as a 'for example': I started on this because I saw that the code
was saving match data, which had me on a wild goose chase hunting for
why and where it was necessary - I found nothing, and removing the code
doesn't seem to have ill effect.

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

[-- Attachment #2: auto-revert-28-cosmetic.patch --]
[-- Type: text/x-diff, Size: 6203 bytes --]

diff --git a/autorevert.el b/autorevert.el
index 011febf..de4407b 100644
--- a/autorevert.el
+++ b/autorevert.el
@@ -869,6 +869,62 @@ This is an internal function used by Auto-Revert Mode."
       (restore-buffer-modified-p modified)))
   (set-visited-file-modtime))

+(defun auto-revert--buffer-candidates ()
+  "Return a prioritized list of buffers to maybe auto-revert.
+The differences between this return value and the reference
+variable `auto-revert-buffer-list'. include: 1) this has more
+entries when in global-auto-revert-mode; 2) this prioritizes
+buffers not reverted last time due to user interruption. "
+  (let (remaining new
+        (bufs (delq nil
+               ;; Buffers with remote contents shall be reverted only
+               ;; if the connection is established already.
+                    (mapcar
+                     (lambda (buf)
+                       (and (buffer-live-p buf)
+                            (with-current-buffer buf
+                              (and
+                               (or (not (file-remote-p default-directory))
+                                   (file-remote-p default-directory nil t))
+                                   buf))))
+                     (auto-revert--polled-buffers)))))
+    ;; Partition `bufs' into two halves depending on whether or not
+    ;; the buffers are in `auto-revert-remaining-buffers'.  The two
+    ;; halves are then re-joined with the "remaining" buffers at the
+    ;; head of the list.
+    (dolist (buf auto-revert-remaining-buffers)
+      (if (memq buf bufs)
+          (push buf remaining)))
+    (dolist (buf bufs)
+      (if (not (memq buf remaining))
+          (push buf new)))
+    (nreverse (nconc new remaining))))
+
+(defun auto-revert-buffer (buf)
+  "Revert a single buffer.
+
+This is performed as specified by Auto-Revert and Global
+Auto-Revert Modes."
+  (if (not (buffer-live-p buf))
+    (auto-revert-remove-current-buffer buf)
+   (with-current-buffer buf
+     ;; Test if someone has turned off Auto-Revert Mode
+     ;; in a non-standard way, for example by changing
+     ;; major mode.
+     (and (not auto-revert-mode)
+          (not auto-revert-tail-mode)
+          (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)
+                  (or buffer-file-name
+                      buffer-auto-revert-by-notification))
+         (auto-revert-notify-add-watch))
+       (auto-revert-handler)))))
+
 (defun auto-revert-buffers ()
   "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.

@@ -892,66 +948,17 @@ are checked first the next time this function is called.
 This function is also responsible for removing buffers no longer in
 Auto-Revert Mode from `auto-revert-buffer-list', and for canceling
 the timer when no buffers need to be checked."
-
-  (save-match-data
-    (let ((bufs (auto-revert--polled-buffers))
-	  remaining new)
-      ;; Buffers with remote contents shall be reverted only if the
-      ;; connection is established already.
-      (setq bufs (delq nil
-                       (mapcar
-                        (lambda (buf)
-                          (and (buffer-live-p buf)
-                               (with-current-buffer buf
-                                 (and
-                                  (or (not (file-remote-p default-directory))
-                                      (file-remote-p default-directory nil t))
-                                      buf))))
-                        bufs)))
-      ;; Partition `bufs' into two halves depending on whether or not
-      ;; the buffers are in `auto-revert-remaining-buffers'.  The two
-      ;; halves are then re-joined with the "remaining" buffers at the
-      ;; head of the list.
-      (dolist (buf auto-revert-remaining-buffers)
-	(if (memq buf bufs)
-	    (push buf remaining)))
-      (dolist (buf bufs)
-	(if (not (memq buf remaining))
-	    (push buf new)))
-      (setq bufs (nreverse (nconc new remaining)))
+    (let ((bufs (auto-revert--buffer-candidates)))
       (while (and bufs
 		  (not (and auto-revert-stop-on-user-input
 			    (input-pending-p))))
-	(let ((buf (car bufs)))
-          (if (not (buffer-live-p buf))
-              ;; Remove dead buffer from `auto-revert-buffer-list'.
-              (auto-revert-remove-current-buffer buf)
-            (with-current-buffer buf
-              ;; Test if someone has turned off Auto-Revert Mode
-              ;; in a non-standard way, for example by changing
-              ;; major mode.
-              (if (and (not auto-revert-mode)
-                       (not auto-revert-tail-mode)
-                       (memq buf auto-revert-buffer-list))
-                  (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)
-                           (or buffer-file-name
-                               buffer-auto-revert-by-notification))
-                  (auto-revert-notify-add-watch))
-                (auto-revert-handler)))))
-	(setq bufs (cdr bufs)))
+        (auto-revert-buffer (pop bufs)))
       (setq auto-revert-remaining-buffers bufs)
       ;; Check if we should cancel the timer.
       (unless (auto-revert--need-polling-p)
-        (if (timerp auto-revert-timer)
-            (cancel-timer auto-revert-timer))
-	(setq auto-revert-timer nil)))))
-
+        (when (timerp auto-revert-timer)
+          (cancel-timer auto-revert-timer))
+	(setq auto-revert-timer nil))))

 ;; The end:
 (provide 'autorevert)

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-10-01  5:42 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-30  6:26 bug#43714: 28.1: auto-revert code improvements [PATCH] Boruch Baum
2020-09-30 13:48 ` Lars Ingebrigtsen
2020-09-30 14:25   ` Eli Zaretskii
2020-09-30 15:28     ` Boruch Baum
2020-09-30 16:03       ` Eli Zaretskii
2020-09-30 16:59         ` Boruch Baum
2020-09-30 17:01           ` Lars Ingebrigtsen
2020-09-30 17:13             ` Boruch Baum
2020-09-30 17:21     ` Michael Albinus
2020-09-30 15:09   ` Boruch Baum
2020-09-30 15:12     ` Lars Ingebrigtsen
2020-09-30 17:41     ` Glenn Morris
2020-09-30 18:33       ` Boruch Baum
2020-09-30 23:55         ` Lars Ingebrigtsen
2020-10-01  5:42           ` Boruch Baum
2020-09-30 16:51 ` bug#43714: [boruch_baum@gmx.com: Re: bug#43714: 28.1: auto-revert code improvements [PATCH]] Boruch Baum
2020-09-30 16:54   ` Lars Ingebrigtsen
2020-09-30 17:10     ` Boruch Baum

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.