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

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

Re: Best way to detect font-lock mode is on?


From: Tim X
Subject: Re: Best way to detect font-lock mode is on?
Date: Wed, 05 Jan 2011 18:55:26 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Yes, that is how I plan to do it if font-lock is not enabled. I'm
>> currently experimenting with syntax-ppss and parse-partial-sexp to see
>> if the cached version can be used reliably or if the uncaching variant
>> is required and if this has too high a penalty. I have found that with
>> syntax-ppss, I do get false positives fairly frequently if I don't first
>> call syntax-pps-flush-cache, which would seem to defeat its benefits
>> over parse-partial-sexp.
>
> font-lock uses syntax-ppss, so if syntax-ppss is wrong, font-lock should
> be wrong as well.
>
>> As the buffer is being edited, potentially changing the syntax at
>> random places, it is difficult to determine when the cache will need
>> to be flushed (though I have a couple of ideas that may strike an
>> acceptable balance).
>
> syntax-ppss is supposed to automatically flush the (relevant part of)
> the cache after any buffer modification.  The only exceptions are when
> the buffer is modified in a context where inhibit-modification-hooks is
> set (e.g. font-lock-syntactic-keywords).

hmm, that is interesting. I was getting a problem where characters were
being incorrectly classified as comments when I ran syntax-ppss if I
didn't also run syntax-ppss-flush-cache before calling syntax-ppss, but
the characters were not being fontified as comments. If font-lock is
using the same mechanism, I would have expected more consistency - must
be something else going on.

>
>>>> As you can see, I'm using font-lock-defaults to test whether font-lock
>>>> is enabled. Is this the best way to go or is there a more
>>>> reliable/better test to use?
>>> Any reason not to use `font-lock-mode'?
>> Only that some people don't like to use font-lock. I wanted the mode's
>> functionality to be independent of font-lock and not force people to use
>> it.
>
> No, I mean to use the variable `font-lock-mode' rather than
> `font-lock-defaults'.

Ah, must have missed that - didn't realise there was a local variable
called font-lock-mode. Much better solution. thanks.

Tim


-- 
tcross (at) rapttech dot com dot au


reply via email to

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