]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a synchronous way to get parser change ranges (bug#78402)
authorYuan Fu <casouri@gmail.com>
Wed, 9 Jul 2025 06:14:20 +0000 (23:14 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 07:52:14 +0000 (09:52 +0200)
This commit only adds the new function, the fix for the bug is
in the next commit.

* doc/lispref/parsing.texi (Using Parser): Add docs.
* lisp/treesit.el (treesit): Add shortdoc.
* src/treesit.c (treesit_get_affected_ranges): New function
extracted from treesit_call_after_change_functions.
(treesit_call_after_change_functions): Extract out.
(treesit_ensure_parsed): Return affected regions.
(Ftreesit_parser_changed_regions): New function that returns the
affected regions.

(cherry picked from commit 564b947745b2a685edcd93eb8f0d8825352030b8)

doc/lispref/parsing.texi
lisp/treesit.el

index 922ba217920ef7a43a44899b7dc840dcfe1fb01e..91dc5d35e5444486808bf7faa029c32c3425f463 100644 (file)
@@ -573,6 +573,17 @@ symbol, rather than a lambda function.
 This function returns the list of @var{parser}'s notifier functions.
 @end defun
 
+A lisp program can also choose to force a parser to reparse and get the
+changed regions immediately with @code{treesit-parser-changed-regions}.
+
+@defun treesit-parser-changed-regions parser
+This function force @var{parser} to reparse, and return the affected
+regions: a list of @w{@code{(@var{start} . @var{end})}}.  If the parser
+has nothing new to reparse, or the affected regions are empty,
+@code{nil} is returned.
+@end defun
+
+
 @heading Substitute parser for another language
 @cindex remap language grammar, tree-sitter
 @cindex replace language grammar, tree-sitter
index dfe7efe7d4fbf7d5b13bb236f8d776a14e423d09..a137160b382694e1f68a38c60b8441602fd746e4 100644 (file)
@@ -5430,6 +5430,19 @@ Tree-sitter grammar for `%s' is missing; install it?"
   (treesit-parser-language
    :no-eval (treesit-parser-language parser)
    :eg-result c)
+  (treesit-parser-tag
+   :no-eval (treesit-parser-tag parser)
+   :eg-result 'embeded)
+  (treesit-parser-changed-regions
+   :no-eval (treesit-parser-changed-regions parser)
+   :eg-result '((1 . 10) (24 . 58)))
+
+  (treesit-parser-embed-level
+   :no-eval (treesit-parser-embed-level parser)
+   :eg-result 1)
+  (treesit-parser-set-embed-level
+   :no-eval (treesit-parser-set-embed-level parser 1))
+
   (treesit-parser-add-notifier)
   (treesit-parser-remove-notifier)
   (treesit-parser-notifiers