[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cannot activate font-lock-mode
From: |
Chong Yidong |
Subject: |
Re: cannot activate font-lock-mode |
Date: |
Thu, 31 May 2007 15:14:42 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux) |
martin rudalics <address@hidden> writes:
>> (set (make-local-variable 'font-lock-keywords)
>> ! (font-lock-eval-keywords (or keywords font-lock-keywords)))
>
> Wouldn't this mean that old keywords survive a major-mode change?
> What about the companions in `font-lock-defaults'? In general I
> think all those should survive iff they have been hacked before.
It's saner to treat font-lock-keywords as an internal variable, so
that anything that wants to change font lock highlighting should use
font-lock-defaults or font-lock-add/remove-keywords. This is already
implicitly the case: according to the font-lock-keywords docstring,
Normally the [value of font-lock-keywords] would come from
`font-lock-defaults' ... You can also alter it by calling
`font-lock-add-keywords' or `font-lock-remove-keywords'...
The proximate cause for the problem seen by Francesco Potorti is that
font-lock-set-defaults recomputes the value of font-lock-keywords.
One easy way to avoid this is, as mentioned by Francesco Potorti, to
change font-lock-defaults; another way (since font-lock-add-keywords
runs font-lock-set-defaults) is:
Local variables:
eval: (font-lock-add-keywords nil '("^asdf"))
end:
Since setting font-lock-keywords in file local variables is something
of a hack in the first place, I don't think this should delay the
Emacs 22.1 release.
As for making font-lock-keywords and font-lock-defaults survive a
major-mode change if they have been hacked on before, I think that is
a bad idea, because it introduces an unnecessary complication. Any
"external" Lisp code that hacks font-lock-keywords/defaults and wants
it to persist through major-mode changes can easily arrange to
re-apply its changes.