diff options
| author | Kenichi Handa | 2000-05-20 00:01:34 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2000-05-20 00:01:34 +0000 |
| commit | b16afa45bb6a0b0b68658c5d4e563e2010b12169 (patch) | |
| tree | 1a783c95aba917761cdc6a89b38bec061584521d /src | |
| parent | f55d03b19bb2e9ff3b2c88bbd93d49a89d0d543b (diff) | |
| download | emacs-b16afa45bb6a0b0b68658c5d4e563e2010b12169.tar.gz emacs-b16afa45bb6a0b0b68658c5d4e563e2010b12169.zip | |
(adjust_markers_for_record_delete): Deleted.
(adjust_markers_for_insert): Argument changed. Caller changed.
(adjust_markers_for_replace): Likewise.
(ADJUST_CHAR_POS, combine_bytes, byte_combining_error,
CHECK_BYTE_COMBINING_FOR_INSERT): Deleted.
(copy_text): Delete unused local varialbe c_save. For converting
to multibyte, be sure to make all 8-bit characters in valid
multibyte form.
(count_size_as_multibyte): Handle 8-bit characters correctly.
(insert_1_both, insert_from_string_1, insert_from_buffer_1,
adjust_after_replace, replace_range, del_range_2)
[BYTE_COMBINING_DEBUG]: Abort if byte combining occurs.
(insert_1_both, insert_from_string_1, insert_from_buffer_1,
adjust_after_replace, replace_range, del_range_2) Delete codes for
handling byte combining.
(adjust_before_replace): Deleted.
Diffstat (limited to 'src')
| -rw-r--r-- | src/insdel.c | 711 |
1 files changed, 78 insertions, 633 deletions
diff --git a/src/insdel.c b/src/insdel.c index 06e638526bc..a2756e4e2ed 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -40,9 +40,9 @@ static void insert_from_buffer_1 (); | |||
| 40 | static void gap_left P_ ((int, int, int)); | 40 | static void gap_left P_ ((int, int, int)); |
| 41 | static void gap_right P_ ((int, int)); | 41 | static void gap_right P_ ((int, int)); |
| 42 | static void adjust_markers_gap_motion P_ ((int, int, int)); | 42 | static void adjust_markers_gap_motion P_ ((int, int, int)); |
| 43 | static void adjust_markers_for_insert P_ ((int, int, int, int, int, int, int)); | 43 | static void adjust_markers_for_insert P_ ((int, int, int, int, int)); |
| 44 | void adjust_markers_for_delete P_ ((int, int, int, int)); | 44 | void adjust_markers_for_delete P_ ((int, int, int, int)); |
| 45 | static void adjust_markers_for_record_delete P_ ((int, int, int, int)); | 45 | static void adjust_markers_for_replace P_ ((int, int, int, int, int, int)); |
| 46 | static void adjust_point P_ ((int, int)); | 46 | static void adjust_point P_ ((int, int)); |
| 47 | 47 | ||
| 48 | Lisp_Object Fcombine_after_change_execute (); | 48 | Lisp_Object Fcombine_after_change_execute (); |
| @@ -380,56 +380,18 @@ adjust_markers_for_delete (from, from_byte, to, to_byte) | |||
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | /* Adjust all markers for calling record_delete for combining bytes. | ||
| 384 | whose range in bytes is FROM_BYTE to TO_BYTE. | ||
| 385 | The range in charpos is FROM to TO. */ | ||
| 386 | |||
| 387 | static void | ||
| 388 | adjust_markers_for_record_delete (from, from_byte, to, to_byte) | ||
| 389 | register int from, from_byte, to, to_byte; | ||
| 390 | { | ||
| 391 | Lisp_Object marker; | ||
| 392 | register struct Lisp_Marker *m; | ||
| 393 | register int charpos; | ||
| 394 | |||
| 395 | marker = BUF_MARKERS (current_buffer); | ||
| 396 | |||
| 397 | while (!NILP (marker)) | ||
| 398 | { | ||
| 399 | m = XMARKER (marker); | ||
| 400 | charpos = m->charpos; | ||
| 401 | |||
| 402 | /* If the marker is after the deletion, | ||
| 403 | relocate by number of chars / bytes deleted. */ | ||
| 404 | if (charpos > to) | ||
| 405 | ; | ||
| 406 | /* Here's the case where a marker is inside text being deleted. */ | ||
| 407 | else if (charpos > from) | ||
| 408 | record_marker_adjustment (marker, from - charpos); | ||
| 409 | |||
| 410 | marker = m->chain; | ||
| 411 | } | ||
| 412 | } | ||
| 413 | |||
| 414 | /* Adjust markers for an insertion that stretches from FROM / FROM_BYTE | 383 | /* Adjust markers for an insertion that stretches from FROM / FROM_BYTE |
| 415 | to TO / TO_BYTE. We have to relocate the charpos of every marker | 384 | to TO / TO_BYTE. We have to relocate the charpos of every marker |
| 416 | that points after the insertion (but not their bytepos). | 385 | that points after the insertion (but not their bytepos). |
| 417 | 386 | ||
| 418 | COMBINED_BEFORE_BYTES is the number of bytes at the start of the insertion | ||
| 419 | that combine into one character with the text before the insertion. | ||
| 420 | COMBINED_AFTER_BYTES is the number of bytes after the insertion | ||
| 421 | that combine into one character with the last inserted bytes. | ||
| 422 | |||
| 423 | When a marker points at the insertion point, | 387 | When a marker points at the insertion point, |
| 424 | we advance it if either its insertion-type is t | 388 | we advance it if either its insertion-type is t |
| 425 | or BEFORE_MARKERS is true. */ | 389 | or BEFORE_MARKERS is true. */ |
| 426 | 390 | ||
| 427 | static void | 391 | static void |
| 428 | adjust_markers_for_insert (from, from_byte, to, to_byte, | 392 | adjust_markers_for_insert (from, from_byte, to, to_byte, before_markers) |
| 429 | combined_before_bytes, combined_after_bytes, | ||
| 430 | before_markers) | ||
| 431 | register int from, from_byte, to, to_byte; | 393 | register int from, from_byte, to, to_byte; |
| 432 | int combined_before_bytes, combined_after_bytes, before_markers; | 394 | int before_markers; |
| 433 | { | 395 | { |
| 434 | Lisp_Object marker; | 396 | Lisp_Object marker; |
| 435 | int adjusted = 0; | 397 | int adjusted = 0; |
| @@ -442,10 +404,8 @@ adjust_markers_for_insert (from, from_byte, to, to_byte, | |||
| 442 | { | 404 | { |
| 443 | register struct Lisp_Marker *m = XMARKER (marker); | 405 | register struct Lisp_Marker *m = XMARKER (marker); |
| 444 | 406 | ||
| 445 | /* In a single-byte buffer, a marker's two positions must be equal. | 407 | /* In a single-byte buffer, a marker's two positions must be |
| 446 | (If this insertion is going to combine characters, Z will | 408 | equal. */ |
| 447 | become different from Z_BYTE, but they might be the same now. | ||
| 448 | If so, the two OLD positions of the marker should be equal.) */ | ||
| 449 | if (Z == Z_BYTE) | 409 | if (Z == Z_BYTE) |
| 450 | { | 410 | { |
| 451 | if (m->charpos != m->bytepos) | 411 | if (m->charpos != m->bytepos) |
| @@ -456,45 +416,16 @@ adjust_markers_for_insert (from, from_byte, to, to_byte, | |||
| 456 | { | 416 | { |
| 457 | if (m->insertion_type || before_markers) | 417 | if (m->insertion_type || before_markers) |
| 458 | { | 418 | { |
| 459 | m->bytepos = to_byte + combined_after_bytes; | 419 | m->bytepos = to_byte; |
| 460 | m->charpos = to - combined_before_bytes; | 420 | m->charpos = to; |
| 461 | /* Point the marker before the combined character, | ||
| 462 | so that undoing the insertion puts it back where it was. */ | ||
| 463 | if (combined_after_bytes) | ||
| 464 | DEC_BOTH (m->charpos, m->bytepos); | ||
| 465 | if (m->insertion_type) | 421 | if (m->insertion_type) |
| 466 | adjusted = 1; | 422 | adjusted = 1; |
| 467 | } | 423 | } |
| 468 | else if (combined_before_bytes) | ||
| 469 | { | ||
| 470 | /* This marker doesn't "need relocation", | ||
| 471 | but don't leave it pointing in the middle of a character. | ||
| 472 | Point the marker after the combined character, | ||
| 473 | so that undoing the insertion puts it back where it was. */ | ||
| 474 | m->bytepos += combined_before_bytes; | ||
| 475 | if (combined_before_bytes == nbytes) | ||
| 476 | /* All new bytes plus combined_after_bytes (if any) | ||
| 477 | are combined. */ | ||
| 478 | m->bytepos += combined_after_bytes; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | /* If a marker was pointing into the combining bytes | ||
| 482 | after the insertion, don't leave it there | ||
| 483 | in the middle of a character. */ | ||
| 484 | else if (combined_after_bytes && m->bytepos >= from_byte | ||
| 485 | && m->bytepos < from_byte + combined_after_bytes) | ||
| 486 | { | ||
| 487 | /* Put it after the combining bytes. */ | ||
| 488 | m->bytepos = to_byte + combined_after_bytes; | ||
| 489 | m->charpos = to - combined_before_bytes; | ||
| 490 | /* Now move it back before the combined character, | ||
| 491 | so that undoing the insertion will put it where it was. */ | ||
| 492 | DEC_BOTH (m->charpos, m->bytepos); | ||
| 493 | } | 424 | } |
| 494 | else if (m->bytepos > from_byte) | 425 | else if (m->bytepos > from_byte) |
| 495 | { | 426 | { |
| 496 | m->bytepos += nbytes; | 427 | m->bytepos += nbytes; |
| 497 | m->charpos += nchars - combined_after_bytes - combined_before_bytes; | 428 | m->charpos += nchars; |
| 498 | } | 429 | } |
| 499 | 430 | ||
| 500 | marker = m->chain; | 431 | marker = m->chain; |
| @@ -531,22 +462,16 @@ adjust_point (nchars, nbytes) | |||
| 531 | 462 | ||
| 532 | /* Adjust markers for a replacement of a text at FROM (FROM_BYTE) of | 463 | /* Adjust markers for a replacement of a text at FROM (FROM_BYTE) of |
| 533 | length OLD_CHARS (OLD_BYTES) to a new text of length NEW_CHARS | 464 | length OLD_CHARS (OLD_BYTES) to a new text of length NEW_CHARS |
| 534 | (NEW_BYTES). | 465 | (NEW_BYTES). */ |
| 535 | |||
| 536 | See the comment of adjust_markers_for_insert for the args | ||
| 537 | COMBINED_BEFORE_BYTES and COMBINED_AFTER_BYTES. */ | ||
| 538 | 466 | ||
| 539 | static void | 467 | static void |
| 540 | adjust_markers_for_replace (from, from_byte, old_chars, old_bytes, | 468 | adjust_markers_for_replace (from, from_byte, old_chars, old_bytes, |
| 541 | new_chars, new_bytes, | 469 | new_chars, new_bytes) |
| 542 | combined_before_bytes, combined_after_bytes) | ||
| 543 | int from, from_byte, old_chars, old_bytes, new_chars, new_bytes; | 470 | int from, from_byte, old_chars, old_bytes, new_chars, new_bytes; |
| 544 | int combined_before_bytes, combined_after_bytes; | ||
| 545 | { | 471 | { |
| 546 | Lisp_Object marker = BUF_MARKERS (current_buffer); | 472 | Lisp_Object marker = BUF_MARKERS (current_buffer); |
| 547 | int prev_to_byte = from_byte + old_bytes; | 473 | int prev_to_byte = from_byte + old_bytes; |
| 548 | int diff_chars | 474 | int diff_chars = new_chars - old_chars; |
| 549 | = (new_chars - combined_before_bytes) - (old_chars + combined_after_bytes); | ||
| 550 | int diff_bytes = new_bytes - old_bytes; | 475 | int diff_bytes = new_bytes - old_bytes; |
| 551 | 476 | ||
| 552 | while (!NILP (marker)) | 477 | while (!NILP (marker)) |
| @@ -560,28 +485,13 @@ adjust_markers_for_replace (from, from_byte, old_chars, old_bytes, | |||
| 560 | insertion point and should stay before the insertion. */ | 485 | insertion point and should stay before the insertion. */ |
| 561 | || m->bytepos > from_byte || m->insertion_type)) | 486 | || m->bytepos > from_byte || m->insertion_type)) |
| 562 | { | 487 | { |
| 563 | if (m->bytepos < prev_to_byte + combined_after_bytes) | 488 | m->charpos = min (from + new_chars, m->charpos + diff_chars); |
| 564 | { | 489 | m->bytepos = min (from_byte + new_bytes, m->bytepos + diff_bytes); |
| 565 | /* Put it after the combining bytes. */ | ||
| 566 | m->bytepos = from_byte + new_bytes + combined_after_bytes; | ||
| 567 | m->charpos = from + new_chars - combined_before_bytes; | ||
| 568 | } | ||
| 569 | else | ||
| 570 | { | ||
| 571 | m->charpos = min (from + new_chars, m->charpos + diff_chars); | ||
| 572 | m->bytepos = min (from_byte + new_bytes, | ||
| 573 | m->bytepos + diff_bytes); | ||
| 574 | } | ||
| 575 | } | 490 | } |
| 576 | else if (m->bytepos >= from_byte) | 491 | else if (m->bytepos >= from_byte) |
| 577 | { | 492 | { |
| 578 | m->charpos = from; | 493 | m->charpos = from; |
| 579 | m->bytepos = from_byte + combined_before_bytes; | 494 | m->bytepos = from_byte; |
| 580 | /* If all new bytes are combined in addition to that there | ||
| 581 | are after combining bytes, we must set byte position of | ||
| 582 | the marker after the after combining bytes. */ | ||
| 583 | if (combined_before_bytes == new_bytes) | ||
| 584 | m->bytepos += combined_after_bytes; | ||
| 585 | } | 495 | } |
| 586 | 496 | ||
| 587 | marker = m->chain; | 497 | marker = m->chain; |
| @@ -696,8 +606,8 @@ copy_text (from_addr, to_addr, nbytes, | |||
| 696 | /* Convert multibyte to single byte. */ | 606 | /* Convert multibyte to single byte. */ |
| 697 | while (bytes_left > 0) | 607 | while (bytes_left > 0) |
| 698 | { | 608 | { |
| 699 | int thislen, c, c_save; | 609 | int thislen, c; |
| 700 | c = c_save = STRING_CHAR_AND_LENGTH (from_addr, bytes_left, thislen); | 610 | c = STRING_CHAR_AND_LENGTH (from_addr, bytes_left, thislen); |
| 701 | if (!SINGLE_BYTE_CHAR_P (c)) | 611 | if (!SINGLE_BYTE_CHAR_P (c)) |
| 702 | c = multibyte_char_to_unibyte (c, tbl); | 612 | c = multibyte_char_to_unibyte (c, tbl); |
| 703 | *to_addr++ = c; | 613 | *to_addr++ = c; |
| @@ -716,9 +626,7 @@ copy_text (from_addr, to_addr, nbytes, | |||
| 716 | { | 626 | { |
| 717 | int c = *from_addr++; | 627 | int c = *from_addr++; |
| 718 | 628 | ||
| 719 | if (c < 0400 | 629 | if (c >= 0200) |
| 720 | && (c >= 0240 | ||
| 721 | || (c >= 0200 && !NILP (Vnonascii_translation_table)))) | ||
| 722 | { | 630 | { |
| 723 | c = unibyte_char_to_multibyte (c); | 631 | c = unibyte_char_to_multibyte (c); |
| 724 | to_addr += CHAR_STRING (c, to_addr); | 632 | to_addr += CHAR_STRING (c, to_addr); |
| @@ -748,7 +656,7 @@ count_size_as_multibyte (ptr, nbytes) | |||
| 748 | { | 656 | { |
| 749 | unsigned int c = *ptr++; | 657 | unsigned int c = *ptr++; |
| 750 | 658 | ||
| 751 | if (c < 0200 || (c < 0240 && NILP (Vnonascii_translation_table))) | 659 | if (c < 0200) |
| 752 | outgoing_nbytes++; | 660 | outgoing_nbytes++; |
| 753 | else | 661 | else |
| 754 | { | 662 | { |
| @@ -875,7 +783,10 @@ insert_1 (string, nbytes, inherit, prepare, before_markers) | |||
| 875 | insert_1_both (string, chars_in_text (string, nbytes), nbytes, | 783 | insert_1_both (string, chars_in_text (string, nbytes), nbytes, |
| 876 | inherit, prepare, before_markers); | 784 | inherit, prepare, before_markers); |
| 877 | } | 785 | } |
| 786 | |||
| 878 | 787 | ||
| 788 | #ifdef BYTE_COMBINING_DEBUG | ||
| 789 | |||
| 879 | /* See if the bytes before POS/POS_BYTE combine with bytes | 790 | /* See if the bytes before POS/POS_BYTE combine with bytes |
| 880 | at the start of STRING to form a single character. | 791 | at the start of STRING to form a single character. |
| 881 | If so, return the number of bytes at the start of STRING | 792 | If so, return the number of bytes at the start of STRING |
| @@ -987,62 +898,7 @@ count_combining_after (string, length, pos, pos_byte) | |||
| 987 | return (bytes <= pos_byte - opos_byte ? bytes : pos_byte - opos_byte); | 898 | return (bytes <= pos_byte - opos_byte ? bytes : pos_byte - opos_byte); |
| 988 | } | 899 | } |
| 989 | 900 | ||
| 990 | /* Adjust the position TARGET/TARGET_BYTE for the combining of NBYTES | 901 | #endif |
| 991 | following the position POS/POS_BYTE to the character preceding POS. | ||
| 992 | If TARGET is after POS+NBYTES, we only have to adjust the character | ||
| 993 | position TARGET, else, if TARGET is after POS, we have to adjust | ||
| 994 | both the character position TARGET and the byte position | ||
| 995 | TARGET_BYTE, else we don't have to do any adjustment. */ | ||
| 996 | |||
| 997 | #define ADJUST_CHAR_POS(target, target_byte) \ | ||
| 998 | do { \ | ||
| 999 | if (target > pos + nbytes) \ | ||
| 1000 | target -= nbytes; \ | ||
| 1001 | else if (target >= pos) \ | ||
| 1002 | { \ | ||
| 1003 | target = pos; \ | ||
| 1004 | target_byte = pos_byte + nbytes; \ | ||
| 1005 | } \ | ||
| 1006 | } while (0) | ||
| 1007 | |||
| 1008 | /* Combine NBYTES stray trailing-codes, which were formerly separate | ||
| 1009 | characters, with the preceding character. These bytes | ||
| 1010 | are located after position POS / POS_BYTE, and the preceding character | ||
| 1011 | is located just before that position. | ||
| 1012 | |||
| 1013 | This function does not adjust markers for byte combining. That | ||
| 1014 | should be done in advance by the functions | ||
| 1015 | adjust_markers_for_insert or adjust_markers_for_replace. */ | ||
| 1016 | |||
| 1017 | static void | ||
| 1018 | combine_bytes (pos, pos_byte, nbytes) | ||
| 1019 | int pos, pos_byte, nbytes; | ||
| 1020 | { | ||
| 1021 | adjust_overlays_for_delete (pos, nbytes); | ||
| 1022 | |||
| 1023 | ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); | ||
| 1024 | ADJUST_CHAR_POS (GPT, GPT_BYTE); | ||
| 1025 | ADJUST_CHAR_POS (Z, Z_BYTE); | ||
| 1026 | ADJUST_CHAR_POS (ZV, ZV_BYTE); | ||
| 1027 | |||
| 1028 | if (BUF_INTERVALS (current_buffer) != 0) | ||
| 1029 | offset_intervals (current_buffer, pos, - nbytes); | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | void | ||
| 1033 | byte_combining_error () | ||
| 1034 | { | ||
| 1035 | error ("Byte combining across boundary of accessible buffer text inhibitted"); | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | /* If we are going to combine bytes at POS which is at a narrowed | ||
| 1039 | region boundary, signal an error. */ | ||
| 1040 | #define CHECK_BYTE_COMBINING_FOR_INSERT(pos) \ | ||
| 1041 | do { \ | ||
| 1042 | if ((combined_before_bytes && pos == BEGV) \ | ||
| 1043 | || (combined_after_bytes && pos == ZV)) \ | ||
| 1044 | byte_combining_error (); \ | ||
| 1045 | } while (0) | ||
| 1046 | 902 | ||
| 1047 | 903 | ||
| 1048 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes | 904 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes |
| @@ -1055,8 +911,6 @@ insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers) | |||
| 1055 | register int nchars, nbytes; | 911 | register int nchars, nbytes; |
| 1056 | int inherit, prepare, before_markers; | 912 | int inherit, prepare, before_markers; |
| 1057 | { | 913 | { |
| 1058 | int combined_before_bytes, combined_after_bytes; | ||
| 1059 | |||
| 1060 | if (NILP (current_buffer->enable_multibyte_characters)) | 914 | if (NILP (current_buffer->enable_multibyte_characters)) |
| 1061 | nchars = nbytes; | 915 | nchars = nbytes; |
| 1062 | 916 | ||
| @@ -1071,59 +925,21 @@ insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers) | |||
| 1071 | if (GAP_SIZE < nbytes) | 925 | if (GAP_SIZE < nbytes) |
| 1072 | make_gap (nbytes - GAP_SIZE); | 926 | make_gap (nbytes - GAP_SIZE); |
| 1073 | 927 | ||
| 1074 | combined_before_bytes | 928 | #ifdef BYTE_COMBINING_DEBUG |
| 1075 | = count_combining_before (string, nbytes, PT, PT_BYTE); | 929 | if (count_combining_before (string, nbytes, PT, PT_BYTE) |
| 1076 | combined_after_bytes | 930 | || count_combining_after (string, nbytes, PT, PT_BYTE)) |
| 1077 | = count_combining_after (string, nbytes, PT, PT_BYTE); | 931 | abort (); |
| 1078 | CHECK_BYTE_COMBINING_FOR_INSERT (PT); | 932 | #endif |
| 1079 | 933 | ||
| 1080 | /* Record deletion of the surrounding text that combines with | 934 | /* Record deletion of the surrounding text that combines with |
| 1081 | the insertion. This, together with recording the insertion, | 935 | the insertion. This, together with recording the insertion, |
| 1082 | will add up to the right stuff in the undo list. | 936 | will add up to the right stuff in the undo list. */ |
| 1083 | 937 | record_insert (PT, nchars); | |
| 1084 | But there is no need to actually delete the combining bytes | ||
| 1085 | from the buffer and reinsert them. */ | ||
| 1086 | |||
| 1087 | if (combined_after_bytes) | ||
| 1088 | { | ||
| 1089 | Lisp_Object deletion; | ||
| 1090 | deletion = Qnil; | ||
| 1091 | |||
| 1092 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1093 | deletion = make_buffer_string_both (PT, PT_BYTE, | ||
| 1094 | PT + combined_after_bytes, | ||
| 1095 | PT_BYTE + combined_after_bytes, 1); | ||
| 1096 | |||
| 1097 | adjust_markers_for_record_delete (PT, PT_BYTE, | ||
| 1098 | PT + combined_after_bytes, | ||
| 1099 | PT_BYTE + combined_after_bytes); | ||
| 1100 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1101 | record_delete (PT, deletion); | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | if (combined_before_bytes) | ||
| 1105 | { | ||
| 1106 | Lisp_Object deletion; | ||
| 1107 | deletion = Qnil; | ||
| 1108 | |||
| 1109 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1110 | deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1111 | PT, PT_BYTE, 1); | ||
| 1112 | adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1113 | PT, PT_BYTE); | ||
| 1114 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1115 | record_delete (PT - 1, deletion); | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | record_insert (PT - !!combined_before_bytes, | ||
| 1119 | nchars - combined_before_bytes + !!combined_before_bytes); | ||
| 1120 | MODIFF++; | 938 | MODIFF++; |
| 1121 | 939 | ||
| 1122 | bcopy (string, GPT_ADDR, nbytes); | 940 | bcopy (string, GPT_ADDR, nbytes); |
| 1123 | 941 | ||
| 1124 | GAP_SIZE -= nbytes; | 942 | GAP_SIZE -= nbytes; |
| 1125 | /* When we have combining at the end of the insertion, | ||
| 1126 | this is the character position before the combined character. */ | ||
| 1127 | GPT += nchars; | 943 | GPT += nchars; |
| 1128 | ZV += nchars; | 944 | ZV += nchars; |
| 1129 | Z += nchars; | 945 | Z += nchars; |
| @@ -1132,17 +948,12 @@ insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers) | |||
| 1132 | Z_BYTE += nbytes; | 948 | Z_BYTE += nbytes; |
| 1133 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 949 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 1134 | 950 | ||
| 1135 | if (combined_after_bytes) | ||
| 1136 | move_gap_both (GPT + combined_after_bytes, | ||
| 1137 | GPT_BYTE + combined_after_bytes); | ||
| 1138 | |||
| 1139 | if (GPT_BYTE < GPT) | 951 | if (GPT_BYTE < GPT) |
| 1140 | abort (); | 952 | abort (); |
| 1141 | 953 | ||
| 1142 | adjust_overlays_for_insert (PT, nchars); | 954 | adjust_overlays_for_insert (PT, nchars); |
| 1143 | adjust_markers_for_insert (PT, PT_BYTE, | 955 | adjust_markers_for_insert (PT, PT_BYTE, |
| 1144 | PT + nchars, PT_BYTE + nbytes, | 956 | PT + nchars, PT_BYTE + nbytes, |
| 1145 | combined_before_bytes, combined_after_bytes, | ||
| 1146 | before_markers); | 957 | before_markers); |
| 1147 | 958 | ||
| 1148 | if (BUF_INTERVALS (current_buffer) != 0) | 959 | if (BUF_INTERVALS (current_buffer) != 0) |
| @@ -1152,18 +963,7 @@ insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers) | |||
| 1152 | set_text_properties (make_number (PT), make_number (PT + nchars), | 963 | set_text_properties (make_number (PT), make_number (PT + nchars), |
| 1153 | Qnil, Qnil, Qnil); | 964 | Qnil, Qnil, Qnil); |
| 1154 | 965 | ||
| 1155 | { | 966 | adjust_point (nchars, nbytes); |
| 1156 | int pos = PT, pos_byte = PT_BYTE; | ||
| 1157 | |||
| 1158 | adjust_point (nchars + combined_after_bytes, | ||
| 1159 | nbytes + combined_after_bytes); | ||
| 1160 | |||
| 1161 | if (combined_after_bytes) | ||
| 1162 | combine_bytes (pos + nchars, pos_byte + nbytes, combined_after_bytes); | ||
| 1163 | |||
| 1164 | if (combined_before_bytes) | ||
| 1165 | combine_bytes (pos, pos_byte, combined_before_bytes); | ||
| 1166 | } | ||
| 1167 | 967 | ||
| 1168 | CHECK_MARKERS (); | 968 | CHECK_MARKERS (); |
| 1169 | } | 969 | } |
| @@ -1218,7 +1018,6 @@ insert_from_string_1 (string, pos, pos_byte, nchars, nbytes, | |||
| 1218 | { | 1018 | { |
| 1219 | struct gcpro gcpro1; | 1019 | struct gcpro gcpro1; |
| 1220 | int outgoing_nbytes = nbytes; | 1020 | int outgoing_nbytes = nbytes; |
| 1221 | int combined_before_bytes, combined_after_bytes; | ||
| 1222 | INTERVAL intervals; | 1021 | INTERVAL intervals; |
| 1223 | 1022 | ||
| 1224 | /* Make OUTGOING_NBYTES describe the text | 1023 | /* Make OUTGOING_NBYTES describe the text |
| @@ -1249,63 +1048,18 @@ insert_from_string_1 (string, pos, pos_byte, nchars, nbytes, | |||
| 1249 | STRING_MULTIBYTE (string), | 1048 | STRING_MULTIBYTE (string), |
| 1250 | ! NILP (current_buffer->enable_multibyte_characters)); | 1049 | ! NILP (current_buffer->enable_multibyte_characters)); |
| 1251 | 1050 | ||
| 1051 | #ifdef BYTE_COMBINING_DEBUG | ||
| 1252 | /* We have copied text into the gap, but we have not altered | 1052 | /* We have copied text into the gap, but we have not altered |
| 1253 | PT or PT_BYTE yet. So we can pass PT and PT_BYTE | 1053 | PT or PT_BYTE yet. So we can pass PT and PT_BYTE |
| 1254 | to these functions and get the same results as we would | 1054 | to these functions and get the same results as we would |
| 1255 | have got earlier on. Meanwhile, PT_ADDR does point to | 1055 | have got earlier on. Meanwhile, PT_ADDR does point to |
| 1256 | the text that has been stored by copy_text. */ | 1056 | the text that has been stored by copy_text. */ |
| 1057 | if (count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE) | ||
| 1058 | || count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE)) | ||
| 1059 | abort (); | ||
| 1060 | #endif | ||
| 1257 | 1061 | ||
| 1258 | combined_before_bytes | 1062 | record_insert (PT, nchars); |
| 1259 | = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | ||
| 1260 | combined_after_bytes | ||
| 1261 | = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | ||
| 1262 | { | ||
| 1263 | unsigned char save = *(GPT_ADDR); | ||
| 1264 | *(GPT_ADDR) = 0; | ||
| 1265 | CHECK_BYTE_COMBINING_FOR_INSERT (PT); | ||
| 1266 | *(GPT_ADDR) = save; | ||
| 1267 | } | ||
| 1268 | |||
| 1269 | /* Record deletion of the surrounding text that combines with | ||
| 1270 | the insertion. This, together with recording the insertion, | ||
| 1271 | will add up to the right stuff in the undo list. | ||
| 1272 | |||
| 1273 | But there is no need to actually delete the combining bytes | ||
| 1274 | from the buffer and reinsert them. */ | ||
| 1275 | |||
| 1276 | if (combined_after_bytes) | ||
| 1277 | { | ||
| 1278 | Lisp_Object deletion; | ||
| 1279 | deletion = Qnil; | ||
| 1280 | |||
| 1281 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1282 | deletion = make_buffer_string_both (PT, PT_BYTE, | ||
| 1283 | PT + combined_after_bytes, | ||
| 1284 | PT_BYTE + combined_after_bytes, 1); | ||
| 1285 | |||
| 1286 | adjust_markers_for_record_delete (PT, PT_BYTE, | ||
| 1287 | PT + combined_after_bytes, | ||
| 1288 | PT_BYTE + combined_after_bytes); | ||
| 1289 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1290 | record_delete (PT, deletion); | ||
| 1291 | } | ||
| 1292 | |||
| 1293 | if (combined_before_bytes) | ||
| 1294 | { | ||
| 1295 | Lisp_Object deletion; | ||
| 1296 | deletion = Qnil; | ||
| 1297 | |||
| 1298 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1299 | deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1300 | PT, PT_BYTE, 1); | ||
| 1301 | adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1302 | PT, PT_BYTE); | ||
| 1303 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1304 | record_delete (PT - 1, deletion); | ||
| 1305 | } | ||
| 1306 | |||
| 1307 | record_insert (PT - !!combined_before_bytes, | ||
| 1308 | nchars - combined_before_bytes + !!combined_before_bytes); | ||
| 1309 | MODIFF++; | 1063 | MODIFF++; |
| 1310 | 1064 | ||
| 1311 | GAP_SIZE -= outgoing_nbytes; | 1065 | GAP_SIZE -= outgoing_nbytes; |
| @@ -1317,24 +1071,18 @@ insert_from_string_1 (string, pos, pos_byte, nchars, nbytes, | |||
| 1317 | Z_BYTE += outgoing_nbytes; | 1071 | Z_BYTE += outgoing_nbytes; |
| 1318 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1072 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 1319 | 1073 | ||
| 1320 | if (combined_after_bytes) | ||
| 1321 | move_gap_both (GPT + combined_after_bytes, | ||
| 1322 | GPT_BYTE + combined_after_bytes); | ||
| 1323 | |||
| 1324 | if (GPT_BYTE < GPT) | 1074 | if (GPT_BYTE < GPT) |
| 1325 | abort (); | 1075 | abort (); |
| 1326 | 1076 | ||
| 1327 | adjust_overlays_for_insert (PT, nchars); | 1077 | adjust_overlays_for_insert (PT, nchars); |
| 1328 | adjust_markers_for_insert (PT, PT_BYTE, PT + nchars, | 1078 | adjust_markers_for_insert (PT, PT_BYTE, PT + nchars, |
| 1329 | PT_BYTE + outgoing_nbytes, | 1079 | PT_BYTE + outgoing_nbytes, |
| 1330 | combined_before_bytes, combined_after_bytes, | ||
| 1331 | before_markers); | 1080 | before_markers); |
| 1332 | 1081 | ||
| 1333 | offset_intervals (current_buffer, PT, nchars); | 1082 | offset_intervals (current_buffer, PT, nchars); |
| 1334 | 1083 | ||
| 1335 | intervals = XSTRING (string)->intervals; | 1084 | intervals = XSTRING (string)->intervals; |
| 1336 | /* Get the intervals for the part of the string we are inserting-- | 1085 | /* Get the intervals for the part of the string we are inserting. */ |
| 1337 | not including the combined-before bytes. */ | ||
| 1338 | if (nbytes < STRING_BYTES (XSTRING (string))) | 1086 | if (nbytes < STRING_BYTES (XSTRING (string))) |
| 1339 | intervals = copy_intervals (intervals, pos, nchars); | 1087 | intervals = copy_intervals (intervals, pos, nchars); |
| 1340 | 1088 | ||
| @@ -1342,19 +1090,7 @@ insert_from_string_1 (string, pos, pos_byte, nchars, nbytes, | |||
| 1342 | graft_intervals_into_buffer (intervals, PT, nchars, | 1090 | graft_intervals_into_buffer (intervals, PT, nchars, |
| 1343 | current_buffer, inherit); | 1091 | current_buffer, inherit); |
| 1344 | 1092 | ||
| 1345 | { | 1093 | adjust_point (nchars, outgoing_nbytes); |
| 1346 | int pos = PT, pos_byte = PT_BYTE; | ||
| 1347 | |||
| 1348 | adjust_point (nchars + combined_after_bytes, | ||
| 1349 | outgoing_nbytes + combined_after_bytes); | ||
| 1350 | |||
| 1351 | if (combined_after_bytes) | ||
| 1352 | combine_bytes (pos + nchars, pos_byte + outgoing_nbytes, | ||
| 1353 | combined_after_bytes); | ||
| 1354 | |||
| 1355 | if (combined_before_bytes) | ||
| 1356 | combine_bytes (pos, pos_byte, combined_before_bytes); | ||
| 1357 | } | ||
| 1358 | } | 1094 | } |
| 1359 | 1095 | ||
| 1360 | /* Insert text from BUF, NCHARS characters starting at CHARPOS, into the | 1096 | /* Insert text from BUF, NCHARS characters starting at CHARPOS, into the |
| @@ -1389,7 +1125,6 @@ insert_from_buffer_1 (buf, from, nchars, inherit) | |||
| 1389 | int to_byte = buf_charpos_to_bytepos (buf, from + nchars); | 1125 | int to_byte = buf_charpos_to_bytepos (buf, from + nchars); |
| 1390 | int incoming_nbytes = to_byte - from_byte; | 1126 | int incoming_nbytes = to_byte - from_byte; |
| 1391 | int outgoing_nbytes = incoming_nbytes; | 1127 | int outgoing_nbytes = incoming_nbytes; |
| 1392 | int combined_before_bytes, combined_after_bytes; | ||
| 1393 | INTERVAL intervals; | 1128 | INTERVAL intervals; |
| 1394 | 1129 | ||
| 1395 | /* Make OUTGOING_NBYTES describe the text | 1130 | /* Make OUTGOING_NBYTES describe the text |
| @@ -1460,62 +1195,18 @@ insert_from_buffer_1 (buf, from, nchars, inherit) | |||
| 1460 | ! NILP (buf->enable_multibyte_characters), | 1195 | ! NILP (buf->enable_multibyte_characters), |
| 1461 | ! NILP (current_buffer->enable_multibyte_characters)); | 1196 | ! NILP (current_buffer->enable_multibyte_characters)); |
| 1462 | 1197 | ||
| 1198 | #ifdef BYTE_COMBINING_DEBUG | ||
| 1463 | /* We have copied text into the gap, but we have not altered | 1199 | /* We have copied text into the gap, but we have not altered |
| 1464 | PT or PT_BYTE yet. So we can pass PT and PT_BYTE | 1200 | PT or PT_BYTE yet. So we can pass PT and PT_BYTE |
| 1465 | to these functions and get the same results as we would | 1201 | to these functions and get the same results as we would |
| 1466 | have got earlier on. Meanwhile, GPT_ADDR does point to | 1202 | have got earlier on. Meanwhile, GPT_ADDR does point to |
| 1467 | the text that has been stored by copy_text. */ | 1203 | the text that has been stored by copy_text. */ |
| 1468 | combined_before_bytes | 1204 | if (count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE) |
| 1469 | = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1205 | || count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE)) |
| 1470 | combined_after_bytes | 1206 | abort (); |
| 1471 | = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1207 | #endif |
| 1472 | { | ||
| 1473 | unsigned char save = *(GPT_ADDR); | ||
| 1474 | *(GPT_ADDR) = 0; | ||
| 1475 | CHECK_BYTE_COMBINING_FOR_INSERT (PT); | ||
| 1476 | *(GPT_ADDR) = save; | ||
| 1477 | } | ||
| 1478 | |||
| 1479 | /* Record deletion of the surrounding text that combines with | ||
| 1480 | the insertion. This, together with recording the insertion, | ||
| 1481 | will add up to the right stuff in the undo list. | ||
| 1482 | |||
| 1483 | But there is no need to actually delete the combining bytes | ||
| 1484 | from the buffer and reinsert them. */ | ||
| 1485 | |||
| 1486 | if (combined_after_bytes) | ||
| 1487 | { | ||
| 1488 | Lisp_Object deletion; | ||
| 1489 | deletion = Qnil; | ||
| 1490 | |||
| 1491 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1492 | deletion = make_buffer_string_both (PT, PT_BYTE, | ||
| 1493 | PT + combined_after_bytes, | ||
| 1494 | PT_BYTE + combined_after_bytes, 1); | ||
| 1495 | |||
| 1496 | adjust_markers_for_record_delete (PT, PT_BYTE, | ||
| 1497 | PT + combined_after_bytes, | ||
| 1498 | PT_BYTE + combined_after_bytes); | ||
| 1499 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1500 | record_delete (PT, deletion); | ||
| 1501 | } | ||
| 1502 | |||
| 1503 | if (combined_before_bytes) | ||
| 1504 | { | ||
| 1505 | Lisp_Object deletion; | ||
| 1506 | deletion = Qnil; | ||
| 1507 | |||
| 1508 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1509 | deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1510 | PT, PT_BYTE, 1); | ||
| 1511 | adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), | ||
| 1512 | PT, PT_BYTE); | ||
| 1513 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1514 | record_delete (PT - 1, deletion); | ||
| 1515 | } | ||
| 1516 | 1208 | ||
| 1517 | record_insert (PT - !!combined_before_bytes, | 1209 | record_insert (PT, nchars); |
| 1518 | nchars - combined_before_bytes + !!combined_before_bytes); | ||
| 1519 | MODIFF++; | 1210 | MODIFF++; |
| 1520 | 1211 | ||
| 1521 | GAP_SIZE -= outgoing_nbytes; | 1212 | GAP_SIZE -= outgoing_nbytes; |
| @@ -1527,23 +1218,18 @@ insert_from_buffer_1 (buf, from, nchars, inherit) | |||
| 1527 | Z_BYTE += outgoing_nbytes; | 1218 | Z_BYTE += outgoing_nbytes; |
| 1528 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1219 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 1529 | 1220 | ||
| 1530 | if (combined_after_bytes) | ||
| 1531 | move_gap_both (GPT + combined_after_bytes, | ||
| 1532 | GPT_BYTE + combined_after_bytes); | ||
| 1533 | |||
| 1534 | if (GPT_BYTE < GPT) | 1221 | if (GPT_BYTE < GPT) |
| 1535 | abort (); | 1222 | abort (); |
| 1536 | 1223 | ||
| 1537 | adjust_overlays_for_insert (PT, nchars); | 1224 | adjust_overlays_for_insert (PT, nchars); |
| 1538 | adjust_markers_for_insert (PT, PT_BYTE, PT + nchars, | 1225 | adjust_markers_for_insert (PT, PT_BYTE, PT + nchars, |
| 1539 | PT_BYTE + outgoing_nbytes, | 1226 | PT_BYTE + outgoing_nbytes, |
| 1540 | combined_before_bytes, combined_after_bytes, 0); | 1227 | 0); |
| 1541 | 1228 | ||
| 1542 | if (BUF_INTERVALS (current_buffer) != 0) | 1229 | if (BUF_INTERVALS (current_buffer) != 0) |
| 1543 | offset_intervals (current_buffer, PT, nchars); | 1230 | offset_intervals (current_buffer, PT, nchars); |
| 1544 | 1231 | ||
| 1545 | /* Get the intervals for the part of the string we are inserting-- | 1232 | /* Get the intervals for the part of the string we are inserting. */ |
| 1546 | not including the combined-before bytes. */ | ||
| 1547 | intervals = BUF_INTERVALS (buf); | 1233 | intervals = BUF_INTERVALS (buf); |
| 1548 | if (outgoing_nbytes < BUF_Z_BYTE (buf) - BUF_BEG_BYTE (buf)) | 1234 | if (outgoing_nbytes < BUF_Z_BYTE (buf) - BUF_BEG_BYTE (buf)) |
| 1549 | { | 1235 | { |
| @@ -1555,45 +1241,9 @@ insert_from_buffer_1 (buf, from, nchars, inherit) | |||
| 1555 | /* Insert those intervals. */ | 1241 | /* Insert those intervals. */ |
| 1556 | graft_intervals_into_buffer (intervals, PT, nchars, current_buffer, inherit); | 1242 | graft_intervals_into_buffer (intervals, PT, nchars, current_buffer, inherit); |
| 1557 | 1243 | ||
| 1558 | { | 1244 | adjust_point (nchars, outgoing_nbytes); |
| 1559 | int pos = PT, pos_byte = PT_BYTE; | ||
| 1560 | |||
| 1561 | adjust_point (nchars + combined_after_bytes, | ||
| 1562 | outgoing_nbytes + combined_after_bytes); | ||
| 1563 | |||
| 1564 | if (combined_after_bytes) | ||
| 1565 | combine_bytes (pos + nchars, pos_byte + outgoing_nbytes, | ||
| 1566 | combined_after_bytes); | ||
| 1567 | |||
| 1568 | if (combined_before_bytes) | ||
| 1569 | combine_bytes (pos, pos_byte, combined_before_bytes); | ||
| 1570 | } | ||
| 1571 | } | 1245 | } |
| 1572 | 1246 | ||
| 1573 | /* This function should be called after moving gap to FROM and before | ||
| 1574 | altering text between FROM and TO. This adjusts various position | ||
| 1575 | keepers and markers as if the text is deleted. Don't forget to | ||
| 1576 | call adjust_after_replace after you actually alter the text. */ | ||
| 1577 | |||
| 1578 | void | ||
| 1579 | adjust_before_replace (from, from_byte, to, to_byte) | ||
| 1580 | int from, from_byte, to, to_byte; | ||
| 1581 | { | ||
| 1582 | Lisp_Object deletion; | ||
| 1583 | |||
| 1584 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1585 | deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); | ||
| 1586 | |||
| 1587 | CHECK_MARKERS (); | ||
| 1588 | |||
| 1589 | adjust_markers_for_delete (from, from_byte, to, to_byte); | ||
| 1590 | |||
| 1591 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1592 | record_delete (from, deletion); | ||
| 1593 | |||
| 1594 | adjust_overlays_for_delete (from, to - from); | ||
| 1595 | } | ||
| 1596 | |||
| 1597 | /* Record undo information and adjust markers and position keepers for | 1247 | /* Record undo information and adjust markers and position keepers for |
| 1598 | a replacement of a text PREV_TEXT at FROM to a new text of LEN | 1248 | a replacement of a text PREV_TEXT at FROM to a new text of LEN |
| 1599 | chars (LEN_BYTE bytes) which resides in the gap just after | 1249 | chars (LEN_BYTE bytes) which resides in the gap just after |
| @@ -1606,67 +1256,20 @@ adjust_after_replace (from, from_byte, prev_text, len, len_byte) | |||
| 1606 | int from, from_byte, len, len_byte; | 1256 | int from, from_byte, len, len_byte; |
| 1607 | Lisp_Object prev_text; | 1257 | Lisp_Object prev_text; |
| 1608 | { | 1258 | { |
| 1609 | int combined_before_bytes | ||
| 1610 | = count_combining_before (GPT_ADDR, len_byte, from, from_byte); | ||
| 1611 | int combined_after_bytes | ||
| 1612 | = count_combining_after (GPT_ADDR, len_byte, from, from_byte); | ||
| 1613 | /* This flag tells if we combine some bytes with a character before | ||
| 1614 | FROM. This happens even if combined_before_bytes is zero. */ | ||
| 1615 | int combine_before = (combined_before_bytes | ||
| 1616 | || (len == 0 && combined_after_bytes)); | ||
| 1617 | |||
| 1618 | int nchars_del = 0, nbytes_del = 0; | 1259 | int nchars_del = 0, nbytes_del = 0; |
| 1619 | 1260 | ||
| 1261 | #ifdef BYTE_COMBINING_DEBUG | ||
| 1262 | if (count_combining_before (GPT_ADDR, len_byte, from, from_byte) | ||
| 1263 | || count_combining_after (GPT_ADDR, len_byte, from, from_byte)) | ||
| 1264 | abort (); | ||
| 1265 | #endif | ||
| 1266 | |||
| 1620 | if (STRINGP (prev_text)) | 1267 | if (STRINGP (prev_text)) |
| 1621 | { | 1268 | { |
| 1622 | nchars_del = XSTRING (prev_text)->size; | 1269 | nchars_del = XSTRING (prev_text)->size; |
| 1623 | nbytes_del = STRING_BYTES (XSTRING (prev_text)); | 1270 | nbytes_del = STRING_BYTES (XSTRING (prev_text)); |
| 1624 | } | 1271 | } |
| 1625 | 1272 | ||
| 1626 | if ((combine_before && from == BEGV) | ||
| 1627 | || (combined_after_bytes && from == ZV)) | ||
| 1628 | { | ||
| 1629 | /* We can't combine bytes nor signal an error here. So, let's | ||
| 1630 | pretend that the new text is just a single space. */ | ||
| 1631 | len = len_byte = 1; | ||
| 1632 | combined_before_bytes = combined_after_bytes = 0; | ||
| 1633 | *(GPT_ADDR) = ' '; | ||
| 1634 | } | ||
| 1635 | |||
| 1636 | if (combined_after_bytes) | ||
| 1637 | { | ||
| 1638 | Lisp_Object deletion; | ||
| 1639 | deletion = Qnil; | ||
| 1640 | |||
| 1641 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1642 | deletion = make_buffer_string_both (from, from_byte, | ||
| 1643 | from + combined_after_bytes, | ||
| 1644 | from_byte + combined_after_bytes, | ||
| 1645 | 1); | ||
| 1646 | |||
| 1647 | adjust_markers_for_record_delete (from, from_byte, | ||
| 1648 | from + combined_after_bytes, | ||
| 1649 | from_byte + combined_after_bytes); | ||
| 1650 | |||
| 1651 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1652 | record_delete (from + nchars_del, deletion); | ||
| 1653 | } | ||
| 1654 | |||
| 1655 | if (combined_before_bytes | ||
| 1656 | || (len_byte == 0 && combined_after_bytes > 0)) | ||
| 1657 | { | ||
| 1658 | Lisp_Object deletion; | ||
| 1659 | deletion = Qnil; | ||
| 1660 | |||
| 1661 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1662 | deletion = make_buffer_string_both (from - 1, CHAR_TO_BYTE (from - 1), | ||
| 1663 | from, from_byte, 1); | ||
| 1664 | adjust_markers_for_record_delete (from - 1, CHAR_TO_BYTE (from - 1), | ||
| 1665 | from, from_byte); | ||
| 1666 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1667 | record_delete (from - 1, deletion); | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | /* Update various buffer positions for the new text. */ | 1273 | /* Update various buffer positions for the new text. */ |
| 1671 | GAP_SIZE -= len_byte; | 1274 | GAP_SIZE -= len_byte; |
| 1672 | ZV += len; Z+= len; | 1275 | ZV += len; Z+= len; |
| @@ -1674,22 +1277,14 @@ adjust_after_replace (from, from_byte, prev_text, len, len_byte) | |||
| 1674 | GPT += len; GPT_BYTE += len_byte; | 1277 | GPT += len; GPT_BYTE += len_byte; |
| 1675 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1278 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 1676 | 1279 | ||
| 1677 | /* The gap should be at character boundary. */ | ||
| 1678 | if (combined_after_bytes) | ||
| 1679 | move_gap_both (GPT + combined_after_bytes, | ||
| 1680 | GPT_BYTE + combined_after_bytes); | ||
| 1681 | |||
| 1682 | adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, | 1280 | adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, |
| 1683 | len, len_byte, | 1281 | len, len_byte); |
| 1684 | combined_before_bytes, combined_after_bytes); | 1282 | |
| 1685 | if (! EQ (current_buffer->undo_list, Qt)) | 1283 | if (! EQ (current_buffer->undo_list, Qt)) |
| 1686 | { | 1284 | { |
| 1687 | if (nchars_del > 0) | 1285 | if (nchars_del > 0) |
| 1688 | record_delete (from - combine_before, prev_text); | 1286 | record_delete (from, prev_text); |
| 1689 | if (combine_before) | 1287 | record_insert (from, len); |
| 1690 | record_insert (from - 1, len - combined_before_bytes + 1); | ||
| 1691 | else | ||
| 1692 | record_insert (from, len); | ||
| 1693 | } | 1288 | } |
| 1694 | 1289 | ||
| 1695 | if (len > nchars_del) | 1290 | if (len > nchars_del) |
| @@ -1701,22 +1296,8 @@ adjust_after_replace (from, from_byte, prev_text, len, len_byte) | |||
| 1701 | offset_intervals (current_buffer, from, len - nchars_del); | 1296 | offset_intervals (current_buffer, from, len - nchars_del); |
| 1702 | } | 1297 | } |
| 1703 | 1298 | ||
| 1704 | { | 1299 | if (from < PT) |
| 1705 | if (from < PT) | 1300 | adjust_point (len - nchars_del, len_byte - nbytes_del); |
| 1706 | adjust_point (len - nchars_del, len_byte - nbytes_del); | ||
| 1707 | |||
| 1708 | if (combined_after_bytes) | ||
| 1709 | { | ||
| 1710 | if (combined_before_bytes == len_byte) | ||
| 1711 | /* This is the case that all new bytes are combined. */ | ||
| 1712 | combined_before_bytes += combined_after_bytes; | ||
| 1713 | else | ||
| 1714 | combine_bytes (from + len, from_byte + len_byte, | ||
| 1715 | combined_after_bytes); | ||
| 1716 | } | ||
| 1717 | if (combined_before_bytes) | ||
| 1718 | combine_bytes (from, from_byte, combined_before_bytes); | ||
| 1719 | } | ||
| 1720 | 1301 | ||
| 1721 | /* As byte combining will decrease Z, we must check this again. */ | 1302 | /* As byte combining will decrease Z, we must check this again. */ |
| 1722 | if (Z - GPT < END_UNCHANGED) | 1303 | if (Z - GPT < END_UNCHANGED) |
| @@ -1772,7 +1353,6 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1772 | int nbytes_del, nchars_del; | 1353 | int nbytes_del, nchars_del; |
| 1773 | register Lisp_Object temp; | 1354 | register Lisp_Object temp; |
| 1774 | struct gcpro gcpro1; | 1355 | struct gcpro gcpro1; |
| 1775 | int combined_before_bytes, combined_after_bytes; | ||
| 1776 | INTERVAL intervals; | 1356 | INTERVAL intervals; |
| 1777 | int outgoing_insbytes = insbytes; | 1357 | int outgoing_insbytes = insbytes; |
| 1778 | Lisp_Object deletion; | 1358 | Lisp_Object deletion; |
| @@ -1830,7 +1410,8 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1830 | /* Even if we don't record for undo, we must keep the original text | 1410 | /* Even if we don't record for undo, we must keep the original text |
| 1831 | because we may have to recover it because of inappropriate byte | 1411 | because we may have to recover it because of inappropriate byte |
| 1832 | combining. */ | 1412 | combining. */ |
| 1833 | deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); | 1413 | if (! EQ (current_buffer->undo_list, Qt)) |
| 1414 | deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); | ||
| 1834 | 1415 | ||
| 1835 | if (markers) | 1416 | if (markers) |
| 1836 | /* Relocate all markers pointing into the new, larger gap | 1417 | /* Relocate all markers pointing into the new, larger gap |
| @@ -1865,84 +1446,21 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1865 | STRING_MULTIBYTE (new), | 1446 | STRING_MULTIBYTE (new), |
| 1866 | ! NILP (current_buffer->enable_multibyte_characters)); | 1447 | ! NILP (current_buffer->enable_multibyte_characters)); |
| 1867 | 1448 | ||
| 1449 | #ifdef BYTE_COMBINING_DEBUG | ||
| 1868 | /* We have copied text into the gap, but we have not marked | 1450 | /* We have copied text into the gap, but we have not marked |
| 1869 | it as part of the buffer. So we can use the old FROM and FROM_BYTE | 1451 | it as part of the buffer. So we can use the old FROM and FROM_BYTE |
| 1870 | here, for both the previous text and the following text. | 1452 | here, for both the previous text and the following text. |
| 1871 | Meanwhile, GPT_ADDR does point to | 1453 | Meanwhile, GPT_ADDR does point to |
| 1872 | the text that has been stored by copy_text. */ | 1454 | the text that has been stored by copy_text. */ |
| 1873 | 1455 | if (count_combining_before (GPT_ADDR, outgoing_insbytes, from, from_byte) | |
| 1874 | combined_before_bytes | 1456 | || count_combining_after (GPT_ADDR, outgoing_insbytes, from, from_byte)) |
| 1875 | = count_combining_before (GPT_ADDR, outgoing_insbytes, from, from_byte); | 1457 | abort (); |
| 1876 | combined_after_bytes | 1458 | #endif |
| 1877 | = count_combining_after (GPT_ADDR, outgoing_insbytes, from, from_byte); | ||
| 1878 | |||
| 1879 | if ((combined_before_bytes && from == BEGV) | ||
| 1880 | || (combined_after_bytes && from == ZV)) | ||
| 1881 | { | ||
| 1882 | /* Bytes are being combined across the region boundary. We | ||
| 1883 | should avoid it. We recover the original contents before | ||
| 1884 | signaling an error. */ | ||
| 1885 | bcopy (XSTRING (deletion)->data, GPT_ADDR, nbytes_del); | ||
| 1886 | GAP_SIZE -= nbytes_del; | ||
| 1887 | ZV += nchars_del; | ||
| 1888 | Z += nchars_del; | ||
| 1889 | ZV_BYTE += nbytes_del; | ||
| 1890 | Z_BYTE += nbytes_del; | ||
| 1891 | GPT = from + nchars_del; | ||
| 1892 | GPT_BYTE = from_byte + nbytes_del; | ||
| 1893 | *(GPT_ADDR) = 0; /* Put an anchor. */ | ||
| 1894 | if (markers) | ||
| 1895 | adjust_markers_for_insert (from, from_byte, to, to_byte, 0, 0, 0); | ||
| 1896 | UNGCPRO; | ||
| 1897 | byte_combining_error (); | ||
| 1898 | GCPRO1 (new); | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | /* Record deletion of the surrounding text that combines with | ||
| 1902 | the insertion. This, together with recording the insertion, | ||
| 1903 | will add up to the right stuff in the undo list. | ||
| 1904 | |||
| 1905 | But there is no need to actually delete the combining bytes | ||
| 1906 | from the buffer and reinsert them. */ | ||
| 1907 | |||
| 1908 | if (combined_after_bytes) | ||
| 1909 | { | ||
| 1910 | Lisp_Object deletion; | ||
| 1911 | deletion = Qnil; | ||
| 1912 | |||
| 1913 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1914 | deletion = make_buffer_string_both (from, from_byte, | ||
| 1915 | from + combined_after_bytes, | ||
| 1916 | from_byte + combined_after_bytes, | ||
| 1917 | 1); | ||
| 1918 | |||
| 1919 | adjust_markers_for_record_delete (from, from_byte, | ||
| 1920 | from + combined_after_bytes, | ||
| 1921 | from_byte + combined_after_bytes); | ||
| 1922 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1923 | record_delete (from + nchars_del, deletion); | ||
| 1924 | } | ||
| 1925 | |||
| 1926 | if (combined_before_bytes) | ||
| 1927 | { | ||
| 1928 | Lisp_Object deletion; | ||
| 1929 | deletion = Qnil; | ||
| 1930 | |||
| 1931 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1932 | deletion = make_buffer_string_both (from - 1, CHAR_TO_BYTE (from - 1), | ||
| 1933 | from, from_byte, 1); | ||
| 1934 | adjust_markers_for_record_delete (from - 1, CHAR_TO_BYTE (from - 1), | ||
| 1935 | from, from_byte); | ||
| 1936 | if (! EQ (current_buffer->undo_list, Qt)) | ||
| 1937 | record_delete (from - 1, deletion); | ||
| 1938 | } | ||
| 1939 | 1459 | ||
| 1940 | if (! EQ (current_buffer->undo_list, Qt)) | 1460 | if (! EQ (current_buffer->undo_list, Qt)) |
| 1941 | { | 1461 | { |
| 1942 | record_delete (from - !!combined_before_bytes, deletion); | 1462 | record_delete (from, deletion); |
| 1943 | record_insert (from - !!combined_before_bytes, | 1463 | record_insert (from, inschars); |
| 1944 | (inschars - combined_before_bytes | ||
| 1945 | + !!combined_before_bytes)); | ||
| 1946 | } | 1464 | } |
| 1947 | 1465 | ||
| 1948 | GAP_SIZE -= outgoing_insbytes; | 1466 | GAP_SIZE -= outgoing_insbytes; |
| @@ -1954,10 +1472,6 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1954 | Z_BYTE += outgoing_insbytes; | 1472 | Z_BYTE += outgoing_insbytes; |
| 1955 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1473 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 1956 | 1474 | ||
| 1957 | if (combined_after_bytes) | ||
| 1958 | move_gap_both (GPT + combined_after_bytes, | ||
| 1959 | GPT_BYTE + combined_after_bytes); | ||
| 1960 | |||
| 1961 | if (GPT_BYTE < GPT) | 1475 | if (GPT_BYTE < GPT) |
| 1962 | abort (); | 1476 | abort (); |
| 1963 | 1477 | ||
| @@ -1968,7 +1482,7 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1968 | if (markers) | 1482 | if (markers) |
| 1969 | adjust_markers_for_insert (from, from_byte, | 1483 | adjust_markers_for_insert (from, from_byte, |
| 1970 | from + inschars, from_byte + outgoing_insbytes, | 1484 | from + inschars, from_byte + outgoing_insbytes, |
| 1971 | combined_before_bytes, combined_after_bytes, 0); | 1485 | 0); |
| 1972 | 1486 | ||
| 1973 | offset_intervals (current_buffer, from, inschars - nchars_del); | 1487 | offset_intervals (current_buffer, from, inschars - nchars_del); |
| 1974 | 1488 | ||
| @@ -1985,22 +1499,6 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 1985 | (from_byte + outgoing_insbytes | 1499 | (from_byte + outgoing_insbytes |
| 1986 | - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); | 1500 | - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); |
| 1987 | 1501 | ||
| 1988 | if (combined_after_bytes) | ||
| 1989 | { | ||
| 1990 | if (combined_before_bytes == outgoing_insbytes) | ||
| 1991 | /* This is the case that all new bytes are combined. */ | ||
| 1992 | combined_before_bytes += combined_after_bytes; | ||
| 1993 | else | ||
| 1994 | combine_bytes (from + inschars, from_byte + outgoing_insbytes, | ||
| 1995 | combined_after_bytes); | ||
| 1996 | } | ||
| 1997 | if (combined_before_bytes) | ||
| 1998 | combine_bytes (from, from_byte, combined_before_bytes); | ||
| 1999 | |||
| 2000 | /* As byte combining will decrease Z, we must check this again. */ | ||
| 2001 | if (Z - GPT < END_UNCHANGED) | ||
| 2002 | END_UNCHANGED = Z - GPT; | ||
| 2003 | |||
| 2004 | if (outgoing_insbytes == 0) | 1502 | if (outgoing_insbytes == 0) |
| 2005 | evaporate_overlays (from); | 1503 | evaporate_overlays (from); |
| 2006 | 1504 | ||
| @@ -2149,9 +1647,7 @@ del_range_2 (from, from_byte, to, to_byte, ret_string) | |||
| 2149 | int from, from_byte, to, to_byte, ret_string; | 1647 | int from, from_byte, to, to_byte, ret_string; |
| 2150 | { | 1648 | { |
| 2151 | register int nbytes_del, nchars_del; | 1649 | register int nbytes_del, nchars_del; |
| 2152 | int combined_after_bytes; | ||
| 2153 | Lisp_Object deletion; | 1650 | Lisp_Object deletion; |
| 2154 | int from_byte_1; | ||
| 2155 | 1651 | ||
| 2156 | CHECK_MARKERS (); | 1652 | CHECK_MARKERS (); |
| 2157 | 1653 | ||
| @@ -2164,56 +1660,25 @@ del_range_2 (from, from_byte, to, to_byte, ret_string) | |||
| 2164 | if (to < GPT) | 1660 | if (to < GPT) |
| 2165 | gap_left (to, to_byte, 0); | 1661 | gap_left (to, to_byte, 0); |
| 2166 | 1662 | ||
| 2167 | combined_after_bytes | 1663 | #ifdef BYTE_COMBINING_DEBUG |
| 2168 | = count_combining_before (BUF_BYTE_ADDRESS (current_buffer, to_byte), | 1664 | if (count_combining_before (BUF_BYTE_ADDRESS (current_buffer, to_byte), |
| 2169 | Z_BYTE - to_byte, from, from_byte); | 1665 | Z_BYTE - to_byte, from, from_byte)) |
| 2170 | if (combined_after_bytes) | 1666 | abort (); |
| 2171 | { | 1667 | #endif |
| 2172 | if (from == BEGV || to == ZV) | ||
| 2173 | byte_combining_error (); | ||
| 2174 | from_byte_1 = from_byte; | ||
| 2175 | DEC_POS (from_byte_1); | ||
| 2176 | } | ||
| 2177 | else | ||
| 2178 | from_byte_1 = from_byte; | ||
| 2179 | 1668 | ||
| 2180 | if (ret_string || ! EQ (current_buffer->undo_list, Qt)) | 1669 | if (ret_string || ! EQ (current_buffer->undo_list, Qt)) |
| 2181 | deletion | 1670 | deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); |
| 2182 | = make_buffer_string_both (from - !!combined_after_bytes, | ||
| 2183 | from_byte_1, | ||
| 2184 | to + combined_after_bytes, | ||
| 2185 | to_byte + combined_after_bytes, 1); | ||
| 2186 | else | 1671 | else |
| 2187 | deletion = Qnil; | 1672 | deletion = Qnil; |
| 2188 | 1673 | ||
| 2189 | if (combined_after_bytes) | ||
| 2190 | /* COMBINED_AFTER_BYTES nonzero means that the above code moved | ||
| 2191 | the gap. We must move the gap again to a proper place. */ | ||
| 2192 | move_gap_both (from, from_byte); | ||
| 2193 | |||
| 2194 | /* Relocate all markers pointing into the new, larger gap | 1674 | /* Relocate all markers pointing into the new, larger gap |
| 2195 | to point at the end of the text before the gap. | 1675 | to point at the end of the text before the gap. |
| 2196 | Do this before recording the deletion, | 1676 | Do this before recording the deletion, |
| 2197 | so that undo handles this after reinserting the text. */ | 1677 | so that undo handles this after reinserting the text. */ |
| 2198 | adjust_markers_for_delete (from, from_byte, to, to_byte); | 1678 | adjust_markers_for_delete (from, from_byte, to, to_byte); |
| 2199 | if (combined_after_bytes) | 1679 | |
| 2200 | { | ||
| 2201 | /* Adjust markers for the phony deletion | ||
| 2202 | that we are about to call record_undo for. */ | ||
| 2203 | |||
| 2204 | /* Here we delete the markers that formerly | ||
| 2205 | pointed at TO ... TO + COMBINED_AFTER_BYTES. | ||
| 2206 | But because of the call to adjust_markers_for_delete, above, | ||
| 2207 | they now point at FROM ... FROM + COMBINED_AFTER_BYTES. */ | ||
| 2208 | adjust_markers_for_record_delete (from, from_byte, | ||
| 2209 | from + combined_after_bytes, | ||
| 2210 | from_byte + combined_after_bytes); | ||
| 2211 | |||
| 2212 | adjust_markers_for_record_delete (from - 1, from_byte_1, | ||
| 2213 | from, from_byte); | ||
| 2214 | } | ||
| 2215 | if (! EQ (current_buffer->undo_list, Qt)) | 1680 | if (! EQ (current_buffer->undo_list, Qt)) |
| 2216 | record_delete (from - !!combined_after_bytes, deletion); | 1681 | record_delete (from, deletion); |
| 2217 | MODIFF++; | 1682 | MODIFF++; |
| 2218 | 1683 | ||
| 2219 | /* Relocate point as if it were a marker. */ | 1684 | /* Relocate point as if it were a marker. */ |
| @@ -2234,11 +1699,6 @@ del_range_2 (from, from_byte, to, to_byte, ret_string) | |||
| 2234 | Z -= nchars_del; | 1699 | Z -= nchars_del; |
| 2235 | GPT = from; | 1700 | GPT = from; |
| 2236 | GPT_BYTE = from_byte; | 1701 | GPT_BYTE = from_byte; |
| 2237 | |||
| 2238 | if (combined_after_bytes) | ||
| 2239 | move_gap_both (GPT + combined_after_bytes, | ||
| 2240 | GPT_BYTE + combined_after_bytes); | ||
| 2241 | |||
| 2242 | *(GPT_ADDR) = 0; /* Put an anchor. */ | 1702 | *(GPT_ADDR) = 0; /* Put an anchor. */ |
| 2243 | 1703 | ||
| 2244 | if (GPT_BYTE < GPT) | 1704 | if (GPT_BYTE < GPT) |
| @@ -2249,21 +1709,6 @@ del_range_2 (from, from_byte, to, to_byte, ret_string) | |||
| 2249 | if (Z - GPT < END_UNCHANGED) | 1709 | if (Z - GPT < END_UNCHANGED) |
| 2250 | END_UNCHANGED = Z - GPT; | 1710 | END_UNCHANGED = Z - GPT; |
| 2251 | 1711 | ||
| 2252 | if (combined_after_bytes) | ||
| 2253 | { | ||
| 2254 | /* Adjust markers for byte combining. As we have already | ||
| 2255 | adjuted markers without concerning byte combining, here we | ||
| 2256 | must concern only byte combining. */ | ||
| 2257 | adjust_markers_for_replace (from, from_byte, 0, 0, 0, 0, | ||
| 2258 | 0, combined_after_bytes); | ||
| 2259 | combine_bytes (from, from_byte, combined_after_bytes); | ||
| 2260 | |||
| 2261 | record_insert (GPT - 1, 1); | ||
| 2262 | |||
| 2263 | if (Z - GPT < END_UNCHANGED) | ||
| 2264 | END_UNCHANGED = Z - GPT; | ||
| 2265 | } | ||
| 2266 | |||
| 2267 | CHECK_MARKERS (); | 1712 | CHECK_MARKERS (); |
| 2268 | 1713 | ||
| 2269 | evaporate_overlays (from); | 1714 | evaporate_overlays (from); |