@var{tag} can be any symbol except @code{t}, and defaults to
@code{nil}. Different parsers can have the same tag.
-
-If that buffer is an indirect buffer, its base buffer is used instead.
-That is, indirect buffers use their base buffer's parsers. If the
-base buffer is narrowed, an indirect buffer might not be able to
-retrieve information of the portion of the buffer text that is
-invisible in the base buffer. Lisp programs should widen as necessary
-should they want to use a parser in an indirect buffer.
@end defun
Given a parser, we can query information about it.
@defun treesit-parser-list &optional buffer language tag
This function returns the parser list of @var{buffer}, filtered by
@var{language} and @var{tag}. If @var{buffer} is @code{nil} or
-omitted, it defaults to the current buffer. If that buffer is an
-indirect buffer, its base buffer is used instead. That is, indirect
-buffers use their base buffer's parsers.
+omitted, it defaults to the current buffer.
If @var{language} is non-@var{nil}, only include parsers for that
language, and only include parsers with @var{tag}. @var{tag} defaults
** The customization group 'wp' has been removed.
It has been obsolete since Emacs 26.1. Use the group 'text' instead.
+** Tree-sitter changes
+
++++
+*** Indirect buffers can have their own parser list.
+Before, indirect buffers share their base buffer’s parser list and
+parsers. Now they can have their own parser list.
+
++++
+*** New variable 'treesit-language-remap-alist'.
+This variable allows a user to remap one language into another, such
+that creating a parser for language A actually creates a parser for
+language B. By extension, any font-lock rules or indentation rules for
+language A will be applied to language B instead.
+
+This is useful for reusing font-lock rules and indentation rules of
+language A for language B, when language B is a strict superset of
+language A.
\f
* Changes in Emacs 31.1 on Non-Free Operating Systems
These are all imaginary scenarios but they are not impossible
:-)
- Parsers in indirect buffers: We make indirect buffers to share the
- parser of its base buffer. Indirect buffers and their base buffer
+ Parsers in indirect buffers: We make indirect buffers share the
+ parser of their base buffer. Indirect buffers and their base buffer
share the same buffer content but not other buffer attributes. If
they have separate parser lists, changes made in an indirect buffer
- will only update parsers of that indirect buffer, and not parsers
- in the base buffer or other indirect buffers, and vice versa. We
- could keep track of all the base and indirect buffers, and update
- all of their parsers, but ultimately decide to take a simpler
- approach, which is to make indirect buffers share their base
- buffer's parser list. The discussion can be found in bug#59693. */
+ will only update parsers of that indirect buffer, and not parsers in
+ the base buffer or other indirect buffers, and vice versa. For that
+ reason, the base buffer and all ot its indirect buffers share a
+ single parser list. But each parser in this shared parser list still
+ points to their own buffer. On top of that, treesit-parser-list only
+ return parsers that belongs to the calling buffer. So ultimately,
+ from the user's POV, each buffer, regardless of indirect or not,
+ appears to have their own parser list. A discussion can be found in
+ bug#59693. Note that that discussion led to an earlier design, which
+ is different from the current one. */
\f
/*** Initialization */
CHECK_SYMBOL (language);
CHECK_SYMBOL (tag);
struct buffer *buf;
+ Lisp_Object buf_orig;
+
if (NILP (buffer))
- buf = current_buffer;
+ {
+ buf = current_buffer;
+ XSETBUFFER (buf_orig, current_buffer);
+ }
else
{
CHECK_BUFFER (buffer);
buf = XBUFFER (buffer);
+ buf_orig = buffer;
}
+
if (buf->base_buffer)
buf = buf->base_buffer;
ts_parser_set_language (parser, lang);
/* Create parser. */
- Lisp_Object lisp_buf;
- XSETBUFFER (lisp_buf, buf);
- Lisp_Object lisp_parser = make_treesit_parser (lisp_buf,
+ Lisp_Object lisp_parser = make_treesit_parser (buf_orig,
parser, NULL,
language, tag);
(Lisp_Object buffer, Lisp_Object language, Lisp_Object tag)
{
struct buffer *buf;
+ Lisp_Object buf_orig;
+
if (NILP (buffer))
- buf = current_buffer;
+ {
+ buf = current_buffer;
+ XSETBUFFER (buf_orig, current_buffer);
+ }
else
{
CHECK_BUFFER (buffer);
buf = XBUFFER (buffer);
+ buf_orig = buffer;
}
+
if (buf->base_buffer)
buf = buf->base_buffer;
{
struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail));
if ((NILP (language) || EQ (language, parser->language_symbol))
- && (EQ (tag, Qt) || EQ (tag, parser->tag)))
+ && (EQ (tag, Qt) || EQ (tag, parser->tag))
+ /* Indirect buffers and base buffer shares the same parser
+ * list, so we need the filtering here. */
+ && (EQ (parser->buffer, buf_orig)))
return_list = Fcons (XCAR (tail), return_list);
}