From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Best way to detect font-lock mode is on? Date: Mon, 03 Jan 2011 13:51:15 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <87ei8uvgws.fsf@puma.rapttech.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1294026044 9557 80.91.229.12 (3 Jan 2011 03:40:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 3 Jan 2011 03:40:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 03 04:40:40 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PZbHk-0001aa-Ax for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Jan 2011 04:40:40 +0100 Original-Received: from localhost ([127.0.0.1]:52117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZbHj-0005RQ-SB for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jan 2011 22:40:39 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.glorb.com!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:1yBogOD1dcC0+isWpkCZXYSlMVs= Original-Lines: 31 Original-NNTP-Posting-Host: 6375d7e0.news.astraweb.com Original-X-Trace: DXC=1l>APFd6JcA0UO2<>T]L; AL?0kYOcDh@JW\:Hm@YlDbJZCW2QGXDh2@Y1nLd:V List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78082 Archived-At: 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