Mercurial > emacs
comparison src/insdel.c @ 23597:fda73fa21974
(byte_combining_error): New function.
(CHECK_BYTE_COMBINING_FOR_INSERT): Call byte_combining_error.
(insert_from_string_1): Set *(GPT_ADDR) to 0 before calling
CHECK_BYTE_COMBINING_FOR_INSERT.
(insert_from_buffer_1): Likewise.
(adjust_after_replace): Check the posibility of inhibitted byte
combining correctly.
(replace_range): Before signaling an error for inhibitted byte
combining, recover the buffer in a safe state.
(del_range_2): Check the posibility of inhibitted byte combining
correctly.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 31 Oct 1998 05:12:07 +0000 |
parents | 25baa4bda79d |
children | db1ded871074 |
comparison
equal
deleted
inserted
replaced
23596:8dcbcad4482c | 23597:fda73fa21974 |
---|---|
1027 if (BUF_INTERVALS (current_buffer) != 0) | 1027 if (BUF_INTERVALS (current_buffer) != 0) |
1028 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ | 1028 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ |
1029 offset_intervals (current_buffer, pos, - nbytes); | 1029 offset_intervals (current_buffer, pos, - nbytes); |
1030 } | 1030 } |
1031 | 1031 |
1032 void | |
1033 byte_combining_error () | |
1034 { | |
1035 error ("Byte combining across region boundary inhibitted"); | |
1036 } | |
1037 | |
1032 /* If we are going to combine bytes at POS which is at a narrowed | 1038 /* If we are going to combine bytes at POS which is at a narrowed |
1033 region boundary, signal an error. */ | 1039 region boundary, signal an error. */ |
1034 #define CHECK_BYTE_COMBINING_FOR_INSERT(pos) \ | 1040 #define CHECK_BYTE_COMBINING_FOR_INSERT(pos) \ |
1035 do { \ | 1041 do { \ |
1036 if (combined_before_bytes && pos == BEGV \ | 1042 if (combined_before_bytes && pos == BEGV \ |
1037 || combined_after_bytes && pos == ZV) \ | 1043 || combined_after_bytes && pos == ZV) \ |
1038 error ("Byte combining across region boundary inhibitted"); \ | 1044 byte_combining_error (); \ |
1039 } while (0) | 1045 } while (0) |
1040 | 1046 |
1041 | 1047 |
1042 /* Insert a sequence of NCHARS chars which occupy NBYTES bytes | 1048 /* Insert a sequence of NCHARS chars which occupy NBYTES bytes |
1043 starting at STRING. INHERIT, PREPARE and BEFORE_MARKERS | 1049 starting at STRING. INHERIT, PREPARE and BEFORE_MARKERS |
1257 = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1263 = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); |
1258 combined_after_bytes | 1264 combined_after_bytes |
1259 = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1265 = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); |
1260 { | 1266 { |
1261 unsigned char save = *(GPT_ADDR); | 1267 unsigned char save = *(GPT_ADDR); |
1268 *(GPT_ADDR) = 0; | |
1262 CHECK_BYTE_COMBINING_FOR_INSERT (PT); | 1269 CHECK_BYTE_COMBINING_FOR_INSERT (PT); |
1263 *(GPT_ADDR) = save; | 1270 *(GPT_ADDR) = save; |
1264 } | 1271 } |
1265 | 1272 |
1266 /* Record deletion of the surrounding text that combines with | 1273 /* Record deletion of the surrounding text that combines with |
1442 = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1449 = count_combining_before (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); |
1443 combined_after_bytes | 1450 combined_after_bytes |
1444 = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); | 1451 = count_combining_after (GPT_ADDR, outgoing_nbytes, PT, PT_BYTE); |
1445 { | 1452 { |
1446 unsigned char save = *(GPT_ADDR); | 1453 unsigned char save = *(GPT_ADDR); |
1454 *(GPT_ADDR) = 0; | |
1447 CHECK_BYTE_COMBINING_FOR_INSERT (PT); | 1455 CHECK_BYTE_COMBINING_FOR_INSERT (PT); |
1448 *(GPT_ADDR) = save; | 1456 *(GPT_ADDR) = save; |
1449 } | 1457 } |
1450 | 1458 |
1451 /* Record deletion of the surrounding text that combines with | 1459 /* Record deletion of the surrounding text that combines with |
1578 { | 1586 { |
1579 int combined_before_bytes | 1587 int combined_before_bytes |
1580 = count_combining_before (GPT_ADDR, len_byte, from, from_byte); | 1588 = count_combining_before (GPT_ADDR, len_byte, from, from_byte); |
1581 int combined_after_bytes | 1589 int combined_after_bytes |
1582 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); | 1590 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); |
1591 /* This flag tells if we combine some bytes with a character before | |
1592 FROM. This happens even if combined_before_bytes is zero. */ | |
1593 int combine_before = (combined_before_bytes | |
1594 || (len == 0 && combined_after_bytes)); | |
1595 | |
1583 int nchars_del = 0, nbytes_del = 0; | 1596 int nchars_del = 0, nbytes_del = 0; |
1584 | 1597 |
1585 if (STRINGP (prev_text)) | 1598 if (STRINGP (prev_text)) |
1586 { | 1599 { |
1587 nchars_del = XSTRING (prev_text)->size; | 1600 nchars_del = XSTRING (prev_text)->size; |
1588 nbytes_del = STRING_BYTES (XSTRING (prev_text)); | 1601 nbytes_del = STRING_BYTES (XSTRING (prev_text)); |
1589 } | 1602 } |
1590 | 1603 |
1591 if (combined_before_bytes && from == BEGV | 1604 if (combine_before && from == BEGV |
1592 || combined_after_bytes && from == ZV) | 1605 || combined_after_bytes && from == ZV) |
1593 { | 1606 { |
1594 /* We can't combine bytes nor signal an error here. So, let's | 1607 /* We can't combine bytes nor signal an error here. So, let's |
1595 pretend that the new text is just a single space. */ | 1608 pretend that the new text is just a single space. */ |
1596 len = len_byte = 1; | 1609 len = len_byte = 1; |
1647 adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, | 1660 adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, |
1648 len, len_byte, | 1661 len, len_byte, |
1649 combined_before_bytes, combined_after_bytes); | 1662 combined_before_bytes, combined_after_bytes); |
1650 if (! EQ (current_buffer->undo_list, Qt)) | 1663 if (! EQ (current_buffer->undo_list, Qt)) |
1651 { | 1664 { |
1652 /* This flag tells if we combine some bytes with a character | |
1653 before FROM. This happens even if combined_before_bytes is | |
1654 zero. */ | |
1655 int combine_before = (combined_before_bytes | |
1656 || (len == 0 && combined_after_bytes)); | |
1657 | |
1658 if (nchars_del > 0) | 1665 if (nchars_del > 0) |
1659 record_delete (from - combine_before, prev_text); | 1666 record_delete (from - combine_before, prev_text); |
1660 if (combine_before) | 1667 if (combine_before) |
1661 record_insert (from - 1, len - combined_before_bytes + 1); | 1668 record_insert (from - 1, len - combined_before_bytes + 1); |
1662 else | 1669 else |
1801 if (from > GPT) | 1808 if (from > GPT) |
1802 gap_right (from, from_byte); | 1809 gap_right (from, from_byte); |
1803 if (to < GPT) | 1810 if (to < GPT) |
1804 gap_left (to, to_byte, 0); | 1811 gap_left (to, to_byte, 0); |
1805 | 1812 |
1806 deletion = Qnil; | 1813 /* Even if we don't record for undo, we must keep the original text |
1807 | 1814 because we may have to recover it because of inappropriate byte |
1808 if (! EQ (current_buffer->undo_list, Qt)) | 1815 combining. */ |
1809 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); | 1816 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); |
1810 | 1817 |
1811 if (markers) | 1818 if (markers) |
1812 /* Relocate all markers pointing into the new, larger gap | 1819 /* Relocate all markers pointing into the new, larger gap |
1813 to point at the end of the text before the gap. | 1820 to point at the end of the text before the gap. |
1814 Do this before recording the deletion, | 1821 Do this before recording the deletion, |
1849 | 1856 |
1850 combined_before_bytes | 1857 combined_before_bytes |
1851 = count_combining_before (GPT_ADDR, outgoing_insbytes, from, from_byte); | 1858 = count_combining_before (GPT_ADDR, outgoing_insbytes, from, from_byte); |
1852 combined_after_bytes | 1859 combined_after_bytes |
1853 = count_combining_after (GPT_ADDR, outgoing_insbytes, from, from_byte); | 1860 = count_combining_after (GPT_ADDR, outgoing_insbytes, from, from_byte); |
1854 { | 1861 |
1855 unsigned char save = *(GPT_ADDR); | 1862 if (combined_before_bytes && from == BEGV |
1856 CHECK_BYTE_COMBINING_FOR_INSERT (from); | 1863 || combined_after_bytes && from == ZV) |
1857 *(GPT_ADDR) = save; | 1864 { |
1858 } | 1865 /* Bytes are being combined across the region boundary. We |
1866 should avoid it. We recover the original contents before | |
1867 signaling an error. */ | |
1868 bcopy (XSTRING (deletion)->data, GPT_ADDR, nbytes_del); | |
1869 GAP_SIZE -= nbytes_del; | |
1870 ZV += nchars_del; | |
1871 Z += nchars_del; | |
1872 ZV_BYTE += nbytes_del; | |
1873 Z_BYTE += nbytes_del; | |
1874 GPT = from + nchars_del; | |
1875 GPT_BYTE = from_byte + nbytes_del; | |
1876 *(GPT_ADDR) = 0; /* Put an anchor. */ | |
1877 if (markers) | |
1878 adjust_markers_for_insert (from, from_byte, to, to_byte, 0, 0, 0); | |
1879 byte_combining_error (); | |
1880 } | |
1859 | 1881 |
1860 /* Record deletion of the surrounding text that combines with | 1882 /* Record deletion of the surrounding text that combines with |
1861 the insertion. This, together with recording the insertion, | 1883 the insertion. This, together with recording the insertion, |
1862 will add up to the right stuff in the undo list. | 1884 will add up to the right stuff in the undo list. |
1863 | 1885 |
2114 combined_after_bytes | 2136 combined_after_bytes |
2115 = count_combining_before (BUF_BYTE_ADDRESS (current_buffer, to_byte), | 2137 = count_combining_before (BUF_BYTE_ADDRESS (current_buffer, to_byte), |
2116 Z_BYTE - to_byte, from, from_byte); | 2138 Z_BYTE - to_byte, from, from_byte); |
2117 if (combined_after_bytes) | 2139 if (combined_after_bytes) |
2118 { | 2140 { |
2119 if (to == ZV_BYTE) | 2141 if (from == BEGV || to == ZV) |
2120 error ("Byte combining across region boundary inhibitted"); | 2142 byte_combining_error (); |
2121 from_byte_1 = from_byte; | 2143 from_byte_1 = from_byte; |
2122 DEC_POS (from_byte_1); | 2144 DEC_POS (from_byte_1); |
2123 } | 2145 } |
2124 else | 2146 else |
2125 from_byte_1 = from_byte; | 2147 from_byte_1 = from_byte; |