[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Call for volunteers: add tree-sitter support to major modes
From: |
Yuan Fu |
Subject: |
Re: Call for volunteers: add tree-sitter support to major modes |
Date: |
Mon, 10 Oct 2022 13:54:38 -0700 |
>
>> I think we can use the same major mode, just skip the cc-mode
>> initialization and only enable tree-sitter stuff if
>> java-use-tree-sitter is true. But I want to know Alan’s thought on
>> this. I included him in CC.
>
> Thanks! At the moment, I'm still trying to get a handle on what
> tree-sitter is and can do. The idea of including lots of tree-sitter
> modes in Emacs 29 came up very suddenly over the weekend.
I can fill you in :-)
Basically tree-sitter gives you a parser so fast that it can produce a correct
syntax tree of the buffer as you edit the buffer. For us developers, having a
syntax tree available all the time simplifies many things.
For example, font-lock: instead of writing regex patterns to find entities to
highlight, you now asks the syntax tree: “give me all the function_definition
nodes between BEG and END”. And you get a bunch of function_definition nodes.
We know function_definition nodes has the following structure:
(function_definition name: (identifier) body: (block_statement …))
So we can just get the “name” child node, which is an identifier, and apply
font-lock-function-name-face to the text corresponding to that node.
Basically there is no need to parse or pattern-match ourselves anymore, the
answer is readily available.
Another example, for beginning/end-of-defun, there is no need to look for the
beginning/end pattern for a function anymore. We just ask the syntax tree to
give us the next/previous (say) “function_definition” node after/before POS,
and if there is one, jump to the end/beginning of that node.
For indent it’s the same story: you can get the node at the beginning of
current line, then by its type (identifier, statement, expression, bracket,
etc) and its relative position in the tree, you can decide how to indent it.
Hope that helps,
Yuan
- Re: Call for volunteers: add tree-sitter support to major modes, (continued)
- Re: Call for volunteers: add tree-sitter support to major modes, Brian, 2022/10/10
- Re: Call for volunteers: add tree-sitter support to major modes, Yuan Fu, 2022/10/10
- Re: Call for volunteers: add tree-sitter support to major modes, Stefan Monnier, 2022/10/09
- Re: Call for volunteers: add tree-sitter support to major modes, Eli Zaretskii, 2022/10/10
- Re: Call for volunteers: add tree-sitter support to major modes, Brian, 2022/10/10
Re: Call for volunteers: add tree-sitter support to major modes, Theodor Thornhill, 2022/10/09
- Re: Call for volunteers: add tree-sitter support to major modes, Stefan Kangas, 2022/10/09
- Re: Call for volunteers: add tree-sitter support to major modes, Yuan Fu, 2022/10/09
- Re: Call for volunteers: add tree-sitter support to major modes, Alan Mackenzie, 2022/10/10
- Re: Call for volunteers: add tree-sitter support to major modes,
Yuan Fu <=
- Re: Call for volunteers: add tree-sitter support to major modes, Eli Zaretskii, 2022/10/17
- Re: Call for volunteers: add tree-sitter support to major modes, Alan Mackenzie, 2022/10/17
- Re: Call for volunteers: add tree-sitter support to major modes, Stefan Monnier, 2022/10/17
- Re: Call for volunteers: add tree-sitter support to major modes, Ketevan Lomidze, 2022/10/18
- Re: Call for volunteers: add tree-sitter support to major modes, Po Lu, 2022/10/17
- Re: Call for volunteers: add tree-sitter support to major modes, Yuan Fu, 2022/10/18
- Re: Call for volunteers: add tree-sitter support to major modes, Po Lu, 2022/10/18
- Re: Call for volunteers: add tree-sitter support to major modes, Eli Zaretskii, 2022/10/18
- Re: Call for volunteers: add tree-sitter support to major modes, Po Lu, 2022/10/18
- Re: Call for volunteers: add tree-sitter support to major modes, Eli Zaretskii, 2022/10/18