Function: treesit-parent-while
treesit-parent-while is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-parent-while NODE PRED)
Documentation
Return the furthest parent of NODE (including NODE) that satisfies PRED.
This function successively examines NODE, the parent of NODE, then the parent of the parent, etc., until it finds a node which no longer satisfies the predicate PRED; it returns the last examined node that satisfies PRED. If no node satisfies PRED, it returns nil.
PRED can be a predicate function, a regexp matching node type,
and more; see docstring of treesit-thing-settings.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-parent-while node (lambda (p) (eq (treesit-node-start p) (point))))
e.g. => #<treesit-node (declaration) in 1-11>
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-parent-while (node pred)
"Return the furthest parent of NODE (including NODE) that satisfies PRED.
This function successively examines NODE, the parent of NODE,
then the parent of the parent, etc., until it finds a node which
no longer satisfies the predicate PRED; it returns the last
examined node that satisfies PRED. If no node satisfies PRED, it
returns nil.
PRED can be a predicate function, a regexp matching node type,
and more; see docstring of `treesit-thing-settings'."
(let ((last nil))
(while (and node (treesit-node-match-p node pred))
(setq last node
node (treesit-node-parent node)))
last))