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 PARSER)
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.
If PARSER is non-nil, only use that parser's parse tree. Otherwise each parser covering point is tried from most specific (deepest embedded) to least specific. If there are multiple parsers with the same embed level at POS, which parser is tried first is undefined. If PARSER is a language symbol, the parsers tried are limited to ones for that language.
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 parser)
"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'.
If PARSER is non-nil, only use that parser's parse tree. Otherwise each
parser covering point is tried from most specific (deepest embedded) to
least specific. If there are multiple parsers with the same embed level
at POS, which parser is tried first is undefined. If PARSER is a
language symbol, the parsers tried are limited to ones for that
language."
(treesit--some (parser (cond ((null parser)
(treesit-parsers-at pos))
((symbolp parser)
(treesit-parsers-at pos parser))
(t (list parser))))
(let ((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
(treesit-node-at pos parser) iter-pred t))))