-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better and smart indentation for major modes #34
Conversation
How does Atom do it? Does it include some indentation rules alongside TS grammars? |
I honestly have absolute no idea how they do it or how to proceed with the branch, jaja. I will check them out and see what I can find, but I was thinking in something like a list of rules for this or that programming language and the rule is pick according to the context at point, but I don't feel confident with such approach. |
2b75958
to
aa289c4
Compare
aa289c4
to
bb2162e
Compare
answering @dgutov atom has a long pending PR to implement this. The author points out that that particular PR doesn't modify indent, since it needs a proper indent config ( provided separately ). The implementation is very similar to what Emacs is supposed to have: a line (row) indenter function. It checks what node is it standing on, walks upwards on current opened branch until it gets to a top level node and then it counts the indentation by walking downwards to the node we're standing on. Do mind that only certain node types are supposed to increase the indentation count. This a per-language configuration and "we" need to maintain it ourselves. Lastly, I want to point out the following. I understand that the emacs-tree-sitter package is supposed to be targeted to other package maintainers. This feature sounds like it should be a separate package. |
This looks very interesting. Indeed, Emacs could use this approach, and someone could even routinely import Atom's indentation rules, since they're in this kind of readable format. Emacs could also have a way to write new indentation rules programmatically, when this format is deemed not powerful enough.
I think the end goal is still to have this capability inside Emacs proper. Then, whether this is a separate package or just a separate file, will become a moot concern. |
Either way, the indenter seems to be short enough for a straight port to Elisp. |
I'm currently working on this feature as a separate package here |
@ubolonton I'm lacking the time to work on this now, but I wonder if @FelipeLema is right and this feature should be offered in a separate package. In my view, if emacs-tree-sitter offers coding highlight it should also offer code indentation. |
bb2162e
to
f000eaa
Compare
I think indentation being in a separate package is fine. |
Just got tree-sitter-indent out of alpha status and putting it out there. |
@FelipeLema why you rely on Emacs 26.1 on your package if dynamic modules is a |
hey, @shackra I think there's no actual need to use 26.1, but I currently cannot test with 25. Please, file a bug if something needs to be addressed |
The indentation is for tree-sitter to "take the wheel" and manage indentation in files for any major mode without disregarding any possible user customization (like values set by the user in
js-indent-level
for instance) and provide a way for user and/or package maintainers to enable indentation between a language supported by tree-sitter and their preferred and unsupported major mode.thread about this feature in emacs-devel: https://lists.gnu.org/archive/html/emacs-devel/2020-03/msg00871.html