unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
@ 2024-11-24  9:15 Jørgen Kvalsvik
  2024-11-29  4:56 ` Yuan Fu
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-11-24  9:15 UTC (permalink / raw)
  To: 74507; +Cc: theo, casouri

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

Tags: patch

Tags: patch


I found that the coumpounded statements are anchored to the wrong object
when 1. the compound is not at beginning-of-line and 2. it is not
preceeded by a construct such as fndecl/for/if/while/etc., which differs
from how c-mode indents it.

Non-BOL compound statements is actually quite common with macros and
testing frameworks (see the test case). For example, you want this to
indent:

TEST_CASE(1) {
    assert (...);
}

The heuristic is quite course - it simply checks if the grandparent is
function-definition or not, which is really if this node is a top-level
sibling in the function body.  If that is the case, the old rules should
apply and standalone-parent should be the guide; otherwise, it should be
the parent-BOL. This feels a bit shaky but does seem to work well for
the test cases, and can be refined in the future.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Indent-compounds-c-ts-mode-when-is-not-BOL.patch --]
[-- Type: text/patch, Size: 3858 bytes --]

From ad5c50851710711fa1d62708633d7bae92f82fae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= <j@lambda.is>
Date: Tue, 19 Nov 2024 08:01:01 +0100
Subject: [PATCH] Indent compounds c-ts-mode when { is not BOL

Properly indent the body of compound expressions, even when then
compound expression is not at the beginning of line and the parent is
not an if/for/while/etc., and matches the behavior of c-mode.

This fixes a problem that is common with macros and in testing
frameworks. For example, you expect this to indent:

TEST_CASE(1) {
    assert (...);
}

If the compound statement is the function body itself, don't apply this
new rule and instead guide by the parent and first sibling.

I'm sure there are subtle interactions that aren't handled properly by
checking for "function_definition" rather than something more general,
but it does fix the test case and the check can be improved as more
cases are found.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
New function.
(c-ts-mode--indent-styles): Use it.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
statement test.
---
 lisp/progmodes/c-ts-mode.el                   |  8 +++++
 .../progmodes/c-ts-mode-resources/indent.erts | 30 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 3823c553fda..80233e90241 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -402,6 +402,11 @@ c-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
 
+(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
+  "Matches when PARENT is not the top level compound statement,
+the {} that immediately follows the signature."
+  (not (equal "function_definition" (treesit-node-type (treesit-node-parent parent)))))
+
 (defun c-ts-mode--indent-styles (mode)
   "Indent rules supported by `c-ts-mode'.
 MODE is either `c' or `cpp'."
