Subject: bug#62412: 29.0.60; strange c++ indentation behavior with tree sitter

From: Theodor Thornhill <[email-masked]>
Date: Fri, 24 Mar 2023 21:04:24 +0100

On 24 March 2023 19:17:28 CET, Yuan Fu <[email-masked]> wrote:
>
>"Herman, Geza" <[email-masked]> writes:
>
>> Copy this half-written program to a c++-ts-mode buffer:
>>
>> ----- 8< -----------------------
>>
>> void foo() {
>>   for (int i=0
>> }
>>
>> int main(int argc, char *argv[]) {
>> }
>>
>> ----- 8< -----------------------
>>
>> Move the point to the end of the line of the for loop, and press ";"
>> (as if you continued to write the loop). Notice that the line will
>> lose its indentation ("for" will be moved to column 1). If you
>> continue writing the for loop, it will be correctly re-indented after
>> the closing parenthesis (for example, continue the line with "; i<10;
>> i++)", and notice that after pressing ")", the line will be
>> re-indented).
>>
>> This doesn't happen if the main function is deleted. I'm not sure
>> whether this is a tree-sitter or emacs problem, but I reported here
>> because I think it's more likely that this is some emacs problem.
>
>I believe this is due to this rule:
>
>((query "(ERROR (ERROR)) @indent") column-0 0)
>
>I’m not sure about the original purpose for this rule, CC’ing Theo.
>
>Yuan
I'll look more deeply into the cause of this, but the rule is covering some preproc directives iirc.

Unfortunately tree-sitter behaves better when auto pairs is used. I would advise people to use electric-pairs-mode (if that's the correct name, on mobile now) to avoid these sorts of issues. 

Theo