From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "immerrr again..." <immerrr+lua@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: font-lock-syntactic-keywords: evaluating arbitrary elisp inside matchers?
Date: Mon, 24 Sep 2012 21:03:28 -0400 [thread overview]
Message-ID: <jwvobkvorrf.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <505CD2A0.1090906@gmail.com> (immerrr again...'s message of "Sat, 22 Sep 2012 00:48:32 +0400")
> 1. `(,(rx
> 2. (or (seq (or line-start (not (any "-")))
> 3. (group-n 1 "-") "-[" (group-n 5 (0+ "=")))
> 4. (seq (group-n 3 "[") (group-n 6 (0+ "="))))
> 5. "[" (minimal-match (0+ anything)) "]"
> 6. (or (seq (backref 5) (group-n 2 "]"))
> 7. (seq (backref 6) (group-n 4 "]"))))
> 8. (1 "!" nil t) (2 "!" nil t)
> 9. (3 "|" nil t) (4 "|" nil t))
Here's your problem: the comments/strings you want to match may span
several lines, yet the patterns on font-lock-syntactic-keywords cannot
reliably match more than a single line (because when a line is modified,
font-lock only looked for that pattern in that line, for example).
So you need to do something more like:
For syntax-propertize (which is Emacs-24's successor to
font-lock-syntactic-keywords), I'd use something like:
(defun lua-syntax-propertize (start end)
(goto-char start)
(lua-syntax-propertize-string-or-comment-end end)
(funcall
(syntax-propertize-rules
("\\(?:\\(?:^\\|[^-]\\)\\(-\\)-\\)?\\([\\)=*["
(1 "< b") ;; Only applied if sub-group1 exists.
(2 (prog1 (unless (match-beginning 1) (string-to-syntax "|"))
(lua-syntax-propertize-string-or-comment-end end)))))
start end))
and then in lua-syntax-propertize-string-or-comment I'd use syntax-ppss
to check the parser state (i.e. determine if I'm in a type-b comment or
delimited-string corresponding to a long-bracket construct as opposed to
some type-a comment or standard string, or plain old code), and if I'm
in one of those long-bracket-constructs, use (nth 8 ppss) to find the
beginning, count the number of = used there, then search for the
matching ]==] pattern and place the matching "> b" or "|" syntax on the
second closing bracket.
This should reliably work even for long-brackets that span many many lines.
Stefan
next prev parent reply other threads:[~2012-09-25 1:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-21 20:48 font-lock-syntactic-keywords: evaluating arbitrary elisp inside matchers? immerrr again...
2012-09-25 1:03 ` Stefan Monnier [this message]
2012-09-25 11:31 ` immerrr again...
2012-09-25 13:20 ` Stefan Monnier
2012-09-28 8:19 ` immerrr again
2012-09-28 12:28 ` Stefan Monnier
2012-09-29 6:50 ` immerrr again
2013-03-26 13:48 ` immerrr again
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=jwvobkvorrf.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=immerrr+lua@gmail.com \
/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.