@@ -478,6 +483,7 @@ c-ts-mode--indent-styles
            ;; Closing bracket.  This should be before initializer_list
            ;; (and probably others) rule because that rule (and other
            ;; similar rules) will match the closing bracket.  (Bug#61398)
+           ((and (node-is "}") c-ts-mode--parent-is-not-top-compound) parent-bol 0)
            ((node-is "}") standalone-parent 0)
            ,@(when (eq mode 'cpp)
                '(((node-is "access_specifier") parent-bol 0)
@@ -497,6 +503,8 @@ c-ts-mode--indent-styles
            ((parent-is "field_declaration_list") c-ts-mode--anchor-prev-sibling 0)
 
            ;; Statement in {} blocks.
+           ((and (parent-is "compound_statement") c-ts-mode--parent-is-not-top-compound)
+            parent-bol c-ts-mode-indent-offset)
            ((or (and (parent-is "compound_statement")
                      ;; If the previous sibling(s) are not on their
                      ;; own line, indent as if this node is the first
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 2f3540c3970..61e61677ed7 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -223,6 +223,36 @@ make_pair(int long_identifier_a[], int long_identifier_b[],
 
 =-=-=
 
+Name: Compound Statement after code
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+IOTA (v, 10) {
+printf("%d ", v);
+}
+
+const char *msg = "Hello, world!"; {
+puts("Hello, world!");
+}
+}
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+  IOTA (v, 10) {
+    printf("%d ", v);
+  }
+
+  const char *msg = "Hello, world!"; {
+    puts("Hello, world!");
+  }
+}
+
+=-=-=
+
 Name: Switch-Case statement
 
 =-=
-- 
2.39.5


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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-24  9:15 bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL Jørgen Kvalsvik
@ 2024-11-29  4:56 ` Yuan Fu
  2024-11-29  7:54   ` Eli Zaretskii
  2024-11-29  9:04   ` Jørgen Kvalsvik
  2024-11-29  7:57 ` Eli Zaretskii
  2024-11-30 15:39 ` bug#74507: [PATCH] Indent compounds in " Jørgen Kvalsvik
  2 siblings, 2 replies; 14+ messages in thread
From: Yuan Fu @ 2024-11-29  4:56 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: theo, 74507



> On Nov 24, 2024, at 1:15 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
> 
> Tags: patch
> 
> Tags: patch
> 
> 
> I found that the coumpounded statements are anchored to the wrong object
> when 1. the compound is not at beginning-of-line and 2. it is not
> preceeded by a construct such as fndecl/for/if/while/etc., which differs
> from how c-mode indents it.
> 
> Non-BOL compound statements is actually quite common with macros and
> testing frameworks (see the test case). For example, you want this to
> indent:
> 
> TEST_CASE(1) {
>    assert (...);
> }
> 
> The heuristic is quite course - it simply checks if the grandparent is
> function-definition or not, which is really if this node is a top-level
> sibling in the function body.  If that is the case, the old rules should
> apply and standalone-parent should be the guide; otherwise, it should be
> the parent-BOL. This feels a bit shaky but does seem to work well for
> the test cases, and can be refined in the future.
> 
> <0001-Indent-compounds-c-ts-mode-when-is-not-BOL.patch>

Thank you very much! Especially for the test case ;-) What’s the progress of your copyright assignment? Has it completed?

I’m working on refactoring the indentation rules for c-ts-mode. Let me see if I can integrate this situation into the new rules I’m writing.

Yuan




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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-29  4:56 ` Yuan Fu
@ 2024-11-29  7:54   ` Eli Zaretskii
  2024-11-29  9:04   ` Jørgen Kvalsvik
  1 sibling, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2024-11-29  7:54 UTC (permalink / raw)
  To: Yuan Fu; +Cc: theo, j, 74507

> Cc: theo@thornhill.no, 74507@debbugs.gnu.org
> From: Yuan Fu <casouri@gmail.com>
> Date: Thu, 28 Nov 2024 20:56:26 -0800
> 
> Thank you very much! Especially for the test case ;-) What’s the progress of your copyright assignment? Has it completed?

Jørgen's assignment is on file, so we are good in that department.





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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-24  9:15 bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL Jørgen Kvalsvik
  2024-11-29  4:56 ` Yuan Fu
@ 2024-11-29  7:57 ` Eli Zaretskii
  2024-11-29  9:05   ` Jørgen Kvalsvik
  2024-11-30 15:39 ` bug#74507: [PATCH] Indent compounds in " Jørgen Kvalsvik
  2 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2024-11-29  7:57 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: casouri, theo, 74507

> Cc: theo@thornhill.no,casouri@gmail.com
> From: Jørgen Kvalsvik <j@lambda.is>
> Date: Sun, 24 Nov 2024 10:15:12 +0100
> 
> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
> New function.
> (c-ts-mode--indent-styles): Use it.
> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
> statement test.

Please make sure the lines here are not too long (see CONTRIBUTE for
details).

> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
> +  "Matches when PARENT is not the top level compound statement,
> +the {} that immediately follows the signature."

The first line of a doc string should be a single complete sentence.

Thanks.





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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-29  4:56 ` Yuan Fu
  2024-11-29  7:54   ` Eli Zaretskii
@ 2024-11-29  9:04   ` Jørgen Kvalsvik
  1 sibling, 0 replies; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-11-29  9:04 UTC (permalink / raw)
  To: Yuan Fu; +Cc: theo, 74507

On 11/29/24 05:56, Yuan Fu wrote:
> 
> 
>> On Nov 24, 2024, at 1:15 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>
>> Tags: patch
>>
>> Tags: patch
>>
>>
>> I found that the coumpounded statements are anchored to the wrong object
>> when 1. the compound is not at beginning-of-line and 2. it is not
>> preceeded by a construct such as fndecl/for/if/while/etc., which differs
>> from how c-mode indents it.
>>
>> Non-BOL compound statements is actually quite common with macros and
>> testing frameworks (see the test case). For example, you want this to
>> indent:
>>
>> TEST_CASE(1) {
>>     assert (...);
>> }
>>
>> The heuristic is quite course - it simply checks if the grandparent is
>> function-definition or not, which is really if this node is a top-level
>> sibling in the function body.  If that is the case, the old rules should
>> apply and standalone-parent should be the guide; otherwise, it should be
>> the parent-BOL. This feels a bit shaky but does seem to work well for
>> the test cases, and can be refined in the future.
>>
>> <0001-Indent-compounds-c-ts-mode-when-is-not-BOL.patch>
> 
> Thank you very much! Especially for the test case ;-) What’s the progress of your copyright assignment? Has it completed?

As Eli says, I have submitted the paperwork.

> 
> I’m working on refactoring the indentation rules for c-ts-mode. Let me see if I can integrate this situation into the new rules I’m writing.
> 
> Yuan

Splendid, thanks.






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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-29  7:57 ` Eli Zaretskii
@ 2024-11-29  9:05   ` Jørgen Kvalsvik
  2024-11-30  0:16     ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-11-29  9:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: casouri, theo, 74507

On 11/29/24 08:57, Eli Zaretskii wrote:
>> Cc: theo@thornhill.no,casouri@gmail.com
>> From: Jørgen Kvalsvik <j@lambda.is>
>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>
>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>> New function.
>> (c-ts-mode--indent-styles): Use it.
>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>> statement test.
> 
> Please make sure the lines here are not too long (see CONTRIBUTE for
> details).
> 
>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>> +  "Matches when PARENT is not the top level compound statement,
>> +the {} that immediately follows the signature."
> 
> The first line of a doc string should be a single complete sentence.
> 
> Thanks.

Ok. Yuan, would you like me to submit a revision?





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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-29  9:05   ` Jørgen Kvalsvik
@ 2024-11-30  0:16     ` Yuan Fu
  2024-11-30 20:49       ` Jørgen Kvalsvik
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2024-11-30  0:16 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: Eli Zaretskii, theo, 74507



> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
> 
> On 11/29/24 08:57, Eli Zaretskii wrote:
>>> Cc: theo@thornhill.no,casouri@gmail.com
>>> From: Jørgen Kvalsvik <j@lambda.is>
>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>> 
>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>> New function.
>>> (c-ts-mode--indent-styles): Use it.
>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>> statement test.
>> Please make sure the lines here are not too long (see CONTRIBUTE for
>> details).
>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>> +  "Matches when PARENT is not the top level compound statement,
>>> +the {} that immediately follows the signature."
>> The first line of a doc string should be a single complete sentence.
>> Thanks.
> 
> Ok. Yuan, would you like me to submit a revision?

Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!

Yuan




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

* bug#74507: [PATCH] Indent compounds in c-ts-mode when { is not BOL
  2024-11-24  9:15 bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL Jørgen Kvalsvik
  2024-11-29  4:56 ` Yuan Fu
  2024-11-29  7:57 ` Eli Zaretskii
@ 2024-11-30 15:39 ` Jørgen Kvalsvik
  2 siblings, 0 replies; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-11-30 15:39 UTC (permalink / raw)
  To: 74507

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

 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Indent-compounds-in-c-ts-mode-when-is-not-BOL.patch --]
[-- Type: text/patch, Size: 3651 bytes --]

Properly indent the body of compound expressions, even when then
compound expression is not at the beginning of line and the parent is
not an if/for/while/etc., and matches the behavior of c-mode.
This fixes a problem that is common with macros and in testing
frameworks. For example, you expect this to indent:
TEST_CASE(1) {
    assert (...);
}
If the compound statement is the function body itself, don't apply this
new rule and instead guide by the parent and first sibling.
I'm sure there are subtle interactions that aren't handled properly by
checking for "function_definition" rather than something more general,
but it does fix the test case and the check can be improved as more
cases are found.
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--parent-is-not-top-compound): New function.
(c-ts-mode--indent-styles): Use it.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New
compound statement test.
---
 lisp/progmodes/c-ts-mode.el                   |  9 ++++++
 .../progmodes/c-ts-mode-resources/indent.erts | 30 +++++++++++++++++++
 2 files changed, 39 insertions(+)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 3823c553fda..b635e621b03 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -402,6 +402,12 @@ c-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
+(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
+  "Matches when PARENT is not the top level compound statement.
+The top-level compound is the {} that immediately follows the function
+signature."
+  (not (equal "function_definition" (treesit-node-type (treesit-node-parent parent)))))
+
 (defun c-ts-mode--indent-styles (mode)
   "Indent rules supported by `c-ts-mode'.
 MODE is either `c' or `cpp'."
@@ -478,6 +484,7 @@ c-ts-mode--indent-styles
            ;; Closing bracket.  This should be before initializer_list
            ;; (and probably others) rule because that rule (and other
            ;; similar rules) will match the closing bracket.  (Bug#61398)
+           ((and (node-is "}") c-ts-mode--parent-is-not-top-compound) parent-bol 0)
            ((node-is "}") standalone-parent 0)
            ,@(when (eq mode 'cpp)
                '(((node-is "access_specifier") parent-bol 0)
@@ -497,6 +504,8 @@ c-ts-mode--indent-styles
            ((parent-is "field_declaration_list") c-ts-mode--anchor-prev-sibling 0)
            ;; Statement in {} blocks.
+           ((and (parent-is "compound_statement") c-ts-mode--parent-is-not-top-compound)
+            parent-bol c-ts-mode-indent-offset)
            ((or (and (parent-is "compound_statement")
                      ;; If the previous sibling(s) are not on their
                      ;; own line, indent as if this node is the first
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 2f3540c3970..61e61677ed7 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -223,6 +223,36 @@ make_pair(int long_identifier_a[], int long_identifier_b[],
 =-=-=
+Name: Compound Statement after code
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+IOTA (v, 10) {
+printf("%d ", v);
+}
+
+const char *msg = "Hello, world!"; {
+puts("Hello, world!");
+}
+}
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+  IOTA (v, 10) {
+    printf("%d ", v);
+  }
+
+  const char *msg = "Hello, world!"; {
+    puts("Hello, world!");
+  }
+}
+
+=-=-=
+
 Name: Switch-Case statement
 =-=
-- 
2.39.5

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-30  0:16     ` Yuan Fu
@ 2024-11-30 20:49       ` Jørgen Kvalsvik
  2024-12-01  9:25         ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-11-30 20:49 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Eli Zaretskii, theo, 74507

On 11/30/24 01:16, Yuan Fu wrote:
> 
> 
>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>
>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>
>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>> New function.
>>>> (c-ts-mode--indent-styles): Use it.
>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>> statement test.
>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>> details).
>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>> +  "Matches when PARENT is not the top level compound statement,
>>>> +the {} that immediately follows the signature."
>>> The first line of a doc string should be a single complete sentence.
>>> Thanks.
>>
>> Ok. Yuan, would you like me to submit a revision?
> 
> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
> 
> Yuan

Certainly - I posted it on the bug tracker.

Thanks,
Jørgen





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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-11-30 20:49       ` Jørgen Kvalsvik
@ 2024-12-01  9:25         ` Yuan Fu
  2024-12-01  9:51           ` Jørgen Kvalsvik
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2024-12-01  9:25 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: Eli Zaretskii, theo, 74507



> On Nov 30, 2024, at 12:49 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
> 
> On 11/30/24 01:16, Yuan Fu wrote:
>>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>> 
>>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>> 
>>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>>> New function.
>>>>> (c-ts-mode--indent-styles): Use it.
>>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>>> statement test.
>>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>>> details).
>>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>>> +  "Matches when PARENT is not the top level compound statement,
>>>>> +the {} that immediately follows the signature."
>>>> The first line of a doc string should be a single complete sentence.
>>>> Thanks.
>>> 
>>> Ok. Yuan, would you like me to submit a revision?
>> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
>> Yuan
> 
> Certainly - I posted it on the bug tracker.

Thanks Jørgen. What did you use to generate the patch? For some reason I can’t apply it. My git skill isn’t that great so it could be my problem. If you can apply it fine maybe you can share the command you used?

BTW, the commit title is missing. When you add the title, you can also add the bug number. For example:

Improve c-ts-mode indentation for macros (bug#74507)

Yuan




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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-12-01  9:25         ` Yuan Fu
@ 2024-12-01  9:51           ` Jørgen Kvalsvik
  2024-12-01 21:48             ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-12-01  9:51 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Eli Zaretskii, theo, 74507

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

On 12/1/24 10:25, Yuan Fu wrote:
> 
> 
>> On Nov 30, 2024, at 12:49 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>
>> On 11/30/24 01:16, Yuan Fu wrote:
>>>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>
>>>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>>>
>>>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>>>> New function.
>>>>>> (c-ts-mode--indent-styles): Use it.
>>>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>>>> statement test.
>>>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>>>> details).
>>>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>>>> +  "Matches when PARENT is not the top level compound statement,
>>>>>> +the {} that immediately follows the signature."
>>>>> The first line of a doc string should be a single complete sentence.
>>>>> Thanks.
>>>>
>>>> Ok. Yuan, would you like me to submit a revision?
>>> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
>>> Yuan
>>
>> Certainly - I posted it on the bug tracker.
> 
> Thanks Jørgen. What did you use to generate the patch? For some reason I can’t apply it. My git skill isn’t that great so it could be my problem. If you can apply it fine maybe you can share the command you used?

I used git format-patch HEAD~1, and I just tested applying it to master 
with `git am 0001-Indent-compounds-in-c-ts-mode-when-is-not-BOL.patch' 
which worked.

> 
> BTW, the commit title is missing. When you add the title, you can also add the bug number. For example:
> 
> Improve c-ts-mode indentation for macros (bug#74507)
> 
> Yuan

Sure. I've attached a new patch with the bug in it. I tested it and it 
applies cleanly with `git am 
0001-Improve-c-ts-mode-compound-indents-bug-74507.patch'

[-- Attachment #2: 0001-Improve-c-ts-mode-compound-indents-bug-74507.patch --]
[-- Type: text/x-patch, Size: 3898 bytes --]

From a6af85298de99cdbfc78c95659224c9dd7e6a4c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= <j@lambda.is>
Date: Tue, 19 Nov 2024 08:01:01 +0100
Subject: [PATCH] Improve c-ts-mode compound indents (bug#74507)

Properly indent the body of compound expressions, even when then
compound expression is not at the beginning of line and the parent is
not an if/for/while/etc., and matches the behavior of c-mode.

This fixes a problem that is common with macros and in testing
frameworks. For example, you expect this to indent:

TEST_CASE(1) {
    assert (...);
}

If the compound statement is the function body itself, don't apply this
new rule and instead guide by the parent and first sibling.

I'm sure there are subtle interactions that aren't handled properly by
checking for "function_definition" rather than something more general,
but it does fix the test case and the check can be improved as more
cases are found.

* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--parent-is-not-top-compound): New function.
(c-ts-mode--indent-styles): Use it.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New
compound statement test.
---
 lisp/progmodes/c-ts-mode.el                   |  9 ++++++
 .../progmodes/c-ts-mode-resources/indent.erts | 30 +++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index cbb103cfaf7..59b34ef6b8b 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -403,6 +403,12 @@ c-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
 
+(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
+  "Matches when PARENT is not the top level compound statement.
+The top-level compound is the {} that immediately follows the function
+signature."
+  (not (equal "function_definition" (treesit-node-type (treesit-node-parent parent)))))
+
 (defun c-ts-mode--indent-styles (mode)
   "Indent rules supported by `c-ts-mode'.
 MODE is either `c' or `cpp'."
@@ -479,6 +485,7 @@ c-ts-mode--indent-styles
            ;; Closing bracket.  This should be before initializer_list
            ;; (and probably others) rule because that rule (and other
            ;; similar rules) will match the closing bracket.  (Bug#61398)
+           ((and (node-is "}") c-ts-mode--parent-is-not-top-compound) parent-bol 0)
            ((node-is "}") standalone-parent 0)
            ,@(when (eq mode 'cpp)
                '(((node-is "access_specifier") parent-bol 0)
@@ -498,6 +505,8 @@ c-ts-mode--indent-styles
            ((parent-is "field_declaration_list") c-ts-mode--anchor-prev-sibling 0)
 
            ;; Statement in {} blocks.
+           ((and (parent-is "compound_statement") c-ts-mode--parent-is-not-top-compound)
+            parent-bol c-ts-mode-indent-offset)
            ((or (and (parent-is "compound_statement")
                      ;; If the previous sibling(s) are not on their
                      ;; own line, indent as if this node is the first
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 2f3540c3970..61e61677ed7 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -223,6 +223,36 @@ make_pair(int long_identifier_a[], int long_identifier_b[],
 
 =-=-=
 
+Name: Compound Statement after code
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+IOTA (v, 10) {
+printf("%d ", v);
+}
+
+const char *msg = "Hello, world!"; {
+puts("Hello, world!");
+}
+}
+
+=-=
+#define IOTA(var, n) for (int var = 0; var != (n); ++var)
+int main()
+{
+  IOTA (v, 10) {
+    printf("%d ", v);
+  }
+
+  const char *msg = "Hello, world!"; {
+    puts("Hello, world!");
+  }
+}
+
+=-=-=
+
 Name: Switch-Case statement
 
 =-=
-- 
2.39.5


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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-12-01  9:51           ` Jørgen Kvalsvik
@ 2024-12-01 21:48             ` Yuan Fu
  2024-12-01 22:46               ` Jørgen Kvalsvik
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2024-12-01 21:48 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: Eli Zaretskii, theo, 74507



> On Dec 1, 2024, at 1:51 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
> 
> On 12/1/24 10:25, Yuan Fu wrote:
>>> On Nov 30, 2024, at 12:49 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>> 
>>> On 11/30/24 01:16, Yuan Fu wrote:
>>>>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>> 
>>>>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>>>> 
>>>>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>>>>> New function.
>>>>>>> (c-ts-mode--indent-styles): Use it.
>>>>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>>>>> statement test.
>>>>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>>>>> details).
>>>>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>>>>> +  "Matches when PARENT is not the top level compound statement,
>>>>>>> +the {} that immediately follows the signature."
>>>>>> The first line of a doc string should be a single complete sentence.
>>>>>> Thanks.
>>>>> 
>>>>> Ok. Yuan, would you like me to submit a revision?
>>>> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
>>>> Yuan
>>> 
>>> Certainly - I posted it on the bug tracker.
>> Thanks Jørgen. What did you use to generate the patch? For some reason I can’t apply it. My git skill isn’t that great so it could be my problem. If you can apply it fine maybe you can share the command you used?
> 
> I used git format-patch HEAD~1, and I just tested applying it to master with `git am 0001-Indent-compounds-in-c-ts-mode-when-is-not-BOL.patch' which worked.
> 
>> BTW, the commit title is missing. When you add the title, you can also add the bug number. For example:
>> Improve c-ts-mode indentation for macros (bug#74507)
>> Yuan
> 
> Sure. I've attached a new patch with the bug in it. I tested it and it applies cleanly with `git am 0001-Improve-c-ts-mode-compound-indents-bug-74507.patch'
> <0001-Improve-c-ts-mode-compound-indents-bug-74507.patch>

Thanks. This patch applied without a problem. 

I reworked your heuristic into a function rule for better organization, and changed the condition slightly:

(defun c-ts-mode--macro-heuristic-rules (node parent &rest _)
  "Heuristic indent rule for control flow macros.

Eg,

    #define IOTA(var, n) for (int var = 0; var != (n); ++var)

    int main()
    {
      IOTA (v, 10) {
        printf(\"%d \", v);   <-- Here we want to indent
        counter++;            <-- Use baseline rule to align
    }                             to prev sibling

Checked by \"Compound Statement after code (Bug#74507)\" test.

NODE and PARENT are the same as other indent rules."
  (when (and (treesit-node-match-p parent "compound_statement")
             (treesit-node-match-p (treesit-node-prev-sibling parent)
                                   "expression_statement"))
    (let ((parent-bol
           (lambda () (save-excursion
                        (goto-char (treesit-node-start parent))
                        (back-to-indentation)
                        (point)))))
      (cond
       ;; Closing brace.
       ((treesit-node-match-p node "}")
        (cons (funcall parent-bol) 0))
       ;; First sibling.
       ((treesit-node-eq (treesit-node-child parent 0 'named) node)
        (cons (funcall parent-bol)
              c-ts-mode-indent-offset))))))

Instead of checking whether PARENT is top-level compound_statement, I make it check whether the previous sibling is an expression_statement. This way the heuristic works when the macro isn’t at top-level too. Here’s the updated test:

#define IOTA(var, n) for (int var = 0; var != (n); ++var)
int main()
{
  IOTA (v, 10) {
    printf("%d ", v);
  }

  const char *msg = "Hello, world!"; {
    puts("Hello, world!");
  }

  for (int i = 0;
       i < 10;
       i++) {
    IOTA (v, 10) {
      printf("%d ", v);
    }
  }

  {
    IOTA (v, 10) {
      printf("%d ", v);
    }
  }
}

The only test case that doesn’t pass right now is this one:

  const char *msg = "Hello, world!"; {
    puts("Hello, world!");
  }

Is this a real use-case?

Yuan




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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-12-01 21:48             ` Yuan Fu
@ 2024-12-01 22:46               ` Jørgen Kvalsvik
  2024-12-02  2:13                 ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Jørgen Kvalsvik @ 2024-12-01 22:46 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Eli Zaretskii, theo, 74507

On 12/1/24 22:48, Yuan Fu wrote:
> 
> 
>> On Dec 1, 2024, at 1:51 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>
>> On 12/1/24 10:25, Yuan Fu wrote:
>>>> On Nov 30, 2024, at 12:49 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>
>>>> On 11/30/24 01:16, Yuan Fu wrote:
>>>>>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>>>
>>>>>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>>>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>>>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>>>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>>>>>
>>>>>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>>>>>> New function.
>>>>>>>> (c-ts-mode--indent-styles): Use it.
>>>>>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>>>>>> statement test.
>>>>>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>>>>>> details).
>>>>>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>>>>>> +  "Matches when PARENT is not the top level compound statement,
>>>>>>>> +the {} that immediately follows the signature."
>>>>>>> The first line of a doc string should be a single complete sentence.
>>>>>>> Thanks.
>>>>>>
>>>>>> Ok. Yuan, would you like me to submit a revision?
>>>>> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
>>>>> Yuan
>>>>
>>>> Certainly - I posted it on the bug tracker.
>>> Thanks Jørgen. What did you use to generate the patch? For some reason I can’t apply it. My git skill isn’t that great so it could be my problem. If you can apply it fine maybe you can share the command you used?
>>
>> I used git format-patch HEAD~1, and I just tested applying it to master with `git am 0001-Indent-compounds-in-c-ts-mode-when-is-not-BOL.patch' which worked.
>>
>>> BTW, the commit title is missing. When you add the title, you can also add the bug number. For example:
>>> Improve c-ts-mode indentation for macros (bug#74507)
>>> Yuan
>>
>> Sure. I've attached a new patch with the bug in it. I tested it and it applies cleanly with `git am 0001-Improve-c-ts-mode-compound-indents-bug-74507.patch'
>> <0001-Improve-c-ts-mode-compound-indents-bug-74507.patch>
> 
> Thanks. This patch applied without a problem.
> 
> I reworked your heuristic into a function rule for better organization, and changed the condition slightly:
> 
> (defun c-ts-mode--macro-heuristic-rules (node parent &rest _)
>    "Heuristic indent rule for control flow macros.
> 
> Eg,
> 
>      #define IOTA(var, n) for (int var = 0; var != (n); ++var)
> 
>      int main()
>      {
>        IOTA (v, 10) {
>          printf(\"%d \", v);   <-- Here we want to indent
>          counter++;            <-- Use baseline rule to align
>      }                             to prev sibling
> 
> Checked by \"Compound Statement after code (Bug#74507)\" test.
> 
> NODE and PARENT are the same as other indent rules."
>    (when (and (treesit-node-match-p parent "compound_statement")
>               (treesit-node-match-p (treesit-node-prev-sibling parent)
>                                     "expression_statement"))
>      (let ((parent-bol
>             (lambda () (save-excursion
>                          (goto-char (treesit-node-start parent))
>                          (back-to-indentation)
>                          (point)))))
>        (cond
>         ;; Closing brace.
>         ((treesit-node-match-p node "}")
>          (cons (funcall parent-bol) 0))
>         ;; First sibling.
>         ((treesit-node-eq (treesit-node-child parent 0 'named) node)
>          (cons (funcall parent-bol)
>                c-ts-mode-indent-offset))))))
> 
> Instead of checking whether PARENT is top-level compound_statement, I make it check whether the previous sibling is an expression_statement. This way the heuristic works when the macro isn’t at top-level too. Here’s the updated test:
> 
> #define IOTA(var, n) for (int var = 0; var != (n); ++var)
> int main()
> {
>    IOTA (v, 10) {
>      printf("%d ", v);
>    }
> 
>    const char *msg = "Hello, world!"; {
>      puts("Hello, world!");
>    }
> 
>    for (int i = 0;
>         i < 10;
>         i++) {
>      IOTA (v, 10) {
>        printf("%d ", v);
>      }
>    }
> 
>    {
>      IOTA (v, 10) {
>        printf("%d ", v);
>      }
>    }
> }
> 
> The only test case that doesn’t pass right now is this one:
> 
>    const char *msg = "Hello, world!"; {
>      puts("Hello, world!");
>    }
> 
> Is this a real use-case?
> 
> Yuan

Maybe - I included it to show that the problem was not tied to it being 
a macro, but rather { not being the first thing on the line. It would be 
nice to support it, and c-mode also indents it properly.

That being said, it is probably rare enough in practice to prio it less.

Thanks,
Jørgen





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

* bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL
  2024-12-01 22:46               ` Jørgen Kvalsvik
@ 2024-12-02  2:13                 ` Yuan Fu
  0 siblings, 0 replies; 14+ messages in thread
From: Yuan Fu @ 2024-12-02  2:13 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: Eli Zaretskii, Theodor Thornhill, 74507-done



> On Dec 1, 2024, at 2:46 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
> 
> On 12/1/24 22:48, Yuan Fu wrote:
>>> On Dec 1, 2024, at 1:51 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>> 
>>> On 12/1/24 10:25, Yuan Fu wrote:
>>>>> On Nov 30, 2024, at 12:49 PM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>> 
>>>>> On 11/30/24 01:16, Yuan Fu wrote:
>>>>>>> On Nov 29, 2024, at 1:05 AM, Jørgen Kvalsvik <j@lambda.is> wrote:
>>>>>>> 
>>>>>>> On 11/29/24 08:57, Eli Zaretskii wrote:
>>>>>>>>> Cc: theo@thornhill.no,casouri@gmail.com
>>>>>>>>> From: Jørgen Kvalsvik <j@lambda.is>
>>>>>>>>> Date: Sun, 24 Nov 2024 10:15:12 +0100
>>>>>>>>> 
>>>>>>>>> * lisp/progmodes/c-ts-mode.el (c-ts-mode--parent-is-not-top-compound):
>>>>>>>>> New function.
>>>>>>>>> (c-ts-mode--indent-styles): Use it.
>>>>>>>>> * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New compound
>>>>>>>>> statement test.
>>>>>>>> Please make sure the lines here are not too long (see CONTRIBUTE for
>>>>>>>> details).
>>>>>>>>> +(defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _)
>>>>>>>>> +  "Matches when PARENT is not the top level compound statement,
>>>>>>>>> +the {} that immediately follows the signature."
>>>>>>>> The first line of a doc string should be a single complete sentence.
>>>>>>>> Thanks.
>>>>>>> 
>>>>>>> Ok. Yuan, would you like me to submit a revision?
>>>>>> Since your assignment is already done, let’s just apply your patch, and I’ll rebase my changes on top of yours. So yeah, do send the revision patch, thanks!
>>>>>> Yuan
>>>>> 
>>>>> Certainly - I posted it on the bug tracker.
>>>> Thanks Jørgen. What did you use to generate the patch? For some reason I can’t apply it. My git skill isn’t that great so it could be my problem. If you can apply it fine maybe you can share the command you used?
>>> 
>>> I used git format-patch HEAD~1, and I just tested applying it to master with `git am 0001-Indent-compounds-in-c-ts-mode-when-is-not-BOL.patch' which worked.
>>> 
>>>> BTW, the commit title is missing. When you add the title, you can also add the bug number. For example:
>>>> Improve c-ts-mode indentation for macros (bug#74507)
>>>> Yuan
>>> 
>>> Sure. I've attached a new patch with the bug in it. I tested it and it applies cleanly with `git am 0001-Improve-c-ts-mode-compound-indents-bug-74507.patch'
>>> <0001-Improve-c-ts-mode-compound-indents-bug-74507.patch>
>> Thanks. This patch applied without a problem.
>> I reworked your heuristic into a function rule for better organization, and changed the condition slightly:
>> (defun c-ts-mode--macro-heuristic-rules (node parent &rest _)
>>   "Heuristic indent rule for control flow macros.
>> Eg,
>>     #define IOTA(var, n) for (int var = 0; var != (n); ++var)
>>     int main()
>>     {
>>       IOTA (v, 10) {
>>         printf(\"%d \", v);   <-- Here we want to indent
>>         counter++;            <-- Use baseline rule to align
>>     }                             to prev sibling
>> Checked by \"Compound Statement after code (Bug#74507)\" test.
>> NODE and PARENT are the same as other indent rules."
>>   (when (and (treesit-node-match-p parent "compound_statement")
>>              (treesit-node-match-p (treesit-node-prev-sibling parent)
>>                                    "expression_statement"))
>>     (let ((parent-bol
>>            (lambda () (save-excursion
>>                         (goto-char (treesit-node-start parent))
>>                         (back-to-indentation)
>>                         (point)))))
>>       (cond
>>        ;; Closing brace.
>>        ((treesit-node-match-p node "}")
>>         (cons (funcall parent-bol) 0))
>>        ;; First sibling.
>>        ((treesit-node-eq (treesit-node-child parent 0 'named) node)
>>         (cons (funcall parent-bol)
>>               c-ts-mode-indent-offset))))))
>> Instead of checking whether PARENT is top-level compound_statement, I make it check whether the previous sibling is an expression_statement. This way the heuristic works when the macro isn’t at top-level too. Here’s the updated test:
>> #define IOTA(var, n) for (int var = 0; var != (n); ++var)
>> int main()
>> {
>>   IOTA (v, 10) {
>>     printf("%d ", v);
>>   }
>>   const char *msg = "Hello, world!"; {
>>     puts("Hello, world!");
>>   }
>>   for (int i = 0;
>>        i < 10;
>>        i++) {
>>     IOTA (v, 10) {
>>       printf("%d ", v);
>>     }
>>   }
>>   {
>>     IOTA (v, 10) {
>>       printf("%d ", v);
>>     }
>>   }
>> }
>> The only test case that doesn’t pass right now is this one:
>>   const char *msg = "Hello, world!"; {
>>     puts("Hello, world!");
>>   }
>> Is this a real use-case?
>> Yuan
> 
> Maybe - I included it to show that the problem was not tied to it being a macro, but rather { not being the first thing on the line. It would be nice to support it, and c-mode also indents it properly.
> 
> That being said, it is probably rare enough in practice to prio it less.

Ok, I pushed your patch and my indentation rework to master. I end up removing the test mentioned above since it’s not a real use-case, in favor of making the heuristic indent rule more specific.

Yuan







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

end of thread, other threads:[~2024-12-02  2:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-24  9:15 bug#74507: [PATCH] Indent compounds c-ts-mode when { is not BOL Jørgen Kvalsvik
2024-11-29  4:56 ` Yuan Fu
2024-11-29  7:54   ` Eli Zaretskii
2024-11-29  9:04   ` Jørgen Kvalsvik
2024-11-29  7:57 ` Eli Zaretskii
2024-11-29  9:05   ` Jørgen Kvalsvik
2024-11-30  0:16     ` Yuan Fu
2024-11-30 20:49       ` Jørgen Kvalsvik
2024-12-01  9:25         ` Yuan Fu
2024-12-01  9:51           ` Jørgen Kvalsvik
2024-12-01 21:48             ` Yuan Fu
2024-12-01 22:46               ` Jørgen Kvalsvik
2024-12-02  2:13                 ` Yuan Fu
2024-11-30 15:39 ` bug#74507: [PATCH] Indent compounds in " Jørgen Kvalsvik

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).