From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Boruch Baum Newsgroups: gmane.emacs.bugs Subject: bug#43714: 28.1: auto-revert code improvements [PATCH] Date: Wed, 30 Sep 2020 02:26:33 -0400 Message-ID: <20200930062633.n3ntw2lmmantsx47@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="5ou2waw76t5nyno3" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15671"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 To: 43714@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 30 08:27:33 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNVaP-0003zq-6n for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 08:27:33 +0200 Original-Received: from localhost ([::1]:34344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNVaN-0007Mm-UR for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 02:27:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNVZu-0007MZ-F8 for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 02:27:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46352) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNVZu-0007Xy-6O for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 02:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNVZu-0001tS-2W for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 02:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Sep 2020 06:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43714 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Emacs Bug Reporting Original-Received: via spool by submit@debbugs.gnu.org id=B.16014472037251 (code B ref -1); Wed, 30 Sep 2020 06:27:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Sep 2020 06:26:43 +0000 Original-Received: from localhost ([127.0.0.1]:57898 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNVZb-0001st-3S for submit@debbugs.gnu.org; Wed, 30 Sep 2020 02:26:43 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:51346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNVZZ-0001sk-OM for submit@debbugs.gnu.org; Wed, 30 Sep 2020 02:26:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNVZZ-0007Le-EC for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 02:26:41 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:45091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNVZX-0007W2-0T for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 02:26:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1601447196; bh=wNBSr/wSK/bH/A9l0b01uuYGcGvOnXt9TqJG7Txl/9A=; h=X-UI-Sender-Class:Date:From:To:Subject; b=IH2rTNaq/MwQn8/Lr1awNX5zUgilf5iGJV3TPG/+qw16Y8ZzbdN1Dghj5Si14N+Sb NjZ8MLazxrgLHaqcCtw4mP/CrsniuLzff3JW0zBk9D07oiNvVvAtqpBcvOW8EOJc2B cRbikbrwGQk4gcOxE+JmFuZzkiw4u1DPLUHv++4Q= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1M7b2T-1kKVI90qDd-007zz9 for ; Wed, 30 Sep 2020 08:26:36 +0200 Content-Disposition: inline X-Provags-ID: V03:K1:m761G7R/gnLSf1o6fTVyIXHzFTdj+HFScE6km6+PoL5x5xqPrdA z1ZB973TaEOm9qtvvECfuqM8SenbkM9prVdHjyxNoEDJVFI8KViqTEAwa4oF79KpE/TOj9K Q7sF9e0AMMaMxDWL51W/AUPA+l1mWY46yWUnjcUphlAb1+ANb2gS8qTxDtfHCocwNW1Xrlt lyZWXtjBmUZcpLCir3x3g== X-UI-Out-Filterresults: notjunk:1;V03:K0:JCs3p2R3b9o=:FAwNhFwxR+g3CrKyR137PQ P0F6kLJmNfEidmjxdxqWaS5YuIfpnZ2+HVwt2zbkBlW7TzHoOADTRb/KzmJaiE9i5tDEIsSeY H9ToTnyiUipJ85b5Y9FQLvcDx1t4LpuhNCyH2n3oH64ru+WwNMJp/H+QaQ5stLDhdN9YoUiCp nxUNr7j7fH3DHhRstoW746UgDYyOcWH1lFuN9CXVd8GQam7a7AwSTI1bosErEzUM3H1wtcLkg 0Cy0ToOZw7plQ9OFZVKdovI2jG9YsTEIdKJ79ZJShwNEfP45rJ9v9oogA/qW7Ku/9E2Dsf6LD kzofcTOSBHCwbWe5lT39jG/a+5vEHz4YLyk+c2yz7DEPzPOqvRTD3isMZGpcj0v+bkXIvVYbP O2sJCskGYZtmSHrQ3heUoMqbUDpa90bTCRKAVBeGgzaMLk+2Kd5Vs+NdUoeo2JitErYtltHV/ pQTfZEecW6sD6+2vII9L+vC+AyfsFJUPUOT/qcmMIKcMrMIG9BGjzkIRS9vBAwlKMCPI+x7ip TskFUmMAinAhiAci9A5jN9tUHwtx4ZwbufpTRoLgm6twS6aO2clOyWh8xgYGoXHY2YIgwMkQB 4eOyWm6C/qTHrjutrjYEtiei6hDATFDr4WLs589Dexb41JBqvT0GN7whU2MOXy9xRODAMNE1i p7R3IJgtHuk4YywVmKiTz4D5Pss+MYABsEWNLGOxxmxgznrz/VOWCvhNdcPlBv32VXphsElJA q0u4EXGSZrKmKbQd13PNbpmAQy45Diff1P/8xgpH0g3r0bcw5weUcIYTe5eDM+vKnk8i3x+p Received-SPF: pass client-ip=212.227.17.22; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 02:26:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.614, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:189310 Archived-At: --5ou2waw76t5nyno3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --5ou2waw76t5nyno3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="auto-revert-28-cosmetic.patch" Content-Transfer-Encoding: quoted-printable diff --git a/autorevert.el b/autorevert.el index 011febf..de4407b 100644 =2D-- 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 cal= led. 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-directo= ry)) - (file-remote-p default-directory ni= l 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) --5ou2waw76t5nyno3--