all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: Best way to detect font-lock mode is on?
Date: Mon, 03 Jan 2011 17:08:18 +1100	[thread overview]
Message-ID: <8762u6v7sd.fsf@puma.rapttech.com.au> (raw)
In-Reply-To: jwvbp3yega3.fsf-monnier+gnu.emacs.help@gnu.org

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

>> Just wanting to know what people would suggest as the best way to detect
>> if font-lock mode is enabled. 
>
> Wrong question, I suspect.
>
>> 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,
>
> So IIUC the real question is how to determine if you're within a comment
> or string.  The answer is (nth 4 (syntax-ppss)) and (nth
> 3 (syntax-ppss)) respectively (and (nth 8 (syntax-ppss)) if you want to
> check whether you're within either of the two).

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. These are quite 'heavy' operations and may not
be fast enough if the source file is large enough. 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).

>
>> 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. The tests to determine whether you are in a comment or a string are
used in the calculation of indentation. Using text properties when under
font-lock mode is merely a simple optimisation that will be faster for
large files than parsing the whole file from the beginning. When not
using font-lock, the calculation will be performed using syntax-ppss.
Yes, this does mean that anyone not using font-lock may encounter slower
performance on large files, but at least will probably not be affected
with small/medium sized ones. 

Tim

-- 
tcross (at) rapttech dot com dot au


  reply	other threads:[~2011-01-03  6:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8762u6v7sd.fsf@puma.rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.