mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-17 18:37:33 +00:00
Byte-compile treesit-simple-indent-presets
* lisp/treesit.el (treesit-simple-indent-presets): Byte-compile these functions.
This commit is contained in:
parent
0c7a7df98e
commit
f46eb3d3ca
1 changed files with 115 additions and 98 deletions
213
lisp/treesit.el
213
lisp/treesit.el
|
|
@ -696,114 +696,131 @@ For MATCHER and ANCHOR, Emacs provides some convenient presets.
|
|||
See `treesit-simple-indent-presets'.")
|
||||
|
||||
(defvar treesit-simple-indent-presets
|
||||
'((match . (lambda
|
||||
(&optional node-type parent-type node-field
|
||||
node-index-min node-index-max)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(and (or (null ,node-type)
|
||||
(string-match-p
|
||||
,node-type (or (treesit-node-type node) "")))
|
||||
(or (null ,parent-type)
|
||||
(string-match-p
|
||||
,parent-type (treesit-node-type parent)))
|
||||
(or (null ,node-field)
|
||||
(string-match-p
|
||||
,node-field
|
||||
(or (treesit-node-field-name node) "")))
|
||||
(or (null ,node-index-min)
|
||||
(>= (treesit-node-index node t)
|
||||
,node-index-min))
|
||||
(or (null ,node-index-max)
|
||||
(<= (treesit-node-index node t)
|
||||
,node-index-max))))))
|
||||
`((match . ,(byte-compile
|
||||
(lambda
|
||||
(&optional node-type parent-type node-field
|
||||
node-index-min node-index-max)
|
||||
(lambda (node parent &rest _)
|
||||
(and (or (null node-type)
|
||||
(string-match-p
|
||||
node-type (or (treesit-node-type node) "")))
|
||||
(or (null parent-type)
|
||||
(string-match-p
|
||||
parent-type (treesit-node-type parent)))
|
||||
(or (null node-field)
|
||||
(string-match-p
|
||||
node-field
|
||||
(or (treesit-node-field-name node) "")))
|
||||
(or (null node-index-min)
|
||||
(>= (treesit-node-index node t)
|
||||
node-index-min))
|
||||
(or (null node-index-max)
|
||||
(<= (treesit-node-index node t)
|
||||
node-index-max)))))))
|
||||
;; TODO: Document if genuinely useful.
|
||||
(n-p-gp . (lambda (node-t parent-t grand-parent-t)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(and (or (null ,node-t)
|
||||
(string-match-p
|
||||
,node-t (or (treesit-node-type node) "")))
|
||||
(or (null ,parent-t)
|
||||
(string-match-p
|
||||
,parent-t (treesit-node-type parent)))
|
||||
(or (null ,grand-parent-t)
|
||||
(string-match-p
|
||||
,grand-parent-t
|
||||
(treesit-node-type
|
||||
(treesit-node-parent parent))))))))
|
||||
(no-node . (lambda (node parent bol &rest _) (null node)))
|
||||
(parent-is . (lambda (type)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(string-match-p
|
||||
,type (treesit-node-type parent)))))
|
||||
(n-p-gp . ,(byte-compile
|
||||
(lambda (node-t parent-t grand-parent-t)
|
||||
(lambda (node parent &rest _)
|
||||
(and (or (null node-t)
|
||||
(string-match-p
|
||||
node-t (or (treesit-node-type node) "")))
|
||||
(or (null ,parent-t)
|
||||
(string-match-p
|
||||
parent-t (treesit-node-type parent)))
|
||||
(or (null ,grand-parent-t)
|
||||
(string-match-p
|
||||
grand-parent-t
|
||||
(treesit-node-type
|
||||
(treesit-node-parent parent)))))))))
|
||||
(no-node . ,(byte-compile
|
||||
(lambda (node &rest _) (null node))))
|
||||
(parent-is . ,(byte-compile
|
||||
(lambda (type)
|
||||
(lambda (_n parent &rest _)
|
||||
(string-match-p
|
||||
type (treesit-node-type parent))))))
|
||||
|
||||
(node-is . (lambda (type)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(string-match-p
|
||||
,type (or (treesit-node-type node) "")))))
|
||||
(field-is . (lambda (name)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(node-is . ,(byte-compile
|
||||
(lambda (type)
|
||||
(lambda (node &rest _)
|
||||
(string-match-p
|
||||
,name (or (treesit-node-field-name node) "")))))
|
||||
type (or (treesit-node-type node) ""))))))
|
||||
(field-is . ,(byte-compile
|
||||
(lambda (name)
|
||||
(lambda (node &rest _)
|
||||
(string-match-p
|
||||
name (or (treesit-node-field-name node) ""))))))
|
||||
;; TODO: Document.
|
||||
(catch-all . (lambda (&rest _) t))
|
||||
(catch-all . ,(byte-compile (lambda (&rest _) t)))
|
||||
|
||||
(query . (lambda (pattern)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(cl-loop for capture
|
||||
in (treesit-query-capture
|
||||
parent ,pattern)
|
||||
if (treesit-node-eq node (cdr capture))
|
||||
return t
|
||||
finally return nil))))
|
||||
(first-sibling . (lambda (node parent bol &rest _)
|
||||
(treesit-node-start
|
||||
(treesit-node-child parent 0))))
|
||||
(query . ,(byte-compile
|
||||
(lambda (pattern)
|
||||
(lambda (node parent &rest _)
|
||||
(cl-loop for capture
|
||||
in (treesit-query-capture
|
||||
parent pattern)
|
||||
if (treesit-node-eq node (cdr capture))
|
||||
return t
|
||||
finally return nil)))))
|
||||
(first-sibling . ,(byte-compile
|
||||
(lambda (_n parent &rest _)
|
||||
(treesit-node-start
|
||||
(treesit-node-child parent 0)))))
|
||||
;; TODO: Document.
|
||||
(nth-sibling . (lambda (n &optional named)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(nth-sibling . ,(byte-compile
|
||||
(lambda (n &optional named)
|
||||
(lambda (_n parent &rest _)
|
||||
(treesit-node-start
|
||||
(treesit-node-child parent n named))))))
|
||||
(parent . ,(byte-compile
|
||||
(lambda (_n parent &rest _)
|
||||
(treesit-node-start parent))))
|
||||
;; TODO: Document.
|
||||
(grand-parent . ,(byte-compile
|
||||
(lambda (_n parent &rest _)
|
||||
(treesit-node-start (treesit-node-parent parent)))))
|
||||
(parent-bol . ,(byte-compile
|
||||
(lambda (_n parent &rest _)
|
||||
(save-excursion
|
||||
(goto-char (treesit-node-start parent))
|
||||
(back-to-indentation)
|
||||
(point)))))
|
||||
(prev-sibling . ,(byte-compile
|
||||
(lambda (node &rest _)
|
||||
(treesit-node-start
|
||||
(treesit-node-child parent ,n ,named)))))
|
||||
(parent . (lambda (node parent bol &rest _)
|
||||
(treesit-node-start parent)))
|
||||
(treesit-node-prev-sibling node)))))
|
||||
(no-indent . ,(byte-compile (lambda (_n _p bol &rest _) bol)))
|
||||
(prev-line . ,(byte-compile (lambda (_n _p bol &rest _)
|
||||
(save-excursion
|
||||
(goto-char bol)
|
||||
(forward-line -1)
|
||||
(skip-chars-forward " \t")))))
|
||||
;; TODO: Document.
|
||||
(grand-parent . (lambda (node parent bol &rest _)
|
||||
(treesit-node-start (treesit-node-parent parent))))
|
||||
(parent-bol . (lambda (node parent bol &rest _)
|
||||
(save-excursion
|
||||
(goto-char (treesit-node-start parent))
|
||||
(back-to-indentation)
|
||||
(point))))
|
||||
(prev-sibling . (lambda (node parent bol &rest _)
|
||||
(treesit-node-start
|
||||
(treesit-node-prev-sibling node))))
|
||||
(no-indent . (lambda (node parent bol &rest _) bol))
|
||||
(prev-line . (lambda (node parent bol &rest _)
|
||||
(save-excursion
|
||||
(goto-char bol)
|
||||
(forward-line -1)
|
||||
(skip-chars-forward " \t"))))
|
||||
;; TODO: Document.
|
||||
(and . (lambda (&rest fns)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(cl-reduce (lambda (a b) (and a b))
|
||||
(and . ,(byte-compile
|
||||
(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))))))
|
||||
(or . ,(byte-compile
|
||||
(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)))))
|
||||
(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)))))
|
||||
(not . (lambda (fn)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(debug)
|
||||
(not (funcall ,fn node parent bol)))))
|
||||
(list . (lambda (&rest fns)
|
||||
`(lambda (node parent bol &rest _)
|
||||
(mapcar (lambda (fn)
|
||||
(funcall fn node parent bol))
|
||||
',fns)))))
|
||||
fns))))))
|
||||
(not . ,(byte-compile
|
||||
(lambda (fn)
|
||||
(lambda (node parent bol &rest _)
|
||||
(debug)
|
||||
(not (funcall fn node parent bol))))))
|
||||
(list . ,(byte-compile
|
||||
(lambda (&rest fns)
|
||||
(lambda (node parent bol &rest _)
|
||||
(mapcar (lambda (fn)
|
||||
(funcall fn node parent bol))
|
||||
fns))))))
|
||||
"A list of presets.
|
||||
These presets that can be used as MATHER and ANCHOR in
|
||||
`treesit-simple-indent-rules'.
|
||||
|
|
|
|||
Loading…
Reference in a new issue