mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
Make treesit-query-compile compile compiled-query eagerly
* src/treesit.c (treesit_ensure_query_compiled_signal): Extrat out into a function. (Ftreesit_query_compile): If EAGER is non-nil and QUERY is a lazily compiled query, compile it eagerily.
This commit is contained in:
parent
07e9f27c3e
commit
2832871c72
1 changed files with 25 additions and 11 deletions
|
|
@ -1459,6 +1459,20 @@ treesit_ensure_query_compiled (Lisp_Object query, Lisp_Object *signal_symbol,
|
|||
return treesit_query;
|
||||
}
|
||||
|
||||
/* Bsically treesit_ensure_query_compiled but can signal. */
|
||||
static
|
||||
void treesit_ensure_query_compiled_signal (Lisp_Object lisp_query)
|
||||
{
|
||||
Lisp_Object signal_symbol = Qnil;
|
||||
Lisp_Object signal_data = Qnil;
|
||||
TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query,
|
||||
&signal_symbol,
|
||||
&signal_data);
|
||||
|
||||
if (treesit_query == NULL)
|
||||
xsignal (signal_symbol, signal_data);
|
||||
}
|
||||
|
||||
|
||||
/* Lisp definitions. */
|
||||
|
||||
|
|
@ -2919,6 +2933,8 @@ DEFUN ("treesit-query-compile",
|
|||
doc: /* Compile QUERY to a compiled query.
|
||||
|
||||
Querying with a compiled query is much faster than an uncompiled one.
|
||||
So it's a good idea to use compiled query in tight loops, etc.
|
||||
|
||||
LANGUAGE is the language this query is for.
|
||||
|
||||
If EAGER is non-nil, immediately load LANGUAGE and compile the query.
|
||||
|
|
@ -2932,11 +2948,17 @@ You can use `treesit-query-validate' to validate and debug a query. */)
|
|||
if (NILP (Ftreesit_query_p (query)))
|
||||
wrong_type_argument (Qtreesit_query_p, query);
|
||||
CHECK_SYMBOL (language);
|
||||
if (TS_COMPILED_QUERY_P (query))
|
||||
return query;
|
||||
|
||||
treesit_initialize ();
|
||||
|
||||
if (TS_COMPILED_QUERY_P (query))
|
||||
{
|
||||
if (NILP (eager))
|
||||
return query;
|
||||
treesit_ensure_query_compiled_signal (query);
|
||||
return query;
|
||||
}
|
||||
|
||||
Lisp_Object lisp_query = make_treesit_query (query, language);
|
||||
|
||||
/* Maybe actually compile. */
|
||||
|
|
@ -2944,15 +2966,7 @@ You can use `treesit-query-validate' to validate and debug a query. */)
|
|||
return lisp_query;
|
||||
else
|
||||
{
|
||||
Lisp_Object signal_symbol = Qnil;
|
||||
Lisp_Object signal_data = Qnil;
|
||||
TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query,
|
||||
&signal_symbol,
|
||||
&signal_data);
|
||||
|
||||
if (treesit_query == NULL)
|
||||
xsignal (signal_symbol, signal_data);
|
||||
|
||||
treesit_ensure_query_compiled_signal (lisp_query);
|
||||
return lisp_query;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue