From: Yuan Fu <casouri@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>,
Theodor Thornhill <theo@thornhill.no>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Recent updates to tree-sitter branch
Date: Sun, 2 Oct 2022 15:54:54 -0700 [thread overview]
Message-ID: <67BF9BE5-4131-49CF-BB0A-687D51BB4870@gmail.com> (raw)
In-Reply-To: <87zgeeznl3.fsf@localhost>
> On Oct 2, 2022, at 12:33 AM, Ihor Radchenko <yantar92@gmail.com> wrote:
>
> Yuan Fu <casouri@gmail.com> writes:
>
>>> I disagree. The current default in font-lock-keywords is not to
>>> override. If programmatic font-lock behaves differently, it will be
>>> confusing.
>>
>> I think the tree-sitter queries are different enough from font-lock keywords that it will not bring confusion. Further more, default to override should make things easier, especially to delicate things like string interpolation, or other nested constructs, where tree-sitter shines. By default, if the to-be-fontified region has any existing face, the whole fontification is given up instead of filling in new fontification. That would be IMO confusing because user would think the match failed.
>
> I do agree that it may be confusing. Yet, it is how the default
> fontification works. I do not think that tree-sitter matching is
> conceptually different compared to regexp matching. (And this particular
> area is not even limited to tree-sitter, AFAIU).
It’s not conceptually different from regex matching, but the tooling is different enough that may bear to be different in some aspect without creating confusion. But I understand that this is purely subjective.
I cc’ed Stefan. Maybe he has more educated opinions about this. (Aka could you make a decision please because I couldn’t.)
>
> I do not insist on my idea being actually used, but wanted to leave a
> data point to be considered.
Thanks. I don’t think my opinion is definitely better, either. Both sides seems reasonable to me. I hope that through discussion we can explore the topic throughly.
>
>> Also bear in mind that the override flag can only be applied to the whole query, rather than individual captured nodes.
>
> How does it change anything? I may be misunderstanding something---can
> you provide some illustrative example clarifying whole query vs.
> individual notes?
What I meant is that, for font-lock-keywords, one can set override flag for each individual match:
(string-regex font-lock-string-face t)
(function-name-regexp font-lock-function-name-face nil)
(class-name-regexp font-lock-type-face t)
...
But for tree-sitter, a query contains many matches and the flag is set for the query. So if I want to use different override flag for different matches, I need to split them into two queries:
(treesit-font-lock-rules
:language 'python
:override 'append
'((string) @python--treesit-fontify-string
((string) @font-lock-doc-face
(:match "^\"\"\"" @font-lock-doc-face))
(interpolation (identifier) @font-lock-variable-name-face))
:language 'python
:override nil
'((function_definition
name: (identifier) @font-lock-function-name-face)
(class_definition
name: (identifier) @font-lock-type-face)
;; Comment and string.
(comment) @font-lock-comment-face))
That means if we use override=nil as default, it is very likely that users need to explicitly set override to t for the whole query, or split the query into separate parts. Nothing serious, but it seems less convenient.
A real use-case for override is how I fontified Python strings above. I have three matches for (1) all strings (2) docstrings (3) variable names in string interpolations. IMO it’s intuitive and convenient for later more specific matches to override earlier more general matches.
Yuan
next prev parent reply other threads:[~2022-10-02 22:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-25 4:27 Recent updates to tree-sitter branch Yuan Fu
2022-09-25 6:17 ` Ihor Radchenko
2022-09-26 8:35 ` Yuan Fu
2022-09-26 9:43 ` Ihor Radchenko
2022-09-27 22:28 ` Yuan Fu
2022-09-29 4:01 ` Ihor Radchenko
2022-09-30 21:03 ` Yuan Fu
2022-10-01 4:20 ` Ihor Radchenko
2022-10-02 3:46 ` Yuan Fu
2022-10-02 7:33 ` Ihor Radchenko
2022-10-02 22:54 ` Yuan Fu [this message]
2022-10-03 5:58 ` Ihor Radchenko
2022-10-04 16:58 ` Yuan Fu
2022-09-29 10:13 ` Aurélien Aptel
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=67BF9BE5-4131-49CF-BB0A-687D51BB4870@gmail.com \
--to=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=theo@thornhill.no \
--cc=yantar92@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 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).