GNU bug report logs - #67357
[PATCH] Fix c-ts-mode block indent when first-siblings are comments

Previous Next

Package: emacs;

Reported by: Noah Peart <noah.v.peart <at> gmail.com>

Date: Wed, 22 Nov 2023 01:52:02 UTC

Severity: normal

Tags: patch

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


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

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Eli Zaretskii <eliz <at> gnu.org>, Noah Peart <noah.v.peart <at> gmail.com>,
 Yuan Fu <casouri <at> gmail.com>
Cc: 67357 <at> debbugs.gnu.org
Subject: Re: bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings
 are comments
Date: Thu, 23 Nov 2023 15:17:40 +0200
On 23/11/2023 09:35, Eli Zaretskii wrote:
>> From: Noah Peart<noah.v.peart <at> gmail.com>
>> Date: Tue, 21 Nov 2023 17:50:52 -0800
>>
>> I wasn't sure if these should be two separate bugs, so I separated them just
>> in case.
>>
>> * lisp/progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentation
>> in block statements for cases when the first-sibling(s) are comments or
>> nested keywords (else_clause/do while).
>>
>> Bug: The first statement in a compound statement that is preceded by a
>> comment (or multiple comments) isn't indented.
>>
>> For example, the `if` statement isnt indented in the following code in
>> `c-ts-mode` using `linux` style.
>>
>>      int main() {
>>        while (true) { /* foo */
>>       if (true) { // this line isnt indented
>>            puts ("Hello"); // and this isnt either
>>          }
>>        }
>>      }
>>
>> * lisp/progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentation
>> for else_clause and do-while in bracket-less block statements using
>> `linux` style.
>>
>> Bug: There is no matching indent rule for bracket-less else_clause
>> statements and the "while" in a bracket-less do-while statement is
>> indented to the same level as the do body.
>>
>> To reproduce, using `linux` style in `c-ts-mode`.
>>
>>      int main() {
>>        if (true)
>>          puts("Hello");
>>        else
>>        puts("No matched rule!");
>>        do
>>          puts("Hello");
>>          while (indented_as_part_of_block);
>>      }
> I'm not sure I can reproduce these, it seems to me that the
> indentation is correct in these case when I try the examples.  So
> please show a detailed recipe, starting from "emacs -Q", for each of
> the two problems, so that we could be sure that we are seeing the same
> problems.

I can easily reproduce the first one (comment-related): the two 
indicated lines just don't reindent at all. That's with the default 
'gnu' indentation style, but also with 'linux' and perhaps others (I 
haven't tried).

To reproduce the second one, you first need to enable the 'linux' style:

  (setq c-ts-mode-indent-style 'linux)
  M-x c-ts-mode

Then 'while' indents the same level as 'puts'. Unless this is actually 
indended for the 'linux' style (I have no idea), it's a bug too.




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

Previous Next


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