aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuan Fu2024-12-02 20:14:55 -0800
committerYuan Fu2024-12-04 22:39:28 -0800
commit4ecd1639b19345786020c0f7a5f3672129dae466 (patch)
treed963fd295de18ed74b6bd8431f12ecbfb8d1517a /src
parent5d535334f30b874ebb8e2c286c1e059d86ccd41f (diff)
downloademacs-4ecd1639b19345786020c0f7a5f3672129dae466.tar.gz
emacs-4ecd1639b19345786020c0f7a5f3672129dae466.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c36
1 files 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,
1516 return treesit_query; 1516 return treesit_query;
1517} 1517}
1518 1518
1519/* Bsically treesit_ensure_query_compiled but can signal. */
1520static
1521void treesit_ensure_query_compiled_signal (Lisp_Object lisp_query)
1522{
1523 Lisp_Object signal_symbol = Qnil;
1524 Lisp_Object signal_data = Qnil;
1525 TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query,
1526 &signal_symbol,
1527 &signal_data);
1528
1529 if (treesit_query == NULL)
1530 xsignal (signal_symbol, signal_data);
1531}
1532
1519/* Resolve language symbol LANG according to 1533/* Resolve language symbol LANG according to
1520 treesit-language-remap-alist. */ 1534 treesit-language-remap-alist. */
1521static 1535static
@@ -3051,6 +3065,8 @@ DEFUN ("treesit-query-compile",
3051 doc: /* Compile QUERY to a compiled query. 3065 doc: /* Compile QUERY to a compiled query.
3052 3066
3053Querying with a compiled query is much faster than an uncompiled one. 3067Querying with a compiled query is much faster than an uncompiled one.
3068So it's a good idea to use compiled query in tight loops, etc.
3069
3054LANGUAGE is the language this query is for. 3070LANGUAGE is the language this query is for.
3055 3071
3056If EAGER is non-nil, immediately load LANGUAGE and compile the query. 3072If 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. */)
3064 if (NILP (Ftreesit_query_p (query))) 3080 if (NILP (Ftreesit_query_p (query)))
3065 wrong_type_argument (Qtreesit_query_p, query); 3081 wrong_type_argument (Qtreesit_query_p, query);
3066 CHECK_SYMBOL (language); 3082 CHECK_SYMBOL (language);
3067 if (TS_COMPILED_QUERY_P (query))
3068 return query;
3069 3083
3070 treesit_initialize (); 3084 treesit_initialize ();
3071 3085
3086 if (TS_COMPILED_QUERY_P (query))
3087 {
3088 if (NILP (eager))
3089 return query;
3090 treesit_ensure_query_compiled_signal (query);
3091 return query;
3092 }
3093
3072 Lisp_Object lisp_query = make_treesit_query (query, language); 3094 Lisp_Object lisp_query = make_treesit_query (query, language);
3073 3095
3074 /* Maybe actually compile. */ 3096 /* Maybe actually compile. */
@@ -3076,15 +3098,7 @@ You can use `treesit-query-validate' to validate and debug a query. */)
3076 return lisp_query; 3098 return lisp_query;
3077 else 3099 else
3078 { 3100 {
3079 Lisp_Object signal_symbol = Qnil; 3101 treesit_ensure_query_compiled_signal (lisp_query);
3080 Lisp_Object signal_data = Qnil;
3081 TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query,
3082 &signal_symbol,
3083 &signal_data);
3084
3085 if (treesit_query == NULL)
3086 xsignal (signal_symbol, signal_data);
3087
3088 return lisp_query; 3102 return lisp_query;
3089 } 3103 }
3090} 3104}