Function: treesit-simple-indent-add-rules
treesit-simple-indent-add-rules is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-simple-indent-add-rules LANGUAGE RULES &optional WHERE ANCHOR)
Documentation
Add simple indent RULES for LANGUAGE.
This function only affects treesit-simple-indent-rules,
treesit-simple-indent-override-rules is not affected.
WHERE can be either :before or :after, which means adding RULES before
or after the existing rules in treesit-simple-indent-rules. If
omitted, default to adding the rules before (so it overrides existing
rules).
If ANCHOR is non-nil, add RULES before/after the rules in
treesit-simple-indent-rules that's equal to ANCHOR. If ANCHOR is
omitted or no existing rules matches it, add RULES at the beginning or
end of existing rules.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-simple-indent-add-rules (language rules &optional where anchor)
"Add simple indent RULES for LANGUAGE.
This function only affects `treesit-simple-indent-rules',
`treesit-simple-indent-override-rules' is not affected.
WHERE can be either :before or :after, which means adding RULES before
or after the existing rules in `treesit-simple-indent-rules'. If
omitted, default to adding the rules before (so it overrides existing
rules).
If ANCHOR is non-nil, add RULES before/after the rules in
`treesit-simple-indent-rules' that's `equal' to ANCHOR. If ANCHOR is
omitted or no existing rules matches it, add RULES at the beginning or
end of existing rules."
(when (not (memq where '(nil :before :after)))
(error "WHERE must be either :before, :after, or nil"))
(let* ((existing-rules (alist-get language treesit-simple-indent-rules))
(anchor-idx (and anchor (seq-position existing-rules anchor)))
(new-rules
(if anchor-idx
(let* ((pivot (if (eq where :after)
(1+ anchor-idx)
anchor-idx))
(first-half (seq-subseq existing-rules 0 pivot))
(second-half (seq-subseq existing-rules pivot)))
(append first-half rules second-half))
(if (eq where :after)
(append existing-rules rules)
(append rules existing-rules)))))
(setf (alist-get language treesit-simple-indent-rules) new-rules)))