-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add textobjects and indents to c and cpp #1293
Conversation
Also found another problem for (;;) {<hit enter>
} works correctly, but for (;;
) {<hit enter>
} leads to for (;;
) {
<cursor here with one indentation too much
} I guess this is an issue outside the |
I think some of these were fixed after #1341 Can you resolve the |
The issues you found are expected behavior, it's just that the current indentation system is (as far as I can see) not powerful enough to correctly indent C/C++ code in all cases. In the first example, the In the second example, the issue is that both for (;;)
{
printf("Hello World");
} Maybe there is a better way to structure the indent system but I haven't been able to think of one. The main limitation right now is that the indent queries can only specify node types without any additional context. In grammars that reuse a lot of nodes this makes writing indent queries quite hard. For now, maybe you could try removing the if, while and for statement nodes from the indent list and the for (;;)
printf("Hello World"); but as far as I know leaving out the braces is considered bad style anyways. |
Indentation of single line statements doesn't work, i.e. for (;;)<hit enter> leads to for(;;) <cursor here> Only blocks with curly braces are indented.
Thanks for the explanation @Triton171, it makes a lot of sense now. It seems to work well now. |
@Triton171 I've seen https://github.com/emacsmirror/tree-sitter-indent/blob/5f80e89b7da2074ea7f083b769448eb7026865dc/tree-sitter-indent.el#L83-L104 that uses more scopes to distinguish between different behaviors but I found it harder to write. Maybe we could use sub-scopes so that the behavior could be opt-in? |
Somehow, indentation inside conditions doesn't work, i.e.
leads to
but the expected result should be
But it is a lot better than before.