Function: treesit-thing-at

treesit-thing-at is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-thing-at POS THING &optional STRICT)

Documentation

Return the smallest THING enclosing POS.

The returned node, if non-nil, must enclose POS, i.e., its start
<= POS, its end > POS. If STRICT is non-nil, the returned node's
start must < POS rather than <= POS.

THING should be a thing defined in treesit-thing-settings, or it can be a predicate described in treesit-thing-settings.

View in manual

Probably introduced at or before Emacs version 30.1.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-thing-at (pos thing &optional strict)
  "Return the smallest THING enclosing POS.

The returned node, if non-nil, must enclose POS, i.e., its start
<= POS, its end > POS.  If STRICT is non-nil, the returned node's
start must < POS rather than <= POS.

THING should be a thing defined in `treesit-thing-settings', or
it can be a predicate described in `treesit-thing-settings'."
  (let* ((cursor (treesit-node-at pos))
         (iter-pred (lambda (node)
                      (and (treesit-node-match-p node thing t)
                           (if strict
                               (< (treesit-node-start node) pos)
                             (<= (treesit-node-start node) pos))
                           (< pos (treesit-node-end node))))))
    (treesit-parent-until cursor iter-pred t)))