[Top][All Lists]

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

Re: Migrating from font-lock-syntactic-keywords to syntax-propertize-fun

From: Stefan Monnier
Subject: Re: Migrating from font-lock-syntactic-keywords to syntax-propertize-function
Date: Tue, 12 May 2020 10:49:11 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>   (defun my-make-syntax-propertize-function ()
>     (syntax-propertize-rules
>       ;; My rules here.
>       ))

Note that this is a "constant function".  It macroexpands to

    (defun my-make-syntax-propertize-function ()
      (lambda (..) ...))

> 1. With `font-lock-syntactic-keywords', a MATCH-HIGHLIGHT could have the
>    `syntax-propertize-rules' only (NUMBER SYNTAX) is allowed where
>    SUBEXP and NUMBER have the same meaning.  So how does one convert
>    entries which use OVERRIDE and/or LAXMATCH to the new mechanism?  (I
>    don't use LAXMATCH, so that's not too important.)

font-lock-syntactic-keywords was applied by scanning the whole region
to apply the first rule, then scanning the whole region again to apply
the second rules, etc...
So OVERRIDE was needed to decide what to do when two rules match
on the same chunk of text.

syntax-propertize-rules applies all the rules in a single scan, so only
one rule can match at a given spot, and hence OVERRIDE is not useful.
(as for LAXMATCH, the rules behave the same way as if LAXMATCH was
always set).

> 2. Some of my syntax rules are not static, so I cannot provide a fixed
>    set of rules to `syntax-propertize-rules'.  Is there anything better
>    than using `eval' like
>      (defun my-make-syntax-propertize-function ()
>        (eval
>         `(syntax-propertize-rules
>           ,@(mapcar
>              #'my-convert-legacy-syntactic-keywords
>              (my-compute-syntactic-keywords)))))

If your regexps are not static, then indeed you need to resort to `eval`.
This is done in `fortran-make-syntax-propertize-function`, if you want
to see an example.

>    or should I prefer writing a manual `syntax-propertize-function'?

It's up to you.
Of course, another option is `syntax-propertize-via-font-lock`, which
I'd not recommend, but if you're just looking for a quick-fix...


reply via email to

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