GNU bug report logs - #61026
29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace

Previous Next

Package: emacs;

Reported by: Mohammed Sadiq <sadiq <at> sadiqpk.org>

Date: Mon, 23 Jan 2023 11:18:02 UTC

Severity: normal

Found in version 29.0.60

To reply to this bug, email your comments to 61026 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Mon, 23 Jan 2023 11:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mohammed Sadiq <sadiq <at> sadiqpk.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 23 Jan 2023 11:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mohammed Sadiq <sadiq <at> sadiqpk.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.60; c-ts-mode: Broken indentation for loops and conditions
 without brace
Date: Mon, 23 Jan 2023 16:47:38 +0530
The following code has broken indentation with c-ts-mode:

  while (true)
    if (true) {
    puts ("Hello");
  }

  if (true)
    if (true)
      {
      puts ("World");
    }

For which, I expect to get the following indentation (with default 
config):

  while (true)
    if (true) {
      puts ("Hello");
    }

  if (true)
    if (true)
      {
        puts ("World");
      }



In GNU Emacs 29.0.60 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.36, cairo version 1.16.0) of 2023-01-23 built on purism
Repository revision: e6c5f32e77dceed4e26b16889cc56547093bdc45
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 
11.0.12101006
System Description: Debian GNU/Linux bookworm/sid




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Wed, 25 Jan 2023 20:22:01 GMT) Full text and rfc822 format available.

Message #8 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Mohammed Sadiq <sadiq <at> sadiqpk.org>
Cc: 61026 <at> debbugs.gnu.org, Yuan Fu <casouri <at> gmail.com>
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and
 conditions without brace
Date: Wed, 25 Jan 2023 21:21:27 +0100
Mohammed Sadiq <sadiq <at> sadiqpk.org> writes:

> The following code has broken indentation with c-ts-mode:
>
>   while (true)
>     if (true) {
>     puts ("Hello");
>   }
>
>   if (true)
>     if (true)
>       {
>       puts ("World");
>     }
>
> For which, I expect to get the following indentation (with default config):
>
>   while (true)
>     if (true) {
>       puts ("Hello");
>     }
>
>   if (true)
>     if (true)
>       {
>         puts ("World");
>       }
>
>

Thanks, Mohammed!

Yuan, I'm not sure the new brace counting method is a good enough
improvement just yet considering its complexity and the number of issues
we are seeing.  Do you see any simple fixes for these issues?

I can try to debug this this weekend, but not sure I really have time to
fix it.  All of these issues work fine in js-ts-mode or java-ts-mode, if
I'm not mistaken.

Theo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Thu, 26 Jan 2023 07:55:01 GMT) Full text and rfc822 format available.

Message #11 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: Mohammed Sadiq <sadiq <at> sadiqpk.org>, 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and 
 conditions without brace
Date: Wed, 25 Jan 2023 23:54:08 -0800
Theodor Thornhill <theo <at> thornhill.no> writes:

> Mohammed Sadiq <sadiq <at> sadiqpk.org> writes:
>
>> The following code has broken indentation with c-ts-mode:
>>
>>   while (true)
>>     if (true) {
>>     puts ("Hello");
>>   }
>>
>>   if (true)
>>     if (true)
>>       {
>>       puts ("World");
>>     }
>>
>> For which, I expect to get the following indentation (with default config):
>>
>>   while (true)
>>     if (true) {
>>       puts ("Hello");
>>     }
>>
>>   if (true)
>>     if (true)
>>       {
>>         puts ("World");
>>       }
>>
>>
>
> Thanks, Mohammed!
>
> Yuan, I'm not sure the new brace counting method is a good enough
> improvement just yet considering its complexity and the number of issues
> we are seeing.  Do you see any simple fixes for these issues?

I fixed it.

> I can try to debug this this weekend, but not sure I really have time to
> fix it.  All of these issues work fine in js-ts-mode or java-ts-mode, if
> I'm not mistaken.

Yes, because js and java doesn’t allow omitting brackets. So we only
need to add a special-case for C/C++, so it isn’t too bad.

Yuan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Thu, 26 Jan 2023 07:58:01 GMT) Full text and rfc822 format available.

Message #14 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Mohammed Sadiq <sadiq <at> sadiqpk.org>, 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and
 conditions without brace
Date: Thu, 26 Jan 2023 08:57:23 +0100
Yuan Fu <casouri <at> gmail.com> writes:

