Change tree-sitter indent anchor 'point-min' to 'column-0'

Point-min isn't necessarily at column 0, using line-beginning-position
is better. column-0 is also more intuitive.

* doc/lispref/modes.texi (Parser-based Indentation): Update manual.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles):
* lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules):
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode--indent-rules):
* lisp/progmodes/typescript-ts-mode.el:
(typescript-ts-mode--indent-rules): Change point-min to column-0.
* lisp/treesit.el (treesit-simple-indent-presets): Change point-min to
column-0.
This commit is contained in:
Yuan Fu 2023-03-04 01:09:00 -08:00
parent f47b393015
commit 4c16fd3a51
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
6 changed files with 29 additions and 26 deletions

View file

@ -5117,10 +5117,10 @@ This anchor is a function that is called with 3 arguments: @var{node},
@var{parent}, and @var{bol}, and returns the first non-whitespace
character on the previous line.
@item point-min
@item column-0
This anchor is a function that is called with 3 arguments: @var{node},
@var{parent}, and @var{bol}, and returns the beginning of the buffer.
This is useful as the beginning of the buffer is always at column 0.
@var{parent}, and @var{bol}, and returns the beginning of the current
line, which is at column 0.
@item comment-start
This anchor is a function that is called with 3 arguments: @var{node},

View file

@ -309,8 +309,8 @@ PARENT, BOL, ARGS are the same as other anchor functions."
"Indent rules supported by `c-ts-mode'.
MODE is either `c' or `cpp'."
(let ((common
`(((parent-is "translation_unit") point-min 0)
((query "(ERROR (ERROR)) @indent") point-min 0)
`(((parent-is "translation_unit") column-0 0)
((query "(ERROR (ERROR)) @indent") column-0 0)
((node-is ")") parent 1)
((node-is "]") parent-bol 0)
((node-is "else") parent-bol 0)
@ -330,11 +330,11 @@ MODE is either `c' or `cpp'."
((parent-is "labeled_statement")
c-ts-mode--standalone-grandparent c-ts-mode-indent-offset)
((node-is "preproc") point-min 0)
((node-is "#endif") point-min 0)
((match "preproc_call" "compound_statement") point-min 0)
((node-is "preproc") column-0 0)
((node-is "#endif") column-0 0)
((match "preproc_call" "compound_statement") column-0 0)
((n-p-gp nil "preproc" "translation_unit") point-min 0)
((n-p-gp nil "preproc" "translation_unit") column-0 0)
((n-p-gp nil "\n" "preproc") great-grand-parent c-ts-mode--preproc-offset)
((parent-is "preproc") grand-parent c-ts-mode-indent-offset)
@ -392,14 +392,14 @@ MODE is either `c' or `cpp'."
`((gnu
;; Prepend rules to set highest priority
((match "while" "do_statement") parent 0)
(c-ts-mode--top-level-label-matcher point-min 1)
(c-ts-mode--top-level-label-matcher column-0 1)
,@common)
(k&r ,@common)
(linux
;; Reference:
;; https://www.kernel.org/doc/html/latest/process/coding-style.html,
;; and script/Lindent in Linux kernel repository.
((node-is "labeled_statement") point-min 0)
((node-is "labeled_statement") column-0 0)
,@common)
(bsd
((node-is "}") parent-bol 0)

View file

@ -69,10 +69,10 @@
(defvar java-ts-mode--indent-rules
`((java
((parent-is "program") point-min 0)
((parent-is "program") column-0 0)
((match "}" "element_value_array_initializer")
parent-bol 0)
((node-is "}") point-min c-ts-common-statement-offset)
((node-is "}") column-0 c-ts-common-statement-offset)
((node-is ")") parent-bol 0)
((node-is "else") parent-bol 0)
((node-is "]") parent-bol 0)
@ -80,15 +80,15 @@
c-ts-common-comment-start-after-first-star -1)
((parent-is "comment") prev-adaptive-prefix 0)
((parent-is "text_block") no-indent)
((parent-is "class_body") point-min c-ts-common-statement-offset)
((parent-is "class_body") column-0 c-ts-common-statement-offset)
((parent-is "array_initializer") parent-bol java-ts-mode-indent-offset)
((parent-is "annotation_type_body") point-min c-ts-common-statement-offset)
((parent-is "interface_body") point-min c-ts-common-statement-offset)
((parent-is "constructor_body") point-min c-ts-common-statement-offset)
((parent-is "annotation_type_body") column-0 c-ts-common-statement-offset)
((parent-is "interface_body") column-0 c-ts-common-statement-offset)
((parent-is "constructor_body") column-0 c-ts-common-statement-offset)
((parent-is "enum_body_declarations") parent-bol 0)
((parent-is "enum_body") point-min c-ts-common-statement-offset)
((parent-is "switch_block") point-min c-ts-common-statement-offset)
((parent-is "record_declaration_body") point-min c-ts-common-statement-offset)
((parent-is "enum_body") column-0 c-ts-common-statement-offset)
((parent-is "switch_block") column-0 c-ts-common-statement-offset)
((parent-is "record_declaration_body") column-0 c-ts-common-statement-offset)
((query "(method_declaration (block _ @indent))") parent-bol java-ts-mode-indent-offset)
((query "(method_declaration (block (_) @indent))") parent-bol java-ts-mode-indent-offset)
((parent-is "local_variable_declaration") parent-bol java-ts-mode-indent-offset)
@ -121,7 +121,7 @@
((parent-is "case_statement") parent-bol java-ts-mode-indent-offset)
((parent-is "labeled_statement") parent-bol java-ts-mode-indent-offset)
((parent-is "do_statement") parent-bol java-ts-mode-indent-offset)
((parent-is "block") point-min c-ts-common-statement-offset)))
((parent-is "block") column-0 c-ts-common-statement-offset)))
"Tree-sitter indent rules.")
(defvar java-ts-mode--keywords

View file

@ -71,7 +71,7 @@
(defvar rust-ts-mode--indent-rules
`((rust
((parent-is "source_file") point-min 0)
((parent-is "source_file") column-0 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is "}") (and parent parent-bol) 0)

View file

@ -69,7 +69,7 @@
"Rules used for indentation.
Argument LANGUAGE is either `typescript' or `tsx'."
`((,language
((parent-is "program") point-min 0)
((parent-is "program") column-0 0)
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)

View file

@ -1254,7 +1254,10 @@ See `treesit-simple-indent-presets'.")
(goto-char bol)
(forward-line -1)
(skip-chars-forward " \t"))))
(cons 'point-min (lambda (&rest _) (point-min)))
(cons 'column-0 (lambda (_n _p bol &rest _)
(save-excursion
(goto-char bol)
(line-beginning-position))))
;; TODO: Document.
(cons 'and (lambda (&rest fns)
(lambda (node parent bol &rest _)
@ -1358,9 +1361,9 @@ prev-line
Returns the first non-whitespace character on the previous line.
point-min
column-0
Returns the beginning of buffer, which is always at column 0.
Returns the beginning of the current line, which is at column 0.
comment-start