From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#57534: 29.0.50; Highlighting lost after auto-revert-mode triggers Date: Tue, 25 Jun 2024 09:52:27 +0300 Organization: LINKOV.NET Message-ID: <861q4liket.fsf@mail.linkov.net> References: <87o7vyhg72.fsf@shorty.mail-host-address-is-not-set> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11429"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: 57534@debbugs.gnu.org To: Dima Kogan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 25 09:01:40 2024 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 1sM0BQ-0002s4-2J for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 Jun 2024 09:01:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0Aq-0007lQ-CB; Tue, 25 Jun 2024 03:01:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM0An-0007j8-Aw for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2024 03:01:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0An-0006Ko-2L for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2024 03:01:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sM0Ao-0007go-DK for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2024 03:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Jun 2024 07:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57534 X-GNU-PR-Package: emacs Original-Received: via spool by 57534-submit@debbugs.gnu.org id=B57534.171929885029525 (code B ref 57534); Tue, 25 Jun 2024 07:01:02 +0000 Original-Received: (at 57534) by debbugs.gnu.org; 25 Jun 2024 07:00:50 +0000 Original-Received: from localhost ([127.0.0.1]:36161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sM0Ac-0007g3-0x for submit@debbugs.gnu.org; Tue, 25 Jun 2024 03:00:50 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:44373) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sM0AY-0007fn-HR for 57534@debbugs.gnu.org; Tue, 25 Jun 2024 03:00:49 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id BF44140003; Tue, 25 Jun 2024 07:00:36 +0000 (UTC) In-Reply-To: <87o7vyhg72.fsf@shorty.mail-host-address-is-not-set> (Dima Kogan's message of "Thu, 01 Sep 2022 15:40:01 -0700") X-GND-Sasl: juri@linkov.net 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287876 Archived-At: --=-=-= Content-Type: text/plain > 1. seq 10 > /tmp/file > > 2. emacs -Q /tmp/file > > 3. (highlight-lines-matching-regexp "3") > > This is bound to "M-s h l". I see the line containing "3" highlighted > in yellow, as expected > > 4. M-x auto-revert-mode > > 5. Back in the shell: seq 20 > /tmp/file > > auto-revert-mode kicks in, updating the buffer with the results of 'seq > 20' (possibly updating to an empty buffer first, if we react immediately > to the file truncation). At this point I would expect either: > > 1. The buffer being fully reverted, with all the highlighting > disappearing. This is what happens if we did M-x revert buffer > > 2. The buffer contents being reverted, but the highlighting being > reapplied > > In this auto-revert scenario, we get something in-between: after the > auto-revert hi-lock-interactive-patterns still contains the highlighting > regex, but no highlighting actually happens. It'd be really nice and > useful if the highlighting stayed. Now re-highlighting after revert is implemented in Emacs 30. However, I noticed one problem that makes this feature unusable: when a file contains file patterns, then after every revert it asks again and again. This is because hi-lock-file-patterns-policy missed the value `always', now added in this patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=hi-lock-file-patterns-policy.patch diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 64b84cdf859..de4384054ef 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -122,9 +122,10 @@ hi-lock-file-patterns-policy "Specify when hi-lock should use patterns found in file. If `ask', prompt when patterns found in buffer; if bound to a function, use patterns when function returns t (function is called with patterns -as first argument); if nil or `never' or anything else, don't use file -patterns." +as first argument); if `always', use file patterns without prompt; +if nil or `never' or anything else, don't use file patterns." :type '(choice (const :tag "Do not use file patterns" never) + (const :tag "Always use file patterns" always) (const :tag "Ask about file patterns" ask) (function :tag "Function to check file patterns")) :group 'hi-lock @@ -334,8 +335,8 @@ hi-lock-mode (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns], any valid `font-lock-keywords' form is acceptable. When a file is loaded the patterns are read if `hi-lock-file-patterns-policy' is - `ask' and the user responds y to the prompt, or if - `hi-lock-file-patterns-policy' is bound to a function and that + `always' or if it's `ask' and the user responds y to the prompt, + or if `hi-lock-file-patterns-policy' is bound to a function and that function returns t. \\[hi-lock-find-patterns] @@ -852,6 +853,7 @@ hi-lock-find-patterns (funcall hi-lock-file-patterns-policy all-patterns)) ((eq hi-lock-file-patterns-policy 'ask) (y-or-n-p "Add patterns from this buffer to hi-lock? ")) + ((eq hi-lock-file-patterns-policy 'always) t) (t nil))) (hi-lock-set-file-patterns all-patterns) (if (called-interactively-p 'interactive) @@ -866,12 +868,16 @@ hi-lock-font-lock-hook (defun hi-lock-revert-buffer-rehighlight () "Rehighlight hi-lock patterns after `revert-buffer'. Apply the previous patterns after reverting the buffer." - (when-let ((patterns hi-lock-interactive-lighters)) - (lambda () - (when hi-lock-interactive-lighters - (hi-lock-unface-buffer t)) - (dolist (pattern (reverse patterns)) - (highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern)))))))) + (let ((policy (if hi-lock-file-patterns 'always 'never)) + (patterns hi-lock-interactive-lighters)) + (when patterns + (lambda () + (unless hi-lock-mode + (let ((hi-lock-file-patterns-policy policy)) + (when hi-lock-interactive-lighters + (hi-lock-unface-buffer t)) + (dolist (pattern (reverse patterns)) + (highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern))))))))))) (defvar hi-lock--hashcons-hash (make-hash-table :test 'equal :weakness t) --=-=-=--