> Theodor Thornhill <theo <at> thornhill.no> writes:
>
>> Mohammed Sadiq <sadiq <at> sadiqpk.org> writes:
>>
>>> The following code has broken indentation with c-ts-mode:
>>>
>>>   while (true)
>>>     if (true) {
>>>     puts ("Hello");
>>>   }
>>>
>>>   if (true)
>>>     if (true)
>>>       {
>>>       puts ("World");
>>>     }
>>>
>>> For which, I expect to get the following indentation (with default config):
>>>
>>>   while (true)
>>>     if (true) {
>>>       puts ("Hello");
>>>     }
>>>
>>>   if (true)
>>>     if (true)
>>>       {
>>>         puts ("World");
>>>       }
>>>
>>>
>>
>> Thanks, Mohammed!
>>
>> Yuan, I'm not sure the new brace counting method is a good enough
>> improvement just yet considering its complexity and the number of issues
>> we are seeing.  Do you see any simple fixes for these issues?
>
> I fixed it.
>
>> I can try to debug this this weekend, but not sure I really have time to
>> fix it.  All of these issues work fine in js-ts-mode or java-ts-mode, if
>> I'm not mistaken.
>
> Yes, because js and java doesn’t allow omitting brackets. So we only
> need to add a special-case for C/C++, so it isn’t too bad.
>
> Yuan

They allow that just fine, don't they? 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Sun, 29 Jan 2023 08:23:01 GMT) Full text and rfc822 format available.

Message #17 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: Mohammed Sadiq <sadiq <at> sadiqpk.org>, 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and 
 conditions without brace
Date: Sun, 29 Jan 2023 00:22:26 -0800
Theodor Thornhill <theo <at> thornhill.no> writes:

> Yuan Fu <casouri <at> gmail.com> writes:
>
>> Theodor Thornhill <theo <at> thornhill.no> writes:
>>
>>> Mohammed Sadiq <sadiq <at> sadiqpk.org> writes:
>>>
>>>> The following code has broken indentation with c-ts-mode:
>>>>
>>>>   while (true)
>>>>     if (true) {
>>>>     puts ("Hello");
>>>>   }
>>>>
>>>>   if (true)
>>>>     if (true)
>>>>       {
>>>>       puts ("World");
>>>>     }
>>>>
>>>> For which, I expect to get the following indentation (with default config):
>>>>
>>>>   while (true)
>>>>     if (true) {
>>>>       puts ("Hello");
>>>>     }
>>>>
>>>>   if (true)
>>>>     if (true)
>>>>       {
>>>>         puts ("World");
>>>>       }
>>>>
>>>>
>>>
>>> Thanks, Mohammed!
>>>
>>> Yuan, I'm not sure the new brace counting method is a good enough
>>> improvement just yet considering its complexity and the number of issues
>>> we are seeing.  Do you see any simple fixes for these issues?
>>
>> I fixed it.
>>
>>> I can try to debug this this weekend, but not sure I really have time to
>>> fix it.  All of these issues work fine in js-ts-mode or java-ts-mode, if
>>> I'm not mistaken.
>>
>> Yes, because js and java doesn’t allow omitting brackets. So we only
>> need to add a special-case for C/C++, so it isn’t too bad.
>>
>> Yuan
>
> They allow that just fine, don't they? 

You are right. I made the fix general and moved everything to
c-ts-common.el. The next step is to make other modes use it.

Yuan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Sun, 29 Jan 2023 08:56:01 GMT) Full text and rfc822 format available.

Message #20 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Mohammed Sadiq <sadiq <at> sadiqpk.org>, 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and  conditions without brace
Date: Sun, 29 Jan 2023 09:55:42 +0100

On 29 January 2023 09:22:26 CET, Yuan Fu <casouri <at> gmail.com> wrote:
>
>Theodor Thornhill <theo <at> thornhill.no> writes:
>
>> Yuan Fu <casouri <at> gmail.com> writes:
>>
>>> Theodor Thornhill <theo <at> thornhill.no> writes:
>>>
>>>> Mohammed Sadiq <sadiq <at> sadiqpk.org> writes:
>>>>
>>>>> The following code has broken indentation with c-ts-mode:
>>>>>
>>>>>   while (true)
>>>>>     if (true) {
>>>>>     puts ("Hello");
>>>>>   }
>>>>>
>>>>>   if (true)
>>>>>     if (true)
>>>>>       {
>>>>>       puts ("World");
>>>>>     }
>>>>>
>>>>> For which, I expect to get the following indentation (with default config):
>>>>>
>>>>>   while (true)
>>>>>     if (true) {
>>>>>       puts ("Hello");
>>>>>     }
>>>>>
>>>>>   if (true)
>>>>>     if (true)
>>>>>       {
>>>>>         puts ("World");
>>>>>       }
>>>>>
>>>>>
>>>>
>>>> Thanks, Mohammed!
>>>>
>>>> Yuan, I'm not sure the new brace counting method is a good enough
>>>> improvement just yet considering its complexity and the number of issues
>>>> we are seeing.  Do you see any simple fixes for these issues?
>>>
>>> I fixed it.
>>>
>>>> I can try to debug this this weekend, but not sure I really have time to
>>>> fix it.  All of these issues work fine in js-ts-mode or java-ts-mode, if
>>>> I'm not mistaken.
>>>
>>> Yes, because js and java doesn’t allow omitting brackets. So we only
>>> need to add a special-case for C/C++, so it isn’t too bad.
>>>
>>> Yuan
>>
>> They allow that just fine, don't they? 
>
>You are right. I made the fix general and moved everything to
>c-ts-common.el. The next step is to make other modes use it.
>
>Yuan

