From: Dmitry Gutov Date: Sat, 7 Jan 2023 00:02:25 +0000 (+0200) Subject: (treesit-simple-indent-presets): Short-circuit 'and' and 'or' X-Git-Tag: emacs-29.0.90~819 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f2ebe43362c;p=emacs.git (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. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 987942c507a..a85eb699ee1 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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)))))