Function: treesit-query-range
treesit-query-range is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-query-range NODE QUERY &optional BEG END OFFSET RANGE-FN)
Documentation
Query the current buffer and return ranges of captured nodes.
QUERY, NODE, BEG, END are the same as in treesit-query-capture.
This function returns a list of (START . END), where START and
END specifics the range of each captured node. OFFSET is an
optional pair of numbers (START-OFFSET . END-OFFSET). The
respective offset values are added to each (START . END) range
being returned. Capture names generally don't matter, but names
that starts with an underscore are ignored.
RANGE-FN, if non-nil, is a function that takes a NODE and OFFSET, and returns the ranges to use for that NODE.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-query-range node '((script_element) @cap))
e.g. => ((1 . 4) (5 . 8))
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-query-range (node query &optional beg end offset range-fn)
"Query the current buffer and return ranges of captured nodes.
QUERY, NODE, BEG, END are the same as in `treesit-query-capture'.
This function returns a list of (START . END), where START and
END specifics the range of each captured node. OFFSET is an
optional pair of numbers (START-OFFSET . END-OFFSET). The
respective offset values are added to each (START . END) range
being returned. Capture names generally don't matter, but names
that starts with an underscore are ignored.
RANGE-FN, if non-nil, is a function that takes a NODE and OFFSET, and
returns the ranges to use for that NODE."
(let ((offset-left (or (car offset) 0))
(offset-right (or (cdr offset) 0)))
(cl-loop for capture
in (treesit-query-capture node query beg end)
for name = (car capture)
for node = (cdr capture)
if (not (string-prefix-p "_" (symbol-name name)))
append
(if range-fn
(funcall range-fn node offset)
(list (cons (+ (treesit-node-start node) offset-left)
(+ (treesit-node-end node) offset-right)))))))