Mercurial > emacs
comparison src/insdel.c @ 23259:a3f818e927ba
(adjust_markers_for_replace): Don't adjust a byte
position if it is FROM.
(adjust_markers_for_combining): New function.
(combine_bytes): Call adjust_markers_for_combining instead of
adjust_markers_for_replace.
(adjust_after_replace): Record deletion of combining after bytes
with the correct position. Don't add combining bytes to the args
given to adjust_point. Handle correctly the case that there are
both before and after combining bytes.
(replace_range): Likewise. Record the actual deletion after
recoding deletions of combining bytes.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 16 Sep 1998 07:21:31 +0000 |
parents | 42fcd022d4e5 |
children | 6df1b016f5fc |
comparison
equal
deleted
inserted
replaced
23258:2f8585bcea90 | 23259:a3f818e927ba |
---|---|
398 } | 398 } |
399 | 399 |
400 marker = m->chain; | 400 marker = m->chain; |
401 } | 401 } |
402 } | 402 } |
403 | |
404 /* Adjust all markers for a byte combining of NBYTES at char position | |
405 FROM and byte position FROM_BYTE. */ | |
406 | |
407 static void | |
408 adjust_markers_for_combining (from, from_byte, nbytes) | |
409 register int from, from_byte, nbytes; | |
410 { | |
411 Lisp_Object marker; | |
412 register struct Lisp_Marker *m; | |
413 register int bytepos; | |
414 register int to_byte = from_byte + nbytes; | |
415 | |
416 marker = BUF_MARKERS (current_buffer); | |
417 | |
418 while (!NILP (marker)) | |
419 { | |
420 m = XMARKER (marker); | |
421 bytepos = m->bytepos; | |
422 | |
423 if (bytepos >= to_byte) | |
424 { | |
425 record_marker_adjustment (marker, - nbytes); | |
426 m->charpos -= nbytes; | |
427 } | |
428 else if (bytepos > from_byte) | |
429 { | |
430 record_marker_adjustment (marker, from - m->charpos); | |
431 m->charpos = from; | |
432 m->bytepos = to_byte; | |
433 } | |
434 else if (bytepos == from_byte) | |
435 { | |
436 m->bytepos = to_byte; | |
437 } | |
438 | |
439 marker = m->chain; | |
440 } | |
441 } | |
403 | 442 |
404 /* Adjust all markers for calling record_delete for combining bytes. | 443 /* Adjust all markers for calling record_delete for combining bytes. |
405 whose range in bytes is FROM_BYTE to TO_BYTE. | 444 whose range in bytes is FROM_BYTE to TO_BYTE. |
406 The range in charpos is FROM to TO. */ | 445 The range in charpos is FROM to TO. */ |
407 | 446 |
593 { | 632 { |
594 record_marker_adjustment (marker, from - m->charpos); | 633 record_marker_adjustment (marker, from - m->charpos); |
595 m->charpos = from; | 634 m->charpos = from; |
596 m->bytepos = from_byte; | 635 m->bytepos = from_byte; |
597 } | 636 } |
598 else if (m->bytepos == from_byte) | |
599 { | |
600 if (combined_before_bytes) | |
601 { | |
602 DEC_BOTH (m->charpos, m->bytepos); | |
603 INC_BOTH (m->charpos, m->bytepos); | |
604 } | |
605 } | |
606 | 637 |
607 marker = m->chain; | 638 marker = m->chain; |
608 } | 639 } |
609 } | 640 } |
610 | 641 |
1011 static void | 1042 static void |
1012 combine_bytes (pos, pos_byte, nbytes) | 1043 combine_bytes (pos, pos_byte, nbytes) |
1013 int pos, pos_byte, nbytes; | 1044 int pos, pos_byte, nbytes; |
1014 { | 1045 { |
1015 /* Adjust all markers. */ | 1046 /* Adjust all markers. */ |
1016 adjust_markers_for_delete (pos, pos_byte, pos + nbytes, pos_byte); | 1047 adjust_markers_for_combining (pos, pos_byte, nbytes); |
1017 | 1048 |
1018 adjust_overlays_for_delete (pos, nbytes); | 1049 adjust_overlays_for_delete (pos, nbytes); |
1019 | 1050 |
1020 ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); | 1051 ADJUST_CHAR_POS (BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer)); |
1021 ADJUST_CHAR_POS (GPT, GPT_BYTE); | 1052 ADJUST_CHAR_POS (GPT, GPT_BYTE); |
1574 adjust_markers_for_record_delete (from, from_byte, | 1605 adjust_markers_for_record_delete (from, from_byte, |
1575 from + combined_after_bytes, | 1606 from + combined_after_bytes, |
1576 from_byte + combined_after_bytes); | 1607 from_byte + combined_after_bytes); |
1577 | 1608 |
1578 if (! EQ (current_buffer->undo_list, Qt)) | 1609 if (! EQ (current_buffer->undo_list, Qt)) |
1579 record_delete (from, deletion); | 1610 record_delete (from + len, deletion); |
1580 } | 1611 } |
1581 | 1612 |
1582 if (combined_before_bytes) | 1613 if (combined_before_bytes) |
1583 { | 1614 { |
1584 Lisp_Object deletion; | 1615 Lisp_Object deletion; |
1703 struct gcpro gcpro1; | 1734 struct gcpro gcpro1; |
1704 int combined_before_bytes, combined_after_bytes; | 1735 int combined_before_bytes, combined_after_bytes; |
1705 int adjusted_inschars; | 1736 int adjusted_inschars; |
1706 INTERVAL intervals; | 1737 INTERVAL intervals; |
1707 int outgoing_insbytes = insbytes; | 1738 int outgoing_insbytes = insbytes; |
1739 Lisp_Object deletion; | |
1708 | 1740 |
1709 CHECK_MARKERS (); | 1741 CHECK_MARKERS (); |
1710 | 1742 |
1711 GCPRO1 (new); | 1743 GCPRO1 (new); |
1712 | 1744 |
1754 if (from > GPT) | 1786 if (from > GPT) |
1755 gap_right (from, from_byte); | 1787 gap_right (from, from_byte); |
1756 if (to < GPT) | 1788 if (to < GPT) |
1757 gap_left (to, to_byte, 0); | 1789 gap_left (to, to_byte, 0); |
1758 | 1790 |
1759 { | 1791 deletion = Qnil; |
1760 Lisp_Object deletion; | 1792 |
1761 deletion = Qnil; | 1793 if (! EQ (current_buffer->undo_list, Qt)) |
1762 | 1794 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); |
1763 if (! EQ (current_buffer->undo_list, Qt)) | 1795 |
1764 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); | 1796 if (markers) |
1765 | 1797 /* Relocate all markers pointing into the new, larger gap |
1766 if (markers) | 1798 to point at the end of the text before the gap. |
1767 /* Relocate all markers pointing into the new, larger gap | 1799 Do this before recording the deletion, |
1768 to point at the end of the text before the gap. | 1800 so that undo handles this after reinserting the text. */ |
1769 Do this before recording the deletion, | 1801 adjust_markers_for_delete (from, from_byte, to, to_byte); |
1770 so that undo handles this after reinserting the text. */ | |
1771 adjust_markers_for_delete (from, from_byte, to, to_byte); | |
1772 | |
1773 if (! EQ (current_buffer->undo_list, Qt)) | |
1774 record_delete (from, deletion); | |
1775 } | |
1776 | 1802 |
1777 GAP_SIZE += nbytes_del; | 1803 GAP_SIZE += nbytes_del; |
1778 ZV -= nchars_del; | 1804 ZV -= nchars_del; |
1779 Z -= nchars_del; | 1805 Z -= nchars_del; |
1780 ZV_BYTE -= nbytes_del; | 1806 ZV_BYTE -= nbytes_del; |
1830 | 1856 |
1831 adjust_markers_for_record_delete (from, from_byte, | 1857 adjust_markers_for_record_delete (from, from_byte, |
1832 from + combined_after_bytes, | 1858 from + combined_after_bytes, |
1833 from_byte + combined_after_bytes); | 1859 from_byte + combined_after_bytes); |
1834 if (! EQ (current_buffer->undo_list, Qt)) | 1860 if (! EQ (current_buffer->undo_list, Qt)) |
1835 record_delete (from, deletion); | 1861 record_delete (from + inschars, deletion); |
1836 } | 1862 } |
1837 | 1863 |
1838 if (combined_before_bytes) | 1864 if (combined_before_bytes) |
1839 { | 1865 { |
1840 Lisp_Object deletion; | 1866 Lisp_Object deletion; |
1847 from, from_byte); | 1873 from, from_byte); |
1848 if (! EQ (current_buffer->undo_list, Qt)) | 1874 if (! EQ (current_buffer->undo_list, Qt)) |
1849 record_delete (from - 1, deletion); | 1875 record_delete (from - 1, deletion); |
1850 } | 1876 } |
1851 | 1877 |
1852 record_insert (from - !!combined_before_bytes, | 1878 if (! EQ (current_buffer->undo_list, Qt)) |
1853 inschars - combined_before_bytes + !!combined_before_bytes); | 1879 { |
1880 record_delete (from - !!combined_before_bytes, deletion); | |
1881 record_insert (from - !!combined_before_bytes, | |
1882 (inschars - combined_before_bytes | |
1883 + !!combined_before_bytes)); | |
1884 } | |
1854 | 1885 |
1855 GAP_SIZE -= outgoing_insbytes; | 1886 GAP_SIZE -= outgoing_insbytes; |
1856 GPT += inschars; | 1887 GPT += inschars; |
1857 ZV += inschars; | 1888 ZV += inschars; |
1858 Z += inschars; | 1889 Z += inschars; |