Function: treesit-thing-at-point

treesit-thing-at-point is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-thing-at-point PATTERN TACTIC)

Documentation

Return the thing node at point or nil if none is found.

"Thing" is defined by PATTERN, which can be either a string
REGEXP or a cons cell (REGEXP . PRED): if a node's type matches REGEXP, it is a thing. The "thing" could be further restricted by PRED: if non-nil, PRED should be a function that takes a node and returns t if the node is a "thing", and nil if not.

Return the top-level defun if TACTIC is top-level(var)/top-level(fun), return the immediate parent thing if TACTIC is nested.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
;; TODO: In corporate into thing-at-point.
(defun treesit-thing-at-point (pattern tactic)
  "Return the thing node at point or nil if none is found.

\"Thing\" is defined by PATTERN, which can be either a string
REGEXP or a cons cell (REGEXP . PRED): if a node's type matches
REGEXP, it is a thing.  The \"thing\" could be further restricted
by PRED: if non-nil, PRED should be a function that takes a node
and returns t if the node is a \"thing\", and nil if not.

Return the top-level defun if TACTIC is `top-level', return the
immediate parent thing if TACTIC is `nested'."
  (pcase-let* ((`(,regexp . ,pred)
                (treesit--thing-unpack-pattern pattern))
               (`(,_ ,next ,parent)
                (treesit--things-around (point) regexp pred))
               ;; If point is at the beginning of a thing, we
               ;; prioritize that thing over the parent in nested
               ;; mode.
               (node (or (and (eq (treesit-node-start next) (point))
                              next)
                         parent)))
    (if (eq tactic 'top-level)
        (treesit--top-level-thing node regexp pred)
      node)))