unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-devel@gnu.org
Subject: hi-lock and overlays (was: Conflicting overlays and the 'priority property)
Date: Mon, 18 Jan 2010 22:33:58 +0100	[thread overview]
Message-ID: <87ljfvqerd.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: <87hbqk620u.fsf@thinkpad.tsdh.de> (Tassilo Horn's message of "Sun, 17 Jan 2010 19:04:49 +0100")

Hi all,

I was wrong with my previous mail.  The problem that hi-lock pattern on
the current line are not highlighted, when `hl-line-mode' is enabled is
not due to conflicting overlays.  The problem is that hi-lock uses
overlays only when the undocumented variable `font-lock-fontified' is
nil (see `hi-lock-set-pattern').  Else, it uses normal fontification,
and overlays (like the one for the current line created by
`hl-line-mode') take precedence over that.

So now I have some questions:

  - Why does hi-lock use two different styles of highlighting?  IMO, if
    a user does M-x highlight-regexp RET foo RET hi-yellow RET, he
    expects to get that highlighting even if there are other overlays,
    so creating an overlay (and maybe even setting a priority) is the
    only safe bet.

  - Why is the call to `font-lock-add-keywords' done unconditionally,
    although it's possible that overlays might be used.  Isn't that
    superfluous in the overlay case?

I've changed the definition of `hi-lock-set-pattern' like this, which
looks more correct to me.

--8<---------------cut here---------------start------------->8---
diff -u /home/horn/repos/el/emacs/trunk/lisp/hi-lock.el /tmp/buffer-content-6420a_A
--- /home/horn/repos/el/emacs/trunk/lisp/hi-lock.el	2010-01-17 19:26:05.248012589 +0100
+++ /tmp/buffer-content-6420a_A	2010-01-18 22:24:26.839291297 +0100
@@ -568,19 +568,24 @@
   "Inhibit the action of `hi-lock-font-lock-hook'.
 This is used by `hi-lock-set-pattern'.")
 
-(defun hi-lock-set-pattern (regexp face)
-  "Highlight REGEXP with face FACE."
-  (let ((pattern (list regexp (list 0 (list 'quote face) t)))
-	;; The call to `font-lock-add-keywords' below might disable
-	;; and re-enable font-lock mode.  If so, we don't want
-	;; `hi-lock-font-lock-hook' to run.  This can be removed once
-	;; Bug#635 is fixed. -- cyd
-	(hi-lock--inhibit-font-lock-hook t))
+(defun hi-lock-set-pattern (regexp face &optional permit-font-lock)
+  "Highlight REGEXP with face FACE.
+If PERMIT-FONT-LOCK is non-nil, allow normal font-lock
+fontification instead of creating overlays.  In that case,
+matches of REGEXP won't be highlighted, if they occur inside an
+overlay, because overlays take precedence over normal
+fontification."
+  (let ((pattern (list regexp (list 0 (list 'quote face) t))))
     (unless (member pattern hi-lock-interactive-patterns)
-      (font-lock-add-keywords nil (list pattern) t)
       (push pattern hi-lock-interactive-patterns)
-      (if font-lock-fontified
-          (font-lock-fontify-buffer)
+      (if (and font-lock-fontified permit-font-lock)
+          (let (;; The call to `font-lock-add-keywords' below might disable
+		;; and re-enable font-lock mode.  If so, we don't want
+		;; `hi-lock-font-lock-hook' to run.  This can be removed once
+		;; Bug#635 is fixed. -- cyd
+		(hi-lock--inhibit-font-lock-hook t))
+	    (font-lock-add-keywords nil (list pattern) t)
+	    (font-lock-fontify-buffer))
         (let* ((serial (hi-lock-string-serialize regexp))
                (range-min (- (point) (/ hi-lock-highlight-range 2)))
                (range-max (+ (point) (/ hi-lock-highlight-range 2)))
--8<---------------cut here---------------end--------------->8---

I've tested the function with PERMIT-FONT-LOCK set to t, and then it
acts exactly as it does right now, e.g. it highlights every occurence of
REGEXP that is not inside an overlay.

When called with PERMIT-FONT-LOCK set to nil (or omitted), it always
creates overlays and the highlighting is done even if the REGEXP matches
inside other overlays.

Do you think my change is reasonable and should be committed?  Or is
there a rationale for the current way that I didn't grasp till now?

Bye,
Tassilo




  reply	other threads:[~2010-01-18 21:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-17 18:04 Conflicting overlays and the 'priority property Tassilo Horn
2010-01-18 21:33 ` Tassilo Horn [this message]
2010-01-18 21:51   ` hi-lock and overlays (was: Conflicting overlays and the 'priority property) Lennart Borgman
2010-01-19  7:41     ` hi-lock and overlays Tassilo Horn
2010-01-20 15:54   ` Stefan Monnier
2010-01-20 17:19     ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ljfvqerd.fsf@thinkpad.tsdh.de \
    --to=tassilo@member.fsf.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).