GNU bug report logs - #61142
29.0.60; java-ts-mode - Wrong indentation for the body of multiple lines conditions

Previous Next

Package: emacs;

Reported by: 太阳 <zjyzhaojiyang <at> hotmail.com>

Date: Sun, 29 Jan 2023 08:33:03 UTC

Severity: normal

Found in version 29.0.60

Fixed in version 29.1

Done: Theodor Thornhill <theo <at> thornhill.no>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: 赵 纪阳 <zjyzhaojiyang <at> hotmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: "61142 <at> debbugs.gnu.org" <61142 <at> debbugs.gnu.org>
Subject: bug#61142: 回复: bug#61142: 29.0.60; java-ts-mode - Wrong indentation for the body of multiple lines conditions
Date: Sun, 5 Feb 2023 13:09:19 +0000
[Message part 1 (text/plain, inline)]
Thanks for the patch.

I've not tested this patch adequately, but I found an issue:
java-ts-mode indents the body of `else if` with one more level of indentation.

```
public class T {
    int f() {
        int a = 0;
        int b = 1;
        if (a == 0
            && b == 1) {
            // indentation ok
            return 0;
        } else if (a == 1 ) {
                // indentation more
                return 1;
            }
    }
}
```
If the second branch of the if-statement is just an `else` (not `else if`), the body of it will be indented correctly.


I've also tested c-ts-mode (use 'linux as c-ts-mode-indent-style) and it also has this kind of problem.
```
int main() {
    int a = 0;
    if (a == 0) {
        // indentation ok
    } else if (a == 2) {
            // indentation more
        }
}
```

________________________________
发件人: Theodor Thornhill <theo <at> thornhill.no>
发送时间: 2023年2月5日 15:53
收件人: 太阳 <zjyzhaojiyang <at> hotmail.com>
抄送: 61142 <at> debbugs.gnu.org <61142 <at> debbugs.gnu.org>
主题: Re: bug#61142: 29.0.60; java-ts-mode - Wrong indentation for the body of multiple lines conditions

Theodor Thornhill <theo <at> thornhill.no> writes:

> 太阳 <zjyzhaojiyang <at> hotmail.com> writes:
>
>> After reading treesit's manual, I found that we can use `n-p-gp` as the matcher
>> and `grand-parent` as the anchor to match the body of `if` (and `while`, which
>> has a similar issue).
>>
>> I mean a rule looks like the following:
>>
>> ```
>> ((n-p-gp nil "block" "if_statement") grand-parent java-ts-mode-indent-offset)
>> ```
>>
>>
>
>
> Thanks!  We have a mechanism in place for this, see
> 'c-ts-common-statement-offset' in 'c-ts-common.el'.  I didn't get to it
> yet, but I'll try to look at it this evening, unless you want to?  See
> c-ts-mode for examples of how to use it, if you're interested!
>
> Theo

Hi again!

Can you test this patch for me?

@Eli: Is this ok for emacs-29?  I'd love to add some test for this, but
now they are on the master branch.  What is the common procedure to move
stuff from master branch to the release branch?  I _can_ just add some
test to the master branch, but it would be nice to have them on emacs-29
too :-)

Theo

[Message part 2 (text/html, inline)]

This bug report was last modified 2 years and 112 days ago.

Previous Next


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