[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
- feature/tree-sitter updated (3114eb8078 -> 6203b9db34), Yuan Fu, 2022/10/23
- feature/tree-sitter 6203b9db34 7/7: * lisp/treesit.el (treesit-node-at): Remove argument LARGEST., Yuan Fu, 2022/10/23
- feature/tree-sitter 524d10c86b 3/7: Make treesit-node-at return the last leaf node at EOB, Yuan Fu, 2022/10/23
- feature/tree-sitter 6cf2a9c55d 4/7: Make treesit-search-forward-goto accept a NODE argument, Yuan Fu, 2022/10/23
- feature/tree-sitter c120b0ebdb 5/7: Fix treesit-beginning/end-of-defun, Yuan Fu, 2022/10/23
- feature/tree-sitter e45d8dbeea 1/7: ; * lisp/treesit.el (treesit-range-functions): Fix typo., Yuan Fu, 2022/10/23
- feature/tree-sitter 591759d508 2/7: Make treesit-node-child and fiends accept negative index, Yuan Fu, 2022/10/23
- feature/tree-sitter 1787e651d3 6/7: * lisp/treesit.el (treesit-parser-range-on): New function.,
Yuan Fu <=