diff options
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/src/intervals.c b/src/intervals.c index e8ff5bce5b6..6f8dda4294e 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -1317,7 +1317,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t 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 | ptrdiff_t subtract = interval_deletion_adjustment (tree->left, | 1323 | ptrdiff_t subtract = interval_deletion_adjustment (tree->left, |
| @@ -1327,7 +1327,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t 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 | { |
| @@ -1425,9 +1425,8 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1425 | compiler that does not allow calling a static function (here, | 1425 | compiler that does not allow calling a static function (here, |
| 1426 | adjust_intervals_for_deletion) from a non-static inline function. */ | 1426 | adjust_intervals_for_deletion) from a non-static inline function. */ |
| 1427 | 1427 | ||
| 1428 | static inline void | 1428 | void |
| 1429 | static_offset_intervals (struct buffer *buffer, ptrdiff_t start, | 1429 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) |
| 1430 | ptrdiff_t length) | ||
| 1431 | { | 1430 | { |
| 1432 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) | 1431 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) |
| 1433 | return; | 1432 | return; |
| @@ -1440,12 +1439,6 @@ static_offset_intervals (struct buffer *buffer, ptrdiff_t start, | |||
| 1440 | adjust_intervals_for_deletion (buffer, start, -length); | 1439 | adjust_intervals_for_deletion (buffer, start, -length); |
| 1441 | } | 1440 | } |
| 1442 | } | 1441 | } |
| 1443 | |||
| 1444 | inline void | ||
| 1445 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) | ||
| 1446 | { | ||
| 1447 | static_offset_intervals (buffer, start, length); | ||
| 1448 | } | ||
| 1449 | 1442 | ||
| 1450 | /* Merge interval I with its lexicographic successor. The resulting | 1443 | /* Merge interval I with its lexicographic successor. The resulting |
| 1451 | interval is returned, and has the properties of the original | 1444 | interval is returned, and has the properties of the original |
| @@ -1706,54 +1699,37 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1706 | Qnil, buf, 0); | 1699 | Qnil, buf, 0); |
| 1707 | } | 1700 | } |
| 1708 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) | 1701 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) |
| 1709 | /* Shouldn't be necessary. -stef */ | 1702 | /* Shouldn't be necessary. --Stef */ |
| 1710 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); | 1703 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); |
| 1711 | return; | 1704 | return; |
| 1712 | } | 1705 | } |
| 1713 | 1706 | ||
| 1714 | if (NULL_INTERVAL_P (tree)) | 1707 | eassert (length == TOTAL_LENGTH (source)); |
| 1715 | { | 1708 | |
| 1716 | /* 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 | ||
| 1717 | simply copy over the interval structure. */ | 1711 | simply copy over the interval structure. */ |
| 1718 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source)) | ||
| 1719 | { | ||
| 1720 | Lisp_Object buf; | 1712 | Lisp_Object buf; |
| 1721 | XSETBUFFER (buf, buffer); | 1713 | XSETBUFFER (buf, buffer); |
| 1722 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); | 1714 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); |
| 1723 | BUF_INTERVALS (buffer)->position = BEG; | 1715 | BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); |
| 1724 | BUF_INTERVALS (buffer)->up_obj = 1; | 1716 | eassert (BUF_INTERVALS (buffer)->up_obj == 1); |
| 1725 | |||
| 1726 | return; | 1717 | return; |
| 1727 | } | 1718 | } |
| 1728 | 1719 | else if (NULL_INTERVAL_P (tree)) | |
| 1729 | /* Create an interval tree in which to place a copy | 1720 | { /* Create an interval tree in which to place a copy |
| 1730 | of the intervals of the inserted string. */ | 1721 | of the intervals of the inserted string. */ |
| 1731 | { | ||
| 1732 | Lisp_Object buf; | 1722 | Lisp_Object buf; |
| 1733 | XSETBUFFER (buf, buffer); | 1723 | XSETBUFFER (buf, buffer); |
| 1734 | tree = create_root_interval (buf); | 1724 | tree = create_root_interval (buf); |
| 1735 | } | 1725 | } |
| 1736 | } | ||
| 1737 | else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source)) | ||
| 1738 | /* If the buffer contains only the new string, but | ||
| 1739 | there was already some interval tree there, then it may be | ||
| 1740 | some zero length intervals. Eventually, do something clever | ||
| 1741 | about inserting properly. For now, just waste the old intervals. */ | ||
| 1742 | { | ||
| 1743 | BUF_INTERVALS (buffer) = reproduce_tree (source, INTERVAL_PARENT (tree)); | ||
| 1744 | BUF_INTERVALS (buffer)->position = BEG; | ||
| 1745 | BUF_INTERVALS (buffer)->up_obj = 1; | ||
| 1746 | /* Explicitly free the old tree here. */ | ||
| 1747 | |||
| 1748 | return; | ||
| 1749 | } | ||
| 1750 | /* Paranoia -- the text has already been added, so this buffer | 1726 | /* Paranoia -- the text has already been added, so this buffer |
| 1751 | should be of non-zero length. */ | 1727 | should be of non-zero length. */ |
| 1752 | else if (TOTAL_LENGTH (tree) == 0) | 1728 | else if (TOTAL_LENGTH (tree) == 0) |
| 1753 | abort (); | 1729 | abort (); |
| 1754 | 1730 | ||
| 1755 | this = under = find_interval (tree, position); | 1731 | this = under = find_interval (tree, position); |
| 1756 | if (NULL_INTERVAL_P (under)) /* Paranoia */ | 1732 | if (NULL_INTERVAL_P (under)) /* Paranoia. */ |
| 1757 | abort (); | 1733 | abort (); |
| 1758 | over = find_interval (source, interval_start_pos (source)); | 1734 | over = find_interval (source, interval_start_pos (source)); |
| 1759 | 1735 | ||
| @@ -1884,7 +1860,7 @@ lookup_char_property (Lisp_Object plist, register Lisp_Object prop, int textprop | |||
| 1884 | /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to | 1860 | /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to |
| 1885 | byte position BYTEPOS. */ | 1861 | byte position BYTEPOS. */ |
| 1886 | 1862 | ||
| 1887 | inline void | 1863 | void |
| 1888 | temp_set_point_both (struct buffer *buffer, | 1864 | temp_set_point_both (struct buffer *buffer, |
| 1889 | ptrdiff_t charpos, ptrdiff_t bytepos) | 1865 | ptrdiff_t charpos, ptrdiff_t bytepos) |
| 1890 | { | 1866 | { |
| @@ -1904,7 +1880,7 @@ temp_set_point_both (struct buffer *buffer, | |||
| 1904 | 1880 | ||
| 1905 | /* Set point "temporarily", without checking any text properties. */ | 1881 | /* Set point "temporarily", without checking any text properties. */ |
| 1906 | 1882 | ||
| 1907 | inline void | 1883 | void |
| 1908 | temp_set_point (struct buffer *buffer, ptrdiff_t charpos) | 1884 | temp_set_point (struct buffer *buffer, ptrdiff_t charpos) |
| 1909 | { | 1885 | { |
| 1910 | temp_set_point_both (buffer, charpos, | 1886 | temp_set_point_both (buffer, charpos, |
| @@ -2393,7 +2369,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length) | |||
| 2393 | 2369 | ||
| 2394 | /* Give STRING the properties of BUFFER from POSITION to LENGTH. */ | 2370 | /* Give STRING the properties of BUFFER from POSITION to LENGTH. */ |
| 2395 | 2371 | ||
| 2396 | inline void | 2372 | void |
| 2397 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, | 2373 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, |
| 2398 | ptrdiff_t position, ptrdiff_t length) | 2374 | ptrdiff_t position, ptrdiff_t length) |
| 2399 | { | 2375 | { |