[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 0237c5927e 2/3: Add treesit-language-abi-version
From: |
Yuan Fu |
Subject: |
emacs-29 0237c5927e 2/3: Add treesit-language-abi-version |
Date: |
Fri, 30 Dec 2022 05:59:40 -0500 (EST) |
branch: emacs-29
commit 0237c5927e9a741083e4d177bd9a8e9c876cc662
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
doc/lispref/parsing.texi | 8 +++++++-
src/treesit.c | 31 +++++++++++++++++++++++++++----
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index 5411987b5e..8803991b72 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 eaa563a54c..a9bfcb3d9e 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);