[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 4ecd1639b19 3/4: Make treesit-query-compile compile compiled-quer
From: |
Yuan Fu |
Subject: |
master 4ecd1639b19 3/4: Make treesit-query-compile compile compiled-query eagerly |
Date: |
Thu, 5 Dec 2024 01:44:39 -0500 (EST) |
branch: master
commit 4ecd1639b19345786020c0f7a5f3672129dae466
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
src/treesit.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/treesit.c b/src/treesit.c
index 2372944e166..28c94f307c0 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1516,6 +1516,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);
+}
+
/* Resolve language symbol LANG according to
treesit-language-remap-alist. */
static
@@ -3051,6 +3065,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.
@@ -3064,11 +3080,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. */
@@ -3076,15 +3098,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;
}
}