Function: treesit-local-parsers-on

treesit-local-parsers-on is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-local-parsers-on &optional BEG END LANGUAGE WITH-HOST)

Documentation

Return the list of local parsers that cover the region between BEG and END.

BEG and END default to the beginning and end of the buffer's accessible portion.

Local parsers are those that have an embedded tag, and only parse a limited region marked by an overlay with a non-nil treesit-parser-local-p property. If LANGUAGE is non-nil, only return parsers for LANGUAGE.

If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER) instead. HOST-PARSER is the host parser which created the local PARSER.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-local-parsers-on (&optional beg end language with-host)
  "Return the list of local parsers that cover the region between BEG and END.

BEG and END default to the beginning and end of the buffer's accessible
portion.

Local parsers are those that have an `embedded' tag, and only parse a
limited region marked by an overlay with a non-nil `treesit-parser-local-p'
property.  If LANGUAGE is non-nil, only return parsers for LANGUAGE.

If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
instead.  HOST-PARSER is the host parser which created the local
PARSER."
  (let ((res nil))
    ;; Refer to (ref:local-parser-overlay) for more explanation of local
    ;; parser overlays.
    (dolist (ov (if (eq beg end)
                    (overlays-at beg)
                  (overlays-in (or beg (point-min)) (or end (point-max)))))
      (let ((parser (overlay-get ov 'treesit-parser))
            (host-parser (overlay-get ov 'treesit-host-parser))
            (local-p (overlay-get ov 'treesit-parser-local-p)))
        (when (and parser host-parser local-p
                   (or (null language)
                       (eq (treesit-parser-language parser)
                           language)))
          (push (if with-host (cons parser host-parser) parser) res))))
    (nreverse res)))