GNU bug report logs -
#61502
29.0.60; c-ts-mode auto-indent not working
Previous Next
Full log
View this message in rfc822 format
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Theodor Thornhill <theo <at> thornhill.no>
>> Cc: pankaj <at> codeisgreat.org, casouri <at> gmail.com, 61502 <at> debbugs.gnu.org
>> Date: Tue, 14 Feb 2023 21:21:33 +0100
>>
>> int
>> main
>> {
>> for (;;)|
>> ```
>>
>> Now type RET
>>
>> ```
>> int
>> main
>> {
>> for (;;)
>> |
>> ```
>>
>> Now type {
>>
>> ```
>> int
>> main
>> {
>> for (;;)
>> {|
>> ```
>>
>> Now type RET
>>
>> ```
>> int
>> main
>> {
>> for (;;)
>> {
>> |
>> ```
>>
>> Which is what I consider a little confusing. We get different
>> indentation with and without the closed scope.
>
> Any idea why it doesn't choose the 'for' node? That's what a naïve
> user would expect, I think.
That's what any user should expect, IMO. It's due to
treesit-node-on. See its docstring:
"Return the smallest node covering BEG to END.
BEWARE! Calling this function on an empty line that is not
inside any top-level construct (function definition, etc.) most
probably will give you the root node, because the root node is
the smallest node that covers that empty line. You probably want
to use `treesit-node-at' instead.
Return nil if none was found. If NAMED is non-nil, only look for
named node.
If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG
is a language, find the first parser for that language in the
current buffer, or create one if none exists; If PARSER-OR-LANG
is nil, try to guess the language at BEG using `treesit-language-at'."
Rather selecting the first node "above" point sounds more reasonable?
Theo
This bug report was last modified 2 years and 122 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.