emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax-propertize-function vs indentation lexer


From: Stefan Monnier
Subject: Re: syntax-propertize-function vs indentation lexer
Date: Thu, 30 May 2013 10:02:59 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> The doc string for syntax-propertize-function only mentions
> font-lock, not indentation etc; it should say "most syntax uses", or
> better, list all the places it is called. 

Oops, indeed it singles out font-lock.  I just installed the patch below
which should address this problem.

> The later; I'm parsing the entire buffer with an LALR parser in
> ada-mode, and whenever it changes,

Sounds expensive.  How does it cope with large buffers?

> and caching the results for use by indent. So far it's quite fast.

How much time does it take to open a 1MB file?

> So I need to call
> (syntax-propertize (point-max))
> in ada-mode

I wouldn't put it in ada-mode, no.  Instead, I'd put it closer to the
code that actually needs those properties to be applied.  E.g. I'd
either put it in the LALR parser code (if that code needs the syntax
properties) or in the indentation code.  Note that calling
syntax-propertize repeatedly is cheap: if the region has already been
handled, it returns almost instantly since it begins with

  (when (and syntax-propertize-function
             (< syntax-propertize--done pos))

Also I probably wouldn't put (syntax-propertize (point-max)), but
instead use (syntax-propertize end) where `end' is the end of the region
being currently LALR-parsed or being considered by the indentation code.

> (syntax-ppss-flush-cache begin) 
> (syntax-propertize end)
> in the after-change hook.

You might want to put the syntax-ppss-flush-cache there (although
syntax.el should already take care of that, normally), but the
syntax-propertize doesn't belong there either (since it belong to the
code that actually uses those properties, i.e. either the parser or the
indentation).


        Stefan


=== modified file 'lisp/emacs-lisp/syntax.el'
--- lisp/emacs-lisp/syntax.el   2013-04-22 14:11:37 +0000
+++ lisp/emacs-lisp/syntax.el   2013-05-30 13:55:38 +0000
@@ -56,12 +56,13 @@
   ;; syntax-ppss-flush-cache since that would not only flush the cache but also
   ;; reset syntax-propertize--done which should not be done in this case).
   "Mode-specific function to apply `syntax-table' text properties.
-The value of this variable is a function to be called by Font
-Lock mode, prior to performing syntactic fontification on a
-stretch of text.  It is given two arguments, START and END: the
-start and end of the text to be fontified.  Major modes can
-specify a custom function to apply `syntax-table' properties to
-override the default syntax table in special cases.
+It is the work horse of `syntax-propertize', which is called by things like
+Font-Lock and indentation.
+
+It is given two arguments, START and END: the start and end of the text to
+which `syntax-table' might need to be applied.  Major modes can use this to
+override the buffer's syntax table for special syntactic constructs that
+cannot be handled just by the buffer's syntax-table.
 
 The specified function may call `syntax-ppss' on any position
 before END, but it should not call `syntax-ppss-flush-cache',




reply via email to

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