From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 74307@debbugs.gnu.org, Roland Winkler <winkler@gnu.org>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#74307: 30.0.92; emacs-lisp font-locking word regexp
Date: Thu, 05 Dec 2024 09:20:16 +0200 [thread overview]
Message-ID: <87mshak5hz.fsf@mail.linkov.net> (raw)
In-Reply-To: <868qtmkzeo.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 14 Nov 2024 10:11:43 +0200")
>> (setq foo "\\<foo\\>")
>>
>> The part "foo\\" of the string "\\<foo\\>" will get
>> font-lock-variable-name-face, which looks odd.
>>
>> I believe, this is due to a clause in lisp-mode.el that says
>>
>> ;; Words inside \\[], \\<>, \\{} or \\`' tend to be for
>> ;; `substitute-command-keys'.
>>
>> But this assumption is not always correct, in particular if ">" is
>> preceded by "\\", which happens when constructing regexps.
>
> I believe you are saying that in
>
> (,(rx "\\\\" (or (seq "<" (group-n 1 lisp-mode-symbol) ">")
> (seq "{" (group-n 1 lisp-mode-symbol) "}")))
> (1 font-lock-variable-name-face prepend))
>
> we should use something like the below instead?
>
> (,(rx "\\\\" (or (seq "<" (group-n 1 lisp-mode-symbol) (not "\\\\") ">")
> (seq "{" (group-n 1 lisp-mode-symbol) (not "\\\\") "}"))
The problem is that this removes highlighting from the last character
because it doesn't get into the group:
(rx (seq "[" (group-n 1 lisp-mode-symbol) (not "\\") "]"))
=> "\\[\\(?1:\\(?:\\w\\|\\s_\\|\\\\.\\)+\\)[^\\]]"
A possible solution is to move (not "\\") inside the group:
(rx (seq "[" (group-n 1 (seq lisp-mode-symbol (not "\\"))) "]"))
=> "\\[\\(?1:\\(?:\\w\\|\\s_\\|\\\\.\\)+[^\\]\\)]"
But this removes highlighting completely from the reported case of
(setq foo "\\<foo\\>"). However, I guess it should not have highlighting
anyway because this is an incorrect syntax of `substitute-command-keys'
that should match only \\[], \\<>, \\{} or \\`' without the second \\
next prev parent reply other threads:[~2024-12-05 7:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 6:28 bug#74307: 30.0.92; emacs-lisp font-locking word regexp Roland Winkler
2024-11-14 8:11 ` Eli Zaretskii
2024-11-14 16:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-16 14:22 ` Eli Zaretskii
2024-11-14 16:49 ` Roland Winkler
2024-12-05 7:20 ` Juri Linkov [this message]
2024-12-05 7:38 ` Eli Zaretskii
2024-12-05 7:47 ` Juri Linkov
2024-12-05 8:04 ` Eli Zaretskii
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=87mshak5hz.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=74307@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=winkler@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).