diff options
| author | Yuan Fu | 2024-12-02 20:14:55 -0800 |
|---|---|---|
| committer | Yuan Fu | 2024-12-30 01:45:34 -0800 |
| commit | 2832871c727f55aca2580726737f55d10fa6e2e9 (patch) | |
| tree | 732bbe6d999f00872a9557fcebb6471bd34ed120 | |
| parent | 07e9f27c3e029a52669ddcf68d4ecddba0f7903e (diff) | |
| download | emacs-scratch/emacs-30-ts-query-patch.tar.gz emacs-scratch/emacs-30-ts-query-patch.zip | |
Make treesit-query-compile compile compiled-query eagerlyscratch/emacs-30-ts-query-patch
* 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.
| -rw-r--r-- | src/treesit.c | 36 |
1 files 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, | |||
| 1459 | return treesit_query; | 1459 | return treesit_query; |
| 1460 | } | 1460 | } |
| 1461 | 1461 | ||
| 1462 | /* Bsically treesit_ensure_query_compiled but can signal. */ | ||
| 1463 | static | ||
| 1464 | void treesit_ensure_query_compiled_signal (Lisp_Object lisp_query) | ||
| 1465 | { | ||
| 1466 | Lisp_Object signal_symbol = Qnil; | ||
| 1467 | Lisp_Object signal_data = Qnil; | ||
| 1468 | TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query, | ||
| 1469 | &signal_symbol, | ||
| 1470 | &signal_data); | ||
| 1471 | |||
| 1472 | if (treesit_query == NULL) | ||
| 1473 | xsignal (signal_symbol, signal_data); | ||
| 1474 | } | ||
| 1475 | |||
| 1462 | 1476 | ||
| 1463 | /* Lisp definitions. */ | 1477 | /* Lisp definitions. */ |
| 1464 | 1478 | ||
| @@ -2919,6 +2933,8 @@ DEFUN ("treesit-query-compile", | |||
| 2919 | doc: /* Compile QUERY to a compiled query. | 2933 | doc: /* Compile QUERY to a compiled query. |
| 2920 | 2934 | ||
| 2921 | Querying with a compiled query is much faster than an uncompiled one. | 2935 | Querying with a compiled query is much faster than an uncompiled one. |
| 2936 | So it's a good idea to use compiled query in tight loops, etc. | ||
| 2937 | |||
| 2922 | LANGUAGE is the language this query is for. | 2938 | LANGUAGE is the language this query is for. |
| 2923 | 2939 | ||
| 2924 | If EAGER is non-nil, immediately load LANGUAGE and compile the query. | 2940 | 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. */) | |||
| 2932 | if (NILP (Ftreesit_query_p (query))) | 2948 | if (NILP (Ftreesit_query_p (query))) |
| 2933 | wrong_type_argument (Qtreesit_query_p, query); | 2949 | wrong_type_argument (Qtreesit_query_p, query); |
| 2934 | CHECK_SYMBOL (language); | 2950 | CHECK_SYMBOL (language); |
| 2935 | if (TS_COMPILED_QUERY_P (query)) | ||
| 2936 | return query; | ||
| 2937 | 2951 | ||
| 2938 | treesit_initialize (); | 2952 | treesit_initialize (); |
| 2939 | 2953 | ||
| 2954 | if (TS_COMPILED_QUERY_P (query)) | ||
| 2955 | { | ||
| 2956 | if (NILP (eager)) | ||
| 2957 | return query; | ||
| 2958 | treesit_ensure_query_compiled_signal (query); | ||
| 2959 | return query; | ||
| 2960 | } | ||
| 2961 | |||
| 2940 | Lisp_Object lisp_query = make_treesit_query (query, language); | 2962 | Lisp_Object lisp_query = make_treesit_query (query, language); |
| 2941 | 2963 | ||
| 2942 | /* Maybe actually compile. */ | 2964 | /* Maybe actually compile. */ |
| @@ -2944,15 +2966,7 @@ You can use `treesit-query-validate' to validate and debug a query. */) | |||
| 2944 | return lisp_query; | 2966 | return lisp_query; |
| 2945 | else | 2967 | else |
| 2946 | { | 2968 | { |
| 2947 | Lisp_Object signal_symbol = Qnil; | 2969 | treesit_ensure_query_compiled_signal (lisp_query); |
| 2948 | Lisp_Object signal_data = Qnil; | ||
| 2949 | TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query, | ||
| 2950 | &signal_symbol, | ||
| 2951 | &signal_data); | ||
| 2952 | |||
| 2953 | if (treesit_query == NULL) | ||
| 2954 | xsignal (signal_symbol, signal_data); | ||
| 2955 | |||
| 2956 | return lisp_query; | 2970 | return lisp_query; |
| 2957 | } | 2971 | } |
| 2958 | } | 2972 | } |