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 node enclosing POS for THING.
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 be < POS rather than <= POS.
THING should be a thing defined in treesit-thing-settings for
the current buffer's major mode, or it can be a predicate
described in treesit-thing-settings.
Other relevant functions are documented in the treesit group.
Probably introduced at or before Emacs version 30.1.
Shortdoc
;; treesit
(treesit-thing-at 3943)
e.g. => #<treesit-node (identifier) in 3941-3949>
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-thing-at (pos thing &optional strict)
"Return the smallest node enclosing POS for THING.
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 be < POS rather than <= POS.
THING should be a thing defined in `treesit-thing-settings' for
the current buffer's major mode, 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)))