[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter integration on feature/tree-sitter
From: |
Yuan Fu |
Subject: |
Re: Tree-sitter integration on feature/tree-sitter |
Date: |
Sat, 7 May 2022 12:11:06 -0700 |
> On May 7, 2022, at 11:48 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 7 May 2022 11:27:11 -0700
>> Cc: emacs-devel@gnu.org
>>
>>> Would you please suggest how to "play with it"? What features to turn
>>> on and how, what commands and displays to try, etc. Posting such
>>> instructions should allow all of us get to testing this branch much
>>> sooner and easier.
>>
>> Some suggestions on top of my head:
>>
>> - Load the attached treesit-demo.el which contains a very basic C major
>> mode, ts-c-mode, that gives you some font-locking and indentation using
>> tree-sitter features.
>> - Get a C file, change its extension to .tsc, and open it
>> - The major mode should be ts-c-mode, and it should have some basic
>> fontification.
>> - Type M-x treesit-show-buffer-tree RET to see the AST of the C file,
>> probably want to use this on a smaller C file.
>> - Type M-x treesit-inspect-mode RET to display the AST of the node at point
>> in the mode-line, see more explanation in its doctoring.
>> - Set treesit--indent-verbose to t, and try to indent some lines, and see
>> which indentation rule is matched.
>>
>> Is this the sort of things you are looking for?
>
> Yes, thanks.
>
> However, I hoped that the font-lock and indentation are already
> integrated with tree-sitter, and all that is needed for a given
> major-mode to use it is to flip some variable. I didn't expect to
> need a completely separate major mode for C sources, for example.
>
> It sounds like we are farther from the goal that I thought we were,
> and some serious work is still ahead of us to get this integrated into
> the existing major modes.
I used a separate major mode because I don’t want to touch the existing one,
and this is only a simple demo. For the author of a major-mode, they only need
to port their font-lock-defaults and indent function to use tree-sitter
features. If you look at the definition of ts-c-mode, its roughly
(if (treesit-should-enable-p)
(set tree-sitter font-lock and indent variables)
(set font-lock-defaults etc))
Then a user could choose whether to turn on tree-sitter for a particular major
mode by changing treesit-disabled-modes. Maybe it should be
treesit-enabled-modes, or something more elaborate, but that’s another topic.
Of course, if a major-mode author pleases, they could also define separate
major modes, as Theodor pointed out.
> However, I hoped that the font-lock and indentation are already
> integrated with tree-sitter, and all that is needed for a given
> major-mode to use it is to flip some variable.
That’s too much magic to ask from tree-sitter. It is just an
incremental-parser, work is still needed from major mode authors to use the
parsed AST to font-lock/indent/etc. But at least I’ve made that process as easy
as possible.
Yuan
- Re: Tree-sitter integration on feature/tree-sitter, (continued)
- Re: Tree-sitter integration on feature/tree-sitter, Eli Zaretskii, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Yuan Fu, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter,
Yuan Fu <=
- Re: Tree-sitter integration on feature/tree-sitter, Eli Zaretskii, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Yuan Fu, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Theodor Thornhill, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Stefan Monnier, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Theodor Thornhill, 2022/05/07
- Re: Tree-sitter integration on feature/tree-sitter, Eli Zaretskii, 2022/05/08
- Re: Tree-sitter integration on feature/tree-sitter, Dmitry Gutov, 2022/05/08
- Re: Tree-sitter integration on feature/tree-sitter, Stefan Monnier, 2022/05/08
- Re: Tree-sitter integration on feature/tree-sitter, Eli Zaretskii, 2022/05/08
- Re: Tree-sitter integration on feature/tree-sitter, Dmitry Gutov, 2022/05/08