Nice!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Sun, 05 Feb 2023 20:33:01 GMT) Full text and rfc822 format available.

Message #23 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Knut Anders Hatlen <kahatlen <at> gmail.com>
To: 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and
 conditions without brace
Date: Sun, 05 Feb 2023 21:32:44 +0100
Hi,

I'm still seeing odd indentation for conditions without braces. For
example, invoking c-ts-mode-indent-defun (C-c C-q) with the point inside
this function ...

int f(int x) {
if (x > 1)
return x;
else
return x + 1;
}

... results in the following indentation with the default GNU style:

int f(int x) {
  if (x > 1)
return x;
  else
return x + 1;
}

I would have expected this:

int f(int x) {
  if (x > 1)
    return x;
  else
    return x + 1;
}

Is something more needed for this bug, or is the problem I'm seeing a
different bug?

-- 
Knut Anders




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Tue, 07 Feb 2023 02:32:02 GMT) Full text and rfc822 format available.

Message #26 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Knut Anders Hatlen <kahatlen <at> gmail.com>
Cc: 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and 
 conditions without brace
Date: Mon, 6 Feb 2023 18:30:43 -0800
Knut Anders Hatlen <kahatlen <at> gmail.com> writes:

> Hi,
>
> I'm still seeing odd indentation for conditions without braces. For
> example, invoking c-ts-mode-indent-defun (C-c C-q) with the point inside
> this function ...
>
> int f(int x) {
> if (x > 1)
> return x;
> else
> return x + 1;
> }
>
> ... results in the following indentation with the default GNU style:
>
> int f(int x) {
>   if (x > 1)
> return x;
>   else
> return x + 1;
> }
>
> I would have expected this:
>
> int f(int x) {
>   if (x > 1)
>     return x;
>   else
>     return x + 1;
> }
>
> Is something more needed for this bug, or is the problem I'm seeing a
> different bug?

My bad, I made some changes and didn’t push them, and I’m sitting here
wondering why everyone is seeing problems... Everything should indent
fine now.

Yuan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61026; Package emacs. (Tue, 07 Feb 2023 10:42:01 GMT) Full text and rfc822 format available.

Message #29 received at 61026 <at> debbugs.gnu.org (full text, mbox):

From: Knut Anders Hatlen <kahatlen <at> gmail.com>
To: Yuan Fu <casouri <at> gmail.com>
Cc: 61026 <at> debbugs.gnu.org
Subject: Re: bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and
 conditions without brace
Date: Tue, 7 Feb 2023 11:41:17 +0100
[Message part 1 (text/plain, inline)]
tir. 7. feb. 2023 kl. 03:30 skrev Yuan Fu <casouri <at> gmail.com>:

>
> Knut Anders Hatlen <kahatlen <at> gmail.com> writes:
>
> > Hi,
> >
> > I'm still seeing odd indentation for conditions without braces. For
> > example, invoking c-ts-mode-indent-defun (C-c C-q) with the point inside
> > this function ...
> >
> > int f(int x) {
> > if (x > 1)
> > return x;
> > else
> > return x + 1;
> > }
> >
> > ... results in the following indentation with the default GNU style:
> >
> > int f(int x) {
> >   if (x > 1)
> > return x;
> >   else
> > return x + 1;
> > }
> >
> > I would have expected this:
> >
> > int f(int x) {
> >   if (x > 1)
> >     return x;
> >   else
> >     return x + 1;
> > }
> >
> > Is something more needed for this bug, or is the problem I'm seeing a
> > different bug?
>
> My bad, I made some changes and didn’t push them, and I’m sitting here
> wondering why everyone is seeing problems... Everything should indent
> fine now.
>
> Yuan
>

Thanks, Yuan!

It now seems to work fine with the GNU style, K&R style and Linux style.
With BSD style, however, it ends up like this:

int f(int x) {
  if (x > 1)
  return x;
  else
  return x + 1;
}

I assume the return statements should have been indented one more level
here too?

Best regards,

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

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

Previous Next


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