help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: font lock woes


From: Stefan Monnier
Subject: Re: font lock woes
Date: Mon, 04 Mar 2013 17:32:27 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

>>> This suggests to me that I should be able to do:
>>> ,----
>>> | (font-lock-add-keywords nil `((,(regexp-quote "{++") . '(face
>>> | cm-addition-face read-only t))) t)
>>> `----
>>> but for some reason, the only thing that works is:
>>> ,----
>>> | (font-lock-add-keywords nil `((,(regexp-quote "{++") 0 '(face 
>>> cm-addition-face read-only t))
>>> `----
>> In which way does the other one not work?  Did you check the resulting
>> font-lock-keywords?
> Yes, I have, and the matchers are there, but the relevant strings do not
> get fontified: cm-addition-face (which is just a foreground color) isn't
> applied and matching text is not read-only.

Could it be that the relevant strings already have some other face?
If so, you'll want to use an OVERRIDE flag (see C-h v font-lock-keywords).

>>> A second thing I don't understand is how to remove the read-only
>>> property again when the mode is deactivated.  I was thinking I should be
>>> able to do the following:
>> 
>>> ,----
>>> | (font-lock-remove-keywords nil `((,(regexp-quote "{++") 0 '(face
>>> | cm-addition-face read-only t))))
>>> | (let ((inhibit-read-only t))
>>> |   (font-lock-fontify-buffer))
>>> | (setq font-lock-extra-managed-props (delq 'read-only 
>>> font-lock-extra-managed-props))
>>> `----
>> 
>> font-lock-fontify-buffer just schedules a refontification, which will be
>> done later, on-the-fly, piece by piece as text is displayed.

> But then why do the colors get removed? I mean, after disabling the mode
> with the code above, the font lock colors that my mode adds are removed,
> just the read-only property stays.

Because you've removed `read-only' from font-lock-extra-managed-props,
so read-only is not removed any more.

> visible part of the buffer, the call to font-lock-fontify-buffer above
> removes the font-lock-face property but not the read-only property.

No, the call itself does not, it only schedules the buffer for
refontification, i.e. the font-lock-face is only removed (in the visible
part) during the next redisplay, at which point you've already removed
`read-only' from font-lock-extra-managed-props.


        Stefan




reply via email to

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