(treesit-simple-indent-presets): Short-circuit 'and' and 'or'

* lisp/treesit.el (treesit-simple-indent-presets):
Short-circuit the 'and' and 'or' matchers.  To avoid calling all
fns after one returned nil or truthy value, respectively.
This commit is contained in:
Dmitry Gutov 2023-01-07 02:02:25 +02:00
parent 2ea6ee5cbf
commit f2ebe43362

View file

@ -1179,16 +1179,15 @@ See `treesit-simple-indent-presets'.")
;; TODO: Document.
(cons 'and (lambda (&rest fns)
(lambda (node parent bol &rest _)
(cl-reduce (lambda (a b) (and a b))
(mapcar (lambda (fn)
(funcall fn node parent bol))
fns)))))
(not
(seq-find
(lambda (fn) (not (funcall fn node parent bol)))
fns)))))
(cons 'or (lambda (&rest fns)
(lambda (node parent bol &rest _)
(cl-reduce (lambda (a b) (or a b))
(mapcar (lambda (fn)
(funcall fn node parent bol))
fns)))))
(seq-find
(lambda (fn) (funcall fn node parent bol))
fns))))
(cons 'not (lambda (fn)
(lambda (node parent bol &rest _)
(not (funcall fn node parent bol)))))