[Top][All Lists]

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

Re: how to prevent font-lock from messing with a portion of text?

From: Lennart Borgman (gmail)
Subject: Re: how to prevent font-lock from messing with a portion of text?
Date: Mon, 26 Mar 2007 03:59:06 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070221 Thunderbird/ Mnenhy/

Drew Adams wrote:
I can't believe it would be hard for font-lock to check if text it
wants to work with has an ignore-me property.
Nobody asks you to believe it would be hard.

To show what I meant, here's a naive implementation that seems to work.

1. In font-lock.el, use this everywhere that `put-text-property' is used

(defun put-text-property-unless-ignore (start end property value &optional
  "`put-text-property', but ignore text with property `font-lock-ignore'."
  (let ((here (min start end))
        (end1 (max start end)))
    (while (< here end1)
      (unless (get-text-property here 'font-lock-ignore object)
        (put-text-property here (1+ here) property value object))
      (setq here (1+ here)))))

2. In font-lock.el, use this definition of

(defun font-lock-default-unfontify-region (beg end)
  "Unfontify from BEG to END, unless text with property `font-lock-ignore'."
  (let ((here (min beg end))
        (end1 (max beg end)))
    (while (< here end1)
      (unless (get-text-property here 'font-lock-ignore)
         here (1+ here) (append font-lock-extra-managed-props
                                (if font-lock-syntactic-keywords
                                    '(syntax-table face font-lock-multiline)
                                  '(face font-lock-multiline)))))
      (setq here (1+ here)))))

That is enough to get the behavior I described: putting a `font-lock-ignore'
property on selected portions of text tells font-lock "hands off". Try it,
for instance, with highlighting from `facemenu-set-face' (`M-o o') - see end
of mail.

Don't you have to take care of font-lock-default-fontify-region too?

reply via email to

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