aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuan Fu2024-07-26 22:33:17 -0700
committerYuan Fu2024-07-30 17:09:57 -0700
commite4cd26defc0e1a6deafbe4b2310ebdb3ffa4578f (patch)
treed57a2a02c1f7b2c08ecd146738e4c8f949793c94 /src
parenta2c439db687774f7b57959c39560993579c5d1bd (diff)
downloademacs-e4cd26defc0e1a6deafbe4b2310ebdb3ffa4578f.tar.gz
emacs-e4cd26defc0e1a6deafbe4b2310ebdb3ffa4578f.zip
"Separate" tree-sitter parser list for indirect buffers
When create a parser for the indirect buffer, set the buffer field of the parser to the indirect buffer, but add the parser to the base buffer's parser list. This way, all the parsers still get buffer updates, but indirect buffer's parsers can have different narrowing than the parsers of the base buffer. When returning the parser list of a buffer, do filtering and only return the parser for that buffer. From user's POV, indirect buffers appear to have their own parser list. * doc/lispref/parsing.texi (Using Parser): Remove the text describing indirect buffer's special case. * src/treesit.c (Ftreesit_parser_create): When create a parser for the indirect buffer, set the buffer field of the parser to the indirect buffer, but add the parser to the base buffer's parser list. (Ftreesit_parser_list): Filter parser list, only return parsers for this buffer. xx
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 45db71bb5fd..513d0d22c7f 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -392,16 +392,20 @@ init_treesit_functions (void)
392 These are all imaginary scenarios but they are not impossible 392 These are all imaginary scenarios but they are not impossible
393 :-) 393 :-)
394 394
395 Parsers in indirect buffers: We make indirect buffers to share the 395 Parsers in indirect buffers: We make indirect buffers share the
396 parser of its base buffer. Indirect buffers and their base buffer 396 parser of their base buffer. Indirect buffers and their base buffer
397 share the same buffer content but not other buffer attributes. If 397 share the same buffer content but not other buffer attributes. If
398 they have separate parser lists, changes made in an indirect buffer 398 they have separate parser lists, changes made in an indirect buffer
399 will only update parsers of that indirect buffer, and not parsers 399 will only update parsers of that indirect buffer, and not parsers in
400 in the base buffer or other indirect buffers, and vice versa. We 400 the base buffer or other indirect buffers, and vice versa. For that
401 could keep track of all the base and indirect buffers, and update 401 reason, the base buffer and all ot its indirect buffers share a
402 all of their parsers, but ultimately decide to take a simpler 402 single parser list. But each parser in this shared parser list still
403 approach, which is to make indirect buffers share their base 403 points to their own buffer. On top of that, treesit-parser-list only
404 buffer's parser list. The discussion can be found in bug#59693. */ 404 return parsers that belongs to the calling buffer. So ultimately,
405 from the user's POV, each buffer, regardless of indirect or not,
406 appears to have their own parser list. A discussion can be found in
407 bug#59693. Note that that discussion led to an earlier design, which
408 is different from the current one. */
405 409
406 410
407/*** Initialization */ 411/*** Initialization */
@@ -1416,13 +1420,20 @@ an indirect buffer. */)
1416 CHECK_SYMBOL (language); 1420 CHECK_SYMBOL (language);
1417 CHECK_SYMBOL (tag); 1421 CHECK_SYMBOL (tag);
1418 struct buffer *buf; 1422 struct buffer *buf;
1423 Lisp_Object buf_orig;
1424
1419 if (NILP (buffer)) 1425 if (NILP (buffer))
1420 buf = current_buffer; 1426 {
1427 buf = current_buffer;
1428 XSETBUFFER (buf_orig, current_buffer);
1429 }
1421 else 1430 else
1422 { 1431 {
1423 CHECK_BUFFER (buffer); 1432 CHECK_BUFFER (buffer);
1424 buf = XBUFFER (buffer); 1433 buf = XBUFFER (buffer);
1434 buf_orig = buffer;
1425 } 1435 }
1436
1426 if (buf->base_buffer) 1437 if (buf->base_buffer)
1427 buf = buf->base_buffer; 1438 buf = buf->base_buffer;
1428 1439
@@ -1457,9 +1468,7 @@ an indirect buffer. */)
1457 ts_parser_set_language (parser, lang); 1468 ts_parser_set_language (parser, lang);
1458 1469
1459 /* Create parser. */ 1470 /* Create parser. */
1460 Lisp_Object lisp_buf; 1471 Lisp_Object lisp_parser = make_treesit_parser (buf_orig,
1461 XSETBUFFER (lisp_buf, buf);
1462 Lisp_Object lisp_parser = make_treesit_parser (lisp_buf,
1463 parser, NULL, 1472 parser, NULL,
1464 language, tag); 1473 language, tag);
1465 1474
@@ -1505,13 +1514,20 @@ tag. */)
1505 (Lisp_Object buffer, Lisp_Object language, Lisp_Object tag) 1514 (Lisp_Object buffer, Lisp_Object language, Lisp_Object tag)
1506{ 1515{
1507 struct buffer *buf; 1516 struct buffer *buf;
1517 Lisp_Object buf_orig;
1518
1508 if (NILP (buffer)) 1519 if (NILP (buffer))
1509 buf = current_buffer; 1520 {
1521 buf = current_buffer;
1522 XSETBUFFER (buf_orig, current_buffer);
1523 }
1510 else 1524 else
1511 { 1525 {
1512 CHECK_BUFFER (buffer); 1526 CHECK_BUFFER (buffer);
1513 buf = XBUFFER (buffer); 1527 buf = XBUFFER (buffer);
1528 buf_orig = buffer;
1514 } 1529 }
1530
1515 if (buf->base_buffer) 1531 if (buf->base_buffer)
1516 buf = buf->base_buffer; 1532 buf = buf->base_buffer;
1517 1533
@@ -1526,7 +1542,10 @@ tag. */)
1526 { 1542 {
1527 struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail)); 1543 struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail));
1528 if ((NILP (language) || EQ (language, parser->language_symbol)) 1544 if ((NILP (language) || EQ (language, parser->language_symbol))
1529 && (EQ (tag, Qt) || EQ (tag, parser->tag))) 1545 && (EQ (tag, Qt) || EQ (tag, parser->tag))
1546 /* Indirect buffers and base buffer shares the same parser
1547 * list, so we need the filtering here. */
1548 && (EQ (parser->buffer, buf_orig)))
1530 return_list = Fcons (XCAR (tail), return_list); 1549 return_list = Fcons (XCAR (tail), return_list);
1531 } 1550 }
1532 1551