Subject: Re: bug#65006: 29.1.50; c-ts-mode: else block not indented right on TAB

From: john muhl <[email-masked]>
Date: Wed, 02 Aug 2023 11:03:04 -0500

Here is a patch that makes it work and fixes a couple of tests that were
failing in the BSD style. Hope it helps.

>From 43f63fa9fdb5c6e77fd8928a521686ea0b847b2f Mon Sep 17 00:00:00 2001
From: john muhl <[email-masked]>
Date: Wed, 2 Aug 2023 10:30:22 -0500
Subject: [PATCH] Fix indentation after else

* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles):
Indent statement after else_clause.
---
 lisp/progmodes/c-ts-mode.el                         |  2 ++
 test/lisp/progmodes/c-ts-mode-resources/indent.erts | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index f16e06942b9..95d3d43c096 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -452,6 +452,7 @@ c-ts-mode--indent-styles
            ;; These rules are for cases where the body is bracketless.
            ;; Tested by the "Bracketless Simple Statement" test.
            ((parent-is "if_statement") standalone-parent c-ts-mode-indent-offset)
+           ((parent-is "else_clause") standalone-parent c-ts-mode-indent-offset)
            ((parent-is "for_statement") standalone-parent c-ts-mode-indent-offset)
            ((parent-is "while_statement") standalone-parent c-ts-mode-indent-offset)
            ((parent-is "do_statement") standalone-parent c-ts-mode-indent-offset)
@@ -478,6 +479,7 @@ c-ts-mode--indent-styles
        ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset)
        ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset)
        ((parent-is "if_statement") parent-bol 0)
+       ((parent-is "else_clause") parent-bol 0)
        ((parent-is "for_statement") parent-bol 0)
        ((parent-is "while_statement") parent-bol 0)
        ((parent-is "switch_statement") parent-bol 0)
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 221b3d809af..b6a30b8f969 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -478,3 +478,16 @@ main (void)
 {
   |
 =-=-=
+
+Name: Bracketless If/Else Clause
+
+=-=
+int
+main (void)
+{
+  if (true)
+    do_something ();
+  else
+    do_something_else ();
+}
+=-=-=
-- 
2.41.0