aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/editfns.c b/src/editfns.c
index f4e9a022fe2..5d5f4b30015 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2234,6 +2234,19 @@ Both characters must have the same length of multi-byte form. */)
2234 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2234 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2235 int fromc, toc; 2235 int fromc, toc;
2236 2236
2237#ifdef HAVE_TREE_SITTER
2238 ptrdiff_t start_char = fix_position (start);
2239 ptrdiff_t old_end_char = fix_position (end);
2240 ptrdiff_t start_byte = CHAR_TO_BYTE (start_char);
2241 ptrdiff_t old_end_byte = CHAR_TO_BYTE (old_end_char);
2242 struct ts_linecol start_linecol
2243 = treesit_linecol_maybe (start_char, start_byte,
2244 current_buffer->ts_linecol_cache);
2245 struct ts_linecol old_end_linecol
2246 = treesit_linecol_maybe (old_end_char, old_end_byte,
2247 current_buffer->ts_linecol_cache);
2248#endif
2249
2237 restart: 2250 restart:
2238 2251
2239 validate_region (&start, &end); 2252 validate_region (&start, &end);
@@ -2334,7 +2347,8 @@ Both characters must have the same length of multi-byte form. */)
2334 if (changed > 0) 2347 if (changed > 0)
2335 { 2348 {
2336#ifdef HAVE_TREE_SITTER 2349#ifdef HAVE_TREE_SITTER
2337 treesit_record_change (changed, last_changed, last_changed); 2350 treesit_record_change (start_byte, old_end_byte, old_end_byte,
2351 start_linecol, old_end_linecol, old_end_char);
2338#endif 2352#endif
2339 signal_after_change (changed, 2353 signal_after_change (changed,
2340 last_changed - changed, last_changed - changed); 2354 last_changed - changed, last_changed - changed);
@@ -2521,6 +2535,14 @@ It returns the number of characters changed. */)
2521 } 2535 }
2522 else 2536 else
2523 { 2537 {
2538#ifdef HAVE_TREE_SITTER
2539 struct ts_linecol start_linecol
2540 = treesit_linecol_maybe (pos, pos_byte,
2541 current_buffer->ts_linecol_cache);
2542 struct ts_linecol old_end_linecol
2543 = treesit_linecol_maybe (pos + 1, pos_byte + len,
2544 start_linecol);
2545#endif
2524 record_change (pos, 1); 2546 record_change (pos, 1);
2525 while (str_len-- > 0) 2547 while (str_len-- > 0)
2526 *p++ = *str++; 2548 *p++ = *str++;
@@ -2528,12 +2550,13 @@ It returns the number of characters changed. */)
2528 update_compositions (pos, pos + 1, CHECK_BORDER); 2550 update_compositions (pos, pos + 1, CHECK_BORDER);
2529 2551
2530#ifdef HAVE_TREE_SITTER 2552#ifdef HAVE_TREE_SITTER
2531 /* In the previous branch, replace_range() notifies 2553 /* In the previous branch, replace_range() notifies
2532 changes to tree-sitter, but in this branch, we 2554 changes to tree-sitter, but in this branch, we
2533 modified buffer content manually, so we need to 2555 modified buffer content manually, so we need to
2534 notify tree-sitter manually. */ 2556 notify tree-sitter manually. */
2535 treesit_record_change (pos_byte, pos_byte + len, 2557 treesit_record_change (pos_byte, pos_byte + len,
2536 pos_byte + len); 2558 pos_byte + len, start_linecol,
2559 old_end_linecol, pos + 1);
2537#endif 2560#endif
2538 } 2561 }
2539 characters_changed++; 2562 characters_changed++;
@@ -4481,6 +4504,15 @@ ring. */)
4481 start1_byte = CHAR_TO_BYTE (start1); 4504 start1_byte = CHAR_TO_BYTE (start1);
4482 end2_byte = CHAR_TO_BYTE (end2); 4505 end2_byte = CHAR_TO_BYTE (end2);
4483 4506
4507#ifdef HAVE_TREE_SITTER
4508 struct ts_linecol start_linecol
4509 = treesit_linecol_maybe (start1, start1_byte,
4510 current_buffer->ts_linecol_cache);
4511 struct ts_linecol old_end_linecol
4512 = treesit_linecol_maybe (end2, end2_byte,
4513 current_buffer->ts_linecol_cache);
4514#endif
4515
4484 /* Make sure the gap won't interfere, by moving it out of the text 4516 /* Make sure the gap won't interfere, by moving it out of the text
4485 we will operate on. */ 4517 we will operate on. */
4486 if (start1 < gap && gap < end2) 4518 if (start1 < gap && gap < end2)
@@ -4620,10 +4652,8 @@ ring. */)
4620 } 4652 }
4621 4653
4622#ifdef HAVE_TREE_SITTER 4654#ifdef HAVE_TREE_SITTER
4623 /* I don't think it's common to transpose two far-apart regions, so 4655 treesit_record_change (start1_byte, end2_byte, end2_byte,
4624 amalgamating the edit into one should be fine. This is what the 4656 start_linecol, old_end_linecol, end2);
4625 signal_after_change below does, too. */
4626 treesit_record_change (start1_byte, end2_byte, end2_byte);
4627#endif 4657#endif
4628 4658
4629 signal_after_change (start1, end2 - start1, end2 - start1); 4659 signal_after_change (start1, end2 - start1, end2 - start1);