aboutsummaryrefslogtreecommitdiffstats
path: root/src/intervals.c
diff options
context:
space:
mode:
authorRichard M. Stallman2003-09-22 15:51:19 +0000
committerRichard M. Stallman2003-09-22 15:51:19 +0000
commit73792d68fd711b71f655957c545cd5e5b3575cbb (patch)
treef25acfe6d0fd254281fecee3381529861493cc17 /src/intervals.c
parent9eae419dca10b464d7f9346460c1c7b203aabdb1 (diff)
downloademacs-73792d68fd711b71f655957c545cd5e5b3575cbb.tar.gz
emacs-73792d68fd711b71f655957c545cd5e5b3575cbb.zip
(graft_intervals_into_buffer): Correct the main loop
in the case where OVER is longer than UNDER.
Diffstat (limited to 'src/intervals.c')
-rw-r--r--src/intervals.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/intervals.c b/src/intervals.c
index aec80a5e561..a15011f481d 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -1712,6 +1712,7 @@ graft_intervals_into_buffer (source, position, length, buffer, inherit)
1712{ 1712{
1713 register INTERVAL under, over, this, prev; 1713 register INTERVAL under, over, this, prev;
1714 register INTERVAL tree; 1714 register INTERVAL tree;
1715 int over_used;
1715 1716
1716 tree = BUF_INTERVALS (buffer); 1717 tree = BUF_INTERVALS (buffer);
1717 1718
@@ -1814,8 +1815,14 @@ graft_intervals_into_buffer (source, position, length, buffer, inherit)
1814 adjust_intervals_for_insertion, so stickiness has 1815 adjust_intervals_for_insertion, so stickiness has
1815 already been taken care of. */ 1816 already been taken care of. */
1816 1817
1818 /* OVER is the interval we are copying from next.
1819 OVER_USED says how many characters' worth of OVER
1820 have already been copied into target intervals.
1821 UNDER is the next interval in the target. */
1822 over_used = 0;
1817 while (! NULL_INTERVAL_P (over)) 1823 while (! NULL_INTERVAL_P (over))
1818 { 1824 {
1825 /* If UNDER is longer than OVER, split it. */
1819 if (LENGTH (over) < LENGTH (under)) 1826 if (LENGTH (over) < LENGTH (under))
1820 { 1827 {
1821 this = split_interval_left (under, LENGTH (over)); 1828 this = split_interval_left (under, LENGTH (over));
@@ -1823,12 +1830,27 @@ graft_intervals_into_buffer (source, position, length, buffer, inherit)
1823 } 1830 }
1824 else 1831 else
1825 this = under; 1832 this = under;
1826 copy_properties (over, this); 1833
1834 /* THIS is now the interval to copy or merge into.
1835 OVER covers all of it. */
1827 if (inherit) 1836 if (inherit)
1828 merge_properties (over, this); 1837 merge_properties (over, this);
1829 else 1838 else
1830 copy_properties (over, this); 1839 copy_properties (over, this);
1831 over = next_interval (over); 1840
1841 /* If THIS and OVER end at the same place,
1842 advance OVER to a new source interval. */
1843 if (LENGTH (this) == LENGTH (over) - over_used)
1844 {
1845 over = next_interval (over);
1846 over_used = 0;
1847 }
1848 else
1849 /* Otherwise just record that more of OVER has been used. */
1850 over_used += LENGTH (this);
1851
1852 /* Always advance to a new target interval. */
1853 under = next_interval (this);
1832 } 1854 }
1833 1855
1834 if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) 1856 if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer)))