all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
@ 2023-01-23 11:17 Mohammed Sadiq
  2023-01-25 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Mohammed Sadiq @ 2023-01-23 11:17 UTC (permalink / raw)
  To: 61026

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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
@ 2023-01-25 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-26  7:54 ` Yuan Fu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-25 20:21 UTC (permalink / raw)
  To: Mohammed Sadiq; +Cc: 61026, Yuan Fu

Mohammed Sadiq <sadiq@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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
  2023-01-25 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-01-26  7:54 ` Yuan Fu
  2023-01-26  7:57   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-29  8:22 ` Yuan Fu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Yuan Fu @ 2023-01-26  7:54 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: Mohammed Sadiq, 61026


Theodor Thornhill <theo@thornhill.no> writes:

> Mohammed Sadiq <sadiq@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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-26  7:54 ` Yuan Fu
@ 2023-01-26  7:57   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 9+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-26  7:57 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Mohammed Sadiq, 61026

Yuan Fu <casouri@gmail.com> writes:

> Theodor Thornhill <theo@thornhill.no> writes:
>
>> Mohammed Sadiq <sadiq@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? 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
  2023-01-25 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-26  7:54 ` Yuan Fu
@ 2023-01-29  8:22 ` Yuan Fu
  2023-01-29  8:55   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-05 20:32 ` Knut Anders Hatlen
  2023-02-07  2:30 ` Yuan Fu
  4 siblings, 1 reply; 9+ messages in thread
From: Yuan Fu @ 2023-01-29  8:22 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: Mohammed Sadiq, 61026


Theodor Thornhill <theo@thornhill.no> writes:

> Yuan Fu <casouri@gmail.com> writes:
>
>> Theodor Thornhill <theo@thornhill.no> writes:
>>
>>> Mohammed Sadiq <sadiq@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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-29  8:22 ` Yuan Fu
@ 2023-01-29  8:55   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 9+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-29  8:55 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Mohammed Sadiq, 61026



On 29 January 2023 09:22:26 CET, Yuan Fu <casouri@gmail.com> wrote:
>
>Theodor Thornhill <theo@thornhill.no> writes:
>
>> Yuan Fu <casouri@gmail.com> writes:
>>
>>> Theodor Thornhill <theo@thornhill.no> writes:
>>>
>>>> Mohammed Sadiq <sadiq@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!





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
                   ` (2 preceding siblings ...)
  2023-01-29  8:22 ` Yuan Fu
@ 2023-02-05 20:32 ` Knut Anders Hatlen
  2023-02-07  2:30 ` Yuan Fu
  4 siblings, 0 replies; 9+ messages in thread
From: Knut Anders Hatlen @ 2023-02-05 20:32 UTC (permalink / raw)
  To: 61026

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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
                   ` (3 preceding siblings ...)
  2023-02-05 20:32 ` Knut Anders Hatlen
@ 2023-02-07  2:30 ` Yuan Fu
  2023-02-07 10:41   ` Knut Anders Hatlen
  4 siblings, 1 reply; 9+ messages in thread
From: Yuan Fu @ 2023-02-07  2:30 UTC (permalink / raw)
  To: Knut Anders Hatlen; +Cc: 61026


Knut Anders Hatlen <kahatlen@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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace
  2023-02-07  2:30 ` Yuan Fu
@ 2023-02-07 10:41   ` Knut Anders Hatlen
  0 siblings, 0 replies; 9+ messages in thread
From: Knut Anders Hatlen @ 2023-02-07 10:41 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 61026

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

tir. 7. feb. 2023 kl. 03:30 skrev Yuan Fu <casouri@gmail.com>:

>
> Knut Anders Hatlen <kahatlen@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

[-- Attachment #2: Type: text/html, Size: 2083 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-07 10:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-23 11:17 bug#61026: 29.0.60; c-ts-mode: Broken indentation for loops and conditions without brace Mohammed Sadiq
2023-01-25 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-26  7:54 ` Yuan Fu
2023-01-26  7:57   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-29  8:22 ` Yuan Fu
2023-01-29  8:55   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-05 20:32 ` Knut Anders Hatlen
2023-02-07  2:30 ` Yuan Fu
2023-02-07 10:41   ` Knut Anders Hatlen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.