comparison src/insdel.c @ 21191:b4e925500a71

(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.
author Kenichi Handa <handa@m17n.org>
date Mon, 16 Mar 1998 05:51:07 +0000
parents 15d4310cb9e7
children 31a2889105f0
comparison
equal deleted inserted replaced
21190:d704dd953837 21191:b4e925500a71
839 } 839 }
840 840
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
847 is located just before that position. */ 865 is located just before that position. */
848 866
853 /* Adjust all markers. */ 871 /* Adjust all markers. */
854 adjust_markers_for_delete (pos, pos_byte, pos + nbytes, pos_byte); 872 adjust_markers_for_delete (pos, pos_byte, pos + nbytes, pos_byte);
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. */
869 offset_intervals (current_buffer, pos, - nbytes); 883 offset_intervals (current_buffer, pos, - nbytes);
870 } 884 }
1309 /* This function should be called after altering the text between FROM 1323 /* This function should be called after altering the text between FROM
1310 and TO to a new text of LEN chars (LEN_BYTE bytes), but before 1324 and TO to a new text of LEN chars (LEN_BYTE bytes), but before
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);
1319 int combined_after_bytes 1333 int combined_after_bytes
1320 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); 1334 = count_combining_after (GPT_ADDR, len_byte, from, from_byte);
1342 adjust_markers_for_insert (from, from_byte, 1356 adjust_markers_for_insert (from, from_byte,
1343 from + len, from_byte + len_byte, 1357 from + len, from_byte + 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 {
1351 int pos = PT, pos_byte = PT_BYTE; 1369 int pos = PT, pos_byte = PT_BYTE;
1352 1370
1699 gap_right (from, from_byte); 1717 gap_right (from, from_byte);
1700 if (to < GPT) 1718 if (to < GPT)
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.
1708 Do this before recording the deletion, 1727 Do this before recording the deletion,
1709 so that undo handles this after reinserting the text. */ 1728 so that undo handles this after reinserting the text. */
1710 adjust_markers_for_delete (from, from_byte, to, to_byte); 1729 adjust_markers_for_delete (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. */
1717 if (from < PT) 1741 if (from < PT)
1718 adjust_point (from - (PT < to ? PT : to), 1742 adjust_point (from - (PT < to ? PT : to),
1721 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ 1745 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
1722 offset_intervals (current_buffer, from, - nchars_del); 1746 offset_intervals (current_buffer, from, - nchars_del);
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;
1730 Z_BYTE -= nbytes_del; 1754 Z_BYTE -= nbytes_del;
1731 ZV -= nchars_del; 1755 ZV -= nchars_del;
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);
1763
1764 *(GPT_ADDR) = 0; /* Put an anchor. */
1740 1765
1741 if (GPT_BYTE < GPT) 1766 if (GPT_BYTE < GPT)
1742 abort (); 1767 abort ();
1743 1768
1744 if (GPT - BEG < beg_unchanged) 1769 if (GPT - BEG < beg_unchanged)
1745 beg_unchanged = GPT - BEG; 1770 beg_unchanged = GPT - BEG;
1746 if (Z - GPT < end_unchanged) 1771 if (Z - GPT < end_unchanged)
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);
1754 1779
1755 evaporate_overlays (from); 1780 evaporate_overlays (from);