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: Thu, 13 Jan 2011 12:21:26 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> On 2011-01-03, Tim X <timx@nospam.dev.null> wrote:
>>
>> Just wanting to know what people would suggest as the best way to detect
>> if font-lock mode is enabled. 
>>
>> I have two functions I use in a mode to determine if the point is
>> currently within a comment or a string. If font-lock mode is enabled,
>> this is quite a fast operation as I can just test the text property.
>> However, if font-lock is not enabled, I need to do some parsing to try
>> and determine whether point is on a comment or string. I have defined
>> two functions i.e. 
>>
>> (defun pde-in-comment-p ()
>>   "Returns t if point is within a comment, nil otherwise."
>>   (if font-lock-defaults
>>       (eq (get-text-property (point) 'face) 'font-lock-comment-face)
>>     (nth 4 (parse-partial-sexp (point-min) (point)))))
>>
>> (defun pde-in-string-p ()
>>   "Return t if point within a string, nil otherwise."
>>   (if font-lock-defaults
>>       (eq (get-text-property (point) 'face) 'font-lock-string-face)
>>     (nth 3 (parse-partial-sexp (point-min) (point)))))
>>
>> As you can see, I'm using font-lock-defaults to test whether font-lock
>> is enabled.
>
> No matter what is the test, your logic is not enough.  In cperl-mode,
> I pepper all such functions with
>    (cperl-update-fontification pos)
> (sp?) so that lazy-locking is not playing time-sensitive tricks with
> your logic.
>

Thanks. Will have to give it some thought. The functions I showed above
are not used to control font-locking - in fact, I'm using them to
determine indentation information. The mode is derived from another mode
that takescare of the font locking side of things. If I assume that mode
has taken care of the font-lock issues, I expect the above would be
sufficient. 

Tim


-- 
tcross (at) rapttech dot com dot au


reply via email to

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