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)

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. Capture names generally don't matter, but names that starts with an underscore are ignored.

Other relevant functions are documented in the treesit group.

View in manual

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)
  "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.  Capture names
generally don't matter, but names that starts with an underscore
are ignored."
  (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)))
           collect (cons (treesit-node-start node)
                         (treesit-node-end node))))