Function: treesit-parent-until

treesit-parent-until is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-parent-until NODE PRED &optional INCLUDE-NODE)

Documentation

Return the closest parent of NODE that satisfies PRED.

This function successively examines the parent of NODE, then the parent of the parent, etc., until it finds the first ancestor node which satisfies the predicate PRED; then it returns that ancestor node. It returns nil if no ancestor node was found that satisfies PRED.

PRED should be a function that takes one argument, the node to examine, and returns a boolean value indicating whether that node is a match.

If INCLUDE-NODE is non-nil, return NODE if it satisfies PRED.

Other relevant functions are documented in the treesit group.

View in manual

Shortdoc

;; treesit
(treesit-parent-until 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-until (node pred &optional include-node)
  "Return the closest parent of NODE that satisfies PRED.

This function successively examines the parent of NODE, then
the parent of the parent, etc., until it finds the first
ancestor node which satisfies the predicate PRED; then it
returns that ancestor node.  It returns nil if no ancestor
node was found that satisfies PRED.

PRED should be a function that takes one argument, the node to
examine, and returns a boolean value indicating whether that
node is a match.

If INCLUDE-NODE is non-nil, return NODE if it satisfies PRED."
  (let ((node (if include-node node
                (treesit-node-parent node))))
    (while (and node (not (funcall pred node)))
      (setq node (treesit-node-parent node)))
    node))