diff options
| author | Stefan Monnier | 2011-11-18 11:00:40 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2011-11-18 11:00:40 -0500 |
| commit | b50a28de8707794ff4b4b755af3173cd19004976 (patch) | |
| tree | b8d300d66b7c1046ff39e67fb332722181148f61 /src/intervals.c | |
| parent | 6944dbc18a1591bc7435193685db90a6b9343914 (diff) | |
| download | emacs-b50a28de8707794ff4b4b755af3173cd19004976.tar.gz emacs-b50a28de8707794ff4b4b755af3173cd19004976.zip | |
* src/intervals.c: Fix grafting over the whole buffer.
(graft_intervals_into_buffer): Simplify.
Fixes: debbugs:10071
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/intervals.c b/src/intervals.c index a78c7f07f6c..35d05d021f0 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -1317,7 +1317,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, | |||
| 1317 | if (NULL_INTERVAL_P (tree)) | 1317 | if (NULL_INTERVAL_P (tree)) |
| 1318 | return 0; | 1318 | return 0; |
| 1319 | 1319 | ||
| 1320 | /* Left branch */ | 1320 | /* Left branch. */ |
| 1321 | if (relative_position < LEFT_TOTAL_LENGTH (tree)) | 1321 | if (relative_position < LEFT_TOTAL_LENGTH (tree)) |
| 1322 | { | 1322 | { |
| 1323 | EMACS_INT subtract = interval_deletion_adjustment (tree->left, | 1323 | EMACS_INT subtract = interval_deletion_adjustment (tree->left, |
| @@ -1327,7 +1327,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, | |||
| 1327 | CHECK_TOTAL_LENGTH (tree); | 1327 | CHECK_TOTAL_LENGTH (tree); |
| 1328 | return subtract; | 1328 | return subtract; |
| 1329 | } | 1329 | } |
| 1330 | /* Right branch */ | 1330 | /* Right branch. */ |
| 1331 | else if (relative_position >= (TOTAL_LENGTH (tree) | 1331 | else if (relative_position >= (TOTAL_LENGTH (tree) |
| 1332 | - RIGHT_TOTAL_LENGTH (tree))) | 1332 | - RIGHT_TOTAL_LENGTH (tree))) |
| 1333 | { | 1333 | { |
| @@ -1699,54 +1699,37 @@ graft_intervals_into_buffer (INTERVAL source, EMACS_INT position, | |||
| 1699 | Qnil, buf, 0); | 1699 | Qnil, buf, 0); |
| 1700 | } | 1700 | } |
| 1701 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) | 1701 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) |
| 1702 | /* Shouldn't be necessary. -stef */ | 1702 | /* Shouldn't be necessary. --Stef */ |
| 1703 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); | 1703 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); |
| 1704 | return; | 1704 | return; |
| 1705 | } | 1705 | } |
| 1706 | 1706 | ||
| 1707 | if (NULL_INTERVAL_P (tree)) | 1707 | eassert (length == TOTAL_LENGTH (source)); |
| 1708 | { | 1708 | |
| 1709 | /* The inserted text constitutes the whole buffer, so | 1709 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length) |
| 1710 | { /* The inserted text constitutes the whole buffer, so | ||
| 1710 | simply copy over the interval structure. */ | 1711 | simply copy over the interval structure. */ |
| 1711 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source)) | ||
| 1712 | { | ||
| 1713 | Lisp_Object buf; | 1712 | Lisp_Object buf; |
| 1714 | XSETBUFFER (buf, buffer); | 1713 | XSETBUFFER (buf, buffer); |
| 1715 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); | 1714 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); |
| 1716 | BUF_INTERVALS (buffer)->position = BEG; | 1715 | BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); |
| 1717 | BUF_INTERVALS (buffer)->up_obj = 1; | 1716 | eassert (BUF_INTERVALS (buffer)->up_obj == 1); |
| 1718 | |||
| 1719 | return; | 1717 | return; |
| 1720 | } | 1718 | } |
| 1721 | 1719 | else if (NULL_INTERVAL_P (tree)) | |
| 1722 | /* Create an interval tree in which to place a copy | 1720 | { /* Create an interval tree in which to place a copy |
| 1723 | of the intervals of the inserted string. */ | 1721 | of the intervals of the inserted string. */ |
| 1724 | { | ||
| 1725 | Lisp_Object buf; | 1722 | Lisp_Object buf; |
| 1726 | XSETBUFFER (buf, buffer); | 1723 | XSETBUFFER (buf, buffer); |
| 1727 | tree = create_root_interval (buf); | 1724 | tree = create_root_interval (buf); |
| 1728 | } | 1725 | } |
| 1729 | } | ||
| 1730 | else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source)) | ||
| 1731 | /* If the buffer contains only the new string, but | ||
| 1732 | there was already some interval tree there, then it may be | ||
| 1733 | some zero length intervals. Eventually, do something clever | ||
| 1734 | about inserting properly. For now, just waste the old intervals. */ | ||
| 1735 | { | ||
| 1736 | BUF_INTERVALS (buffer) = reproduce_tree (source, INTERVAL_PARENT (tree)); | ||
| 1737 | BUF_INTERVALS (buffer)->position = BEG; | ||
| 1738 | BUF_INTERVALS (buffer)->up_obj = 1; | ||
| 1739 | /* Explicitly free the old tree here. */ | ||
| 1740 | |||
| 1741 | return; | ||
| 1742 | } | ||
| 1743 | /* Paranoia -- the text has already been added, so this buffer | 1726 | /* Paranoia -- the text has already been added, so this buffer |
| 1744 | should be of non-zero length. */ | 1727 | should be of non-zero length. */ |
| 1745 | else if (TOTAL_LENGTH (tree) == 0) | 1728 | else if (TOTAL_LENGTH (tree) == 0) |
| 1746 | abort (); | 1729 | abort (); |
| 1747 | 1730 | ||
| 1748 | this = under = find_interval (tree, position); | 1731 | this = under = find_interval (tree, position); |
| 1749 | if (NULL_INTERVAL_P (under)) /* Paranoia */ | 1732 | if (NULL_INTERVAL_P (under)) /* Paranoia. */ |
| 1750 | abort (); | 1733 | abort (); |
| 1751 | over = find_interval (source, interval_start_pos (source)); | 1734 | over = find_interval (source, interval_start_pos (source)); |
| 1752 | 1735 | ||