From 1787e651d376486909e736478b1be92c949a368d Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sun, 23 Oct 2022 18:51:35 -0700 Subject: [PATCH] * lisp/treesit.el (treesit-parser-range-on): New function. --- lisp/treesit.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.39.2