Function: treesit-simple-indent
treesit-simple-indent is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-simple-indent NODE PARENT BOL)
Documentation
Calculate indentation according to treesit-simple-indent-rules.
BOL is the position of the first non-whitespace character on the current line. NODE is the largest node that starts at BOL, PARENT is NODE's parent.
Return (ANCHOR . OFFSET) where ANCHOR is a node, OFFSET is the indentation offset, meaning indent to align with ANCHOR and add OFFSET.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-simple-indent (node parent bol)
"Calculate indentation according to `treesit-simple-indent-rules'.
BOL is the position of the first non-whitespace character on the
current line. NODE is the largest node that starts at BOL,
PARENT is NODE's parent.
Return (ANCHOR . OFFSET) where ANCHOR is a node, OFFSET is the
indentation offset, meaning indent to align with ANCHOR and add
OFFSET."
(if (null parent)
(progn (when treesit--indent-verbose
(message "PARENT is nil, not indenting"))
(cons nil nil))
(let* ((language (treesit-node-language parent))
(rules (alist-get language
treesit-simple-indent-rules)))
(cl-loop for rule in rules
for pred = (nth 0 rule)
for anchor = (nth 1 rule)
for offset = (nth 2 rule)
if (treesit--simple-indent-eval
(list pred node parent bol))
do (when treesit--indent-verbose
(message "Matched rule: %S" rule))
and
return
(let ((anchor-pos
(treesit--simple-indent-eval
(list anchor node parent bol)))
(offset-val
(cond ((numberp offset) offset)
((and (symbolp offset)
(boundp offset))
(symbol-value offset))
(t (treesit--simple-indent-eval
(list offset node parent bol))))))
(cons anchor-pos offset-val))
finally return
(progn (when treesit--indent-verbose
(message "No matched rule"))
(cons nil nil))))))