Function: treesit-node-top-level
treesit-node-top-level is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-node-top-level NODE &optional PRED INCLUDE-NODE)
Documentation
Return the top-level equivalent of NODE.
Specifically, return the highest parent of NODE that has the same type as it. If no such parent exists, return nil.
If PRED is non-nil, match each parent's type with PRED as a regexp, rather than using NODE's type. PRED can also be a function that takes the node as an argument, and return non-nil/nil for match/no match.
If INCLUDE-NODE is non-nil, return NODE if it satisfies PRED.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-node-top-level node)
e.g. => #<treesit-node (declaration) in 1-11>
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-node-top-level (node &optional pred include-node)
"Return the top-level equivalent of NODE.
Specifically, return the highest parent of NODE that has the same
type as it. If no such parent exists, return nil.
If PRED is non-nil, match each parent's type with PRED as a
regexp, rather than using NODE's type. PRED can also be a
function that takes the node as an argument, and return
non-nil/nil for match/no match.
If INCLUDE-NODE is non-nil, return NODE if it satisfies PRED."
(let ((pred (or pred (treesit-node-type node)))
(result nil))
(cl-loop for cursor = (if include-node node
(treesit-node-parent node))
then (treesit-node-parent cursor)
while cursor
if (if (stringp pred)
(string-match-p pred (treesit-node-type cursor))
(funcall pred cursor))
do (setq result cursor))
result))