all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: font lock woes
Date: Mon, 04 Mar 2013 17:32:27 -0500	[thread overview]
Message-ID: <jwv4ngqbykj.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: slrnkj9rff.d23.joostkremers@j.kremers4.news.arnhem.chello.nl

>>> 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	other threads:[~2013-03-04 22:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-03 23:22 font lock woes Joost Kremers
2013-03-04 16:03 ` Stefan Monnier
     [not found] ` <mailman.21363.1362413049.855.help-gnu-emacs@gnu.org>
2013-03-04 18:54   ` Joost Kremers
2013-03-04 22:32     ` Stefan Monnier [this message]
     [not found]     ` <mailman.21401.1362436369.855.help-gnu-emacs@gnu.org>
2013-03-05 18:07       ` Joost Kremers
2013-03-06  2:43         ` Stefan Monnier
     [not found]         ` <mailman.21515.1362537854.855.help-gnu-emacs@gnu.org>
2013-03-06 20:27           ` Joost Kremers
2013-03-09 13:09             ` Stefan Monnier
     [not found]             ` <mailman.21754.1362834587.855.help-gnu-emacs@gnu.org>
2013-03-11 19:41               ` Joost Kremers

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

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

  git send-email \
    --in-reply-to=jwv4ngqbykj.fsf-monnier+gmane.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.