diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/insdel.c | 71 |
1 files changed, 19 insertions, 52 deletions
diff --git a/src/insdel.c b/src/insdel.c index a7807dd2d91..c8d4de61525 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -401,44 +401,6 @@ adjust_markers_for_delete (from, from_byte, to, to_byte) | |||
| 401 | } | 401 | } |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | /* Adjust all markers for a byte combining of NBYTES at char position | ||
| 405 | FROM and byte position FROM_BYTE. */ | ||
| 406 | |||
| 407 | static void | ||
| 408 | adjust_markers_for_combining (from, from_byte, nbytes) | ||
| 409 | register int from, from_byte, nbytes; | ||
| 410 | { | ||
| 411 | Lisp_Object marker; | ||
| 412 | register struct Lisp_Marker *m; | ||
| 413 | register int bytepos; | ||
| 414 | register int to_byte = from_byte + nbytes; | ||
| 415 | |||
| 416 | marker = BUF_MARKERS (current_buffer); | ||
| 417 | |||
| 418 | while (!NILP (marker)) | ||
| 419 | { | ||
| 420 | m = XMARKER (marker); | ||
| 421 | bytepos = m->bytepos; | ||
| 422 | |||
| 423 | if (bytepos >= to_byte) | ||
| 424 | { | ||
| 425 | record_marker_adjustment (marker, - nbytes); | ||
| 426 | m->charpos -= nbytes; | ||
| 427 | } | ||
| 428 | else if (bytepos > from_byte) | ||
| 429 | { | ||
| 430 | record_marker_adjustment (marker, from - m->charpos); | ||
| 431 | m->charpos = from; | ||
| 432 | m->bytepos = to_byte; | ||
| 433 | } | ||
| 434 | else if (bytepos == from_byte) | ||
| 435 | { | ||
| 436 | m->bytepos = to_byte; | ||
| 437 | } | ||
| 438 | |||
| 439 | marker = m->chain; | ||
| 440 | } | ||
| 441 | } | ||
| 442 | 404 | ||
| 443 | /* Adjust all markers for calling record_delete for combining bytes. | 405 | /* Adjust all markers for calling record_delete for combining bytes. |
| 444 | whose range in bytes is FROM_BYTE to TO_BYTE. | 406 | whose range in bytes is FROM_BYTE to TO_BYTE. |
| @@ -605,7 +567,8 @@ adjust_markers_for_replace (from, from_byte, old_chars, old_bytes, | |||
| 605 | { | 567 | { |
| 606 | Lisp_Object marker = BUF_MARKERS (current_buffer); | 568 | Lisp_Object marker = BUF_MARKERS (current_buffer); |
| 607 | int prev_to_byte = from_byte + old_bytes; | 569 | int prev_to_byte = from_byte + old_bytes; |
| 608 | int diff_chars = new_chars - old_chars; | 570 | int diff_chars |
| 571 | = (new_chars - combined_before_bytes) - (old_chars + combined_after_bytes); | ||
| 609 | int diff_bytes = new_bytes - old_bytes; | 572 | int diff_bytes = new_bytes - old_bytes; |
| 610 | 573 | ||
| 611 | while (!NILP (marker)) | 574 | while (!NILP (marker)) |
| @@ -617,26 +580,30 @@ adjust_markers_for_replace (from, from_byte, old_chars, old_bytes, | |||
| 617 | if (m->bytepos < prev_to_byte + combined_after_bytes) | 580 | if (m->bytepos < prev_to_byte + combined_after_bytes) |
| 618 | { | 581 | { |
| 619 | /* Put it after the combining bytes. */ | 582 | /* Put it after the combining bytes. */ |
| 620 | m->bytepos = from_byte + new_bytes; | 583 | m->bytepos = from_byte + new_bytes + combined_after_bytes; |
| 621 | m->charpos = from + new_chars; | 584 | m->charpos = from + new_chars - combined_before_bytes; |
| 622 | } | 585 | } |
| 623 | else | 586 | else |
| 624 | { | 587 | { |
| 625 | m->charpos += diff_chars; | 588 | m->charpos += diff_chars; |
| 626 | m->bytepos += diff_bytes; | 589 | m->bytepos += diff_bytes; |
| 627 | } | 590 | } |
| 628 | if (m->charpos == from + new_chars) | ||
| 629 | record_marker_adjustment (marker, - old_chars); | ||
| 630 | } | 591 | } |
| 631 | else if (m->bytepos > from_byte) | 592 | else if (m->bytepos >= from_byte) |
| 632 | { | 593 | { |
| 633 | record_marker_adjustment (marker, from - m->charpos); | ||
| 634 | m->charpos = from; | 594 | m->charpos = from; |
| 635 | m->bytepos = from_byte; | 595 | m->bytepos = from_byte + combined_before_bytes; |
| 596 | /* If all new bytes are combined in addition to that there | ||
| 597 | are after combining bytes, we must set byte position of | ||
| 598 | the marker after the after combining bytes. */ | ||
| 599 | if (combined_before_bytes == new_bytes) | ||
| 600 | m->bytepos += combined_after_bytes; | ||
| 636 | } | 601 | } |
| 637 | 602 | ||
| 638 | marker = m->chain; | 603 | marker = m->chain; |
| 639 | } | 604 | } |
| 605 | |||
| 606 | CHECK_MARKERS (); | ||
| 640 | } | 607 | } |
| 641 | 608 | ||
| 642 | 609 | ||
| @@ -1037,15 +1004,17 @@ count_combining_after (string, length, pos, pos_byte) | |||
| 1037 | /* Combine NBYTES stray trailing-codes, which were formerly separate | 1004 | /* Combine NBYTES stray trailing-codes, which were formerly separate |
| 1038 | characters, with the preceding character. These bytes | 1005 | characters, with the preceding character. These bytes |
| 1039 | are located after position POS / POS_BYTE, and the preceding character | 1006 | are located after position POS / POS_BYTE, and the preceding character |
| 1040 | is located just before that position. */ | 1007 | is located just before that position. |
| 1008 | |||
| 1009 | This function does not adjust markers for byte combining. That | ||
| 1010 | should be done in advance by the functions | ||
| 1011 | adjust_markers_for_insert, adjust_markers_for_delete, or | ||
| 1012 | adjust_markers_for_replace. */ | ||
| 1041 | 1013 | ||
| 1042 | static void | 1014 | static void |
| 1043 | combine_bytes (pos, pos_byte, nbytes) | 1015 | combine_bytes (pos, pos_byte, nbytes) |
| 1044 | int pos, pos_byte, nbytes; | 1016 | int pos, pos_byte, nbytes; |
| 1045 | { | 1017 | { |
| 1046 | /* Adjust all markers. */ | ||
| 1047 | adjust_markers_for_combining (pos, pos_byte, nbytes); | ||
| 1048 | |||
| 1049 | adjust_overlays_for_delete (pos, nbytes); | 1018 | adjust_overlays_for_delete (pos, nbytes); |
| 1050 | 1019 | ||
| 1051 | ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); | 1020 | ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); |
| @@ -1056,8 +1025,6 @@ combine_bytes (pos, pos_byte, nbytes) | |||
| 1056 | if (BUF_INTERVALS (current_buffer) != 0) | 1025 | if (BUF_INTERVALS (current_buffer) != 0) |
| 1057 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ | 1026 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ |
| 1058 | offset_intervals (current_buffer, pos, - nbytes); | 1027 | offset_intervals (current_buffer, pos, - nbytes); |
| 1059 | |||
| 1060 | CHECK_MARKERS (); | ||
| 1061 | } | 1028 | } |
| 1062 | 1029 | ||
| 1063 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes | 1030 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes |