Subject: Re: bug#67556: 29.1; java-ts-mode doesn't indent open curly brackets properly

From: Dmitry Gutov <[email-masked]>
Date: Mon, 12 Feb 2024 00:42:50 +0200

On 11/02/2024 10:43, Eli Zaretskii wrote:
> Ping! Ping! Ping! Yuan and Theo, could you please chime in?

Here's a minimal patch, consisting of a new rule and a couple of 
replacements where the new standalone-parent anchor is used instead of 
the helper c-ts-common-statement-offset.

Because the latter behaves differently when the opening curly is on a 
separate line, and we don't really want that.

A more finished change will likely either switch over to 
standalone-parent completely, or go back and revamp 
c-ts-common-statement-offset to avoid this distinction (despite the 
name, it only remains in use in java-ts-mode these days).

The former has been a simpler route so far, so I suggest we at least 
commit the attached.

diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index 0b1ac49b99f..580c979b94f 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -74,7 +74,9 @@ java-ts-mode--indent-rules
      ((parent-is "program") column-0 0)
      ((match "}" "element_value_array_initializer")
       parent-bol 0)
-     ((node-is "}") column-0 c-ts-common-statement-offset)
+     ((match "\\`\\(?:constructor_body\\|class_body\\|interface_body\\|block\\)\\'")
+      parent-bol 0)
+     ((node-is "}") standalone-parent 0)
      ((node-is ")") parent-bol 0)
      ((node-is "else") parent-bol 0)
      ((node-is "]") parent-bol 0)
@@ -86,7 +88,7 @@ java-ts-mode--indent-rules
      ((parent-is "array_initializer") parent-bol java-ts-mode-indent-offset)
      ((parent-is "annotation_type_body") column-0 c-ts-common-statement-offset)
      ((parent-is "interface_body") column-0 c-ts-common-statement-offset)
-     ((parent-is "constructor_body") column-0 c-ts-common-statement-offset)
+     ((parent-is "constructor_body") standalone-parent java-ts-mode-indent-offset)
      ((parent-is "enum_body_declarations") parent-bol 0)
      ((parent-is "enum_body") column-0 c-ts-common-statement-offset)
      ((parent-is "switch_block") column-0 c-ts-common-statement-offset)
@@ -125,7 +127,7 @@ java-ts-mode--indent-rules
      ((parent-is "case_statement") parent-bol java-ts-mode-indent-offset)
      ((parent-is "labeled_statement") parent-bol java-ts-mode-indent-offset)
      ((parent-is "do_statement") parent-bol java-ts-mode-indent-offset)
-     ((parent-is "block") column-0 c-ts-common-statement-offset)))
+     ((parent-is "block") standalone-parent java-ts-mode-indent-offset)))
   "Tree-sitter indent rules.")
 
 (defvar java-ts-mode--keywords