[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Best way to detect font-lock mode is on?
From: |
Tim X |
Subject: |
Best way to detect font-lock mode is on? |
Date: |
Mon, 03 Jan 2011 13:51:15 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
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. Is this the best way to go or is there a more
reliable/better test to use?
Tim
--
tcross (at) rapttech dot com dot au
- Best way to detect font-lock mode is on?,
Tim X <=
Re: Best way to detect font-lock mode is on?, Ilya Zakharevich, 2011/01/11