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#53155: Use overlays in hi-lock Date: Mon, 10 Jan 2022 10:17:15 +0200 Organization: LINKOV.NET Message-ID: <86zgo4ovmw.fsf@mail.linkov.net> 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="6030"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: 53155@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 10 09:31:18 2022 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 1n6q5G-0001HN-2E for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 10 Jan 2022 09:31:18 +0100 Original-Received: from localhost ([::1]:47086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n6q5F-0006k3-4T for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 10 Jan 2022 03:31:17 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6q0A-0000So-Sd for bug-gnu-emacs@gnu.org; Mon, 10 Jan 2022 03:26:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n6q0A-0003Ro-Jm for bug-gnu-emacs@gnu.org; Mon, 10 Jan 2022 03:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n6q0A-0006jh-Gi for bug-gnu-emacs@gnu.org; Mon, 10 Jan 2022 03:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 10 Jan 2022 08:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53155 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164180314725853 (code B ref -1); Mon, 10 Jan 2022 08:26:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Jan 2022 08:25:47 +0000 Original-Received: from localhost ([127.0.0.1]:51751 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n6pzu-0006iu-Fu for submit@debbugs.gnu.org; Mon, 10 Jan 2022 03:25:46 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:39516) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n6pzs-0006ig-Op for submit@debbugs.gnu.org; Mon, 10 Jan 2022 03:25:45 -0500 Original-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 ) id 1n6pzq-0000J4-DM for bug-gnu-emacs@gnu.org; Mon, 10 Jan 2022 03:25:43 -0500 Original-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 ) id 1n6pzo-0003PH-Jb for bug-gnu-emacs@gnu.org; Mon, 10 Jan 2022 03:25:42 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id EDC68E000E for ; Mon, 10 Jan 2022 08:25:34 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.196; envelope-from=juri@linkov.net; 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-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:223875 Archived-At: --=-=-= 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 --=-=-=--