diff options
| -rw-r--r-- | doc/lispref/parsing.texi | 20 | ||||
| -rw-r--r-- | etc/NEWS | 18 | ||||
| -rw-r--r-- | src/treesit.c | 49 | ||||
| -rw-r--r-- | src/treesit.h | 3 |
4 files changed, 4 insertions, 86 deletions
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 35ee5cc648d..645aad94a63 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi | |||
| @@ -540,26 +540,6 @@ symbol, rather than a lambda function. | |||
| 540 | This function returns the list of @var{parser}'s notifier functions. | 540 | This function returns the list of @var{parser}'s notifier functions. |
| 541 | @end defun | 541 | @end defun |
| 542 | 542 | ||
| 543 | Sometimes a Lisp program might need to synchronously get the changed | ||
| 544 | ranges of the last reparse. The function | ||
| 545 | @code{treesit-parser-changed-ranges} exists for this purpose. It | ||
| 546 | returns the ranges which were passed to the notifier functions. | ||
| 547 | |||
| 548 | @defun treesit-parser-changed-ranges parser &optional quiet | ||
| 549 | This function returns the ranges that has been changed since last | ||
| 550 | reparse. It returns a list of cons cells of the form | ||
| 551 | @w{@code{(@var{start} . @var{end})}}, where @var{start} and @var{end} | ||
| 552 | mark the start and the end positions of a range. | ||
| 553 | |||
| 554 | This function should almost always be called immediately after | ||
| 555 | reparsing. If it's called when there are new buffer edits that hasn't | ||
| 556 | been reparsed, Emacs signals the @code{treesit-unparsed-edits} error, | ||
| 557 | unless the optional argument @var{quiet} is non-nil. | ||
| 558 | |||
| 559 | Calling this function multiple times consecutively doesn't change its | ||
| 560 | return value; it always returns the ranges affected by the last reparse. | ||
| 561 | @end defun | ||
| 562 | |||
| 563 | @node Retrieving Nodes | 543 | @node Retrieving Nodes |
| 564 | @section Retrieving Nodes | 544 | @section Retrieving Nodes |
| 565 | @cindex retrieve node, tree-sitter | 545 | @cindex retrieve node, tree-sitter |
| @@ -2872,24 +2872,6 @@ only return parsers for that language. If TAG is given, only return | |||
| 2872 | parsers with that tag. Note that passing nil as tag doesn't mean return | 2872 | parsers with that tag. Note that passing nil as tag doesn't mean return |
| 2873 | all parsers, but rather "all parsers with no tags". | 2873 | all parsers, but rather "all parsers with no tags". |
| 2874 | 2874 | ||
| 2875 | +++ | ||
| 2876 | *** New function 'treesit-parser-changed-ranges'. | ||
| 2877 | This function returns buffer regions that are affected by the last | ||
| 2878 | buffer edits. | ||
| 2879 | |||
| 2880 | *** New function 'treesit-add-font-lock-rules'. | ||
| 2881 | This function helps users to add custom font-lock rules to a tree-sitter | ||
| 2882 | major mode. | ||
| 2883 | |||
| 2884 | --- | ||
| 2885 | ** The variable 'rx-constituents' is now obsolete. | ||
| 2886 | Use 'rx-define', 'rx-let' and 'rx-let-eval' instead. | ||
| 2887 | |||
| 2888 | --- | ||
| 2889 | ** 'defvar-keymap' can specify hints for 'repeat-mode'. | ||
| 2890 | Using ':repeat (:hints ((command . "hint") ...))' will show | ||
| 2891 | the hint string in the echo area together with repeatable keys. | ||
| 2892 | |||
| 2893 | 2875 | ||
| 2894 | * Changes in Emacs 30.1 on Non-Free Operating Systems | 2876 | * Changes in Emacs 30.1 on Non-Free Operating Systems |
| 2895 | 2877 | ||
diff --git a/src/treesit.c b/src/treesit.c index 52d158b1bf8..d86ab501187 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -1017,8 +1017,9 @@ treesit_check_buffer_size (struct buffer *buffer) | |||
| 1017 | 1017 | ||
| 1018 | static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *); | 1018 | static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *); |
| 1019 | 1019 | ||
| 1020 | static Lisp_Object | 1020 | static void |
| 1021 | treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object parser) | 1021 | treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree, |
| 1022 | Lisp_Object parser) | ||
| 1022 | { | 1023 | { |
| 1023 | /* If the old_tree is NULL, meaning this is the first parse, the | 1024 | /* If the old_tree is NULL, meaning this is the first parse, the |
| 1024 | changed range is the whole buffer. */ | 1025 | changed range is the whole buffer. */ |
| @@ -1038,13 +1039,7 @@ treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object pars | |||
| 1038 | lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil); | 1039 | lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil); |
| 1039 | set_buffer_internal (oldbuf); | 1040 | set_buffer_internal (oldbuf); |
| 1040 | } | 1041 | } |
| 1041 | return lisp_ranges; | ||
| 1042 | } | ||
| 1043 | 1042 | ||
| 1044 | static void | ||
| 1045 | treesit_call_after_change_functions (Lisp_Object lisp_ranges, | ||
| 1046 | Lisp_Object parser) | ||
| 1047 | { | ||
| 1048 | specpdl_ref count = SPECPDL_INDEX (); | 1043 | specpdl_ref count = SPECPDL_INDEX (); |
| 1049 | 1044 | ||
| 1050 | /* let's trust the after change functions and not clone a new ranges | 1045 | /* let's trust the after change functions and not clone a new ranges |
| @@ -1096,17 +1091,13 @@ treesit_ensure_parsed (Lisp_Object parser) | |||
| 1096 | XTS_PARSER (parser)->tree = new_tree; | 1091 | XTS_PARSER (parser)->tree = new_tree; |
| 1097 | XTS_PARSER (parser)->need_reparse = false; | 1092 | XTS_PARSER (parser)->need_reparse = false; |
| 1098 | 1093 | ||
| 1099 | Lisp_Object changed_ranges; | ||
| 1100 | changed_ranges = treesit_get_changed_ranges (tree, new_tree, parser); | ||
| 1101 | XTS_PARSER (parser)->last_changed_ranges = changed_ranges; | ||
| 1102 | |||
| 1103 | /* After-change functions should run at the very end, most crucially | 1094 | /* After-change functions should run at the very end, most crucially |
| 1104 | after need_reparse is set to false, this way if the function | 1095 | after need_reparse is set to false, this way if the function |
| 1105 | calls some tree-sitter function which invokes | 1096 | calls some tree-sitter function which invokes |
| 1106 | treesit_ensure_parsed again, it returns early and do not | 1097 | treesit_ensure_parsed again, it returns early and do not |
| 1107 | recursively call the after change functions again. | 1098 | recursively call the after change functions again. |
| 1108 | (ref:notifier-inside-ensure-parsed) */ | 1099 | (ref:notifier-inside-ensure-parsed) */ |
| 1109 | treesit_call_after_change_functions (changed_ranges, parser); | 1100 | treesit_call_after_change_functions (tree, new_tree, parser); |
| 1110 | ts_tree_delete (tree); | 1101 | ts_tree_delete (tree); |
| 1111 | } | 1102 | } |
| 1112 | 1103 | ||
| @@ -1180,7 +1171,6 @@ make_treesit_parser (Lisp_Object buffer, TSParser *parser, | |||
| 1180 | lisp_parser->after_change_functions = Qnil; | 1171 | lisp_parser->after_change_functions = Qnil; |
| 1181 | lisp_parser->tag = tag; | 1172 | lisp_parser->tag = tag; |
| 1182 | lisp_parser->last_set_ranges = Qnil; | 1173 | lisp_parser->last_set_ranges = Qnil; |
| 1183 | lisp_parser->last_changed_ranges = Qnil; | ||
| 1184 | lisp_parser->buffer = buffer; | 1174 | lisp_parser->buffer = buffer; |
| 1185 | lisp_parser->parser = parser; | 1175 | lisp_parser->parser = parser; |
| 1186 | lisp_parser->tree = tree; | 1176 | lisp_parser->tree = tree; |
| @@ -1828,32 +1818,6 @@ positions. PARSER is the parser issuing the notification. */) | |||
| 1828 | return Qnil; | 1818 | return Qnil; |
| 1829 | } | 1819 | } |
| 1830 | 1820 | ||
| 1831 | DEFUN ("treesit-parser-changed-ranges", Ftreesit_parser_changed_ranges, | ||
| 1832 | Streesit_parser_changed_ranges, | ||
| 1833 | 1, 2, 0, | ||
| 1834 | doc: /* Return the buffer regions affected by the last reparse of PARSER. | ||
| 1835 | |||
| 1836 | Returns a list of cons cells (BEG . END), where each cons cell represents | ||
| 1837 | a region in which changes in buffer contents affected the last reparse. | ||
| 1838 | |||
| 1839 | This function should almost always be called immediately after | ||
| 1840 | reparsing. If it's called when there are new buffer edits that hasn't | ||
| 1841 | been reparsed, Emacs signals the `treesit-unparsed-edits' error, unless | ||
| 1842 | optional argument QUIET is non-nil. | ||
| 1843 | |||
| 1844 | Calling this function multiple times consecutively doesn't change its | ||
| 1845 | return value; it always returns the ranges affected by the last | ||
| 1846 | reparse. */) | ||
| 1847 | (Lisp_Object parser, Lisp_Object quiet) | ||
| 1848 | { | ||
| 1849 | treesit_check_parser (parser); | ||
| 1850 | |||
| 1851 | if (XTS_PARSER (parser)->need_reparse && NILP (quiet)) | ||
| 1852 | xsignal1 (Qtreesit_unparsed_edits, parser); | ||
| 1853 | |||
| 1854 | return XTS_PARSER (parser)->last_changed_ranges; | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | 1821 | ||
| 1858 | /*** Node API */ | 1822 | /*** Node API */ |
| 1859 | 1823 | ||
| @@ -4046,7 +4010,6 @@ syms_of_treesit (void) | |||
| 4046 | DEFSYM (Qtreesit_query_error, "treesit-query-error"); | 4010 | DEFSYM (Qtreesit_query_error, "treesit-query-error"); |
| 4047 | DEFSYM (Qtreesit_parse_error, "treesit-parse-error"); | 4011 | DEFSYM (Qtreesit_parse_error, "treesit-parse-error"); |
| 4048 | DEFSYM (Qtreesit_range_invalid, "treesit-range-invalid"); | 4012 | DEFSYM (Qtreesit_range_invalid, "treesit-range-invalid"); |
| 4049 | DEFSYM (Qtreesit_unparsed_edits, "treesit-unparsed_edits"); | ||
| 4050 | DEFSYM (Qtreesit_buffer_too_large, | 4013 | DEFSYM (Qtreesit_buffer_too_large, |
| 4051 | "treesit-buffer-too-large"); | 4014 | "treesit-buffer-too-large"); |
| 4052 | DEFSYM (Qtreesit_load_language_error, | 4015 | DEFSYM (Qtreesit_load_language_error, |
| @@ -4075,8 +4038,6 @@ syms_of_treesit (void) | |||
| 4075 | define_error (Qtreesit_range_invalid, | 4038 | define_error (Qtreesit_range_invalid, |
| 4076 | "RANGES are invalid: they have to be ordered and should not overlap", | 4039 | "RANGES are invalid: they have to be ordered and should not overlap", |
| 4077 | Qtreesit_error); | 4040 | Qtreesit_error); |
| 4078 | define_error (Qtreesit_unparsed_edits, "There are unparsed edits in the buffer", | ||
| 4079 | Qtreesit_error); | ||
| 4080 | define_error (Qtreesit_buffer_too_large, "Buffer too large (> 4GiB)", | 4041 | define_error (Qtreesit_buffer_too_large, "Buffer too large (> 4GiB)", |
| 4081 | Qtreesit_error); | 4042 | Qtreesit_error); |
| 4082 | define_error (Qtreesit_load_language_error, | 4043 | define_error (Qtreesit_load_language_error, |
| @@ -4217,8 +4178,6 @@ the symbol of that THING. For example, (or sexp sentence). */); | |||
| 4217 | defsubr (&Streesit_parser_add_notifier); | 4178 | defsubr (&Streesit_parser_add_notifier); |
| 4218 | defsubr (&Streesit_parser_remove_notifier); | 4179 | defsubr (&Streesit_parser_remove_notifier); |
| 4219 | 4180 | ||
| 4220 | defsubr (&Streesit_parser_changed_ranges); | ||
| 4221 | |||
| 4222 | defsubr (&Streesit_node_type); | 4181 | defsubr (&Streesit_node_type); |
| 4223 | defsubr (&Streesit_node_start); | 4182 | defsubr (&Streesit_node_start); |
| 4224 | defsubr (&Streesit_node_end); | 4183 | defsubr (&Streesit_node_end); |
diff --git a/src/treesit.h b/src/treesit.h index aa71933fe8d..bb81bf0e2b3 100644 --- a/src/treesit.h +++ b/src/treesit.h | |||
| @@ -49,9 +49,6 @@ struct Lisp_TS_Parser | |||
| 49 | ranges the users wants to set, and avoid reparse if the new | 49 | ranges the users wants to set, and avoid reparse if the new |
| 50 | ranges is the same as the last set one. */ | 50 | ranges is the same as the last set one. */ |
| 51 | Lisp_Object last_set_ranges; | 51 | Lisp_Object last_set_ranges; |
| 52 | /* The range of buffer content that was affected by the last | ||
| 53 | re-parse. */ | ||
| 54 | Lisp_Object last_changed_ranges; | ||
| 55 | /* The buffer associated with this parser. */ | 52 | /* The buffer associated with this parser. */ |
| 56 | Lisp_Object buffer; | 53 | Lisp_Object buffer; |
| 57 | /* The pointer to the tree-sitter parser. Never NULL. */ | 54 | /* The pointer to the tree-sitter parser. Never NULL. */ |