]> git.eshelyaron.com Git - emacs.git/commitdiff
Add multivar indent style in typescript-ts-mode (bug#77803)
authorYuan Fu <casouri@gmail.com>
Sat, 26 Apr 2025 00:38:58 +0000 (17:38 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Apr 2025 17:30:17 +0000 (19:30 +0200)
* lisp/progmodes/typescript-ts-mode.el:
(typescript-ts-mode-multivar-indent-style): New option.
(typescript-ts-mode--indent-rules): Support both styles.

(cherry picked from commit 3393644b715a4b5a1b438b556478cc9e45f3e0ad)

lisp/progmodes/typescript-ts-mode.el

index 9b5b7312e1c257e6d7f86bdcc5892360f07b9af8..aaeedae86c42143ed9cf7ba3cddbf25a8fdc0ac1 100644 (file)
   :safe 'integerp
   :group 'typescript)
 
+(defcustom typescript-ts-mode-multivar-indent-style 'indent
+  "Indentation style for multivar declaration.
+
+If the value is `align', align each declaration:
+
+    const foo = 'bar',
+          car = 'cdr',
+          stop = 'start';
+
+If the value is `indent', indent subsequent declarations by one indent
+level:
+
+   const foo = 'bar',
+     car = 'cdr',
+     stop = 'start';
+
+For changes to this variable to take effect, restart the major mode."
+  :version "31.1"
+  :type 'symbol)
+
 (defface typescript-ts-jsx-tag-face
   '((t . (:inherit font-lock-function-call-face)))
   "Face for HTML tags like <div> and <p> in JSX."
@@ -153,7 +173,9 @@ Argument LANGUAGE is either `typescript' or `tsx'."
      ((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "type_parameters") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is ,(rx (or "variable" "lexical") "_" (or "declaration" "declarator")))
-      parent-bol typescript-ts-mode-indent-offset)
+      ,@(pcase typescript-ts-mode-multivar-indent-style
+          ('indent '(parent-bol typescript-ts-mode-indent-offset))
+          ('align '(typescript-ts-mode--anchor-decl 1))))
      ((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "formal_parameters") parent-bol typescript-ts-mode-indent-offset)