unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Migrating from font-lock-syntactic-keywords to syntax-propertize-function
Date: Tue, 12 May 2020 10:49:11 -0400	[thread overview]
Message-ID: <jwvpnb91aj8.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87sgg51msg.fsf@gnu.org

>   (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
>    form (SUBEXP SYNTAX OVERRIDE LAXMATCH) but with
>    `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...


        Stefan




      parent reply	other threads:[~2020-05-12 14:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 10:15 Migrating from font-lock-syntactic-keywords to syntax-propertize-function Tassilo Horn
2020-05-12 13:44 ` Dmitry Gutov
2020-05-12 22:17   ` Tassilo Horn
2020-05-14  9:56     ` Tassilo Horn
2020-05-12 14:49 ` Stefan Monnier [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwvpnb91aj8.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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.
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).