Function: treesit--explorer--nodes-to-highlight

treesit--explorer--nodes-to-highlight is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit--explorer--nodes-to-highlight PARSER)

Documentation

Return nodes for PARSER covered in region.

This function tries to return the largest node possible. If the region covers exactly one node, that node is returned (in a list). If the region covers more than one node, two nodes are returned: the very first one in the region and the very last one in the region.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--explorer--nodes-to-highlight (parser)
  "Return nodes for PARSER covered in region.
This function tries to return the largest node possible.  If the
region covers exactly one node, that node is returned (in a
list).  If the region covers more than one node, two nodes are
returned: the very first one in the region and the very last one
in the region."
  (let* ((beg (region-beginning))
         (end (region-end))
         (node (treesit-node-on beg end parser))
         (node (or (treesit-parent-while
                    node
                    (lambda (n)
                      (<= beg (treesit-node-start n)
                          (treesit-node-end n) end)))
                   node)))
    ;; If NODE is completely contained in the region, return NODE,
    ;; otherwise return its children that are in the region.
    (if (<= beg (treesit-node-start node)
            (treesit-node-end node) end)
        (list node)
      (list (treesit-node-at beg)
            (treesit-search-forward
             (treesit-node-at end)
             (lambda (n)
               (<= (treesit-node-end n) end))
             t t)))))