]> git.eshelyaron.com Git - emacs.git/commitdiff
Make treesit-language-remap-alist completely transparent (bug#72388)
authorYuan Fu <casouri@gmail.com>
Mon, 20 Jan 2025 06:34:11 +0000 (22:34 -0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 20 Jan 2025 18:51:30 +0000 (19:51 +0100)
* doc/lispref/parsing.texi (Using Parser): Update manual.
* src/treesit.c (Ftreesit_parser_create): Use the LANGUAGE
argument given as the language for the parser, not the actual
language.

(cherry picked from commit 458135155675a29a2c064998afc0cb416cd38b52)

doc/lispref/parsing.texi
src/treesit.c

index bd8b0b1f561ca4f82fa544d52cc26d10bd56aabb..8f1ee614ff2bc2009b48a648e65f2a105b8a9b5c 100644 (file)
@@ -570,10 +570,27 @@ The value of this variable should be an alist of
 in the alist, creating a parser for @var{language-a} actually creates a
 parser for @var{language-b}.  By extension, anything that creates a node
 or makes a query of @var{language-a} will be redirected to use
-@var{language-b} instead.
+@var{language-b} instead.  This mapping is completely transparent, the
+parser created will report as @var{language-b}, and the sames goes for
+nodes created by this parser.
 
-Note that calling @code{treesit-parser-language} on a parser for
-@var{language-a} still returns @var{language-a}.
+Specifically, the parser created by @code{treesit-parser-create} will
+report to use whatever @var{language} was given to it.  For example,
+if language @code{cpp} is mapped to @code{cuda}:
+
+@example
+@group
+(setq treesit-language-remap-alist '((cpp . cuda)))
+
+(treesit-parser-language (treesit-parser-create 'cpp))
+;; => 'cpp
+
+(treesit-parser-language (treesit-parser-create 'cuda))
+;; => 'cuda
+@end group
+@end example
+
+Even though both parser are actually @code{cuda} parser.
 @end defvar
 
 @node Retrieving Nodes
index 2f06de67ad8a72337cbd6b860acc8b659eccd981..f179e4561cf1ffdb930a5f19c96d48a35a9182cc 100644 (file)
@@ -1657,8 +1657,8 @@ an indirect buffer.  */)
 
   treesit_check_buffer_size (buf);
 
-  language = resolve_language_symbol (language);
-  CHECK_SYMBOL (language);
+  Lisp_Object remapped_lang = resolve_language_symbol (language);
+  CHECK_SYMBOL (remapped_lang);
 
   /* See if we can reuse a parser.  */
   if (NILP (no_reuse))
@@ -1679,7 +1679,7 @@ an indirect buffer.  */)
   Lisp_Object signal_data = Qnil;
   TSParser *parser = ts_parser_new ();
   struct treesit_loaded_lang loaded_lang
-    = treesit_load_language (language, &signal_symbol, &signal_data);
+    = treesit_load_language (remapped_lang, &signal_symbol, &signal_data);
   TSLanguage *lang = loaded_lang.lang;
   if (lang == NULL)
     xsignal (signal_symbol, signal_data);
@@ -1687,7 +1687,10 @@ an indirect buffer.  */)
      always succeed.  */
   ts_parser_set_language (parser, lang);
 
-  /* Create parser.  */
+  /* Create parser.  Use the unmapped LANGUAGE symbol, so the nodes
+     created by this parser (and this parser) self identify as the
+     unmapped language.  This makes the grammar mapping completely
+     transparent.  */
   Lisp_Object lisp_parser = make_treesit_parser (buf_orig,
                                                 parser, NULL,
                                                 language, tag);