Function: treesit-query-compile
treesit-query-compile is a function defined in treesit.c.
Signature
(treesit-query-compile LANGUAGE QUERY &optional EAGER)
Documentation
Compile QUERY to a compiled query.
Querying with a compiled query is much faster than an uncompiled one. LANGUAGE is the language this query is for.
If EAGER is non-nil, immediately load LANGUAGE and compile the query. Otherwise defer the compilation until the query is first used.
Signal treesit-query-error if QUERY is malformed or something else
goes wrong. (This only happens if EAGER is non-nil.)
You can use treesit-query-validate to validate and debug a query.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-query-compile 'c '((identifier) @id "return" @ret))
e.g. => #<treesit-compiled-query>
Source Code
// Defined in /usr/src/emacs/src/treesit.c
{
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 ();
Lisp_Object lisp_query = make_treesit_query (query, language);
/* Maybe actually compile. */
if (NILP (eager))
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);
return lisp_query;
}
}