diff options
| author | Dmitry Gutov | 2024-02-17 22:34:55 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2024-02-17 22:35:16 +0200 |
| commit | 5a64d2c7595dc393504c6eee9321d74dbd8ae9e2 (patch) | |
| tree | ae8c1b8667d9885142efb4cf5be5e547754e6be8 | |
| parent | 9e56bd5ed8775f53c3025b114525cee7c578e2d0 (diff) | |
| download | emacs-5a64d2c7595dc393504c6eee9321d74dbd8ae9e2.tar.gz emacs-5a64d2c7595dc393504c6eee9321d74dbd8ae9e2.zip | |
java-ts-mode: Indentation for opening brace on a separate line
* lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules):
Support putting the opening brace on a separate line (bug#67556).
* test/lisp/progmodes/java-ts-mode-resources/indent.erts:
Add a test.
| -rw-r--r-- | lisp/progmodes/java-ts-mode.el | 13 | ||||
| -rw-r--r-- | test/lisp/progmodes/java-ts-mode-resources/indent.erts | 31 |
2 files changed, 40 insertions, 4 deletions
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 52d025e365a..5c4bce340f0 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el | |||
| @@ -74,7 +74,12 @@ | |||
| 74 | ((parent-is "program") column-0 0) | 74 | ((parent-is "program") column-0 0) |
| 75 | ((match "}" "element_value_array_initializer") | 75 | ((match "}" "element_value_array_initializer") |
| 76 | parent-bol 0) | 76 | parent-bol 0) |
| 77 | ((node-is "}") column-0 c-ts-common-statement-offset) | 77 | ((node-is |
| 78 | ,(format "\\`%s\\'" | ||
| 79 | (regexp-opt '("constructor_body" "class_body" "interface_body" | ||
| 80 | "block" "switch_block" "array_initializer")))) | ||
| 81 | parent-bol 0) | ||
| 82 | ((node-is "}") standalone-parent 0) | ||
| 78 | ((node-is ")") parent-bol 0) | 83 | ((node-is ")") parent-bol 0) |
| 79 | ((node-is "else") parent-bol 0) | 84 | ((node-is "else") parent-bol 0) |
| 80 | ((node-is "]") parent-bol 0) | 85 | ((node-is "]") parent-bol 0) |
| @@ -86,10 +91,10 @@ | |||
| 86 | ((parent-is "array_initializer") parent-bol java-ts-mode-indent-offset) | 91 | ((parent-is "array_initializer") parent-bol java-ts-mode-indent-offset) |
| 87 | ((parent-is "annotation_type_body") column-0 c-ts-common-statement-offset) | 92 | ((parent-is "annotation_type_body") column-0 c-ts-common-statement-offset) |
| 88 | ((parent-is "interface_body") column-0 c-ts-common-statement-offset) | 93 | ((parent-is "interface_body") column-0 c-ts-common-statement-offset) |
| 89 | ((parent-is "constructor_body") column-0 c-ts-common-statement-offset) | 94 | ((parent-is "constructor_body") standalone-parent java-ts-mode-indent-offset) |
| 90 | ((parent-is "enum_body_declarations") parent-bol 0) | 95 | ((parent-is "enum_body_declarations") parent-bol 0) |
| 91 | ((parent-is "enum_body") column-0 c-ts-common-statement-offset) | 96 | ((parent-is "enum_body") column-0 c-ts-common-statement-offset) |
| 92 | ((parent-is "switch_block") column-0 c-ts-common-statement-offset) | 97 | ((parent-is "switch_block") standalone-parent java-ts-mode-indent-offset) |
| 93 | ((parent-is "record_declaration_body") column-0 c-ts-common-statement-offset) | 98 | ((parent-is "record_declaration_body") column-0 c-ts-common-statement-offset) |
| 94 | ((query "(method_declaration (block _ @indent))") parent-bol java-ts-mode-indent-offset) | 99 | ((query "(method_declaration (block _ @indent))") parent-bol java-ts-mode-indent-offset) |
| 95 | ((query "(method_declaration (block (_) @indent))") parent-bol java-ts-mode-indent-offset) | 100 | ((query "(method_declaration (block (_) @indent))") parent-bol java-ts-mode-indent-offset) |
| @@ -125,7 +130,7 @@ | |||
| 125 | ((parent-is "case_statement") parent-bol java-ts-mode-indent-offset) | 130 | ((parent-is "case_statement") parent-bol java-ts-mode-indent-offset) |
| 126 | ((parent-is "labeled_statement") parent-bol java-ts-mode-indent-offset) | 131 | ((parent-is "labeled_statement") parent-bol java-ts-mode-indent-offset) |
| 127 | ((parent-is "do_statement") parent-bol java-ts-mode-indent-offset) | 132 | ((parent-is "do_statement") parent-bol java-ts-mode-indent-offset) |
| 128 | ((parent-is "block") column-0 c-ts-common-statement-offset))) | 133 | ((parent-is "block") standalone-parent java-ts-mode-indent-offset))) |
| 129 | "Tree-sitter indent rules.") | 134 | "Tree-sitter indent rules.") |
| 130 | 135 | ||
| 131 | (defvar java-ts-mode--keywords | 136 | (defvar java-ts-mode--keywords |
diff --git a/test/lisp/progmodes/java-ts-mode-resources/indent.erts b/test/lisp/progmodes/java-ts-mode-resources/indent.erts index 4fca74dd2e1..514d2e08977 100644 --- a/test/lisp/progmodes/java-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/java-ts-mode-resources/indent.erts | |||
| @@ -110,3 +110,34 @@ public class Java { | |||
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | =-=-= | 112 | =-=-= |
| 113 | |||
| 114 | Name: Opening bracket on separate line (bug#67556) | ||
| 115 | |||
| 116 | =-= | ||
| 117 | public class Java { | ||
| 118 | void foo( | ||
| 119 | String foo) | ||
| 120 | { | ||
| 121 | for (var f : rs) | ||
| 122 | return new String[] | ||
| 123 | { | ||
| 124 | "foo", | ||
| 125 | "bar" | ||
| 126 | }; | ||
| 127 | if (a == 0) | ||
| 128 | { | ||
| 129 | return 0; | ||
| 130 | } else if (a == 1) | ||
| 131 | { | ||
| 132 | return 1; | ||
| 133 | } | ||
| 134 | |||
| 135 | switch(expr) | ||
| 136 | { | ||
| 137 | case x: | ||
| 138 | // code block | ||
| 139 | break; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
| 143 | =-=-= | ||