Function: treesit-simple-indent-modify-rules
treesit-simple-indent-modify-rules is a byte-compiled function defined
in treesit.el.gz.
Signature
(treesit-simple-indent-modify-rules LANG NEW-RULES RULES &optional HOW)
Documentation
Pick out rules for LANG in RULES, and modify it according to NEW_RULES.
RULES should have the same form as treesit-simple-indent-rules, i.e, a
list of (LANG RULES...). Return a new modified rules in the form
of (LANG RULES...).
If HOW is omitted or :replace, for each rule in NEW-RULES, find the old rule that has the same matcher, and replace it.
If HOW is :prepend, just prepend NEW-RULES to the old rules; if HOW is
:append, append NEW-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-modify-rules (lang new-rules rules &optional how)
"Pick out rules for LANG in RULES, and modify it according to NEW_RULES.
RULES should have the same form as `treesit-simple-indent-rules', i.e, a
list of (LANG RULES...). Return a new modified rules in the form
of (LANG RULES...).
If HOW is omitted or :replace, for each rule in NEW-RULES, find the old
rule that has the same matcher, and replace it.
If HOW is :prepend, just prepend NEW-RULES to the old rules; if HOW is
:append, append NEW-RULES."
(cond
((not (alist-get lang rules))
(error "No rules for language %s in RULES" lang))
((not (alist-get lang new-rules))
(error "No rules for language %s in NEW-RULES" lang))
(t (let* ((copy-of-rules (copy-tree rules))
(lang-rules (alist-get lang copy-of-rules))
(lang-new-rules (alist-get lang new-rules)))
(cond
((eq how :prepend)
(setf (alist-get lang copy-of-rules)
(append lang-new-rules lang-rules)))
((eq how :append)
(setf (alist-get lang copy-of-rules)
(append lang-rules lang-new-rules)))
((or (eq how :replace) t)
(let ((tail-new-rules lang-new-rules)
(tail-rules lang-rules)
(new-rule nil)
(rule nil))
(while (setq new-rule (car tail-new-rules))
(while (setq rule (car tail-rules))
(when (equal (nth 0 new-rule) (nth 0 rule))
(setf (car tail-rules) new-rule))
(setq tail-rules (cdr tail-rules)))
(setq tail-new-rules (cdr tail-new-rules))))))
copy-of-rules))))