comparison src/insdel.c @ 22107:5507c26908af

(insert_1_both, insert_from_string_1, replace_range) (insert_from_buffer_1, adjust_before_replace, adjust_after_replace): Don't copy text being deleted, if undo is disabled.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 May 1998 20:34:59 +0000
parents 4dbf2af94988
children 8c063663a19d
comparison
equal deleted inserted replaced
22106:f4a52ea42920 22107:5507c26908af
1012 insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers) 1012 insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers)
1013 register unsigned char *string; 1013 register unsigned char *string;
1014 register int nchars, nbytes; 1014 register int nchars, nbytes;
1015 int inherit, prepare, before_markers; 1015 int inherit, prepare, before_markers;
1016 { 1016 {
1017 register Lisp_Object temp, deletion; 1017 register Lisp_Object temp;
1018 int combined_before_bytes, combined_after_bytes; 1018 int combined_before_bytes, combined_after_bytes;
1019 1019
1020 if (NILP (current_buffer->enable_multibyte_characters)) 1020 if (NILP (current_buffer->enable_multibyte_characters))
1021 nchars = nbytes; 1021 nchars = nbytes;
1022 1022
1043 But there is no need to actually delete the combining bytes 1043 But there is no need to actually delete the combining bytes
1044 from the buffer and reinsert them. */ 1044 from the buffer and reinsert them. */
1045 1045
1046 if (combined_after_bytes) 1046 if (combined_after_bytes)
1047 { 1047 {
1048 deletion = make_buffer_string_both (PT, PT_BYTE, 1048 Lisp_Object deletion;
1049 PT + combined_after_bytes, 1049 deletion = Qnil;
1050 PT_BYTE + combined_after_bytes, 1); 1050
1051 if (! EQ (current_buffer->undo_list, Qt))
1052 deletion = make_buffer_string_both (PT, PT_BYTE,
1053 PT + combined_after_bytes,
1054 PT_BYTE + combined_after_bytes, 1);
1051 1055
1052 adjust_markers_for_record_delete (PT, PT_BYTE, 1056 adjust_markers_for_record_delete (PT, PT_BYTE,
1053 PT + combined_after_bytes, 1057 PT + combined_after_bytes,
1054 PT_BYTE + combined_after_bytes); 1058 PT_BYTE + combined_after_bytes);
1055 record_delete (PT, deletion); 1059 if (! EQ (current_buffer->undo_list, Qt))
1060 record_delete (PT, deletion);
1056 } 1061 }
1057 1062
1058 if (combined_before_bytes) 1063 if (combined_before_bytes)
1059 { 1064 {
1060 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), 1065 Lisp_Object deletion;
1061 PT, PT_BYTE, 1); 1066 deletion = Qnil;
1067
1068 if (! EQ (current_buffer->undo_list, Qt))
1069 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1),
1070 PT, PT_BYTE, 1);
1062 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), 1071 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
1063 PT, PT_BYTE); 1072 PT, PT_BYTE);
1064 record_delete (PT - 1, deletion); 1073 if (! EQ (current_buffer->undo_list, Qt))
1074 record_delete (PT - 1, deletion);
1065 } 1075 }
1066 1076
1067 record_insert (PT - !!combined_before_bytes, 1077 record_insert (PT - !!combined_before_bytes,
1068 nchars - combined_before_bytes + !!combined_before_bytes); 1078 nchars - combined_before_bytes + !!combined_before_bytes);
1069 MODIFF++; 1079 MODIFF++;
1168 struct gcpro gcpro1; 1178 struct gcpro gcpro1;
1169 int outgoing_nbytes = nbytes; 1179 int outgoing_nbytes = nbytes;
1170 int combined_before_bytes, combined_after_bytes; 1180 int combined_before_bytes, combined_after_bytes;
1171 int adjusted_nchars; 1181 int adjusted_nchars;
1172 INTERVAL intervals; 1182 INTERVAL intervals;
1173 Lisp_Object deletion;
1174 1183
1175 /* Make OUTGOING_NBYTES describe the text 1184 /* Make OUTGOING_NBYTES describe the text
1176 as it will be inserted in this buffer. */ 1185 as it will be inserted in this buffer. */
1177 1186
1178 if (NILP (current_buffer->enable_multibyte_characters)) 1187 if (NILP (current_buffer->enable_multibyte_characters))
1218 But there is no need to actually delete the combining bytes 1227 But there is no need to actually delete the combining bytes
1219 from the buffer and reinsert them. */ 1228 from the buffer and reinsert them. */
1220 1229
1221 if (combined_after_bytes) 1230 if (combined_after_bytes)
1222 { 1231 {
1223 deletion = make_buffer_string_both (PT, PT_BYTE, 1232 Lisp_Object deletion;
1224 PT + combined_after_bytes, 1233 deletion = Qnil;
1225 PT_BYTE + combined_after_bytes, 1); 1234
1235 if (! EQ (current_buffer->undo_list, Qt))
1236 deletion = make_buffer_string_both (PT, PT_BYTE,
1237 PT + combined_after_bytes,
1238 PT_BYTE + combined_after_bytes, 1);
1226 1239
1227 adjust_markers_for_record_delete (PT, PT_BYTE, 1240 adjust_markers_for_record_delete (PT, PT_BYTE,
1228 PT + combined_after_bytes, 1241 PT + combined_after_bytes,
1229 PT_BYTE + combined_after_bytes); 1242 PT_BYTE + combined_after_bytes);
1230 record_delete (PT, deletion); 1243 if (! EQ (current_buffer->undo_list, Qt))
1244 record_delete (PT, deletion);
1231 } 1245 }
1232 1246
1233 if (combined_before_bytes) 1247 if (combined_before_bytes)
1234 { 1248 {
1235 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), 1249 Lisp_Object deletion;
1236 PT, PT_BYTE, 1); 1250 deletion = Qnil;
1251
1252 if (! EQ (current_buffer->undo_list, Qt))
1253 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1),
1254 PT, PT_BYTE, 1);
1237 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), 1255 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
1238 PT, PT_BYTE); 1256 PT, PT_BYTE);
1239 record_delete (PT - 1, deletion); 1257 if (! EQ (current_buffer->undo_list, Qt))
1258 record_delete (PT - 1, deletion);
1240 } 1259 }
1241 1260
1242 record_insert (PT - !!combined_before_bytes, 1261 record_insert (PT - !!combined_before_bytes,
1243 nchars - combined_before_bytes + !!combined_before_bytes); 1262 nchars - combined_before_bytes + !!combined_before_bytes);
1244 MODIFF++; 1263 MODIFF++;
1316 insert_from_buffer_1 (buf, from, nchars, inherit) 1335 insert_from_buffer_1 (buf, from, nchars, inherit)
1317 struct buffer *buf; 1336 struct buffer *buf;
1318 int from, nchars; 1337 int from, nchars;
1319 int inherit; 1338 int inherit;
1320 { 1339 {
1321 register Lisp_Object temp, deletion; 1340 register Lisp_Object temp;
1322 int chunk; 1341 int chunk;
1323 int from_byte = buf_charpos_to_bytepos (buf, from); 1342 int from_byte = buf_charpos_to_bytepos (buf, from);
1324 int to_byte = buf_charpos_to_bytepos (buf, from + nchars); 1343 int to_byte = buf_charpos_to_bytepos (buf, from + nchars);
1325 int incoming_nbytes = to_byte - from_byte; 1344 int incoming_nbytes = to_byte - from_byte;
1326 int outgoing_nbytes = incoming_nbytes; 1345 int outgoing_nbytes = incoming_nbytes;
1389 But there is no need to actually delete the combining bytes 1408 But there is no need to actually delete the combining bytes
1390 from the buffer and reinsert them. */ 1409 from the buffer and reinsert them. */
1391 1410
1392 if (combined_after_bytes) 1411 if (combined_after_bytes)
1393 { 1412 {
1394 deletion = make_buffer_string_both (PT, PT_BYTE, 1413 Lisp_Object deletion;
1395 PT + combined_after_bytes, 1414 deletion = Qnil;
1396 PT_BYTE + combined_after_bytes, 1); 1415
1416 if (! EQ (current_buffer->undo_list, Qt))
1417 deletion = make_buffer_string_both (PT, PT_BYTE,
1418 PT + combined_after_bytes,
1419 PT_BYTE + combined_after_bytes, 1);
1397 1420
1398 adjust_markers_for_record_delete (PT, PT_BYTE, 1421 adjust_markers_for_record_delete (PT, PT_BYTE,
1399 PT + combined_after_bytes, 1422 PT + combined_after_bytes,
1400 PT_BYTE + combined_after_bytes); 1423 PT_BYTE + combined_after_bytes);
1401 record_delete (PT, deletion); 1424 if (! EQ (current_buffer->undo_list, Qt))
1425 record_delete (PT, deletion);
1402 } 1426 }
1403 1427
1404 if (combined_before_bytes) 1428 if (combined_before_bytes)
1405 { 1429 {
1406 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), 1430 Lisp_Object deletion;
1407 PT, PT_BYTE, 1); 1431 deletion = Qnil;
1432
1433 if (! EQ (current_buffer->undo_list, Qt))
1434 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1),
1435 PT, PT_BYTE, 1);
1408 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), 1436 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
1409 PT, PT_BYTE); 1437 PT, PT_BYTE);
1410 record_delete (PT - 1, deletion); 1438 if (! EQ (current_buffer->undo_list, Qt))
1439 record_delete (PT - 1, deletion);
1411 } 1440 }
1412 1441
1413 record_insert (PT - !!combined_before_bytes, 1442 record_insert (PT - !!combined_before_bytes,
1414 nchars - combined_before_bytes + !!combined_before_bytes); 1443 nchars - combined_before_bytes + !!combined_before_bytes);
1415 MODIFF++; 1444 MODIFF++;
1472 void 1501 void
1473 adjust_before_replace (from, from_byte, to, to_byte) 1502 adjust_before_replace (from, from_byte, to, to_byte)
1474 int from, from_byte, to, to_byte; 1503 int from, from_byte, to, to_byte;
1475 { 1504 {
1476 Lisp_Object deletion; 1505 Lisp_Object deletion;
1477 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); 1506
1507 if (! EQ (current_buffer->undo_list, Qt))
1508 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1);
1478 1509
1479 CHECK_MARKERS (); 1510 CHECK_MARKERS ();
1480 1511
1481 adjust_markers_for_delete (from, from_byte, to, to_byte); 1512 adjust_markers_for_delete (from, from_byte, to, to_byte);
1482 record_delete (from, deletion); 1513
1514 if (! EQ (current_buffer->undo_list, Qt))
1515 record_delete (from, deletion);
1516
1483 adjust_overlays_for_delete (from, to - from); 1517 adjust_overlays_for_delete (from, to - from);
1484 } 1518 }
1485 1519
1486 /* Record undo information and adjust markers and position keepers for 1520 /* Record undo information and adjust markers and position keepers for
1487 a replacement of a text PREV_TEXT at FROM to a new text of LEN 1521 a replacement of a text PREV_TEXT at FROM to a new text of LEN
1497 { 1531 {
1498 int combined_before_bytes 1532 int combined_before_bytes
1499 = count_combining_before (GPT_ADDR, len_byte, from, from_byte); 1533 = count_combining_before (GPT_ADDR, len_byte, from, from_byte);
1500 int combined_after_bytes 1534 int combined_after_bytes
1501 = count_combining_after (GPT_ADDR, len_byte, from, from_byte); 1535 = count_combining_after (GPT_ADDR, len_byte, from, from_byte);
1502 Lisp_Object deletion;
1503 int nchars_del = 0, nbytes_del = 0; 1536 int nchars_del = 0, nbytes_del = 0;
1504 1537
1505 if (combined_after_bytes) 1538 if (combined_after_bytes)
1506 { 1539 {
1507 deletion = make_buffer_string_both (from, from_byte, 1540 Lisp_Object deletion;
1508 from + combined_after_bytes, 1541 deletion = Qnil;
1509 from_byte + combined_after_bytes, 1); 1542
1543 if (! EQ (current_buffer->undo_list, Qt))
1544 deletion = make_buffer_string_both (from, from_byte,
1545 from + combined_after_bytes,
1546 from_byte + combined_after_bytes,
1547 1);
1510 1548
1511 adjust_markers_for_record_delete (from, from_byte, 1549 adjust_markers_for_record_delete (from, from_byte,
1512 from + combined_after_bytes, 1550 from + combined_after_bytes,
1513 from_byte + combined_after_bytes); 1551 from_byte + combined_after_bytes);
1514 record_delete (from, deletion); 1552
1553 if (! EQ (current_buffer->undo_list, Qt))
1554 record_delete (from, deletion);
1515 } 1555 }
1516 1556
1517 if (combined_before_bytes) 1557 if (combined_before_bytes)
1518 { 1558 {
1519 deletion = make_buffer_string_both (from - 1, CHAR_TO_BYTE (from - 1), 1559 Lisp_Object deletion;
1520 from, from_byte, 1); 1560 deletion = Qnil;
1561
1562 if (! EQ (current_buffer->undo_list, Qt))
1563 deletion = make_buffer_string_both (from - 1, CHAR_TO_BYTE (from - 1),
1564 from, from_byte, 1);
1521 adjust_markers_for_record_delete (from - 1, CHAR_TO_BYTE (from - 1), 1565 adjust_markers_for_record_delete (from - 1, CHAR_TO_BYTE (from - 1),
1522 from, from_byte); 1566 from, from_byte);
1523 record_delete (from - 1, deletion); 1567 if (! EQ (current_buffer->undo_list, Qt))
1568 record_delete (from - 1, deletion);
1524 } 1569 }
1525 1570
1526 /* Update various buffer positions for the new text. */ 1571 /* Update various buffer positions for the new text. */
1527 GAP_SIZE -= len_byte; 1572 GAP_SIZE -= len_byte;
1528 ZV += len; Z+= len; 1573 ZV += len; Z+= len;
1622 struct gcpro gcpro1; 1667 struct gcpro gcpro1;
1623 int combined_before_bytes, combined_after_bytes; 1668 int combined_before_bytes, combined_after_bytes;
1624 int adjusted_inschars; 1669 int adjusted_inschars;
1625 INTERVAL intervals; 1670 INTERVAL intervals;
1626 int outgoing_insbytes = insbytes; 1671 int outgoing_insbytes = insbytes;
1627 Lisp_Object deletion;
1628 1672
1629 CHECK_MARKERS (); 1673 CHECK_MARKERS ();
1630 1674
1631 GCPRO1 (new); 1675 GCPRO1 (new);
1632 1676
1674 if (from > GPT) 1718 if (from > GPT)
1675 gap_right (from, from_byte); 1719 gap_right (from, from_byte);
1676 if (to < GPT) 1720 if (to < GPT)
1677 gap_left (to, to_byte, 0); 1721 gap_left (to, to_byte, 0);
1678 1722
1679 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); 1723 {
1680 1724 Lisp_Object deletion;
1681 if (nomarkers) 1725 deletion = Qnil;
1682 /* Relocate all markers pointing into the new, larger gap 1726
1683 to point at the end of the text before the gap. 1727 if (! EQ (current_buffer->undo_list, Qt))
1684 Do this before recording the deletion, 1728 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1);
1685 so that undo handles this after reinserting the text. */ 1729
1686 adjust_markers_for_delete (from, from_byte, to, to_byte); 1730 if (nomarkers)
1687 1731 /* Relocate all markers pointing into the new, larger gap
1688 record_delete (from, deletion); 1732 to point at the end of the text before the gap.
1733 Do this before recording the deletion,
1734 so that undo handles this after reinserting the text. */
1735 adjust_markers_for_delete (from, from_byte, to, to_byte);
1736
1737 if (! EQ (current_buffer->undo_list, Qt))
1738 record_delete (from, deletion);
1739 }
1689 1740
1690 GAP_SIZE += nbytes_del; 1741 GAP_SIZE += nbytes_del;
1691 ZV -= nchars_del; 1742 ZV -= nchars_del;
1692 Z -= nchars_del; 1743 Z -= nchars_del;
1693 ZV_BYTE -= nbytes_del; 1744 ZV_BYTE -= nbytes_del;
1731 But there is no need to actually delete the combining bytes 1782 But there is no need to actually delete the combining bytes
1732 from the buffer and reinsert them. */ 1783 from the buffer and reinsert them. */
1733 1784
1734 if (combined_after_bytes) 1785 if (combined_after_bytes)
1735 { 1786 {
1736 deletion = make_buffer_string_both (PT, PT_BYTE, 1787 Lisp_Object deletion;
1737 PT + combined_after_bytes, 1788 deletion = Qnil;
1738 PT_BYTE + combined_after_bytes, 1); 1789
1790 if (! EQ (current_buffer->undo_list, Qt))
1791 deletion = make_buffer_string_both (PT, PT_BYTE,
1792 PT + combined_after_bytes,
1793 PT_BYTE + combined_after_bytes, 1);
1739 1794
1740 adjust_markers_for_record_delete (PT, PT_BYTE, 1795 adjust_markers_for_record_delete (PT, PT_BYTE,
1741 PT + combined_after_bytes, 1796 PT + combined_after_bytes,
1742 PT_BYTE + combined_after_bytes); 1797 PT_BYTE + combined_after_bytes);
1743 record_delete (PT, deletion); 1798 if (! EQ (current_buffer->undo_list, Qt))
1799 record_delete (PT, deletion);
1744 } 1800 }
1745 1801
1746 if (combined_before_bytes) 1802 if (combined_before_bytes)
1747 { 1803 {
1748 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1), 1804 Lisp_Object deletion;
1749 PT, PT_BYTE, 1); 1805 deletion = Qnil;
1806
1807 if (! EQ (current_buffer->undo_list, Qt))
1808 deletion = make_buffer_string_both (PT - 1, CHAR_TO_BYTE (PT - 1),
1809 PT, PT_BYTE, 1);
1750 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1), 1810 adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
1751 PT, PT_BYTE); 1811 PT, PT_BYTE);
1752 record_delete (PT - 1, deletion); 1812 if (! EQ (current_buffer->undo_list, Qt))
1813 record_delete (PT - 1, deletion);
1753 } 1814 }
1754 1815
1755 record_insert (PT - !!combined_before_bytes, 1816 record_insert (PT - !!combined_before_bytes,
1756 inschars - combined_before_bytes + !!combined_before_bytes); 1817 inschars - combined_before_bytes + !!combined_before_bytes);
1757 1818
1964 DEC_POS (from_byte_1); 2025 DEC_POS (from_byte_1);
1965 } 2026 }
1966 else 2027 else
1967 from_byte_1 = from_byte; 2028 from_byte_1 = from_byte;
1968 2029
1969 deletion 2030 if (! EQ (current_buffer->undo_list, Qt))
1970 = make_buffer_string_both (from - !!combined_after_bytes, 2031 deletion
1971 from_byte_1, 2032 = make_buffer_string_both (from - !!combined_after_bytes,
1972 to + combined_after_bytes, 2033 from_byte_1,
1973 to_byte + combined_after_bytes, 1); 2034 to + combined_after_bytes,
2035 to_byte + combined_after_bytes, 1);
1974 if (combined_after_bytes) 2036 if (combined_after_bytes)
1975 /* COMBINED_AFTER_BYTES nonzero means that the above code moved 2037 /* COMBINED_AFTER_BYTES nonzero means that the above code moved
1976 the gap. We must move the gap again to a proper place. */ 2038 the gap. We must move the gap again to a proper place. */
1977 move_gap_both (from, from_byte); 2039 move_gap_both (from, from_byte);
1978 2040
1995 from_byte + combined_after_bytes); 2057 from_byte + combined_after_bytes);
1996 2058
1997 adjust_markers_for_record_delete (from - 1, from_byte_1, 2059 adjust_markers_for_record_delete (from - 1, from_byte_1,
1998 from, from_byte); 2060 from, from_byte);
1999 } 2061 }
2000 record_delete (from - !!combined_after_bytes, deletion); 2062 if (! EQ (current_buffer->undo_list, Qt))
2063 record_delete (from - !!combined_after_bytes, deletion);
2001 MODIFF++; 2064 MODIFF++;
2002 2065
2003 /* Relocate point as if it were a marker. */ 2066 /* Relocate point as if it were a marker. */
2004 if (from < PT) 2067 if (from < PT)
2005 adjust_point (from - (PT < to ? PT : to), 2068 adjust_point (from - (PT < to ? PT : to),