Function: treesit--indent-rules-optimize
treesit--indent-rules-optimize is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit--indent-rules-optimize RULES)
Documentation
Optimize simple indent RULES.
RULES should be a value suitable for
treesit-simple-indent-rules. Return the optimized version of
RULES.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--indent-rules-optimize (rules)
"Optimize simple indent RULES.
RULES should be a value suitable for
`treesit-simple-indent-rules'. Return the optimized version of
RULES."
;; Right now this function just compiles queries. It doesn't
;; byte-compile matchers and anchors because it doesn't make much
;; difference.
(cl-loop for setting in rules
for lang = (car setting)
for indent-rules = (cdr setting)
collect
(cl-labels
;; Optimize a matcher or anchor.
((optimize-func (func)
(pcase func
(`(query ,qry)
(list 'query (treesit-query-compile lang qry)))
(`(and . ,fns)
(cons 'and (mapcar #'optimize-func fns)))
(`(or . ,fns)
(cons 'or (mapcar #'optimize-func fns)))
(_ func)))
;; Optimize a rule (MATCHER ANCHOR OFFSET).
(optimize-rule (rule)
(let ((matcher (nth 0 rule))
(anchor (nth 1 rule))
(offset (nth 2 rule)))
(list (optimize-func matcher)
(optimize-func anchor)
offset))))
(cons lang (mapcar #'optimize-rule indent-rules)))))