diff options
| author | Kenichi Handa | 1998-10-31 05:12:07 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-10-31 05:12:07 +0000 |
| commit | 039af53ac41b632547290f765adaafce91845f0c (patch) | |
| tree | 65ac52bbc751e47b8273ee30321507186205d8ad | |
| parent | 48839d2ed7f4752ceb3efa350bd90a532c073421 (diff) | |
| download | emacs-039af53ac41b632547290f765adaafce91845f0c.tar.gz emacs-039af53ac41b632547290f765adaafce91845f0c.zip | |
(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.
| -rw-r--r-- | src/insdel.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/src/insdel.c b/src/insdel.c index 70646a2805e..7ec6f25f225 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -1029,13 +1029,19 @@ combine_bytes (pos, pos_byte, nbytes) | |||
| 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 | ||
| @@ -1259,6 +1265,7 @@ insert_from_string_1 (string, pos, pos_byte, nchars, nbytes, | |||
| 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 | } |
| @@ -1444,6 +1451,7 @@ insert_from_buffer_1 (buf, from, nchars, inherit) | |||
| 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 | } |
| @@ -1580,6 +1588,11 @@ adjust_after_replace (from, from_byte, prev_text, len, len_byte) | |||
| 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)) |
| @@ -1588,7 +1601,7 @@ adjust_after_replace (from, from_byte, prev_text, len, len_byte) | |||
| 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 |
| @@ -1649,12 +1662,6 @@ adjust_after_replace (from, from_byte, prev_text, 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) |
| @@ -1803,10 +1810,10 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 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 |
| @@ -1851,11 +1858,26 @@ replace_range (from, to, new, prepare, inherit, markers) | |||
| 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, |
| @@ -2116,8 +2138,8 @@ del_range_2 (from, from_byte, to, 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 | } |