Function: treesit-node-on
treesit-node-on is a byte-compiled function defined in treesit.el.gz.
Signature
(treesit-node-on BEG END &optional PARSER-OR-LANG NAMED)
Documentation
Return the smallest node covering BEG to END.
BEWARE! Calling this function on an empty line that is not
inside any top-level construct (function definition, etc.) most
probably will give you the root node, because the root node is
the smallest node that covers that empty line. You probably want
to use treesit-node-at instead.
Return nil if none was found. If NAMED is non-nil, only look for named node.
If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG
is a language, find the first parser for that language in the
current buffer, or create one if none exists; If PARSER-OR-LANG
is nil, try to guess the language at BEG using treesit-language-at.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-node-on 18 28)
e.g. => #<treesit-node (compound_statement) in 143-290>
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-node-on (beg end &optional parser-or-lang named)
"Return the smallest node covering BEG to END.
BEWARE! Calling this function on an empty line that is not
inside any top-level construct (function definition, etc.) most
probably will give you the root node, because the root node is
the smallest node that covers that empty line. You probably want
to use `treesit-node-at' instead.
Return nil if none was found. If NAMED is non-nil, only look for
named node.
If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG
is a language, find the first parser for that language in the
current buffer, or create one if none exists; If PARSER-OR-LANG
is nil, try to guess the language at BEG using `treesit-language-at'."
(let ((root (if (treesit-parser-p parser-or-lang)
(treesit-parser-root-node parser-or-lang)
(treesit-buffer-root-node
(or parser-or-lang (treesit-language-at beg))))))
(treesit-node-descendant-for-range root beg (or end beg) named)))