From: Yuan Fu Date: Mon, 24 Oct 2022 01:51:35 +0000 (-0700) Subject: * lisp/treesit.el (treesit-parser-range-on): New function. X-Git-Tag: emacs-29.0.90~1793 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1787e651d376486909e736478b1be92c949a368d;p=emacs.git * lisp/treesit.el (treesit-parser-range-on): New function. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 16c5aab8507..0df9b6c6876 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -298,6 +298,21 @@ in-order. START and END are passed to each range function." (dolist (range-fn treesit-range-functions) (funcall range-fn (or start (point-min)) (or end (point-max))))) +(defun treesit-parser-range-on (parser beg &optional end) + "Check if PARSER's range covers the portion between BEG and END. + +If it does, return the range covering that portion in the form +of (RANGE-BEG . RANGE-END), if not, return nil. If nil or +omitted, default END to BEG." + (let ((ranges (treesit-parser-included-ranges parser)) + (end (or end beg))) + (if (null ranges) + (cons (point-min) (point-max)) + (cl-loop for rng in ranges + if (<= (car rng) beg end (cdr rng)) + return rng + finally return nil)))) + ;;; Font-lock (define-error 'treesit-font-lock-error