unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
@ 2023-11-22  1:50 Noah Peart
  2023-11-23  7:35 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Noah Peart @ 2023-11-22  1:50 UTC (permalink / raw)
  To: 67357


[-- Attachment #1.1: Type: text/plain, Size: 1870 bytes --]

Tags: patch

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);
    }


In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0) of 2023-11-18 built on noah-X580VD
Repository revision: 47b497b4dac91e5ea56102018223bdeb5e21a93b
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.04.3 LTS

Configured using:
 'configure --prefix=/usr/local --with-modules --with-tree-sitter
--with-threads --with-x-toolkit=gtk3 --with-xwidgets --with-gnutls
--with-json --with-mailutils --with-jpeg --with-png --with-rsvg
--with-tiff --with-xml2 --with-xpm --with-imagemagick CC=gcc-12
CXX=gcc-12'

[-- Attachment #1.2: Type: text/html, Size: 2201 bytes --]

[-- Attachment #2: c-ts-mode-first-sib-comments.patch --]
[-- Type: text/x-patch, Size: 2924 bytes --]

From f5c75a515b1fed19d98f41d7a1bc95d285dc4df0 Mon Sep 17 00:00:00 2001
From: nverno <noah.v.peart@gmail.com>
Date: Tue, 21 Nov 2023 16:33:04 -0800
Subject: [PATCH] fix c-ts-mode indentation when first-sibling is a comment

---
 lisp/progmodes/c-ts-mode.el                   |  6 +++-
 .../progmodes/c-ts-mode-resources/indent.erts | 32 ++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 70717a90caa..a93d8beb272 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -443,7 +443,9 @@ c-ts-mode--indent-styles
 
            ;; Statement in {} blocks.
            ((or (match nil "compound_statement" nil 1 1)
-                (match null "compound_statement"))
+                (match null "compound_statement")
+                ;; Case when first sibling(s) are comments
+                (query "(compound_statement _ (comment) (_) @indent)"))
             standalone-parent c-ts-mode-indent-offset)
            ((parent-is "compound_statement") c-ts-mode--anchor-prev-sibling 0)
            ;; Opening bracket.
@@ -454,8 +456,10 @@ c-ts-mode--indent-styles
            ;; Tested by the "Bracketless Simple Statement" test.
            ((parent-is "if_statement") standalone-parent c-ts-mode-indent-offset)
            ((parent-is "for_statement") standalone-parent c-ts-mode-indent-offset)
+           ((match "while" "do_statement") parent-bol 0) ; (do_statement "while")
            ((parent-is "while_statement") standalone-parent c-ts-mode-indent-offset)
            ((parent-is "do_statement") standalone-parent c-ts-mode-indent-offset)
+           ((parent-is "else_clause") standalone-parent c-ts-mode-indent-offset)
 
            ((parent-is "case_statement") standalone-parent c-ts-mode-indent-offset)
 
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 221b3d809af..d29370b41e6 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -310,7 +310,7 @@ label:
 
 Name: Bracket-less Block-Statement (Linux Style) (bug#61026)
 
-=-=-=
+=-=
 int main() {
   while (true)
     if (true) {
@@ -331,6 +331,8 @@ int main() {
     if (true) {
       puts ("Hello");
     }
+    else
+      puts("Hello");
 }
 =-=-=
 
@@ -379,6 +381,34 @@ void foo(
 }
 =-=-=
 
+Name: Block-Statement where first siblings are comments (Linux Style)
+
+=-=
+int main() {
+  while (true) { /* foo */
+    if (true) { // bar
+      puts ("Hello");
+    }
+  }
+  for (;;) {  // 1. fooo
+    /* 2. baaa */
+    /* 3. rrr */
+    if (true)
+      // 2. baaa
+      puts ("Hello");
+  }
+  if (1) { // 1
+    /*
+     * 2
+     */
+    if (1) /*3*/ {
+      /* 4 */
+      puts("Hello");
+    }
+  }
+}
+=-=-=
+
 Name: Initializer List (Linux Style) (Bug#61398)
 
 =-=
-- 
2.34.1


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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-22  1:50 bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments Noah Peart
@ 2023-11-23  7:35 ` Eli Zaretskii
  2023-11-23 13:17   ` Dmitry Gutov
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-11-23  7:35 UTC (permalink / raw)
  To: Noah Peart, Yuan Fu; +Cc: 67357

> From: Noah Peart <noah.v.peart@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.

Also, please tell if the same problems exist on the emacs-29 branch.

Adding Yuan to the discussion.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-23  7:35 ` Eli Zaretskii
@ 2023-11-23 13:17   ` Dmitry Gutov
  2023-11-23 14:33     ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Gutov @ 2023-11-23 13:17 UTC (permalink / raw)
  To: Eli Zaretskii, Noah Peart, Yuan Fu; +Cc: 67357

On 23/11/2023 09:35, Eli Zaretskii wrote:
>> From: Noah Peart<noah.v.peart@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.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-23 13:17   ` Dmitry Gutov
@ 2023-11-23 14:33     ` Eli Zaretskii
  2023-11-23 14:41       ` Dmitry Gutov
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-11-23 14:33 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: noah.v.peart, casouri, 67357

> Date: Thu, 23 Nov 2023 15:17:40 +0200
> Cc: 67357@debbugs.gnu.org
> From: Dmitry Gutov <dmitry@gutov.dev>
> 
> On 23/11/2023 09:35, Eli Zaretskii wrote:
> > 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).

I don't understand what you mean by "reindent".  That wasn't what the
original report was about, AFAIU.

I still think a complete recipe is needed.

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

I tried to reproduce _only_ with the 'linux' style, as the bug report
said.

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

The style is a per-buffer setting, so AFAIU one needs to set the style
after turning on the mode in a buffer, whether manually or
automatically.

A full recipe is supposed to remove all those confusing details and
potential mistakes.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-23 14:33     ` Eli Zaretskii
@ 2023-11-23 14:41       ` Dmitry Gutov
  2023-11-24 13:47         ` Noah Peart
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Gutov @ 2023-11-23 14:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: noah.v.peart, casouri, 67357

On 23/11/2023 16:33, Eli Zaretskii wrote:
>> Date: Thu, 23 Nov 2023 15:17:40 +0200
>> Cc: 67357@debbugs.gnu.org
>> From: Dmitry Gutov <dmitry@gutov.dev>
>>
>> On 23/11/2023 09:35, Eli Zaretskii wrote:
>>> 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).
> 
> I don't understand what you mean by "reindent".  That wasn't what the
> original report was about, AFAIU.

Reindent is when you press tab, and the indentation on a given line 
changes. In that example, no matter which indentation you set on those 
line, pressing TAB doesn't change it.

> I still think a complete recipe is needed.
> 
>> To reproduce the second one, you first need to enable the 'linux' style:
> 
> I tried to reproduce _only_ with the 'linux' style, as the bug report
> said.
> 
>>     (setq c-ts-mode-indent-style 'linux)
>>     M-x c-ts-mode
> 
> The style is a per-buffer setting, so AFAIU one needs to set the style
> after turning on the mode in a buffer, whether manually or
> automatically.

Did you use 'M-x c-ts-mode-set-style', then? That also repros for me.

The style can be set locally - as the above command does - but initially 
the global value is used. And it's applied during the major mode's 
execution, so a simple 'setq' doesn't work.

> A full recipe is supposed to remove all those confusing details and
> potential mistakes.

I don't mind.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-23 14:41       ` Dmitry Gutov
@ 2023-11-24 13:47         ` Noah Peart
  2023-11-24 14:07           ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Noah Peart @ 2023-11-24 13:47 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 67357, casouri

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

Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce bugs,
run the following to configure `c-ts-mode` with `linux` style:

    (defun example-setup ()
      (interactive)
      (c-ts-mode)
      (setq-local indent-tabs-mode nil)
      (setq-local c-ts-mode-indent-offset 2)
      (c-ts-mode-set-style 'linux))

The patch should also fix the missing indent for the `else_clause`
mentioned
in https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-11/msg01266.html.

On Thu, Nov 23, 2023 at 6:41 AM Dmitry Gutov <dmitry@gutov.dev> wrote:

> On 23/11/2023 16:33, Eli Zaretskii wrote:
> >> Date: Thu, 23 Nov 2023 15:17:40 +0200
> >> Cc: 67357@debbugs.gnu.org
> >> From: Dmitry Gutov <dmitry@gutov.dev>
> >>
> >> On 23/11/2023 09:35, Eli Zaretskii wrote:
> >>> 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).
> >
> > I don't understand what you mean by "reindent".  That wasn't what the
> > original report was about, AFAIU.
>
> Reindent is when you press tab, and the indentation on a given line
> changes. In that example, no matter which indentation you set on those
> line, pressing TAB doesn't change it.
>
> > I still think a complete recipe is needed.
> >
> >> To reproduce the second one, you first need to enable the 'linux' style:
> >
> > I tried to reproduce _only_ with the 'linux' style, as the bug report
> > said.
> >
> >>     (setq c-ts-mode-indent-style 'linux)
> >>     M-x c-ts-mode
> >
> > The style is a per-buffer setting, so AFAIU one needs to set the style
> > after turning on the mode in a buffer, whether manually or
> > automatically.
>
> Did you use 'M-x c-ts-mode-set-style', then? That also repros for me.
>
> The style can be set locally - as the above command does - but initially
> the global value is used. And it's applied during the major mode's
> execution, so a simple 'setq' doesn't work.
>
> > A full recipe is supposed to remove all those confusing details and
> > potential mistakes.
>
> I don't mind.
>

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

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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-24 13:47         ` Noah Peart
@ 2023-11-24 14:07           ` Eli Zaretskii
  2023-11-24 14:35             ` Noah Peart
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-11-24 14:07 UTC (permalink / raw)
  To: Noah Peart; +Cc: dmitry, casouri, 67357

> From: Noah Peart <noah.v.peart@gmail.com>
> Date: Fri, 24 Nov 2023 05:47:34 -0800
> Cc: Eli Zaretskii <eliz@gnu.org>, casouri@gmail.com, 67357@debbugs.gnu.org
> 
> Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce bugs,
> run the following to configure `c-ts-mode` with `linux` style:
> 
>     (defun example-setup ()
>       (interactive)
>       (c-ts-mode)
>       (setq-local indent-tabs-mode nil)
>       (setq-local c-ts-mode-indent-offset 2)
>       (c-ts-mode-set-style 'linux))

Thanks, but what to do after (or before?) the above, to actually
reproduce the problem?

I'm sorry I insist on a complete recipe with all the details, but IME
without having such a recipe, it is all too easy to create
misunderstandings about the problem, and harder to test solutions.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-24 14:07           ` Eli Zaretskii
@ 2023-11-24 14:35             ` Noah Peart
  2023-11-24 14:45               ` Noah Peart
  2023-11-24 14:46               ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Noah Peart @ 2023-11-24 14:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: dmitry, casouri, 67357

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

> I'm sorry I insist on a complete recipe with all the details

Ok, lemme try again :)

To reproduce the indentation bugs for unbracketed `else_clause`, and
do-while:
1. open a buffer and insert the following:

    int main() {
      if (true)
        puts("Hello");
      else
                    puts("No matched rule!"); // 1
      do
        puts("Hello");
                    while (indented_as_part_of_block);  // 2
    }

2. call `M-x example-setup` to configure `c-ts-mode`
3. `M-x indent-region` to indent the whole buffer
You should see that the line with comment `1` has not been
indented, and the line with comment `2` has been indented to the
same level as the previous line.

To reproduce the indentation bugs when comments are the first
siblings:
1. open a buffer and insert:

    int main() {
      while (true) { /* foo */
                          if (true) { // 1
                          puts ("Hello"); // 2
       }
      }
    }

2. call `M-x example-setup` to configure `c-ts-mode`
3. `M-x indent-region` to indent the whole buffer

You should see that the lines with comments `1` and `2` have
not been indented at all.

On Fri, Nov 24, 2023 at 6:07 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Noah Peart <noah.v.peart@gmail.com>
> > Date: Fri, 24 Nov 2023 05:47:34 -0800
> > Cc: Eli Zaretskii <eliz@gnu.org>, casouri@gmail.com,
> 67357@debbugs.gnu.org
> >
> > Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce
> bugs,
> > run the following to configure `c-ts-mode` with `linux` style:
> >
> >     (defun example-setup ()
> >       (interactive)
> >       (c-ts-mode)
> >       (setq-local indent-tabs-mode nil)
> >       (setq-local c-ts-mode-indent-offset 2)
> >       (c-ts-mode-set-style 'linux))
>
> Thanks, but what to do after (or before?) the above, to actually
> reproduce the problem?
>
> I'm sorry I insist on a complete recipe with all the details, but IME
> without having such a recipe, it is all too easy to create
> misunderstandings about the problem, and harder to test solutions.
>

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

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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-24 14:35             ` Noah Peart
@ 2023-11-24 14:45               ` Noah Peart
  2023-11-24 14:46               ` Eli Zaretskii
  1 sibling, 0 replies; 15+ messages in thread
From: Noah Peart @ 2023-11-24 14:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: dmitry, casouri, 67357

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

I did notice an issue with testing solutions in
`c-ts-mode-resources/indent.erts`.
In cases where no indentation is applied (eg. comment is first-sibling) or
there
is no matching rule (eg. else_clause), the test case can still pass since
the test cases are written with the proper indentation already.  So, despite
no indentation being applied, the result still matches the expected result.

On Fri, Nov 24, 2023 at 6:35 AM Noah Peart <noah.v.peart@gmail.com> wrote:

> > I'm sorry I insist on a complete recipe with all the details
>
> Ok, lemme try again :)
>
> To reproduce the indentation bugs for unbracketed `else_clause`, and
> do-while:
> 1. open a buffer and insert the following:
>
>     int main() {
>       if (true)
>         puts("Hello");
>       else
>                     puts("No matched rule!"); // 1
>       do
>         puts("Hello");
>                     while (indented_as_part_of_block);  // 2
>     }
>
> 2. call `M-x example-setup` to configure `c-ts-mode`
> 3. `M-x indent-region` to indent the whole buffer
> You should see that the line with comment `1` has not been
> indented, and the line with comment `2` has been indented to the
> same level as the previous line.
>
> To reproduce the indentation bugs when comments are the first
> siblings:
> 1. open a buffer and insert:
>
>     int main() {
>       while (true) { /* foo */
>                           if (true) { // 1
>                           puts ("Hello"); // 2
>        }
>       }
>     }
>
> 2. call `M-x example-setup` to configure `c-ts-mode`
> 3. `M-x indent-region` to indent the whole buffer
>
> You should see that the lines with comments `1` and `2` have
> not been indented at all.
>
> On Fri, Nov 24, 2023 at 6:07 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
>> > From: Noah Peart <noah.v.peart@gmail.com>
>> > Date: Fri, 24 Nov 2023 05:47:34 -0800
>> > Cc: Eli Zaretskii <eliz@gnu.org>, casouri@gmail.com,
>> 67357@debbugs.gnu.org
>> >
>> > Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce
>> bugs,
>> > run the following to configure `c-ts-mode` with `linux` style:
>> >
>> >     (defun example-setup ()
>> >       (interactive)
>> >       (c-ts-mode)
>> >       (setq-local indent-tabs-mode nil)
>> >       (setq-local c-ts-mode-indent-offset 2)
>> >       (c-ts-mode-set-style 'linux))
>>
>> Thanks, but what to do after (or before?) the above, to actually
>> reproduce the problem?
>>
>> I'm sorry I insist on a complete recipe with all the details, but IME
>> without having such a recipe, it is all too easy to create
>> misunderstandings about the problem, and harder to test solutions.
>>
>

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

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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-24 14:35             ` Noah Peart
  2023-11-24 14:45               ` Noah Peart
@ 2023-11-24 14:46               ` Eli Zaretskii
  2023-11-29 13:47                 ` Eli Zaretskii
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-11-24 14:46 UTC (permalink / raw)
  To: Noah Peart; +Cc: dmitry, casouri, 67357

> From: Noah Peart <noah.v.peart@gmail.com>
> Date: Fri, 24 Nov 2023 06:35:06 -0800
> Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org
> 
> To reproduce the indentation bugs for unbracketed `else_clause`, and 
> do-while:
> 1. open a buffer and insert the following:
> 
>     int main() {
>       if (true) 
>         puts("Hello");
>       else 
>                     puts("No matched rule!"); // 1
>       do 
>         puts("Hello");
>                     while (indented_as_part_of_block);  // 2
>     }
> 
> 2. call `M-x example-setup` to configure `c-ts-mode`
> 3. `M-x indent-region` to indent the whole buffer
> You should see that the line with comment `1` has not been
> indented, and the line with comment `2` has been indented to the 
> same level as the previous line.
> 
> To reproduce the indentation bugs when comments are the first
> siblings:
> 1. open a buffer and insert:
> 
>     int main() {
>       while (true) { /* foo */
>                           if (true) { // 1
>                           puts ("Hello"); // 2
>        }
>       }
>     }
> 
> 2. call `M-x example-setup` to configure `c-ts-mode`
> 3. `M-x indent-region` to indent the whole buffer
> 
> You should see that the lines with comments `1` and `2` have
> not been indented at all.

Thanks, I see the problems now.

Let's wait for Yuan to chime in.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-24 14:46               ` Eli Zaretskii
@ 2023-11-29 13:47                 ` Eli Zaretskii
  2023-12-09  8:23                   ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-11-29 13:47 UTC (permalink / raw)
  To: casouri; +Cc: noah.v.peart, 67357, dmitry

> Date: Fri, 24 Nov 2023 16:46:32 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org
> 
> > From: Noah Peart <noah.v.peart@gmail.com>
> > Date: Fri, 24 Nov 2023 06:35:06 -0800
> > Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org
> > 
> > To reproduce the indentation bugs for unbracketed `else_clause`, and 
> > do-while:
> > 1. open a buffer and insert the following:
> > 
> >     int main() {
> >       if (true) 
> >         puts("Hello");
> >       else 
> >                     puts("No matched rule!"); // 1
> >       do 
> >         puts("Hello");
> >                     while (indented_as_part_of_block);  // 2
> >     }
> > 
> > 2. call `M-x example-setup` to configure `c-ts-mode`
> > 3. `M-x indent-region` to indent the whole buffer
> > You should see that the line with comment `1` has not been
> > indented, and the line with comment `2` has been indented to the 
> > same level as the previous line.
> > 
> > To reproduce the indentation bugs when comments are the first
> > siblings:
> > 1. open a buffer and insert:
> > 
> >     int main() {
> >       while (true) { /* foo */
> >                           if (true) { // 1
> >                           puts ("Hello"); // 2
> >        }
> >       }
> >     }
> > 
> > 2. call `M-x example-setup` to configure `c-ts-mode`
> > 3. `M-x indent-region` to indent the whole buffer
> > 
> > You should see that the lines with comments `1` and `2` have
> > not been indented at all.
> 
> Thanks, I see the problems now.
> 
> Let's wait for Yuan to chime in.

Yuan, could you please comment on the proposed solution?  TIA.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-11-29 13:47                 ` Eli Zaretskii
@ 2023-12-09  8:23                   ` Eli Zaretskii
  2023-12-10  9:09                     ` Yuan Fu
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-12-09  8:23 UTC (permalink / raw)
  To: casouri; +Cc: noah.v.peart, 67357, dmitry

Ping! Ping!  Yuan, please chime is, as I'm waiting for your comments
before we install on the release branch.

This and other patches for TS-based modes are currently delaying the
release of Emacs 29.2, so please try to be more responsive, okay?

> Cc: noah.v.peart@gmail.com, 67357@debbugs.gnu.org, dmitry@gutov.dev
> Date: Wed, 29 Nov 2023 15:47:25 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Fri, 24 Nov 2023 16:46:32 +0200
> > From: Eli Zaretskii <eliz@gnu.org>
> > Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org
> > 
> > > From: Noah Peart <noah.v.peart@gmail.com>
> > > Date: Fri, 24 Nov 2023 06:35:06 -0800
> > > Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org
> > > 
> > > To reproduce the indentation bugs for unbracketed `else_clause`, and 
> > > do-while:
> > > 1. open a buffer and insert the following:
> > > 
> > >     int main() {
> > >       if (true) 
> > >         puts("Hello");
> > >       else 
> > >                     puts("No matched rule!"); // 1
> > >       do 
> > >         puts("Hello");
> > >                     while (indented_as_part_of_block);  // 2
> > >     }
> > > 
> > > 2. call `M-x example-setup` to configure `c-ts-mode`
> > > 3. `M-x indent-region` to indent the whole buffer
> > > You should see that the line with comment `1` has not been
> > > indented, and the line with comment `2` has been indented to the 
> > > same level as the previous line.
> > > 
> > > To reproduce the indentation bugs when comments are the first
> > > siblings:
> > > 1. open a buffer and insert:
> > > 
> > >     int main() {
> > >       while (true) { /* foo */
> > >                           if (true) { // 1
> > >                           puts ("Hello"); // 2
> > >        }
> > >       }
> > >     }
> > > 
> > > 2. call `M-x example-setup` to configure `c-ts-mode`
> > > 3. `M-x indent-region` to indent the whole buffer
> > > 
> > > You should see that the lines with comments `1` and `2` have
> > > not been indented at all.
> > 
> > Thanks, I see the problems now.
> > 
> > Let's wait for Yuan to chime in.
> 
> Yuan, could you please comment on the proposed solution?  TIA.
> 
> 
> 
> 





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-12-09  8:23                   ` Eli Zaretskii
@ 2023-12-10  9:09                     ` Yuan Fu
  2023-12-10  9:39                       ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Yuan Fu @ 2023-12-10  9:09 UTC (permalink / raw)
  To: Eli Zaretskii, 67357-done; +Cc: noah.v.peart, 67357, dmitry


> Ping! Ping!  Yuan, please chime is, as I'm waiting for your comments
> before we install on the release branch.
>
> This and other patches for TS-based modes are currently delaying the
> release of Emacs 29.2, so please try to be more responsive, okay?
>
Whoa! Sorry, I just switched to a new email client, and direct CC isn't 
highlight as they were before :-( (And admittedly I haven't been 
browsing the bug tracker lately.)

As for the patch, first of all, thank you, Noah, it's very good. I try 
to avoid query matchers since they could be slow, plus the fundamental 
problem isn't with comments, IMO. The problem is when the first sibling 
isn't on it's own line. (Though in normal C source code, when the first 
sibling isn't on its own line, that sibling is usually a comment.) 
Anyway, please see my reasoning in the commit message for 08fc6bace20.

I also removed the else_clause rule since it's already added by the 
patch for bug#67417, and added another test.

Yuan





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-12-10  9:09                     ` Yuan Fu
@ 2023-12-10  9:39                       ` Eli Zaretskii
  2023-12-11  1:11                         ` Yuan Fu
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2023-12-10  9:39 UTC (permalink / raw)
  To: Yuan Fu; +Cc: noah.v.peart, 67357, dmitry

> Date: Sun, 10 Dec 2023 01:09:15 -0800
> Cc: noah.v.peart@gmail.com, 67357@debbugs.gnu.org, dmitry@gutov.dev
> From: Yuan Fu <casouri@gmail.com>
> 
> 
> > Ping! Ping!  Yuan, please chime is, as I'm waiting for your comments
> > before we install on the release branch.
> >
> > This and other patches for TS-based modes are currently delaying the
> > release of Emacs 29.2, so please try to be more responsive, okay?
> >
> Whoa! Sorry, I just switched to a new email client, and direct CC isn't 
> highlight as they were before :-( (And admittedly I haven't been 
> browsing the bug tracker lately.)

OK, but please look also at other bugs and issues where I asked for
your opinions.

> As for the patch, first of all, thank you, Noah, it's very good. I try 
> to avoid query matchers since they could be slow, plus the fundamental 
> problem isn't with comments, IMO. The problem is when the first sibling 
> isn't on it's own line. (Though in normal C source code, when the first 
> sibling isn't on its own line, that sibling is usually a comment.) 
> Anyway, please see my reasoning in the commit message for 08fc6bace20.
> 
> I also removed the else_clause rule since it's already added by the 
> patch for bug#67417, and added another test.

Thanks, but please in the future mention _all_ relevant bug numbers
in the log message, or merge them if appropriate.





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

* bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments
  2023-12-10  9:39                       ` Eli Zaretskii
@ 2023-12-11  1:11                         ` Yuan Fu
  0 siblings, 0 replies; 15+ messages in thread
From: Yuan Fu @ 2023-12-11  1:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: noah.v.peart, 67357, dmitry



On 12/10/23 1:39 AM, Eli Zaretskii wrote:
>> Date: Sun, 10 Dec 2023 01:09:15 -0800
>> Cc: noah.v.peart@gmail.com, 67357@debbugs.gnu.org, dmitry@gutov.dev
>> From: Yuan Fu <casouri@gmail.com>
>>
>>
>>> Ping! Ping!  Yuan, please chime is, as I'm waiting for your comments
>>> before we install on the release branch.
>>>
>>> This and other patches for TS-based modes are currently delaying the
>>> release of Emacs 29.2, so please try to be more responsive, okay?
>>>
>> Whoa! Sorry, I just switched to a new email client, and direct CC isn't
>> highlight as they were before :-( (And admittedly I haven't been
>> browsing the bug tracker lately.)
> OK, but please look also at other bugs and issues where I asked for
> your opinions.
Yes, I'm trying to setup something that can prevent this in the future, 
and there are so many CC's that I missed, apologies!
>> As for the patch, first of all, thank you, Noah, it's very good. I try
>> to avoid query matchers since they could be slow, plus the fundamental
>> problem isn't with comments, IMO. The problem is when the first sibling
>> isn't on it's own line. (Though in normal C source code, when the first
>> sibling isn't on its own line, that sibling is usually a comment.)
>> Anyway, please see my reasoning in the commit message for 08fc6bace20.
>>
>> I also removed the else_clause rule since it's already added by the
>> patch for bug#67417, and added another test.
> Thanks, but please in the future mention _all_ relevant bug numbers
> in the log message, or merge them if appropriate.
I'll keep that in mind.

Yuan





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

end of thread, other threads:[~2023-12-11  1:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22  1:50 bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments Noah Peart
2023-11-23  7:35 ` Eli Zaretskii
2023-11-23 13:17   ` Dmitry Gutov
2023-11-23 14:33     ` Eli Zaretskii
2023-11-23 14:41       ` Dmitry Gutov
2023-11-24 13:47         ` Noah Peart
2023-11-24 14:07           ` Eli Zaretskii
2023-11-24 14:35             ` Noah Peart
2023-11-24 14:45               ` Noah Peart
2023-11-24 14:46               ` Eli Zaretskii
2023-11-29 13:47                 ` Eli Zaretskii
2023-12-09  8:23                   ` Eli Zaretskii
2023-12-10  9:09                     ` Yuan Fu
2023-12-10  9:39                       ` Eli Zaretskii
2023-12-11  1:11                         ` Yuan Fu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).