unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Best way to detect font-lock mode is on?
@ 2011-01-03  2:51 Tim X
  2011-01-03  4:59 ` Stefan Monnier
  2011-01-12  3:46 ` Ilya Zakharevich
  0 siblings, 2 replies; 14+ messages in thread
From: Tim X @ 2011-01-03  2:51 UTC (permalink / raw)
  To: help-gnu-emacs


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-01-15  7:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-03  2:51 Best way to detect font-lock mode is on? Tim X
2011-01-03  4:59 ` Stefan Monnier
2011-01-03  6:08   ` Tim X
2011-01-05  5:50     ` Stefan Monnier
2011-01-05  7:55       ` Tim X
2011-01-10 17:39         ` Stefan Monnier
2011-01-05 14:52       ` Elena
2011-01-10 17:40         ` Stefan Monnier
2011-01-12  3:46 ` Ilya Zakharevich
2011-01-12 15:45   ` Stefan Monnier
2011-01-13  1:21   ` Tim X
2011-01-14  1:35     ` Ilya Zakharevich
2011-01-14  6:59       ` Tim X
2011-01-15  7:54         ` Ilya Zakharevich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).