GNU bug report logs - #53155
Use overlays in hi-lock

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Juri Linkov <juri@HIDDEN>; dated Mon, 10 Jan 2022 08:26:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 53155 <at> debbugs.gnu.org:


Received: (at 53155) by debbugs.gnu.org; 13 Jan 2022 09:08:19 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 13 04:08:18 2022
Received: from localhost ([127.0.0.1]:60164 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n7w5i-0000xl-O3
	for submit <at> debbugs.gnu.org; Thu, 13 Jan 2022 04:08:18 -0500
Received: from quimby.gnus.org ([95.216.78.240]:52080)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1n7w5h-0000xZ-RQ
 for 53155 <at> debbugs.gnu.org; Thu, 13 Jan 2022 04:08:18 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=Bg2ShR9F6wD5d8WlQquCuHYjpaLXImVNHp7nbQ1HaYM=; b=myo08oxTpyQRepOMhYVRVq4Jw6
 m/SYDy2XXUNEnDxKgAN8mzv8r49xbqpkdf61AVvz+wv1K0rmx/0iIMb54+PZq/gW7Gx51tBg/GiHs
 Qz9PJvpH6+nWJdvtCVq95lyXsfofZgbdUI9pLJwXmhRgkzrsunXXRLvrVZANsx2ycn8g=;
Received: from [84.212.220.105] (helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1n7w5Z-0000nC-Fm; Thu, 13 Jan 2022 10:08:12 +0100
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#53155: Use overlays in hi-lock
References: <86zgo4ovmw.fsf@HIDDEN>
X-Now-Playing: Panoptique Electrical's _Decades (2001-2021)_: "Late Night Sea"
Date: Thu, 13 Jan 2022 10:08:08 +0100
In-Reply-To: <86zgo4ovmw.fsf@HIDDEN> (Juri Linkov's message of "Mon, 
 10 Jan 2022 10:17:15 +0200")
Message-ID: <875yqo6m13.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Juri Linkov <juri@HIDDEN> writes: > But this heuristics
 doesn't work in read-only *vc-change-log* buffers > where expanding commits
 inserts new text that should be highlighted > with font-lock. > > Thus the
 following patch adds a new [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 53155
Cc: 53155 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Juri Linkov <juri@HIDDEN> writes:

> But this heuristics doesn't work in read-only *vc-change-log* buffers
> where expanding commits inserts new text that should be highlighted
> with font-lock.
>
> Thus the following patch adds a new variable hi-lock-use-overlays
> that can be used like:

I guess that makes sense...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#53155; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 10 Jan 2022 08:25:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 10 03:25:46 2022
Received: from localhost ([127.0.0.1]:51751 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6pzu-0006iu-Fu
	for submit <at> debbugs.gnu.org; Mon, 10 Jan 2022 03:25:46 -0500
Received: from lists.gnu.org ([209.51.188.17]:39516)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n6pzs-0006ig-Op
 for submit <at> debbugs.gnu.org; Mon, 10 Jan 2022 03:25:45 -0500
Received: from eggs.gnu.org ([209.51.188.92]:46228)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1n6pzq-0000J4-DM
 for bug-gnu-emacs@HIDDEN; Mon, 10 Jan 2022 03:25:43 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:41001)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1n6pzo-0003PH-Jb
 for bug-gnu-emacs@HIDDEN; Mon, 10 Jan 2022 03:25:42 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id EDC68E000E
 for <bug-gnu-emacs@HIDDEN>; Mon, 10 Jan 2022 08:25:34 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: Use overlays in hi-lock
Organization: LINKOV.NET
Date: Mon, 10 Jan 2022 10:17:15 +0200
Message-ID: <86zgo4ovmw.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=217.70.183.196; envelope-from=juri@HIDDEN;
 helo=relay4-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.6 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

--=-=-=
Content-Type: text/plain

When diff-refine overlays take precedence over hi-lock text properties,
then hi-lock can't be used to review diffs.  Hi-lock provides two modes:
font-lock highlighting and highlighting with overlays.  Using overlays
solves the problem.  But how to decide when overlays should be used?
Detecting whether the buffer is read-only, so no more text is expected
to be added to the buffer?  Then add overlays instead of using font-lock?
But this heuristics doesn't work in read-only *vc-change-log* buffers
where expanding commits inserts new text that should be highlighted
with font-lock.

Thus the following patch adds a new variable hi-lock-use-overlays
that can be used like:

#+begin_src emacs-lisp
(add-hook 'diff-mode-hook
            (lambda ()
              (setq-local hi-lock-use-overlays t)))
#+end_src


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=hi-lock-use-overlays.patch

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index fbd698e234..99e908ad07 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -738,6 +738,17 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
 
+(defvar hi-lock-use-overlays nil
+  "Whether to always use overlays instead of font-lock rules.
+When font-lock-mode is enabled and the buffer specifies font-lock rules,
+highlighting is performed by adding new font-lock rules to the existing ones,
+so when new matching strings are added, they are highlighted by font-lock.
+Otherwise, overlays are used, but new highlighting overlays are not added
+when new matching strings are inserted to the buffer.
+However, sometimes overlays are still preferable even in buffers
+where font-lock is enabled, because hi-lock overlays take precedence
+over other overlays in the same buffer, such as diff-refine overlays, etc.")
+
 (defun hi-lock-set-pattern (regexp face &optional subexp lighter case-fold spaces-regexp)
   "Highlight SUBEXP of REGEXP with face FACE.
 If omitted or nil, SUBEXP defaults to zero, i.e. the entire
@@ -759,7 +770,8 @@ hi-lock-set-pattern
         (add-to-list 'hi-lock--unused-faces (face-name face))
       (push pattern hi-lock-interactive-patterns)
       (push (cons (or lighter regexp) pattern) hi-lock-interactive-lighters)
-      (if (and font-lock-mode (font-lock-specified-p major-mode))
+      (if (and font-lock-mode (font-lock-specified-p major-mode)
+               (not hi-lock-use-overlays))
 	  (progn
 	    (font-lock-add-keywords nil (list pattern) t)
 	    (font-lock-flush))
@@ -781,6 +793,7 @@ hi-lock-set-pattern
                                            (match-end subexp))))
                 (overlay-put overlay 'hi-lock-overlay t)
                 (overlay-put overlay 'hi-lock-overlay-regexp (or lighter regexp))
+                (overlay-put overlay 'priority 1)
                 (overlay-put overlay 'face face))
               (goto-char (match-end 0)))
             (when no-matches

--=-=-=--




Acknowledgement sent to Juri Linkov <juri@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#53155; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 13 Jan 2022 09:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.