Mercurial > emacs
comparison src/insdel.c @ 23538:84ad9e201361
(adjust_markers_for_insert): Adjust markers by taking
combined_before_bytes and combined_after_bytes into account.
(count_combining_after): Handle the case that LENGTH is zero.
(adjust_after_replace): Record deletion at correct buffer
position. Handle the case that LEN is zero.
(replace_range): Record deletion at correct buffer position.
(del_range_2): Call adjust_makers_for_replace to adjust makers for
combined bytes.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 24 Oct 1998 01:17:09 +0000 |
parents | 84276318b663 |
children | 7417378e7cce |
comparison
equal
deleted
inserted
replaced
23537:28cd5faf93dd | 23538:84ad9e201361 |
---|---|
476 | 476 |
477 if (m->bytepos == from_byte) | 477 if (m->bytepos == from_byte) |
478 { | 478 { |
479 if (m->insertion_type || before_markers) | 479 if (m->insertion_type || before_markers) |
480 { | 480 { |
481 m->bytepos += nbytes + combined_after_bytes; | 481 m->bytepos = to_byte + combined_after_bytes; |
482 m->charpos += nchars + !!combined_after_bytes; | 482 m->charpos = to - combined_before_bytes; |
483 /* Point the marker before the combined character, | 483 /* Point the marker before the combined character, |
484 so that undoing the insertion puts it back where it was. */ | 484 so that undoing the insertion puts it back where it was. */ |
485 if (combined_after_bytes) | 485 if (combined_after_bytes) |
486 DEC_BOTH (m->charpos, m->bytepos); | 486 DEC_BOTH (m->charpos, m->bytepos); |
487 if (m->insertion_type) | 487 if (m->insertion_type) |
491 { | 491 { |
492 /* This marker doesn't "need relocation", | 492 /* This marker doesn't "need relocation", |
493 but don't leave it pointing in the middle of a character. | 493 but don't leave it pointing in the middle of a character. |
494 Point the marker after the combined character, | 494 Point the marker after the combined character, |
495 so that undoing the insertion puts it back where it was. */ | 495 so that undoing the insertion puts it back where it was. */ |
496 | 496 m->bytepos += combined_before_bytes; |
497 /* Here we depend on the fact that the gap is after | |
498 all of the combining bytes that we are going to skip over. */ | |
499 DEC_BOTH (m->charpos, m->bytepos); | |
500 INC_BOTH (m->charpos, m->bytepos); | |
501 } | 497 } |
502 } | 498 } |
503 /* If a marker was pointing into the combining bytes | 499 /* If a marker was pointing into the combining bytes |
504 after the insertion, don't leave it there | 500 after the insertion, don't leave it there |
505 in the middle of a character. */ | 501 in the middle of a character. */ |
506 else if (combined_after_bytes && m->bytepos >= from_byte | 502 else if (combined_after_bytes && m->bytepos >= from_byte |
507 && m->bytepos < from_byte + combined_after_bytes) | 503 && m->bytepos < from_byte + combined_after_bytes) |
508 { | 504 { |
509 /* Put it after the combining bytes. */ | 505 /* Put it after the combining bytes. */ |
510 m->bytepos = to_byte + combined_after_bytes; | 506 m->bytepos = to_byte + combined_after_bytes; |
511 m->charpos = to + 1; | 507 m->charpos = to - combined_before_bytes; |
512 /* Now move it back before the combined character, | 508 /* Now move it back before the combined character, |
513 so that undoing the insertion will put it where it was. */ | 509 so that undoing the insertion will put it where it was. */ |
514 DEC_BOTH (m->charpos, m->bytepos); | 510 DEC_BOTH (m->charpos, m->bytepos); |
515 } | 511 } |
516 else if (m->bytepos > from_byte) | 512 else if (m->bytepos > from_byte) |
517 { | 513 { |
518 m->bytepos += nbytes; | 514 m->bytepos += nbytes; |
519 m->charpos += nchars; | 515 m->charpos += nchars - combined_after_bytes - combined_before_bytes; |
520 } | 516 } |
521 | 517 |
522 marker = m->chain; | 518 marker = m->chain; |
523 } | 519 } |
524 | 520 |
943 int i; | 939 int i; |
944 int c; | 940 int c; |
945 | 941 |
946 if (NILP (current_buffer->enable_multibyte_characters)) | 942 if (NILP (current_buffer->enable_multibyte_characters)) |
947 return 0; | 943 return 0; |
948 if (length == 0 || ASCII_BYTE_P (string[length - 1])) | 944 if (length > 0 && ASCII_BYTE_P (string[length - 1])) |
949 return 0; | 945 return 0; |
950 i = length - 1; | 946 i = length - 1; |
951 while (i >= 0 && ! CHAR_HEAD_P (string[i])) | 947 while (i >= 0 && ! CHAR_HEAD_P (string[i])) |
952 { | 948 { |
953 i--; | 949 i--; |
1147 combine_bytes (pos + nchars, pos_byte + nbytes, combined_after_bytes); | 1143 combine_bytes (pos + nchars, pos_byte + nbytes, combined_after_bytes); |
1148 | 1144 |
1149 if (combined_before_bytes) | 1145 if (combined_before_bytes) |
1150 combine_bytes (pos, pos_byte, combined_before_bytes); | 1146 combine_bytes (pos, pos_byte, combined_before_bytes); |
1151 } | 1147 } |
1148 | |
1149 CHECK_MARKERS (); | |
1152 } | 1150 } |
1153 | 1151 |
1154 /* Insert the part of the text of STRING, a Lisp object assumed to be | 1152 /* Insert the part of the text of STRING, a Lisp object assumed to be |
1155 of type string, consisting of the LENGTH characters (LENGTH_BYTE bytes) | 1153 of type string, consisting of the LENGTH characters (LENGTH_BYTE bytes) |
1156 starting at position POS / POS_BYTE. If the text of STRING has properties, | 1154 starting at position POS / POS_BYTE. If the text of STRING has properties, |
1556 = count_combining_before (GPT_ADDR, len_byte, from, from_byte); | 1554 = count_combining_before (GPT_ADDR, len_byte, from, from_byte); |
1557 int combined_after_bytes | 1555 int combined_after_bytes |
1558 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); | 1556 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); |
1559 int nchars_del = 0, nbytes_del = 0; | 1557 int nchars_del = 0, nbytes_del = 0; |
1560 | 1558 |
1559 if (STRINGP (prev_text)) | |
1560 { | |
1561 nchars_del = XSTRING (prev_text)->size; | |
1562 nbytes_del = STRING_BYTES (XSTRING (prev_text)); | |
1563 } | |
1564 | |
1561 if (combined_after_bytes) | 1565 if (combined_after_bytes) |
1562 { | 1566 { |
1563 Lisp_Object deletion; | 1567 Lisp_Object deletion; |
1564 deletion = Qnil; | 1568 deletion = Qnil; |
1565 | 1569 |
1572 adjust_markers_for_record_delete (from, from_byte, | 1576 adjust_markers_for_record_delete (from, from_byte, |
1573 from + combined_after_bytes, | 1577 from + combined_after_bytes, |
1574 from_byte + combined_after_bytes); | 1578 from_byte + combined_after_bytes); |
1575 | 1579 |
1576 if (! EQ (current_buffer->undo_list, Qt)) | 1580 if (! EQ (current_buffer->undo_list, Qt)) |
1577 record_delete (from + len, deletion); | 1581 record_delete (from + nchars_del, deletion); |
1578 } | 1582 } |
1579 | 1583 |
1580 if (combined_before_bytes) | 1584 if (combined_before_bytes |
1585 || len_byte == 0 && combined_after_bytes > 0) | |
1581 { | 1586 { |
1582 Lisp_Object deletion; | 1587 Lisp_Object deletion; |
1583 deletion = Qnil; | 1588 deletion = Qnil; |
1584 | 1589 |
1585 if (! EQ (current_buffer->undo_list, Qt)) | 1590 if (! EQ (current_buffer->undo_list, Qt)) |
1596 ZV += len; Z+= len; | 1601 ZV += len; Z+= len; |
1597 ZV_BYTE += len_byte; Z_BYTE += len_byte; | 1602 ZV_BYTE += len_byte; Z_BYTE += len_byte; |
1598 GPT += len; GPT_BYTE += len_byte; | 1603 GPT += len; GPT_BYTE += len_byte; |
1599 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1604 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
1600 | 1605 |
1606 /* The gap should be at character boundary. */ | |
1601 if (combined_after_bytes) | 1607 if (combined_after_bytes) |
1602 move_gap_both (GPT + combined_after_bytes, | 1608 move_gap_both (GPT + combined_after_bytes, |
1603 GPT_BYTE + combined_after_bytes); | 1609 GPT_BYTE + combined_after_bytes); |
1604 | 1610 |
1605 if (STRINGP (prev_text)) | |
1606 { | |
1607 nchars_del = XSTRING (prev_text)->size; | |
1608 nbytes_del = STRING_BYTES (XSTRING (prev_text)); | |
1609 } | |
1610 adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, | 1611 adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, |
1611 len, len_byte, | 1612 len, len_byte, |
1612 combined_before_bytes, combined_after_bytes); | 1613 combined_before_bytes, combined_after_bytes); |
1613 if (STRINGP (prev_text)) | 1614 if (! EQ (current_buffer->undo_list, Qt)) |
1614 record_delete (from - !!combined_before_bytes, prev_text); | 1615 { |
1615 record_insert (from - !!combined_before_bytes, | 1616 /* This flag tells if we combine some bytes with a character |
1616 len - combined_before_bytes + !!combined_before_bytes); | 1617 before FROM. This happens even if combined_before_bytes is |
1618 zero. */ | |
1619 int combine_before = (combined_before_bytes | |
1620 || (len == 0 && combined_after_bytes)); | |
1621 | |
1622 if (nchars_del > 0) | |
1623 record_delete (from - combine_before, prev_text); | |
1624 if (combine_before) | |
1625 record_insert (from - 1, len - combined_before_bytes + 1); | |
1626 else | |
1627 record_insert (from, len); | |
1628 } | |
1617 | 1629 |
1618 if (len > nchars_del) | 1630 if (len > nchars_del) |
1619 adjust_overlays_for_insert (from, len - nchars_del); | 1631 adjust_overlays_for_insert (from, len - nchars_del); |
1620 else if (len < nchars_del) | 1632 else if (len < nchars_del) |
1621 adjust_overlays_for_delete (from, nchars_del - len); | 1633 adjust_overlays_for_delete (from, nchars_del - len); |
1631 | 1643 |
1632 if (from < PT) | 1644 if (from < PT) |
1633 adjust_point (len - nchars_del, len_byte - nbytes_del); | 1645 adjust_point (len - nchars_del, len_byte - nbytes_del); |
1634 | 1646 |
1635 if (combined_after_bytes) | 1647 if (combined_after_bytes) |
1636 { | 1648 combine_bytes (from + len, from_byte + len_byte, combined_after_bytes); |
1637 if (combined_before_bytes) | |
1638 combined_before_bytes += combined_after_bytes; | |
1639 else | |
1640 combine_bytes (from + len, from_byte + len_byte, | |
1641 combined_after_bytes); | |
1642 } | |
1643 | 1649 |
1644 if (combined_before_bytes) | 1650 if (combined_before_bytes) |
1645 combine_bytes (from, from_byte, combined_before_bytes); | 1651 combine_bytes (from, from_byte, combined_before_bytes); |
1646 } | 1652 } |
1647 | 1653 |
1813 deletion = Qnil; | 1819 deletion = Qnil; |
1814 | 1820 |
1815 if (! EQ (current_buffer->undo_list, Qt)) | 1821 if (! EQ (current_buffer->undo_list, Qt)) |
1816 deletion = make_buffer_string_both (from, from_byte, | 1822 deletion = make_buffer_string_both (from, from_byte, |
1817 from + combined_after_bytes, | 1823 from + combined_after_bytes, |
1818 from_byte + combined_after_bytes, 1); | 1824 from_byte + combined_after_bytes, |
1825 1); | |
1819 | 1826 |
1820 adjust_markers_for_record_delete (from, from_byte, | 1827 adjust_markers_for_record_delete (from, from_byte, |
1821 from + combined_after_bytes, | 1828 from + combined_after_bytes, |
1822 from_byte + combined_after_bytes); | 1829 from_byte + combined_after_bytes); |
1823 if (! EQ (current_buffer->undo_list, Qt)) | 1830 if (! EQ (current_buffer->undo_list, Qt)) |
1824 record_delete (from + inschars, deletion); | 1831 record_delete (from + nchars_del, deletion); |
1825 } | 1832 } |
1826 | 1833 |
1827 if (combined_before_bytes) | 1834 if (combined_before_bytes) |
1828 { | 1835 { |
1829 Lisp_Object deletion; | 1836 Lisp_Object deletion; |
1887 adjust_point ((from + inschars - (PT < to ? PT : to)), | 1894 adjust_point ((from + inschars - (PT < to ? PT : to)), |
1888 (from_byte + outgoing_insbytes | 1895 (from_byte + outgoing_insbytes |
1889 - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); | 1896 - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); |
1890 | 1897 |
1891 if (combined_after_bytes) | 1898 if (combined_after_bytes) |
1892 { | 1899 combine_bytes (from + inschars, from_byte + outgoing_insbytes, |
1893 if (combined_before_bytes) | 1900 combined_after_bytes); |
1894 combined_before_bytes += combined_after_bytes; | |
1895 else | |
1896 combine_bytes (from + inschars, from_byte + outgoing_insbytes, | |
1897 combined_after_bytes); | |
1898 } | |
1899 if (combined_before_bytes) | 1901 if (combined_before_bytes) |
1900 combine_bytes (from, from_byte, combined_before_bytes); | 1902 combine_bytes (from, from_byte, combined_before_bytes); |
1901 | 1903 |
1902 if (outgoing_insbytes == 0) | 1904 if (outgoing_insbytes == 0) |
1903 evaporate_overlays (from); | 1905 evaporate_overlays (from); |
2129 if (Z - GPT < end_unchanged) | 2131 if (Z - GPT < end_unchanged) |
2130 end_unchanged = Z - GPT; | 2132 end_unchanged = Z - GPT; |
2131 | 2133 |
2132 if (combined_after_bytes) | 2134 if (combined_after_bytes) |
2133 { | 2135 { |
2136 /* Adjust markers for byte combining. As we have already | |
2137 adjuted markers without concerning byte combining, here we | |
2138 must concern only byte combining. */ | |
2139 adjust_markers_for_replace (from, from_byte, 0, 0, 0, 0, | |
2140 0, combined_after_bytes); | |
2134 combine_bytes (from, from_byte, combined_after_bytes); | 2141 combine_bytes (from, from_byte, combined_after_bytes); |
2135 | 2142 |
2136 record_insert (GPT - 1, 1); | 2143 record_insert (GPT - 1, 1); |
2137 } | 2144 } |
2138 | 2145 |