GNU bug report logs - #62412
29.0.60; strange c++ indentation behavior with tree sitter

Previous Next

Package: emacs;

Reported by: "Herman, Geza" <geza.herman <at> gmail.com>

Date: Thu, 23 Mar 2023 20:44:02 UTC

Severity: normal

Found in version 29.0.60

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Theodor Thornhill <theo <at> thornhill.no>
To: Yuan Fu <casouri <at> gmail.com>, geza.herman <at> gmail.com
Cc: 62412 <at> debbugs.gnu.org
Subject: bug#62412: 29.0.60; strange c++ indentation behavior with tree  sitter
Date: Fri, 24 Mar 2023 21:04:24 +0100

On 24 March 2023 19:17:28 CET, Yuan Fu <casouri <at> gmail.com> wrote:
>
>"Herman, Geza" <geza.herman <at> gmail.com> 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




This bug report was last modified 1 year and 313 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.