Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

shackra
Copy link
Collaborator

@shackra shackra commented Mar 31, 2020

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

@dgutov
Copy link

dgutov commented Apr 8, 2020

How does Atom do it? Does it include some indentation rules alongside TS grammars?

@shackra
Copy link
Collaborator Author

shackra commented Apr 12, 2020

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.

@FelipeLema
Copy link

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.

@dgutov
Copy link

dgutov commented Aug 20, 2020

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.

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 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.

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.

@dgutov
Copy link

dgutov commented Aug 20, 2020

Either way, the indenter seems to be short enough for a straight port to Elisp.

@FelipeLema
Copy link

I'm currently working on this feature as a separate package here

@shackra
Copy link
Collaborator Author

shackra commented Aug 27, 2020

@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.

@ubolonton
Copy link
Collaborator

I think indentation being in a separate package is fine.
Since @FelipeLema is already working on that, we can close this now.

@ubolonton ubolonton closed this Sep 2, 2020
@FelipeLema
Copy link

Just got tree-sitter-indent out of alpha status and putting it out there.

@shackra shackra deleted the indentation-engine branch September 27, 2020 17:10
@shackra
Copy link
Collaborator Author

shackra commented Nov 12, 2020

@FelipeLema why you rely on Emacs 26.1 on your package if dynamic modules is a emacs 25 thing? what if other packages want to use your project as a dependency but don't to bump their Emacs support too high?

@FelipeLema
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants