]> git.eshelyaron.com Git - emacs.git/commitdiff
Revert "New function treesit-parser-changed-ranges"
authorYuan Fu <casouri@gmail.com>
Wed, 5 Jun 2024 02:55:33 +0000 (19:55 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 5 Jun 2024 10:15:10 +0000 (12:15 +0200)
This reverts commit 996b9576713f9d63ea7ff7e9630a15cb0a0214eb.

For reason see 760b54de080.

(cherry picked from commit 2ee3edce3f5de55fc11997f522cbe2f00a4471fd)

doc/lispref/parsing.texi
etc/NEWS
src/treesit.c
src/treesit.h

index 35ee5cc648d073d7cea57a87399175bff71e6a27..645aad94a639beccdb2ddc9adf34b42fbbe8c07f 100644 (file)
@@ -540,26 +540,6 @@ symbol, rather than a lambda function.
 This function returns the list of @var{parser}'s notifier functions.
 @end defun
 
-Sometimes a Lisp program might need to synchronously get the changed
-ranges of the last reparse.  The function
-@code{treesit-parser-changed-ranges} exists for this purpose.  It
-returns the ranges which were passed to the notifier functions.
-
-@defun treesit-parser-changed-ranges parser &optional quiet
-This function returns the ranges that has been changed since last
-reparse.  It returns a list of cons cells of the form
-@w{@code{(@var{start} . @var{end})}}, where @var{start} and @var{end}
-mark the start and the end positions of a range.
-
-This function should almost always be called immediately after
-reparsing.  If it's called when there are new buffer edits that hasn't
-been reparsed, Emacs signals the @code{treesit-unparsed-edits} error,
-unless the optional argument @var{quiet} is non-nil.
-
-Calling this function multiple times consecutively doesn't change its
-return value; it always returns the ranges affected by the last reparse.
-@end defun
-
 @node Retrieving Nodes
 @section Retrieving Nodes
 @cindex retrieve node, tree-sitter
index f7f4c7dfad23bf17f72288ffb083e797e34ec203..ee458038270e0d4cf1a351566432476cdaf9f827 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3006,24 +3006,6 @@ only return parsers for that language.  If TAG is given, only return
 parsers with that tag.  Note that passing nil as tag doesn't mean return
 all parsers, but rather "all parsers with no tags".
 
-+++
-*** New function 'treesit-parser-changed-ranges'.
-This function returns buffer regions that are affected by the last
-buffer edits.
-
-*** New function 'treesit-add-font-lock-rules'.
-This function helps users to add custom font-lock rules to a tree-sitter
-major mode.
-
----
-** The variable 'rx-constituents' is now obsolete.
-Use 'rx-define', 'rx-let' and 'rx-let-eval' instead.
-
----
-** 'defvar-keymap' can specify hints for 'repeat-mode'.
-Using ':repeat (:hints ((command . "hint") ...))' will show
-the hint string in the echo area together with repeatable keys.
-
 \f
 * Changes in Emacs 30.1 on Non-Free Operating Systems
 
index 52d158b1bf88f6db488c07b7575c7870ab7b4b5b..d86ab5011873ab9e0505e18ab897ccdb2f0ee00e 100644 (file)
@@ -1017,8 +1017,9 @@ treesit_check_buffer_size (struct buffer *buffer)
 
 static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *);
 
-static Lisp_Object
-treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object parser)
+static void
+treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree,
+                                    Lisp_Object parser)
 {
   /* If the old_tree is NULL, meaning this is the first parse, the
      changed range is the whole buffer.  */
@@ -1038,13 +1039,7 @@ treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object pars
       lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil);
       set_buffer_internal (oldbuf);
     }
-  return lisp_ranges;
-}
 
-static void
-treesit_call_after_change_functions (Lisp_Object lisp_ranges,
-                                    Lisp_Object parser)
-{
   specpdl_ref count = SPECPDL_INDEX ();
 
   /* let's trust the after change functions and not clone a new ranges
@@ -1096,17 +1091,13 @@ treesit_ensure_parsed (Lisp_Object parser)
   XTS_PARSER (parser)->tree = new_tree;
   XTS_PARSER (parser)->need_reparse = false;
 
-  Lisp_Object changed_ranges;
-  changed_ranges = treesit_get_changed_ranges (tree, new_tree, parser);
-  XTS_PARSER (parser)->last_changed_ranges = changed_ranges;
-
   /* After-change functions should run at the very end, most crucially
      after need_reparse is set to false, this way if the function
      calls some tree-sitter function which invokes
      treesit_ensure_parsed again, it returns early and do not
      recursively call the after change functions again.
      (ref:notifier-inside-ensure-parsed)  */
-  treesit_call_after_change_functions (changed_ranges, parser);
+  treesit_call_after_change_functions (tree, new_tree, parser);
   ts_tree_delete (tree);
 }
 
@@ -1180,7 +1171,6 @@ make_treesit_parser (Lisp_Object buffer, TSParser *parser,
   lisp_parser->after_change_functions = Qnil;
   lisp_parser->tag = tag;
   lisp_parser->last_set_ranges = Qnil;
-  lisp_parser->last_changed_ranges = Qnil;
   lisp_parser->buffer = buffer;
   lisp_parser->parser = parser;
   lisp_parser->tree = tree;
@@ -1828,32 +1818,6 @@ positions.  PARSER is the parser issuing the notification.   */)
   return Qnil;
 }
 
-DEFUN ("treesit-parser-changed-ranges", Ftreesit_parser_changed_ranges,
-       Streesit_parser_changed_ranges,
-       1, 2, 0,
-       doc: /* Return the buffer regions affected by the last reparse of PARSER.
-
-Returns a list of cons cells (BEG . END), where each cons cell represents
-a region in which changes in buffer contents affected the last reparse.
-
-This function should almost always be called immediately after
-reparsing.  If it's called when there are new buffer edits that hasn't
-been reparsed, Emacs signals the `treesit-unparsed-edits' error, unless
-optional argument QUIET is non-nil.
-
-Calling this function multiple times consecutively doesn't change its
-return value; it always returns the ranges affected by the last
-reparse.  */)
-  (Lisp_Object parser, Lisp_Object quiet)
-{
-  treesit_check_parser (parser);
-
-  if (XTS_PARSER (parser)->need_reparse && NILP (quiet))
-    xsignal1 (Qtreesit_unparsed_edits, parser);
-
-  return XTS_PARSER (parser)->last_changed_ranges;
-}
-
 \f
 /*** Node API  */
 
@@ -4046,7 +4010,6 @@ syms_of_treesit (void)
   DEFSYM (Qtreesit_query_error, "treesit-query-error");
   DEFSYM (Qtreesit_parse_error, "treesit-parse-error");
   DEFSYM (Qtreesit_range_invalid, "treesit-range-invalid");
-  DEFSYM (Qtreesit_unparsed_edits, "treesit-unparsed_edits");
   DEFSYM (Qtreesit_buffer_too_large,
          "treesit-buffer-too-large");
   DEFSYM (Qtreesit_load_language_error,
@@ -4075,8 +4038,6 @@ syms_of_treesit (void)
   define_error (Qtreesit_range_invalid,
                "RANGES are invalid: they have to be ordered and should not overlap",
                Qtreesit_error);
-  define_error (Qtreesit_unparsed_edits, "There are unparsed edits in the buffer",
-               Qtreesit_error);
   define_error (Qtreesit_buffer_too_large, "Buffer too large (> 4GiB)",
                Qtreesit_error);
   define_error (Qtreesit_load_language_error,
@@ -4217,8 +4178,6 @@ the symbol of that THING.  For example, (or sexp sentence).  */);
   defsubr (&Streesit_parser_add_notifier);
   defsubr (&Streesit_parser_remove_notifier);
 
-  defsubr (&Streesit_parser_changed_ranges);
-
   defsubr (&Streesit_node_type);
   defsubr (&Streesit_node_start);
   defsubr (&Streesit_node_end);
index aa71933fe8da960987b6d3342b88e979baae7470..bb81bf0e2b3854daaa5abf18edcaf078d14faaec 100644 (file)
@@ -49,9 +49,6 @@ struct Lisp_TS_Parser
      ranges the users wants to set, and avoid reparse if the new
      ranges is the same as the last set one.  */
   Lisp_Object last_set_ranges;
-  /* The range of buffer content that was affected by the last
-     re-parse.  */
-  Lisp_Object last_changed_ranges;
   /* The buffer associated with this parser.  */
   Lisp_Object buffer;
   /* The pointer to the tree-sitter parser.  Never NULL.  */