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 "\n\n(fn NODE PARENT &rest _)"]]
12 "\n\n(fn &optional NODE-TYPE PARENT-TYPE NODE-FIELD NODE-INDEX-MIN NODE-INDEX-MAX)"])
(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 "\n\n(fn NODE PARENT &rest _)"]]
8 "\n\n(fn NODE-T PARENT-T GRAND-PARENT-T)"])
(no-node .
#[385 "?\207"
[]
3 "\n\n(fn NODE &rest _)"])
(parent-is .
#[257 "\300\301\"\207"
[make-closure
#[642 "\300\301!\302\303\304$\207"
[V0 treesit-node-type nil string-match t]
11 "\n\n(fn N PARENT &rest _)"]]
4 "\n\n(fn TYPE)"])
(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 "\n\n(fn NODE &rest _)"]]
4 "\n\n(fn TYPE)"])
(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 "\n\n(fn NODE &rest _)"]]
4 "\n\n(fn NAME)"])
(comment-end .
#[899 "\212b\210\301\302\")\207"
[comment-end-skip looking-at t]
8 "\n\n(fn NODE PARENT BOL &rest _)"])
(catch-all .
#[128 "\300\207"
[t]
2 "\n\n(fn &rest _)"])
(query .
#[257 "\300\301\"\207"
[make-closure
#[642 "\301\300\"\302\303\302:\203.@\262\304A\"\203#\303\262\302\211\262\202$\303\203.A\262\202?\2054\211\207"
[V0 treesit-query-capture nil t treesit-node-eq]
10 "\n\n(fn NODE PARENT &rest _)"]]
4 "\n\n(fn PATTERN)"])
(first-sibling .
#[642 "\300\301\302\"!\207"
[treesit-node-start treesit-node-child 0]
7 "\n\n(fn N PARENT &rest _)"])
(nth-sibling .
#[513 "\300\301#\207"
[make-closure
#[642 "\302\303\301\300#!\207"
[V0 V1 treesit-node-start treesit-node-child]
8 "\n\n(fn N PARENT &rest _)"]]
6 "\n\n(fn N &optional NAMED)"])
(parent .
#[642 "\300!\207"
[treesit-node-start]
5 "\n\n(fn N PARENT &rest _)"])
(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 "\n\n(fn N PARENT &rest _)"])
(prev-adaptive-prefix .
#[899 "\301\211\212\302!b\210\303 \262b\210\304\305\"\262\205'\306\307\310!\301\311\305$\266\203?\262\312y\210`Y\205R\205R\304!\205R\313\304\305\"\262?\205R\211\203P\314\224\206R\310\225)\207"
[adaptive-fill-regexp nil treesit-node-start line-beginning-position looking-at t "\\`[[:space:]]*\\'" match-string 0 string-match -1 "[[:space:]]*$" 1]
14 "\n\n(fn N PARENT BOL &rest _)"])
(grand-parent .
#[642 "\300\301!!\207"
[treesit-node-start treesit-node-parent]
6 "\n\n(fn N PARENT &rest _)"])
(great-grand-parent .
#[642 "\300\301\211!!!\207"
[treesit-node-start treesit-node-parent]
7 "\n\n(fn N PARENT &rest _)"])
(parent-bol .
#[642 "\212\300!b\210\301 \210`)\207"
[treesit-node-start back-to-indentation]
5 "\n\n(fn N PARENT &rest _)"])
(standalone-parent .
#[642 "\212\3002$\205#\301!b\210\302\303\304 \"\203\305\300`\"\210\306!\262\2020)\207"
[term treesit-node-start looking-back "^[[:space:]]*" line-beginning-position throw treesit-node-parent]
6 "\n\n(fn N PARENT &rest _)"])
(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 "\n\n(fn NODE PARENT BOL &rest _)"])
(no-indent .
#[899 "\207"
[]
5 "\n\n(fn N P BOL &rest _)"])
(prev-line .
#[899 "\212b\210\300y\210\301\302w\210`)\207"
[-1 " " nil]
6 "\n\n(fn N P BOL &rest _)"])
(column-0 .
#[899 "\212b\210\300 )\207"
[line-beginning-position]
5 "\n\n(fn N P BOL &rest _)"])
(and .
#[128 "\300\301\"\207"
[make-closure
#[899 "\301\3022)\300\211\205&\211@\211#\262\204\303\302\304\"\210A\266\202\202\2620\210\207"
[V0 nil break throw t]
11 "\n\n(fn NODE PARENT BOL &rest _)"]]
4 "\n\n(fn &rest FNS)"])
(or .
#[128 "\300\301\"\207"
[make-closure
#[899 "\301\3022)\300\211\205&\211@\211#\262\203\303\302\304\"\210A\266\202\202\2620\210\207"
[V0 nil break throw t]
11 "\n\n(fn NODE PARENT BOL &rest _)"]]
4 "\n\n(fn &rest FNS)"])
(not .
#[257 "\300\301\"\207"
[make-closure
#[899 "\300#?\207"
[V0]
8 "\n\n(fn NODE PARENT BOL &rest _)"]]
4 "\n\n(fn FN)"])
(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 "\n\n(fn FN)"]]
10 "\n\n(fn NODE PARENT BOL &rest _)"]]
4 "\n\n(fn &rest FNS)"]))
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.
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) "")))))
(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-p 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
(catch 'term
(while parent
(goto-char (treesit-node-start parent))
(when (looking-back (rx bol (* whitespace))
(line-beginning-position))
(throw 'term (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 (_n _p bol &rest _)
(save-excursion
(goto-char bol)
(line-beginning-position))))
;; 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.
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.")