* doc/lispref/modes.texi (Parser-based Indentation): Update manual.
* lisp/progmodes/js.el (js--treesit-indent-rules): Change all
occurance of ,js-indent-level to js-indent-level.
* lisp/progmodes/ts-mode.el (ts-mode--indent-rules): Change all
occurance of ,ts-mode-indent-offset to ts-mode-indent-offset.
* lisp/treesit.el (treesit-simple-indent-rules): Change docstring.
(treesit-simple-indent): Allow offset to be a variable.
rule is applicable. Then Emacs passes the node to @var{anchor}, which
returns a buffer position. Emacs takes the column number of that
position, adds @var{offset} to it, and the result is the indentation
-column for the current line.
+column for the current line. @var{offset} can be an integer or a
+variable whose value is an integer.
The @var{matcher} and @var{anchor} are functions, and Emacs provides
convenient defaults for them.
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
- ((parent-is "ternary_expression") parent-bol ,js-indent-level)
- ((parent-is "member_expression") parent-bol ,js-indent-level)
+ ((parent-is "ternary_expression") parent-bol js-indent-level)
+ ((parent-is "member_expression") 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)
- ((parent-is "statement_block") parent-bol ,js-indent-level)
+ ((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)
+ ((parent-is "statement_block") parent-bol js-indent-level)
;; JSX
- ((parent-is "jsx_opening_element") parent ,js-indent-level)
+ ((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 "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)))))
+ ((parent-is "jsx_self_closing_element") parent js-indent-level)))))
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
(defvar js--json-treesit-indent-rules
`((json
- (no-node (js--treesit-backward-up-list) ,js-indent-level)
+ (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)
- ((parent-is "object") parent-bol ,js-indent-level)
+ ((parent-is "object") parent-bol js-indent-level)
)))
;;;###autoload
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
- ((parent-is "ternary_expression") parent-bol ,ts-mode-indent-offset)
- ((parent-is "member_expression") parent-bol ,ts-mode-indent-offset)
- ((parent-is "named_imports") parent-bol ,ts-mode-indent-offset)
- ((parent-is "statement_block") parent-bol ,ts-mode-indent-offset)
- ((parent-is "type_arguments") parent-bol ,ts-mode-indent-offset)
- ((parent-is "variable_declarator") parent-bol ,ts-mode-indent-offset)
- ((parent-is "arguments") parent-bol ,ts-mode-indent-offset)
- ((parent-is "array") parent-bol ,ts-mode-indent-offset)
- ((parent-is "formal_parameters") parent-bol ,ts-mode-indent-offset)
- ((parent-is "template_substitution") parent-bol ,ts-mode-indent-offset)
- ((parent-is "object_pattern") parent-bol ,ts-mode-indent-offset)
- ((parent-is "object") parent-bol ,ts-mode-indent-offset)
- ((parent-is "object_type") parent-bol ,ts-mode-indent-offset)
- ((parent-is "enum_body") parent-bol ,ts-mode-indent-offset)
- ((parent-is "arrow_function") parent-bol ,ts-mode-indent-offset)
- ((parent-is "parenthesized_expression") parent-bol ,ts-mode-indent-offset)
+ ((parent-is "ternary_expression") parent-bol ts-mode-indent-offset)
+ ((parent-is "member_expression") parent-bol ts-mode-indent-offset)
+ ((parent-is "named_imports") parent-bol ts-mode-indent-offset)
+ ((parent-is "statement_block") parent-bol ts-mode-indent-offset)
+ ((parent-is "type_arguments") parent-bol ts-mode-indent-offset)
+ ((parent-is "variable_declarator") parent-bol ts-mode-indent-offset)
+ ((parent-is "arguments") parent-bol ts-mode-indent-offset)
+ ((parent-is "array") parent-bol ts-mode-indent-offset)
+ ((parent-is "formal_parameters") parent-bol ts-mode-indent-offset)
+ ((parent-is "template_substitution") parent-bol ts-mode-indent-offset)
+ ((parent-is "object_pattern") parent-bol ts-mode-indent-offset)
+ ((parent-is "object") parent-bol ts-mode-indent-offset)
+ ((parent-is "object_type") parent-bol ts-mode-indent-offset)
+ ((parent-is "enum_body") parent-bol ts-mode-indent-offset)
+ ((parent-is "arrow_function") parent-bol ts-mode-indent-offset)
+ ((parent-is "parenthesized_expression") parent-bol ts-mode-indent-offset)
;; TSX
- ((parent-is "jsx_opening_element") parent ,ts-mode-indent-offset)
+ ((parent-is "jsx_opening_element") parent ts-mode-indent-offset)
((node-is "jsx_closing_element") parent 0)
- ((parent-is "jsx_element") parent ,ts-mode-indent-offset)
+ ((parent-is "jsx_element") parent ts-mode-indent-offset)
((node-is "/") parent 0)
- ((parent-is "jsx_self_closing_element") parent ,ts-mode-indent-offset)
+ ((parent-is "jsx_self_closing_element") parent ts-mode-indent-offset)
(no-node parent-bol 0)))
"Tree-sitter indent rules.")
uses ANCHOR to find an anchor, it should be a function that takes
the same argument (NODE PARENT BOL) and returns a point.
-Finally Emacs computes the column of that point returned by ANCHOR
-and adds OFFSET to it, and indents to that column.
+Finally Emacs computes the column of that point returned by
+ANCHOR and adds OFFSET to it, and indents to that column. OFFSET
+can be an integer or a variable whose value is an integer.
For MATCHER and ANCHOR, Emacs provides some convenient presets.
See `treesit-simple-indent-presets'.")
(let ((anchor-pos
(treesit--simple-indent-eval
(list anchor node parent bol))))
- (cons anchor-pos offset))
+ (cons anchor-pos (if (symbolp offset)
+ (symbol-value offset)
+ offset)))
finally return
(progn (when treesit--indent-verbose
(message "No matched rule"))