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 14:33:44 -0400 Message-ID: <20200930183343.dmmyg2l6yzmfhkyl@E15-2016.optimum.net> References: <20200930062633.n3ntw2lmmantsx47@E15-2016.optimum.net> <877dsb74ve.fsf@gnus.org> <20200930150938.ns7lmdwgg4efhi4e@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="63vrc7nydud32wto" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16571"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 Cc: Lars Ingebrigtsen , Michael Albinus , 43714@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 30 20:35:39 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 1kNgx0-00046w-Ra for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 20:35:39 +0200 Original-Received: from localhost ([::1]:53588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNgwx-0004hH-8E for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Sep 2020 14:35:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNgvR-00041y-VP for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:34:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNgvR-0000fj-Lr for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:34:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNgvR-0006BA-JW for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2020 14:34:01 -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 18:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43714 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 43714-submit@debbugs.gnu.org id=B43714.160149083723742 (code B ref 43714); Wed, 30 Sep 2020 18:34:01 +0000 Original-Received: (at 43714) by debbugs.gnu.org; 30 Sep 2020 18:33:57 +0000 Original-Received: from localhost ([127.0.0.1]:33118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNgvM-0006As-GS for submit@debbugs.gnu.org; Wed, 30 Sep 2020 14:33:56 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:43941) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNgvK-0006Aa-8H for 43714@debbugs.gnu.org; Wed, 30 Sep 2020 14:33:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1601490827; bh=GuIg0PkIYxvwOf/75rZW4cQerq3i1im5krGmS3m0fhA=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=OD5+v1elOQ5ZvBPd4eDeoxIBnYCKEmHiaD/VzC3jZTvajsQ2glwWSvrQyHwxJ0f1P tffX7Oxd7OlUf2Las7S1NCorSmHSIg1MjqcLZEUYAfKMK9HNnz97TXfG9yvKJl3IFU GkMsreLUOzH9kUQWGE5+gbMyFP/MtvY38TKH6Po8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MI5UN-1kAGGi0XRf-00FBZC; Wed, 30 Sep 2020 20:33:47 +0200 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:ecLtlBc9omBO+Rn71rD5Wuwq2g1NwEO6nrmg0izJIga81fI346i 1GKJ91O12rHMzVCvXHMRnssEAykugU3We/2e1cx3wjK6pv7edKA3uFNxCuXYAWEoAk2443I fYxNma49CNcztIqhzqStLSflnNlvLCt9YpTkYfWcYrjf+oy7LBW+gQjJ0ZOw4hxPYw32V7k Gzqm/bjdReuOIs0u7/Kvg== X-UI-Out-Filterresults: notjunk:1;V03:K0:2ZH0YvCi7WM=:rC2h+omu8+adeMVKRIQstj nxKXmcqM0h9A9VQ3ucPI5ySzHgI6pQFfP49iop5DegQWhI1ESQDvWxCBO2sNM2fYFQdvSYVZC ZBxhq12BSrkz6X7ca76PFj5/WKQE8iQBRfvevdd2szYbfUldIltytxotczwLpjwutbVEyYkDS +W3hKe6piPJdztT5V21m84lTv0l3X+b0RPj7fcDMr3NdmF+p8LQUmXgdszIp3RIVPEU3trol1 rC1pN6kg4sj5nhXXwsDZNVs+AmJsso7739MKxjQOYAvn6I5BBwy7KW7Gj1LsveIyGp90C4QUA gpbuTwdXFdu6KR85gVIdXiZWOmcH93EK8oxWvj2+OfvCRT1xgwm3zEsR/dKh/gCHe7UzN4bPE gRlbNp2IZfojm+ak1na8tVjV7E9L6E+rfVzR+QROGtaDNTsyoXEtLvKwFLh7ZnldMq5fBX0UE hsJCtBhbB1fm6/qtrUFG7oejU8Poi9xyKX5NPiRKr/s+HudlDMzbxjlgKWmdXYbMDIbAVcKSZ HX1S6hgHrCG2wP2gAb5k8KKkfs7GG10GEzoBFFks/McDOX9CXzfPcSqnQRt3kG6OKsYAPs//L FcmKCfUhhiTqyW3ASEAen3xu5svBUS0nfE5UdJyRt6GpcOj+1c3piFGAK5amT7MvNgJqUUOx8 bdyZwq0AY5X4gOGiOUrIORuJmBRaEiPK3d3iLE2nTrRYPJOB/gHrJqOaLZP7LAVt0kEnGCvJc JIwwZrCAsJVXd2haVDgI+5GVvAAoA6Oir4Z2Bs2La/HB4WKkSCM6XjlH+J1xABY6skXorsIR 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:189421 Archived-At: --63vrc7nydud32wto Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-09-30 13:41, Glenn Morris wrote: > The mailing list archives around the time of a commit are often informat= ive. > https://lists.gnu.org/r/emacs-devel/2005-05/msg01414.html Absolutely great, Glenn! An obvious follow-up observation: The patch that was applied was for Luc's option #3, but it seems to me that the honest solution to the problem with timers is his option #2, to put the fix in timers. Was that ever done? I'm guessing a decision at some point was made not to pursue Luc's option #2 because the emacs documentation for timers[1] says, "If a timer function calls functions that can change the match data, it should save and restore the match data. See Saving Match Data". Reconsidering that decision could be of benefit emacs-wide. Attached is a new version of the patch, with the 'save-match-data' restored. Thanks again, Glenn. [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Timers.html =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --63vrc7nydud32wto 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..4ca8010 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,67 +948,19 @@ 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)) + (when (timerp auto-revert-timer) + (cancel-timer auto-revert-timer)) (setq auto-revert-timer nil))))) - ;; The end: (provide 'autorevert) --63vrc7nydud32wto--