emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7f7b418ae6: * lisp/hi-lock.el (hi-lock-use-overlays): New variabl


From: Juri Linkov
Subject: master 7f7b418ae6: * lisp/hi-lock.el (hi-lock-use-overlays): New variable.
Date: Mon, 24 Jan 2022 14:17:21 -0500 (EST)

branch: master
commit 7f7b418ae6321b2164e616941f77a498fb222b57
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/hi-lock.el (hi-lock-use-overlays): New variable.
    
    (hi-lock-set-pattern): Use it.  Set overlay priority to 1.
    (bug#53155)
---
 lisp/hi-lock.el | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index a44d6ea10b..0f5409ef43 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -738,6 +738,17 @@ with completion and history."
       (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, when hi-lock overlays take precedence
+over other overlays in the same buffer.")
+
 (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 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock 
search."
         (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,8 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock 
search."
                                            (match-end subexp))))
                 (overlay-put overlay 'hi-lock-overlay t)
                 (overlay-put overlay 'hi-lock-overlay-regexp (or lighter 
regexp))
+                ;; Use priority higher than default used by e.g. diff-refine.
+                (overlay-put overlay 'priority 1)
                 (overlay-put overlay 'face face))
               (goto-char (match-end 0)))
             (when no-matches



reply via email to

[Prev in Thread] Current Thread [Next in Thread]