emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter 1787e651d3 6/7: * lisp/treesit.el (treesit-parser-ra


From: Yuan Fu
Subject: feature/tree-sitter 1787e651d3 6/7: * lisp/treesit.el (treesit-parser-range-on): New function.
Date: Sun, 23 Oct 2022 22:07:03 -0400 (EDT)

branch: feature/tree-sitter
commit 1787e651d376486909e736478b1be92c949a368d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    * 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 16c5aab850..0df9b6c687 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]