[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/emacs-30-ts-query-patch 2832871c727: Make treesit-query-compile
From: |
Yuan Fu |
Subject: |
scratch/emacs-30-ts-query-patch 2832871c727: Make treesit-query-compile compile compiled-query eagerly |
Date: |
Mon, 30 Dec 2024 04:50:23 -0500 (EST) |
branch: scratch/emacs-30-ts-query-patch
commit 2832871c727f55aca2580726737f55d10fa6e2e9
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 cda6d4af2ee..ffb1f9afedb 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -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;
}
}