aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuan Fu2023-09-04 23:45:21 -0700
committerYuan Fu2023-09-05 21:03:37 -0700
commitcf0986401cee914207e2d81febf62189f74ab40d (patch)
tree5337d011c2df5b7513feb8fa8a69411524d72989 /src
parent686d4ddb87ca2d87bfc0cd8a29ac84decab90ff6 (diff)
downloademacs-cf0986401cee914207e2d81febf62189f74ab40d.tar.gz
emacs-cf0986401cee914207e2d81febf62189f74ab40d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 13be9594963..dfd098e3c85 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1390,8 +1390,8 @@ is nil or omitted, it defaults to the current buffer. If BUFFER
1390already has a parser for LANGUAGE with TAG, return that parser, but if 1390already has a parser for LANGUAGE with TAG, return that parser, but if
1391NO-REUSE is non-nil, always create a new parser. 1391NO-REUSE is non-nil, always create a new parser.
1392 1392
1393TAG should be a symbol and defaults to nil. Different parsers can 1393TAG can be any symbol except t, and defaults to nil. Different
1394have the same tag. 1394parsers can have the same tag.
1395 1395
1396If that buffer is an indirect buffer, its base buffer is used instead. 1396If that buffer is an indirect buffer, its base buffer is used instead.
1397That is, indirect buffers use their base buffer's parsers. Lisp 1397That is, indirect buffers use their base buffer's parsers. Lisp
@@ -1415,6 +1415,9 @@ an indirect buffer. */)
1415 if (buf->base_buffer) 1415 if (buf->base_buffer)
1416 buf = buf->base_buffer; 1416 buf = buf->base_buffer;
1417 1417
1418 if (EQ (tag, Qt))
1419 xsignal2(Qwrong_type_argument, list2(Qnot, Qt), Qt);
1420
1418 treesit_check_buffer_size (buf); 1421 treesit_check_buffer_size (buf);
1419 1422
1420 /* See if we can reuse a parser. */ 1423 /* See if we can reuse a parser. */
@@ -1472,15 +1475,22 @@ See `treesit-parser-list' for the buffer's parser list. */)
1472 return Qnil; 1475 return Qnil;
1473} 1476}
1474 1477
1478/* If TAG is t, include all parsers regardless of their tag. But
1479 don't document this until there's some actual need for it. */
1475DEFUN ("treesit-parser-list", 1480DEFUN ("treesit-parser-list",
1476 Ftreesit_parser_list, Streesit_parser_list, 1481 Ftreesit_parser_list, Streesit_parser_list,
1477 0, 1, 0, 1482 0, 3, 0,
1478 doc: /* Return BUFFER's parser list. 1483 doc: /* Return BUFFER's parser list, filtered by LANGUAGE and TAG.
1479 1484
1480BUFFER defaults to the current buffer. If that buffer is an indirect 1485BUFFER defaults to the current buffer. If that buffer is an indirect
1481buffer, its base buffer is used instead. That is, indirect buffers 1486buffer, its base buffer is used instead. That is, indirect buffers
1482use their base buffer's parsers. */) 1487use their base buffer's parsers.
1483 (Lisp_Object buffer) 1488
1489If LANGUAGE is non-nil, only return parsers for that language.
1490
1491The returned list only contain parsers with TAG. TAG defaults to
1492nil. */)
1493 (Lisp_Object buffer, Lisp_Object language, Lisp_Object tag)
1484{ 1494{
1485 struct buffer *buf; 1495 struct buffer *buf;
1486 if (NILP (buffer)) 1496 if (NILP (buffer))
@@ -1501,7 +1511,12 @@ use their base buffer's parsers. */)
1501 tail = BVAR (buf, ts_parser_list); 1511 tail = BVAR (buf, ts_parser_list);
1502 1512
1503 FOR_EACH_TAIL (tail) 1513 FOR_EACH_TAIL (tail)
1504 return_list = Fcons (XCAR (tail), return_list); 1514 {
1515 struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail));
1516 if ((NILP (language) || EQ (language, parser->language_symbol))
1517 && (EQ (tag, Qt) || EQ (tag, parser->tag)))
1518 return_list = Fcons (XCAR (tail), return_list);
1519 }
1505 1520
1506 return Freverse (return_list); 1521 return Freverse (return_list);
1507} 1522}