Allow filter by tag in treesit-parser-list
* doc/lispref/parsing.texi: Update manual. * src/treesit.c (Ftreesit_parser_create): Disallow using t for tag. (Ftreesit_parser_list): Add LANGUAGE and TAG parameter.
This commit is contained in:
parent
686d4ddb87
commit
cf0986401c
2 changed files with 34 additions and 14 deletions
|
@ -409,8 +409,8 @@ By default, this function reuses a parser if one already exists for
|
|||
@var{language} with @var{tag} in @var{buffer}, but if @var{no-reuse}
|
||||
is non-@code{nil}, this function always creates a new parser.
|
||||
|
||||
@var{tag} should be a symbol and defaults to @code{nil}. Different
|
||||
parsers can have the same tag.
|
||||
@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
|
||||
|
@ -453,11 +453,16 @@ internal parser list. Every time a change is made to the buffer,
|
|||
Emacs updates parsers in this list so they can update their syntax
|
||||
tree incrementally.
|
||||
|
||||
@defun treesit-parser-list &optional buffer
|
||||
This function returns the parser list of @var{buffer}. 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.
|
||||
@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.
|
||||
|
||||
If @var{language} is non-@var{nil}, only include parsers for that
|
||||
language. And only include parsers with @var{tag}. @var{tag} defaults
|
||||
to @code{nil}.
|
||||
@end defun
|
||||
|
||||
@defun treesit-parser-delete parser
|
||||
|
|
|
@ -1390,8 +1390,8 @@ is nil or omitted, it defaults to the current buffer. If BUFFER
|
|||
already has a parser for LANGUAGE with TAG, return that parser, but if
|
||||
NO-REUSE is non-nil, always create a new parser.
|
||||
|
||||
TAG should be a symbol and defaults to nil. Different parsers can
|
||||
have the same tag.
|
||||
TAG can be any symbol except t, and defaults to 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. Lisp
|
||||
|
@ -1415,6 +1415,9 @@ an indirect buffer. */)
|
|||
if (buf->base_buffer)
|
||||
buf = buf->base_buffer;
|
||||
|
||||
if (EQ (tag, Qt))
|
||||
xsignal2(Qwrong_type_argument, list2(Qnot, Qt), Qt);
|
||||
|
||||
treesit_check_buffer_size (buf);
|
||||
|
||||
/* See if we can reuse a parser. */
|
||||
|
@ -1472,15 +1475,22 @@ See `treesit-parser-list' for the buffer's parser list. */)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
/* If TAG is t, include all parsers regardless of their tag. But
|
||||
don't document this until there's some actual need for it. */
|
||||
DEFUN ("treesit-parser-list",
|
||||
Ftreesit_parser_list, Streesit_parser_list,
|
||||
0, 1, 0,
|
||||
doc: /* Return BUFFER's parser list.
|
||||
0, 3, 0,
|
||||
doc: /* Return BUFFER's parser list, filtered by LANGUAGE and TAG.
|
||||
|
||||
BUFFER 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. */)
|
||||
(Lisp_Object buffer)
|
||||
use their base buffer's parsers.
|
||||
|
||||
If LANGUAGE is non-nil, only return parsers for that language.
|
||||
|
||||
The returned list only contain parsers with TAG. TAG defaults to
|
||||
nil. */)
|
||||
(Lisp_Object buffer, Lisp_Object language, Lisp_Object tag)
|
||||
{
|
||||
struct buffer *buf;
|
||||
if (NILP (buffer))
|
||||
|
@ -1501,7 +1511,12 @@ use their base buffer's parsers. */)
|
|||
tail = BVAR (buf, ts_parser_list);
|
||||
|
||||
FOR_EACH_TAIL (tail)
|
||||
return_list = Fcons (XCAR (tail), return_list);
|
||||
{
|
||||
struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail));
|
||||
if ((NILP (language) || EQ (language, parser->language_symbol))
|
||||
&& (EQ (tag, Qt) || EQ (tag, parser->tag)))
|
||||
return_list = Fcons (XCAR (tail), return_list);
|
||||
}
|
||||
|
||||
return Freverse (return_list);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue