diff options
author | Yuan Fu <casouri@gmail.com> | 2022-12-30 02:54:13 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-12-30 02:54:13 -0800 |
commit | 0237c5927e9a741083e4d177bd9a8e9c876cc662 (patch) | |
tree | 3061f9dd597072393f32ece54bf9d8842707593f /src/treesit.c | |
parent | 312f82d36f0f8a68e70a7fbcddc398670680b5b6 (diff) | |
download | emacs-0237c5927e9a741083e4d177bd9a8e9c876cc662.tar.gz |
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.
Diffstat (limited to 'src/treesit.c')
-rw-r--r-- | src/treesit.c | 31 |
1 files changed, 27 insertions, 4 deletions
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); |