From: Yuan Fu Date: Fri, 30 Dec 2022 10:54:13 +0000 (-0800) Subject: Add treesit-language-abi-version X-Git-Tag: emacs-29.0.90~908 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0237c5927e9;p=emacs.git Add treesit-language-abi-version Also rename treesit-language-version to treesit-library-abi-version, because the old name is somewhat misleading. * doc/lispref/parsing.texi (Language Grammar): Update. * src/treesit.c (Ftreesit_library_abi_version): Rename. (Ftreesit_language_abi_version): New function. --- diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 5411987b5e8..8803991b725 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -141,7 +141,7 @@ for a language that considers itself too ``cool'' to abide by conventions. @cindex language grammar version, compatibility -@defun treesit-language-version &optional min-compatible +@defun treesit-library-abi-version &optional min-compatible This function returns the version of the language grammar Application Binary Interface (@acronym{ABI}) supported by the tree-sitter library. By default, it returns the latest ABI version @@ -153,6 +153,12 @@ the tree-sitter library, otherwise the library will be unable to load them. @end defun +@defun treesit-language-abi-version language +This function returns the language grammar @acronym{ABI} version of +language grammar for @var{language} loaded by Emacs. If +@var{language} is unavailable, this function returns @code{nil}. +@end defun + @heading Concrete syntax tree @cindex syntax tree, concrete diff --git a/src/treesit.c b/src/treesit.c index eaa563a54c4..a9bfcb3d9e9 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -662,9 +662,8 @@ If DETAIL is non-nil, return (t . nil) when LANGUAGE is available, } } -DEFUN ("treesit-language-version", - Ftreesit_language_version, - Streesit_language_version, +DEFUN ("treesit-library-abi-version", Ftreesit_library_abi_version, + Streesit_library_abi_version, 0, 1, 0, doc: /* Return the language ABI version of the tree-sitter library. @@ -680,6 +679,29 @@ is non-nil, return the oldest compatible ABI version. */) return make_fixnum (TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION); } +DEFUN ("treesit-language-version", Ftreesit_language_abi_version, + Streesit_language_abi_version, + 0, 1, 0, + doc: /* Return the language ABI version of the tree-sitter LANGUAGE. +Return nil if LANGUAGE is not available. */) + (Lisp_Object language) +{ + if (NILP (Ftreesit_langauge_available_p (language, Qnil))) + return Qnil; + else + { + Lisp_Object signal_symbol = Qnil; + Lisp_Object signal_data = Qnil; + TSLanguage *ts_language = treesit_load_language (language, + &signal_symbol, + &signal_data); + if (ts_language == NULL) + return Qnil; + uint32_t version = ts_language_version (ts_language); + return make_fixnum((ptrdiff_t) version); + } +} + /*** Parsing functions */ static void @@ -3345,7 +3367,8 @@ then in the system default locations for dynamic libraries, in that order. */); Vtreesit_extra_load_path = Qnil; defsubr (&Streesit_language_available_p); - defsubr (&Streesit_language_version); + defsubr (&Streesit_library_abi_version); + defsubr (&Streesit_language_abi_version); defsubr (&Streesit_parser_p); defsubr (&Streesit_node_p);