diff options
| author | Kenichi Handa | 1998-03-16 05:51:07 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-03-16 05:51:07 +0000 |
| commit | e3a87305b87928adb6aa0f64e58ccff79c19c404 (patch) | |
| tree | 2c8b782b67cf2ecbbc050dd9bebcfae9378875ea | |
| parent | 6e44253b80942ba76b4c0cd365723bcdd677d15b (diff) | |
| download | emacs-e3a87305b87928adb6aa0f64e58ccff79c19c404.tar.gz emacs-e3a87305b87928adb6aa0f64e58ccff79c19c404.zip | |
(ADJUST_CHAR_POS): New macro.
(combine_bytes): Use the macro ADJUST_CHAR_POS.
(adjust_after_replace): New arg REPLACE. If it is zero, give LEN
as the arg LENGTH to offset_intervals.
(del_range_2): Give correct args to count_combining_before and
combine_bytes. Adjust the gap position after record_delete if
necessary. Give character position to adjust_overlays_for_delete.
| -rw-r--r-- | src/insdel.c | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/src/insdel.c b/src/insdel.c index 843a76e3d83..fa40da76160 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -841,6 +841,24 @@ count_combining_after (string, length, pos, pos_byte) | |||
| 841 | return pos_byte - opos_byte; | 841 | return pos_byte - opos_byte; |
| 842 | } | 842 | } |
| 843 | 843 | ||
| 844 | /* Adjust the position TARGET/TARGET_BYTE for the combining of NBYTES | ||
| 845 | following the position POS/POS_BYTE to the character preceding POS. | ||
| 846 | If TARGET is after POS+NBYTES, we only have to adjust the character | ||
| 847 | position TARGET, else, if TARGET is after POS, we have to adjust | ||
| 848 | both the character position TARGET and the byte position | ||
| 849 | TARGET_BYTE, else we don't have to do any adjustment. */ | ||
| 850 | |||
| 851 | #define ADJUST_CHAR_POS(target, target_byte) \ | ||
| 852 | do { \ | ||
| 853 | if (target > pos + nbytes) \ | ||
| 854 | target -= nbytes; \ | ||
| 855 | else if (target >= pos) \ | ||
| 856 | { \ | ||
| 857 | target = pos; \ | ||
| 858 | target_byte = pos_byte + nbytes; \ | ||
| 859 | } \ | ||
| 860 | } while (0) | ||
| 861 | |||
| 844 | /* Combine NBYTES stray trailing-codes, which were formerly separate | 862 | /* Combine NBYTES stray trailing-codes, which were formerly separate |
| 845 | characters, with the preceding character. These bytes | 863 | characters, with the preceding character. These bytes |
| 846 | are located after position POS / POS_BYTE, and the preceding character | 864 | are located after position POS / POS_BYTE, and the preceding character |
| @@ -855,14 +873,10 @@ combine_bytes (pos, pos_byte, nbytes) | |||
| 855 | 873 | ||
| 856 | adjust_overlays_for_delete (pos, nbytes); | 874 | adjust_overlays_for_delete (pos, nbytes); |
| 857 | 875 | ||
| 858 | if (PT > pos) | 876 | ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); |
| 859 | BUF_PT (current_buffer) -= nbytes; | 877 | ADJUST_CHAR_POS (GPT, GPT_BYTE); |
| 860 | if (GPT > pos) | 878 | ADJUST_CHAR_POS (Z, Z_BYTE); |
| 861 | GPT -= nbytes; | 879 | ADJUST_CHAR_POS (ZV, ZV_BYTE); |
| 862 | if (Z > pos) | ||
| 863 | Z -= nbytes; | ||
| 864 | if (ZV > pos) | ||
| 865 | ZV -= nbytes; | ||
| 866 | 880 | ||
| 867 | if (BUF_INTERVALS (current_buffer) != 0) | 881 | if (BUF_INTERVALS (current_buffer) != 0) |
| 868 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ | 882 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ |
| @@ -1311,8 +1325,8 @@ adjust_before_replace (from, from_byte, to, to_byte) | |||
| 1311 | making the text a buffer contents. It exists just after GPT_ADDR. */ | 1325 | making the text a buffer contents. It exists just after GPT_ADDR. */ |
| 1312 | 1326 | ||
| 1313 | void | 1327 | void |
| 1314 | adjust_after_replace (from, from_byte, to, to_byte, len, len_byte) | 1328 | adjust_after_replace (from, from_byte, to, to_byte, len, len_byte, replace) |
| 1315 | int from, from_byte, to, to_byte, len, len_byte; | 1329 | int from, from_byte, to, to_byte, len, len_byte, replace; |
| 1316 | { | 1330 | { |
| 1317 | int combined_before_bytes | 1331 | int combined_before_bytes |
| 1318 | = count_combining_before (GPT_ADDR, len_byte, from, from_byte); | 1332 | = count_combining_before (GPT_ADDR, len_byte, from, from_byte); |
| @@ -1344,7 +1358,11 @@ adjust_after_replace (from, from_byte, to, to_byte, len, len_byte) | |||
| 1344 | combined_before_bytes, combined_after_bytes, 0); | 1358 | combined_before_bytes, combined_after_bytes, 0); |
| 1345 | #ifdef USE_TEXT_PROPERTIES | 1359 | #ifdef USE_TEXT_PROPERTIES |
| 1346 | if (BUF_INTERVALS (current_buffer) != 0) | 1360 | if (BUF_INTERVALS (current_buffer) != 0) |
| 1347 | offset_intervals (current_buffer, from, len - (to - from)); | 1361 | /* REPLACE zero means that we have not yet adjusted the interval |
| 1362 | tree for the text between FROM and TO, thus, we must treat the | ||
| 1363 | new text as a newly inserted text, not as a replacement of | ||
| 1364 | something. */ | ||
| 1365 | offset_intervals (current_buffer, from, len - (replace ? to - from : 0)); | ||
| 1348 | #endif | 1366 | #endif |
| 1349 | 1367 | ||
| 1350 | { | 1368 | { |
| @@ -1701,7 +1719,8 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 1701 | gap_left (to, to_byte, 0); | 1719 | gap_left (to, to_byte, 0); |
| 1702 | 1720 | ||
| 1703 | combined_after_bytes | 1721 | combined_after_bytes |
| 1704 | = count_combining_before (GAP_END_ADDR, ZV_BYTE - GPT_BYTE, PT, PT_BYTE); | 1722 | = count_combining_before (BUF_BYTE_ADDRESS (current_buffer, to_byte), |
| 1723 | ZV_BYTE - to_byte, from, from_byte); | ||
| 1705 | 1724 | ||
| 1706 | /* Relocate all markers pointing into the new, larger gap | 1725 | /* Relocate all markers pointing into the new, larger gap |
| 1707 | to point at the end of the text before the gap. | 1726 | to point at the end of the text before the gap. |
| @@ -1711,6 +1730,11 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 1711 | 1730 | ||
| 1712 | record_delete (from - !!combined_after_bytes, | 1731 | record_delete (from - !!combined_after_bytes, |
| 1713 | nchars_del + combined_after_bytes + !!combined_after_bytes); | 1732 | nchars_del + combined_after_bytes + !!combined_after_bytes); |
| 1733 | if (combined_after_bytes) | ||
| 1734 | /* COMBINED_AFTER_BYTES nonzero means that the above record_delete | ||
| 1735 | moved the gap by calling Fbuffer_substring. We must move the | ||
| 1736 | gap again to a proper place. */ | ||
| 1737 | move_gap_both (from, from_byte); | ||
| 1714 | MODIFF++; | 1738 | MODIFF++; |
| 1715 | 1739 | ||
| 1716 | /* Relocate point as if it were a marker. */ | 1740 | /* Relocate point as if it were a marker. */ |
| @@ -1723,7 +1747,7 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 1723 | 1747 | ||
| 1724 | /* Adjust the overlay center as needed. This must be done after | 1748 | /* Adjust the overlay center as needed. This must be done after |
| 1725 | adjusting the markers that bound the overlays. */ | 1749 | adjusting the markers that bound the overlays. */ |
| 1726 | adjust_overlays_for_delete (from_byte, nchars_del); | 1750 | adjust_overlays_for_delete (from, nchars_del); |
| 1727 | 1751 | ||
| 1728 | GAP_SIZE += nbytes_del; | 1752 | GAP_SIZE += nbytes_del; |
| 1729 | ZV_BYTE -= nbytes_del; | 1753 | ZV_BYTE -= nbytes_del; |
| @@ -1732,12 +1756,13 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 1732 | Z -= nchars_del; | 1756 | Z -= nchars_del; |
| 1733 | GPT = from; | 1757 | GPT = from; |
| 1734 | GPT_BYTE = from_byte; | 1758 | GPT_BYTE = from_byte; |
| 1735 | *(GPT_ADDR) = 0; /* Put an anchor. */ | ||
| 1736 | 1759 | ||
| 1737 | if (combined_after_bytes) | 1760 | if (combined_after_bytes) |
| 1738 | move_gap_both (GPT + combined_after_bytes, | 1761 | move_gap_both (GPT + combined_after_bytes, |
| 1739 | GPT_BYTE + combined_after_bytes); | 1762 | GPT_BYTE + combined_after_bytes); |
| 1740 | 1763 | ||
| 1764 | *(GPT_ADDR) = 0; /* Put an anchor. */ | ||
| 1765 | |||
| 1741 | if (GPT_BYTE < GPT) | 1766 | if (GPT_BYTE < GPT) |
| 1742 | abort (); | 1767 | abort (); |
| 1743 | 1768 | ||
| @@ -1747,7 +1772,7 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 1747 | end_unchanged = Z - GPT; | 1772 | end_unchanged = Z - GPT; |
| 1748 | 1773 | ||
| 1749 | if (combined_after_bytes) | 1774 | if (combined_after_bytes) |
| 1750 | combine_bytes (PT, PT_BYTE, combined_after_bytes); | 1775 | combine_bytes (from, from_byte, combined_after_bytes); |
| 1751 | 1776 | ||
| 1752 | if (combined_after_bytes) | 1777 | if (combined_after_bytes) |
| 1753 | record_insert (GPT - 1, 1); | 1778 | record_insert (GPT - 1, 1); |