GNU bug report logs -
#53155
Use overlays in hi-lock
Previous Next
Reported by: Juri Linkov <juri <at> linkov.net>
Date: Mon, 10 Jan 2022 08:26:02 UTC
Severity: normal
Fixed in version 29.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 53155 in the body.
You can then email your comments to 53155 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#53155
; Package
emacs
.
(Mon, 10 Jan 2022 08:26:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Juri Linkov <juri <at> linkov.net>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 10 Jan 2022 08:26:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[hi-lock-use-overlays.patch (text/x-diff, inline)]
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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#53155
; Package
emacs
.
(Thu, 13 Jan 2022 09:09:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 53155 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> 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 <at> gnu.org
:
bug#53155
; Package
emacs
.
(Mon, 24 Jan 2022 19:19:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 53155 <at> debbugs.gnu.org (full text, mbox):
close 53155 29.0.50
stop
>> 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...
So now pushed to master and closed. I'm not sure if the new
variable 'hi-lock-use-overlays' needs to be mentioned in NEWS.
bug marked as fixed in version 29.0.50, send any further explanations to
53155 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net>
Request was from
Juri Linkov <juri <at> linkov.net>
to
control <at> debbugs.gnu.org
.
(Mon, 24 Jan 2022 19:19:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#53155
; Package
emacs
.
(Tue, 25 Jan 2022 12:00:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 53155 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> So now pushed to master and closed. I'm not sure if the new
> variable 'hi-lock-use-overlays' needs to be mentioned in NEWS.
No, probably not.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 22 Feb 2022 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 2 years and 57 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.