Variable: treesit-simple-indent-presets
treesit-simple-indent-presets is a variable defined in treesit.el.gz.
Value
Large value
((match
. #[1280 "\300\301\n&\207"
[make-closure
#[642
"\304\203#\304\305=\203?\202 \304\306!\206\307\310\311\312$\266\203\205e\303\2037\303\306!\310\311\312$\266\203\205e\302\203O\302\313!\206C\307\310\311\312$\266\203\205e\301\203[\314!\301Y\205e\300?\206e\314!\300X\207"
[V0 V1 V2 V3 V4 null treesit-node-type "" nil
string-match t treesit-node-field-name
treesit-node-index]
11
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73215)]]
12
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73130)])
(n-p-gp
. #[771 "\300\301$\207"
[make-closure
#[642
"\302\203\302\303!\206\f\304\305\306\307$\266\203\205F\301\203,\301\303!\305\306\307$\266\203\205F\300?\206F\310!\205F\300\303\310!!\305\306\307$\266\203\207"
[V0 V1 V2 treesit-node-type "" nil string-match t
treesit-node-parent]
11
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73215)]]
8
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73247)])
(no-node
. #[385 "?\207" [] 3
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73290)])
(parent-is
. #[257 "\300\301\"\207"
[make-closure
#[642 "\300\301!\302\303\304$\207"
[V0 treesit-node-type nil string-match t] 11
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73315)])
(node-is
. #[257 "\300\301\"\207"
[make-closure
#[385 "\300\301!\206\302\303\304\305$\207"
[V0 treesit-node-type "" nil string-match t] 10
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73290)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73315)])
(prev-line-is
. #[257 "\300\301\"\207"
[make-closure
#[899 "\301\302!\300\"\207"
[V0 treesit-node-match-p
treesit--indent-prev-line-node]
7
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73361)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73315)])
(field-is
. #[257 "\300\301\"\207"
[make-closure
#[385 "\300\301!\206\302\303\304\305$\207"
[V0 treesit-node-field-name "" nil string-match t] 10
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73290)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73389)])
(comment-end
. #[899 "\212b\210\301\302\")\207"
[comment-end-skip looking-at t] 8
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)])
(catch-all
. #[128 "\300\207" [t] 2
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73442)])
(query
. #[257 "\300\301\"\207"
[make-closure
#[642
"\301\300\"\302\303\302:\203-@\262\304A\"\203\"\210\303\302\211\262\202#\303\203-A\262\202?\2053\211\207"
[V0 treesit-query-capture nil t treesit-node-eq] 10
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73215)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73462)])
(first-sibling
. #[642 "\300\301\302\"!\207"
[treesit-node-start treesit-node-child 0] 7
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(nth-sibling
. #[513 "\300\301#\207"
[make-closure
#[642 "\302\303\301\300#!\207"
[V0 V1 treesit-node-start treesit-node-child] 8
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)]]
6
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73482)])
(parent
. #[642 "\300!\207" [treesit-node-start] 5
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(comment-start
. #[642 "\212\301!b\210\302!\210\303\304!\210`)\207"
[comment-start-skip treesit-node-start re-search-forward
skip-syntax-backward "-"]
5
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(prev-adaptive-prefix
. #[899
"\301\211\212\302!b\210\303 \262b\210\304!\205#\305\306\307!\301\310\311$\266\203?\262\312y\210`Y\205N\205N\304!\205N\313\304\311\"\262?\205N\211\203L\314\224\206N\307\225)\207"
[adaptive-fill-regexp nil treesit-node-start
line-beginning-position looking-at
"\\`[[:space:]]*\\'" match-string 0
string-match t -1 "[[:space:]]*$" 1]
14
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73512)])
(grand-parent
. #[642 "\300\301!!\207" [treesit-node-start treesit-node-parent]
6
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(great-grand-parent
. #[642 "\300\301\211!!!\207"
[treesit-node-start treesit-node-parent] 7
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(parent-bol
. #[642 "\212\300!b\210\301 \210`)\207"
[treesit-node-start back-to-indentation] 5
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(standalone-parent
. #[642
"\212\301\3022;\205:\303!b\210\204\304\305\306 \"\202!!\211\262\2032\307\302\247\203/\2020`\"\210\310!\262\2020)\207"
[treesit-simple-indent-standalone-predicate nil term
treesit-node-start
looking-back
"^[[:space:]]*"
line-beginning-position
throw
treesit-node-parent]
7
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73332)])
(prev-sibling
. #[899
"\300\301\302\"\206\301\303\"\302\"\206\304\305\302#!\207"
[treesit-node-start treesit-node-prev-sibling t
treesit-node-first-child-for-pos
treesit-node-child -1]
9
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)])
(no-indent
. #[899 "\207" [] 5
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73361)])
(prev-line
. #[899 "\212b\210\300y\210\301\302w\210`)\207" [-1 " " nil]
6
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73361)])
(column-0
. #[128 "\300 \207" [pos-bol] 2
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73442)])
(and
. #[128 "\300\301\"\207"
[make-closure
#[899
"\301\3022'\300\211\205$\211@\211#\262\204\303\302\304\"\210\210A\202\2620\210\207"
[V0 nil break throw t] 11
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73545)])
(or
. #[128 "\300\301\"\207"
[make-closure
#[899
"\301\3022'\300\211\205$\211@\211#\262\203\303\302\304\"\210\210A\202\2620\210\207"
[V0 nil break throw t] 11
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73545)])
(not
. #[257 "\300\301\"\207"
[make-closure
#[899 "\300#?\207" [V0] 8
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73567)])
(list
. #[128 "\300\301\"\207"
[make-closure
#[899 "\301\302\303$\300\"\207"
[V0 mapcar make-closure
#[257 "\211\302\301\300#\207" [V0 V1 V2] 5
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73567)]]
10
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73406)]]
4
("/nix/store/yvwy8dm26cpa1j12ixgs1dyiaw2abdk9-emacs-snapshot/share/emacs/31.0.50/lisp/treesit.elc"
. 73545)]))
Documentation
A list of indent rule presets.
These presets can be used as MATCHER and ANCHOR values in
treesit-simple-indent-rules. MATCHERs and ANCHORs are
functions that take 3 arguments: NODE, PARENT, and BOL.
MATCHER:
(match NODE-TYPE PARENT-TYPE NODE-FIELD NODE-INDEX-MIN NODE-INDEX-MAX)
NODE-TYPE checks for NODE's type, PARENT-TYPE checks for
PARENT's type, NODE-FIELD checks for the field name of NODE
in PARENT, NODE-INDEX-MIN and NODE-INDEX-MAX check for
NODE's index in PARENT. Therefore, to match the first child
where PARENT is "argument_list", use
(match nil "argument_list" nil 0 0).
NODE-TYPE, PARENT-TYPE, and NODE-FIELD are regexps.
NODE-TYPE can also be null, which matches when NODE is nil.
no-node
Matches the case where NODE is nil, i.e., there is no node
that starts at point. This is the case when indenting an
empty line.
(parent-is TYPE)
Check that PARENT's type matches regexp TYPE.
(node-is TYPE)
Checks that NODE's type matches regexp TYPE.
(field-is NAME)
Checks that NODE's field name in PARENT matches regexp NAME.
(n-p-gp NODE-TYPE PARENT-TYPE GRANDPARENT-TYPE)
Checks for NODE's, its parent's, and its grandparent's type.
(query QUERY)
Queries PARENT with QUERY, and checks if NODE is
captured (by any capture name).
comment-end
Matches if text after point matches comment-end-skip.
catch-all
Always matches.
ANCHOR:
first-sibling
Returns the start of the first child of PARENT.
(nth-sibling N &optional NAMED)
Returns the start of the Nth child of PARENT.
NAMED non-nil means count only named nodes.
parent
Returns the start of PARENT.
grand-parent
Returns the start of PARENT's parent.
great-grand-parent
Returns the start of PARENT's parent's parent.
parent-bol
Returns the beginning of non-space characters on the line where
PARENT is on.
standalone-parent
Finds the first ancestor node (parent, grandparent, etc.) that
starts on its own line, and returns the start of that node. The
definition of "standalone" can be customized by setting
treesit-simple-indent-standalone-predicate. Some major mode might
want to do that for easier indentation for method chaining.
prev-sibling
Returns the start of NODE's previous sibling.
no-indent
Returns the start of NODE.
prev-line
Returns the first non-whitespace character on the previous line.
column-0
Returns the beginning of the current line, which is at column 0.
comment-start
Goes to the position that comment-start-skip would return,
skips whitespace backwards, and returns the resulting
position. Assumes PARENT is a comment node.
prev-adaptive-prefix
Goes to the beginning of previous non-empty line, and tries
to match adaptive-fill-regexp. If it matches, return the
end of the match, otherwise return nil. However, if the
current line begins with a prefix, return the beginning of
the prefix of the previous line instead, so that the two
prefixes aligns. This is useful for an indent-relative-like
indent behavior for block comments.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defvar treesit-simple-indent-presets
(list (cons 'match
(lambda
(&optional node-type parent-type node-field
node-index-min node-index-max)
(lambda (node parent &rest _)
(and (pcase node-type
('nil t)
('null (null node))
(_ (string-match-p
node-type (or (treesit-node-type node) ""))))
(or (null parent-type)
(string-match-p
parent-type (treesit-node-type parent)))
(or (null node-field)
(string-match-p
node-field
(or (treesit-node-field-name node) "")))
(or (null node-index-min)
(>= (treesit-node-index node)
node-index-min))
(or (null node-index-max)
(<= (treesit-node-index node)
node-index-max))))))
(cons 'n-p-gp
(lambda (node-t parent-t grand-parent-t)
(lambda (node parent &rest _)
(and (or (null node-t)
(string-match-p
node-t (or (treesit-node-type node) "")))
(or (null parent-t)
(string-match-p
parent-t (treesit-node-type parent)))
(or (null grand-parent-t)
(and
(treesit-node-parent parent)
(string-match-p
grand-parent-t
(treesit-node-type
(treesit-node-parent parent)))))))))
(cons 'no-node (lambda (node &rest _) (null node)))
(cons 'parent-is (lambda (type)
(lambda (_n parent &rest _)
(string-match-p
type (treesit-node-type parent)))))
(cons 'node-is (lambda (type)
(lambda (node &rest _)
(string-match-p
type (or (treesit-node-type node) "")))))
;; FIXME: Add to manual.
(cons 'prev-line-is (lambda (type)
(lambda (_n _p bol &rest _)
(treesit-node-match-p
(treesit--indent-prev-line-node bol)
type))))
(cons 'field-is (lambda (name)
(lambda (node &rest _)
(string-match-p
name (or (treesit-node-field-name node) "")))))
(cons 'comment-end (lambda (_node _parent bol &rest _)
(save-excursion
(goto-char bol)
(looking-at-p comment-end-skip))))
(cons 'catch-all (lambda (&rest _) t))
(cons 'query (lambda (pattern)
(lambda (node parent &rest _)
(cl-loop for capture
in (treesit-query-capture
parent pattern)
if (treesit-node-eq node (cdr capture))
return t
finally return nil))))
(cons 'first-sibling (lambda (_n parent &rest _)
(treesit-node-start
(treesit-node-child parent 0))))
(cons 'nth-sibling (lambda (n &optional named)
(lambda (_n parent &rest _)
(treesit-node-start
(treesit-node-child parent n named)))))
(cons 'parent (lambda (_n parent &rest _)
(treesit-node-start parent)))
(cons 'comment-start
(lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
(re-search-forward comment-start-skip)
(skip-syntax-backward "-")
(point))))
(cons 'prev-adaptive-prefix
(lambda (_n parent bol &rest _)
(let (comment-start-bol
this-line-has-prefix)
(save-excursion
(goto-char (treesit-node-start parent))
(setq comment-start-bol (line-beginning-position))
(goto-char bol)
(setq this-line-has-prefix
(and (looking-at adaptive-fill-regexp)
(not (string-match-p
(rx bos (* whitespace) eos)
(match-string 0)))))
(forward-line -1)
(and (>= (point) comment-start-bol)
adaptive-fill-regexp
(looking-at adaptive-fill-regexp)
;; If previous line is an empty line, don't
;; indent.
(not (looking-at-p (rx (* whitespace) eol)))
;; Return the anchor. If the indenting line
;; has a prefix and the previous line also
;; has a prefix, indent to the beginning of
;; prev line's prefix rather than the end of
;; prev line's prefix. (Bug#61314).
(or (and this-line-has-prefix
(match-beginning 1))
(match-end 0)))))))
(cons 'grand-parent
(lambda (_n parent &rest _)
(treesit-node-start (treesit-node-parent parent))))
(cons 'great-grand-parent
(lambda (_n parent &rest _)
(treesit-node-start
(treesit-node-parent
(treesit-node-parent parent)))))
(cons 'parent-bol (lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
(back-to-indentation)
(point))))
(cons
'standalone-parent
(lambda (_n parent &rest _)
(save-excursion
(let (anchor)
(catch 'term
(while parent
(goto-char (treesit-node-start parent))
(when (if (null treesit-simple-indent-standalone-predicate)
(looking-back (rx bol (* whitespace))
(line-beginning-position))
(setq anchor
(funcall
treesit-simple-indent-standalone-predicate
parent)))
(throw 'term (if (numberp anchor) anchor (point))))
(setq parent (treesit-node-parent parent))))))))
(cons 'prev-sibling (lambda (node parent bol &rest _)
(treesit-node-start
(or (treesit-node-prev-sibling node t)
;; If node is nil (indenting empty
;; line), we still try to guess the
;; previous sibling.
(treesit-node-prev-sibling
(treesit-node-first-child-for-pos
parent bol)
t)
(treesit-node-child parent -1 t)))))
(cons 'no-indent (lambda (_n _p bol &rest _) bol))
(cons 'prev-line (lambda (_n _p bol &rest _)
(save-excursion
(goto-char bol)
(forward-line -1)
(skip-chars-forward " \t")
(point))))
(cons 'column-0 (lambda (&rest _) (pos-bol)))
;; TODO: Document.
(cons 'and (lambda (&rest fns)
(lambda (node parent bol &rest _)
(let (res)
(catch 'break
(dolist (fn fns)
(setq res (funcall fn node parent bol))
(unless res (throw 'break t))))
res))))
(cons 'or (lambda (&rest fns)
(lambda (node parent bol &rest _)
(let (res)
(catch 'break
(dolist (fn fns)
(setq res (funcall fn node parent bol))
(and res (throw 'break t))))
res))))
(cons 'not (lambda (fn)
(lambda (node parent bol &rest _)
(not (funcall fn node parent bol)))))
(cons 'list (lambda (&rest fns)
(lambda (node parent bol &rest _)
(mapcar (lambda (fn)
(funcall fn node parent bol))
fns)))))
"A list of indent rule presets.
These presets can be used as MATCHER and ANCHOR values in
`treesit-simple-indent-rules'. MATCHERs and ANCHORs are
functions that take 3 arguments: NODE, PARENT, and BOL.
MATCHER:
\(match NODE-TYPE PARENT-TYPE NODE-FIELD NODE-INDEX-MIN NODE-INDEX-MAX)
NODE-TYPE checks for NODE's type, PARENT-TYPE checks for
PARENT's type, NODE-FIELD checks for the field name of NODE
in PARENT, NODE-INDEX-MIN and NODE-INDEX-MAX check for
NODE's index in PARENT. Therefore, to match the first child
where PARENT is \"argument_list\", use
(match nil \"argument_list\" nil 0 0).
NODE-TYPE, PARENT-TYPE, and NODE-FIELD are regexps.
NODE-TYPE can also be `null', which matches when NODE is nil.
no-node
Matches the case where NODE is nil, i.e., there is no node
that starts at point. This is the case when indenting an
empty line.
\(parent-is TYPE)
Check that PARENT's type matches regexp TYPE.
\(node-is TYPE)
Checks that NODE's type matches regexp TYPE.
\(field-is NAME)
Checks that NODE's field name in PARENT matches regexp NAME.
\(n-p-gp NODE-TYPE PARENT-TYPE GRANDPARENT-TYPE)
Checks for NODE's, its parent's, and its grandparent's type.
\(query QUERY)
Queries PARENT with QUERY, and checks if NODE is
captured (by any capture name).
comment-end
Matches if text after point matches `comment-end-skip'.
catch-all
Always matches.
ANCHOR:
first-sibling
Returns the start of the first child of PARENT.
\(nth-sibling N &optional NAMED)
Returns the start of the Nth child of PARENT.
NAMED non-nil means count only named nodes.
parent
Returns the start of PARENT.
grand-parent
Returns the start of PARENT's parent.
great-grand-parent
Returns the start of PARENT's parent's parent.
parent-bol
Returns the beginning of non-space characters on the line where
PARENT is on.
standalone-parent
Finds the first ancestor node (parent, grandparent, etc.) that
starts on its own line, and returns the start of that node. The
definition of \"standalone\" can be customized by setting
`treesit-simple-indent-standalone-predicate'. Some major mode might
want to do that for easier indentation for method chaining.
prev-sibling
Returns the start of NODE's previous sibling.
no-indent
Returns the start of NODE.
prev-line
Returns the first non-whitespace character on the previous line.
column-0
Returns the beginning of the current line, which is at column 0.
comment-start
Goes to the position that `comment-start-skip' would return,
skips whitespace backwards, and returns the resulting
position. Assumes PARENT is a comment node.
prev-adaptive-prefix
Goes to the beginning of previous non-empty line, and tries
to match `adaptive-fill-regexp'. If it matches, return the
end of the match, otherwise return nil. However, if the
current line begins with a prefix, return the beginning of
the prefix of the previous line instead, so that the two
prefixes aligns. This is useful for an `indent-relative'-like
indent behavior for block comments.")