From: Yuan Fu Date: Fri, 14 Feb 2025 02:23:43 +0000 (-0800) Subject: Add indentation for multi-line string in java-ts-mode (bug#75154) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=53ac01d0afdb3e6b45896f20f0abf72cae2a868b;p=emacs.git Add indentation for multi-line string in java-ts-mode (bug#75154) * lisp/progmodes/java-ts-mode.el: (java-ts-mode--first-line-on-multi-line-string): New function. (java-ts-mode--indent-rules): Add rules. (cherry picked from commit affb2ba77b4a7ec7c000b18cc5c30d237e1b7165) --- diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 441c9db140a..d92850bf629 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -99,6 +99,14 @@ again." table) "Syntax table for `java-ts-mode'.") +(defun java-ts-mode--first-line-on-multi-line-string (_node parent bol &rest _) + "Simple-indent matcher for the first line in a multi-line string block. +PARENT and BOL are the as in other matchers." + (and (treesit-node-match-p parent "multiline_string_fragment") + (save-excursion + ;; Less than 2 newlines between point and string start. + (not (search-backward "\n" (treesit-node-start parent) t 2))))) + (defvar java-ts-mode--indent-rules `((java ((parent-is "program") column-0 0) @@ -116,6 +124,10 @@ again." ((and (parent-is "comment") c-ts-common-looking-at-star) c-ts-common-comment-start-after-first-star -1) ((parent-is "comment") prev-adaptive-prefix 0) + (java-ts-mode--first-line-on-multi-line-string parent-bol + java-ts-mode-indent-offset) + ((parent-is "multiline_string_fragment") prev-adaptive-prefix 0) + ((match "\"\"\"" "string_literal" nil 1) prev-adaptive-prefix 0) ((parent-is "text_block") no-indent) ((parent-is "class_body") column-0 c-ts-common-statement-offset) ((parent-is "array_initializer") parent-bol java-ts-mode-indent-offset)