From: Yuan Fu Date: Fri, 28 Oct 2022 00:07:12 +0000 (-0700) Subject: Add some js-mode tree-sitter indent rules X-Git-Tag: emacs-29.0.90~1768 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9c4dddad456e23892a80303da26774a13250b647;p=emacs.git Add some js-mode tree-sitter indent rules * lisp/progmodes/js.el (js--treesit-indent-rules): Add rules and a let form. --- diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index f258b093f4a..583de0c5032 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3415,32 +3415,39 @@ This function is intended for use in `after-change-functions'." (point)))) (defvar js--treesit-indent-rules - `((javascript - (no-node (js--treesit-backward-up-list) ,js-indent-level) - ((node-is "}") parent-bol 0) - ((node-is ")") parent-bol 0) - ((node-is "]") parent-bol 0) - ((node-is ">") parent-bol 0) - ((node-is "\\.") parent-bol ,js-indent-level) - ((parent-is "named_imports") parent-bol ,js-indent-level) - ((parent-is "statement_block") parent-bol ,js-indent-level) - ((parent-is "variable_declarator") parent-bol ,js-indent-level) - ((parent-is "arguments") parent-bol ,js-indent-level) - ((parent-is "array") parent-bol ,js-indent-level) - ((parent-is "formal_parameters") parent-bol ,js-indent-level) - ((parent-is "template_substitution") parent-bol ,js-indent-level) - ((parent-is "object_pattern") parent-bol ,js-indent-level) - ((parent-is "object") parent-bol ,js-indent-level) - ((parent-is "arrow_function") parent-bol ,js-indent-level) - ((parent-is "parenthesized_expression") parent-bol ,js-indent-level) - - ;; JSX - ((parent-is "jsx_opening_element") parent ,js-indent-level) - ((node-is "jsx_closing_element") parent 0) - ((node-is "jsx_text") parent ,js-indent-level) - ((parent-is "jsx_element") parent ,js-indent-level) - ((node-is "/") parent 0) - ((parent-is "jsx_self_closing_element") parent ,js-indent-level)))) + (let ((switch-case (rx "switch_" (or "case" "default")))) + `((javascript + (no-node (js--treesit-backward-up-list) ,js-indent-level) + ((node-is "}") parent-bol 0) + ((node-is ")") parent-bol 0) + ((node-is "]") parent-bol 0) + ((node-is ">") parent-bol 0) + ((node-is "\\.") parent-bol ,js-indent-level) + ((node-is ,switch-case) parent-bol 0) + ;; "{" on the newline. + ((node-is "statement_block") parent-bol ,js-indent-level) + ((parent-is "named_imports") parent-bol ,js-indent-level) + ((parent-is "statement_block") parent-bol ,js-indent-level) + ((parent-is "variable_declarator") parent-bol ,js-indent-level) + ((parent-is "arguments") parent-bol ,js-indent-level) + ((parent-is "array") parent-bol ,js-indent-level) + ((parent-is "formal_parameters") parent-bol ,js-indent-level) + ((parent-is "template_substitution") parent-bol ,js-indent-level) + ((parent-is "object_pattern") parent-bol ,js-indent-level) + ((parent-is "object") parent-bol ,js-indent-level) + ((parent-is "pair") parent-bol ,js-indent-level) + ((parent-is "arrow_function") parent-bol ,js-indent-level) + ((parent-is "parenthesized_expression") parent-bol ,js-indent-level) + ((parent-is "class_body") parent-bol ,js-indent-level) + ((parent-is ,switch-case) parent-bol ,js-indent-level) + + ;; JSX + ((parent-is "jsx_opening_element") parent ,js-indent-level) + ((node-is "jsx_closing_element") parent 0) + ((node-is "jsx_text") parent ,js-indent-level) + ((parent-is "jsx_element") parent ,js-indent-level) + ((node-is "/") parent 0) + ((parent-is "jsx_self_closing_element") parent ,js-indent-level))))) (defvar js--treesit-keywords '("as" "async" "await" "break" "case" "catch" "class" "const" "continue"