diff options
| author | Po Lu | 2022-12-11 09:34:03 +0800 |
|---|---|---|
| committer | Po Lu | 2022-12-11 09:34:03 +0800 |
| commit | 6d6ca47aba7b72d2a770d7ed01c849d3cc729e21 (patch) | |
| tree | e8181f7188a3a74147549b7ba76ea9c3a696259c /src | |
| parent | e08564432918aa87b49da58ac90bb43718424364 (diff) | |
| parent | 44c5f3614973d8dc389ddcdc1b3f8ab1c809194d (diff) | |
| download | emacs-6d6ca47aba7b72d2a770d7ed01c849d3cc729e21.tar.gz emacs-6d6ca47aba7b72d2a770d7ed01c849d3cc729e21.zip | |
Merge from origin/emacs-29
44c5f361497 ; Fix two byte-compiler warnings
a8ee046fb50 Ensure 'package-vc--version' always returns a version
022ab1061b2 Ensure 'package-vc--main-file' always returns an existing...
357fe91996b Check if package already exists before installing from ch...
5e8bc79f6b2 ; Fix reference in docstring to 'package-vc-install-from-...
af88b00b19c Refresh the package quickstart file in package-vc
5a092c8e461 ; * admin/notes/tree-sitter/starter-guide (Indent): Minor...
ebef8905b0d Make indirect buffers use tree-sitter parsers of their ba...
8f53fa10d94 Fontify "this" as a keyword in c++-ts-mode (bug#59924)
8de8f1dc051 Add class_body indentation for typescript (bug#59680)
839341d7370 Make more granular defun-type-regexp (bug#59873)
8f49137c9bf Add dockerfile-ts-mode (Bug#59894)
1014bcc8e32 Fix fontification of method-invocations in js-ts-mode (bu...
7141920c6af Fix escape-sequence feature in typescript-ts-mode (bug#59...
4df35e3491c Improve fontification in csharp-ts-mode (bug#59909)
33a8415eb7e Use 'project--value-in-dir' for 'project-vc-include-untra...
594267395d5 Update Turkish Hello
940d9070e97 Support newer glib versions (Bug#59061)
0bd26abf7fb ; * doc/misc/use-package.texi: Fix @file.
bcf235acd58 Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/...
2ea7a357fd1 ; * doc/misc/use-package.texi: Fix @acronym.
d268ab1c5d7 Bring back the project--value-in-dir logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/src/treesit.c b/src/treesit.c index 8b485ca4ece..d361a3da932 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -384,7 +384,18 @@ init_treesit_functions (void) | |||
| 384 | mysteriously drops. 3) what if a user uses so many stuff that the | 384 | mysteriously drops. 3) what if a user uses so many stuff that the |
| 385 | default cache size (20) is not enough and we end up thrashing? | 385 | default cache size (20) is not enough and we end up thrashing? |
| 386 | These are all imaginary scenarios but they are not impossible | 386 | These are all imaginary scenarios but they are not impossible |
| 387 | :-) */ | 387 | :-) |
| 388 | |||
| 389 | Parsers in indirect buffers: We make indirect buffers to share the | ||
| 390 | parser of its base buffer. Indirect buffers and their base buffer | ||
| 391 | share the same buffer content but not other buffer attributes. If | ||
| 392 | they have separate parser lists, changes made in an indirect buffer | ||
| 393 | will only update parsers of that indirect buffer, and not parsers | ||
| 394 | in the base buffer or other indirect buffers, and vice versa. We | ||
| 395 | could keep track of all the base and indirect buffers, and update | ||
| 396 | all of their parsers, but ultimately decide to take a simpler | ||
| 397 | approach, which is to make indirect buffers share their base | ||
| 398 | buffer's parser list. The discussion can be found in bug#59693. */ | ||
| 388 | 399 | ||
| 389 | 400 | ||
| 390 | /*** Initialization */ | 401 | /*** Initialization */ |
| @@ -697,9 +708,10 @@ void | |||
| 697 | treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | 708 | treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, |
| 698 | ptrdiff_t new_end_byte) | 709 | ptrdiff_t new_end_byte) |
| 699 | { | 710 | { |
| 700 | Lisp_Object parser_list; | 711 | struct buffer *base_buffer = current_buffer; |
| 701 | 712 | if (current_buffer->base_buffer) | |
| 702 | parser_list = BVAR (current_buffer, ts_parser_list); | 713 | base_buffer = current_buffer->base_buffer; |
| 714 | Lisp_Object parser_list = BVAR (base_buffer, ts_parser_list); | ||
| 703 | 715 | ||
| 704 | FOR_EACH_TAIL_SAFE (parser_list) | 716 | FOR_EACH_TAIL_SAFE (parser_list) |
| 705 | { | 717 | { |
| @@ -1252,12 +1264,16 @@ DEFUN ("treesit-parser-create", | |||
| 1252 | 1, 3, 0, | 1264 | 1, 3, 0, |
| 1253 | doc: /* Create and return a parser in BUFFER for LANGUAGE. | 1265 | doc: /* Create and return a parser in BUFFER for LANGUAGE. |
| 1254 | 1266 | ||
| 1255 | The parser is automatically added to BUFFER's parser list, as | 1267 | The parser is automatically added to BUFFER's parser list, as returned |
| 1256 | returned by `treesit-parser-list'. | 1268 | by `treesit-parser-list'. LANGUAGE is a language symbol. If BUFFER |
| 1257 | LANGUAGE is a language symbol. If BUFFER is nil or omitted, it | 1269 | is nil or omitted, it defaults to the current buffer. If BUFFER |
| 1258 | defaults to the current buffer. If BUFFER already has a parser for | 1270 | already has a parser for LANGUAGE, return that parser, but if NO-REUSE |
| 1259 | LANGUAGE, return that parser, but if NO-REUSE is non-nil, always | 1271 | is non-nil, always create a new parser. |
| 1260 | create a new parser. */) | 1272 | |
| 1273 | If that buffer is an indirect buffer, its base buffer is used instead. | ||
| 1274 | That is, indirect buffers use their base buffer's parsers. Lisp | ||
| 1275 | programs should widen as necessary should they want to use a parser in | ||
| 1276 | an indirect buffer. */) | ||
| 1261 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) | 1277 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) |
| 1262 | { | 1278 | { |
| 1263 | treesit_initialize (); | 1279 | treesit_initialize (); |
| @@ -1271,16 +1287,21 @@ create a new parser. */) | |||
| 1271 | CHECK_BUFFER (buffer); | 1287 | CHECK_BUFFER (buffer); |
| 1272 | buf = XBUFFER (buffer); | 1288 | buf = XBUFFER (buffer); |
| 1273 | } | 1289 | } |
| 1290 | if (buf->base_buffer) | ||
| 1291 | buf = buf->base_buffer; | ||
| 1292 | |||
| 1274 | treesit_check_buffer_size (buf); | 1293 | treesit_check_buffer_size (buf); |
| 1275 | 1294 | ||
| 1276 | /* See if we can reuse a parser. */ | 1295 | /* See if we can reuse a parser. */ |
| 1277 | for (Lisp_Object tail = BVAR (buf, ts_parser_list); | 1296 | if (NILP (no_reuse)) |
| 1278 | NILP (no_reuse) && !NILP (tail); | ||
| 1279 | tail = XCDR (tail)) | ||
| 1280 | { | 1297 | { |
| 1281 | struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail)); | 1298 | Lisp_Object tail = BVAR (buf, ts_parser_list); |
| 1282 | if (EQ (parser->language_symbol, language)) | 1299 | FOR_EACH_TAIL (tail) |
| 1283 | return XCAR (tail); | 1300 | { |
| 1301 | struct Lisp_TS_Parser *parser = XTS_PARSER (XCAR (tail)); | ||
| 1302 | if (EQ (parser->language_symbol, language)) | ||
| 1303 | return XCAR (tail); | ||
| 1304 | } | ||
| 1284 | } | 1305 | } |
| 1285 | 1306 | ||
| 1286 | /* Load language. */ | 1307 | /* Load language. */ |
| @@ -1329,7 +1350,10 @@ DEFUN ("treesit-parser-list", | |||
| 1329 | Ftreesit_parser_list, Streesit_parser_list, | 1350 | Ftreesit_parser_list, Streesit_parser_list, |
| 1330 | 0, 1, 0, | 1351 | 0, 1, 0, |
| 1331 | doc: /* Return BUFFER's parser list. | 1352 | doc: /* Return BUFFER's parser list. |
| 1332 | BUFFER defaults to the current buffer. */) | 1353 | |
| 1354 | BUFFER defaults to the current buffer. If that buffer is an indirect | ||
| 1355 | buffer, its base buffer is used instead. That is, indirect buffers | ||
| 1356 | use their base buffer's parsers. */) | ||
| 1333 | (Lisp_Object buffer) | 1357 | (Lisp_Object buffer) |
| 1334 | { | 1358 | { |
| 1335 | struct buffer *buf; | 1359 | struct buffer *buf; |
| @@ -1340,6 +1364,9 @@ BUFFER defaults to the current buffer. */) | |||
| 1340 | CHECK_BUFFER (buffer); | 1364 | CHECK_BUFFER (buffer); |
| 1341 | buf = XBUFFER (buffer); | 1365 | buf = XBUFFER (buffer); |
| 1342 | } | 1366 | } |
| 1367 | if (buf->base_buffer) | ||
| 1368 | buf = buf->base_buffer; | ||
| 1369 | |||
| 1343 | /* Return a fresh list so messing with that list doesn't affect our | 1370 | /* Return a fresh list so messing with that list doesn't affect our |
| 1344 | internal data. */ | 1371 | internal data. */ |
| 1345 | Lisp_Object return_list = Qnil; | 1372 | Lisp_Object return_list = Qnil; |