diff options
| author | Richard M. Stallman | 1998-01-01 07:08:33 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-01 07:08:33 +0000 |
| commit | ef1900f30c7a35c973b9aeb7da7c5f2a102e6554 (patch) | |
| tree | c0975a304e4982edcc2d8c1ac1309135c7b92942 | |
| parent | 6289dd10a01b4bd2d688098f33ab30bd1f6597a8 (diff) | |
| download | emacs-ef1900f30c7a35c973b9aeb7da7c5f2a102e6554.tar.gz emacs-ef1900f30c7a35c973b9aeb7da7c5f2a102e6554.zip | |
(set_point_both): Renamed from set_point;
New arg BYTE; BUFFER is now first arg; use temp_set_point_both.
(set_point): New function; uses set_point_both.
(temp_set_point_both): New function.
(temp_set_point): Update BUF_PT_BYTE.
(get_local_map): Save and restore both forms of the buffer bounds.
| -rw-r--r-- | src/intervals.c | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/src/intervals.c b/src/intervals.c index 25bc6e3c46b..bd47862bdfa 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -883,7 +883,7 @@ adjust_intervals_for_insertion (tree, position, length) | |||
| 883 | pright = NULL_INTERVAL_P (i) ? Qnil : i->plist; | 883 | pright = NULL_INTERVAL_P (i) ? Qnil : i->plist; |
| 884 | newi.plist = merge_properties_sticky (pleft, pright); | 884 | newi.plist = merge_properties_sticky (pleft, pright); |
| 885 | 885 | ||
| 886 | if(! prev) /* i.e. position == BEG */ | 886 | if (! prev) /* i.e. position == BEG */ |
| 887 | { | 887 | { |
| 888 | if (! intervals_equal (i, &newi)) | 888 | if (! intervals_equal (i, &newi)) |
| 889 | { | 889 | { |
| @@ -1660,31 +1660,82 @@ textget (plist, prop) | |||
| 1660 | } | 1660 | } |
| 1661 | 1661 | ||
| 1662 | 1662 | ||
| 1663 | /* Set point in BUFFER to POSITION. If the target position is | 1663 | /* Set point "temporarily", without checking any text properties. */ |
| 1664 | |||
| 1665 | INLINE void | ||
| 1666 | temp_set_point (buffer, charpos) | ||
| 1667 | struct buffer *buffer; | ||
| 1668 | int charpos; | ||
| 1669 | { | ||
| 1670 | temp_set_point_both (buffer, charpos, | ||
| 1671 | buf_charpos_to_bytepos (buffer, charpos)); | ||
| 1672 | } | ||
| 1673 | |||
| 1674 | /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to | ||
| 1675 | byte position BYTEPOS. */ | ||
| 1676 | |||
| 1677 | INLINE void | ||
| 1678 | temp_set_point_both (buffer, charpos, bytepos) | ||
| 1679 | int charpos; | ||
| 1680 | struct buffer *buffer; | ||
| 1681 | { | ||
| 1682 | /* In a single-byte buffer, the two positions must be equal. */ | ||
| 1683 | if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) | ||
| 1684 | && charpos != bytepos) | ||
| 1685 | abort (); | ||
| 1686 | |||
| 1687 | if (charpos > bytepos) | ||
| 1688 | abort (); | ||
| 1689 | |||
| 1690 | if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) | ||
| 1691 | abort (); | ||
| 1692 | |||
| 1693 | BUF_PT_BYTE (buffer) = bytepos; | ||
| 1694 | BUF_PT (buffer) = charpos; | ||
| 1695 | } | ||
| 1696 | |||
| 1697 | /* Set point in BUFFER to CHARPOS. If the target position is | ||
| 1664 | before an intangible character, move to an ok place. */ | 1698 | before an intangible character, move to an ok place. */ |
| 1665 | 1699 | ||
| 1666 | void | 1700 | void |
| 1667 | set_point (position, buffer) | 1701 | set_point (buffer, charpos) |
| 1668 | register int position; | ||
| 1669 | register struct buffer *buffer; | 1702 | register struct buffer *buffer; |
| 1703 | register int charpos; | ||
| 1704 | { | ||
| 1705 | set_point_both (buffer, charpos, buf_charpos_to_bytepos (buffer, charpos)); | ||
| 1706 | } | ||
| 1707 | |||
| 1708 | /* Set point in BUFFER to CHARPOS, which corresponds to byte | ||
| 1709 | position BYTEPOS. If the target position is | ||
| 1710 | before an intangible character, move to an ok place. */ | ||
| 1711 | |||
| 1712 | void | ||
| 1713 | set_point_both (buffer, charpos, bytepos) | ||
| 1714 | register struct buffer *buffer; | ||
| 1715 | register int charpos; | ||
| 1670 | { | 1716 | { |
| 1671 | register INTERVAL to, from, toprev, fromprev, target; | 1717 | register INTERVAL to, from, toprev, fromprev, target; |
| 1672 | int buffer_point; | 1718 | int buffer_point; |
| 1673 | register Lisp_Object obj; | 1719 | register Lisp_Object obj; |
| 1674 | int old_position = BUF_PT (buffer); | 1720 | int old_position = BUF_PT (buffer); |
| 1675 | int backwards = (position < old_position ? 1 : 0); | 1721 | int backwards = (charpos < old_position ? 1 : 0); |
| 1676 | int have_overlays; | 1722 | int have_overlays; |
| 1677 | int original_position; | 1723 | int original_position; |
| 1678 | 1724 | ||
| 1679 | buffer->point_before_scroll = Qnil; | 1725 | buffer->point_before_scroll = Qnil; |
| 1680 | 1726 | ||
| 1681 | if (position == BUF_PT (buffer)) | 1727 | if (charpos == BUF_PT (buffer)) |
| 1682 | return; | 1728 | return; |
| 1683 | 1729 | ||
| 1730 | /* In a single-byte buffer, the two positions must be equal. */ | ||
| 1731 | if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) | ||
| 1732 | && charpos != bytepos) | ||
| 1733 | abort (); | ||
| 1734 | |||
| 1684 | /* Check this now, before checking if the buffer has any intervals. | 1735 | /* Check this now, before checking if the buffer has any intervals. |
| 1685 | That way, we can catch conditions which break this sanity check | 1736 | That way, we can catch conditions which break this sanity check |
| 1686 | whether or not there are intervals in the buffer. */ | 1737 | whether or not there are intervals in the buffer. */ |
| 1687 | if (position > BUF_ZV (buffer) || position < BUF_BEGV (buffer)) | 1738 | if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) |
| 1688 | abort (); | 1739 | abort (); |
| 1689 | 1740 | ||
| 1690 | have_overlays = (! NILP (buffer->overlays_before) | 1741 | have_overlays = (! NILP (buffer->overlays_before) |
| @@ -1694,17 +1745,17 @@ set_point (position, buffer) | |||
| 1694 | then we can do it quickly. */ | 1745 | then we can do it quickly. */ |
| 1695 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays) | 1746 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays) |
| 1696 | { | 1747 | { |
| 1697 | BUF_PT (buffer) = position; | 1748 | temp_set_point_both (buffer, charpos, bytepos); |
| 1698 | return; | 1749 | return; |
| 1699 | } | 1750 | } |
| 1700 | 1751 | ||
| 1701 | /* Set TO to the interval containing the char after POSITION, | 1752 | /* Set TO to the interval containing the char after CHARPOS, |
| 1702 | and TOPREV to the interval containing the char before POSITION. | 1753 | and TOPREV to the interval containing the char before CHARPOS. |
| 1703 | Either one may be null. They may be equal. */ | 1754 | Either one may be null. They may be equal. */ |
| 1704 | to = find_interval (BUF_INTERVALS (buffer), position); | 1755 | to = find_interval (BUF_INTERVALS (buffer), charpos); |
| 1705 | if (position == BUF_BEGV (buffer)) | 1756 | if (charpos == BUF_BEGV (buffer)) |
| 1706 | toprev = 0; | 1757 | toprev = 0; |
| 1707 | else if (to && to->position == position) | 1758 | else if (to && to->position == charpos) |
| 1708 | toprev = previous_interval (to); | 1759 | toprev = previous_interval (to); |
| 1709 | else | 1760 | else |
| 1710 | toprev = to; | 1761 | toprev = to; |
| @@ -1731,11 +1782,11 @@ set_point (position, buffer) | |||
| 1731 | if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to) | 1782 | if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to) |
| 1732 | && ! have_overlays) | 1783 | && ! have_overlays) |
| 1733 | { | 1784 | { |
| 1734 | BUF_PT (buffer) = position; | 1785 | temp_set_point_both (buffer, charpos, bytepos); |
| 1735 | return; | 1786 | return; |
| 1736 | } | 1787 | } |
| 1737 | 1788 | ||
| 1738 | original_position = position; | 1789 | original_position = charpos; |
| 1739 | 1790 | ||
| 1740 | /* If the new position is between two intangible characters | 1791 | /* If the new position is between two intangible characters |
| 1741 | with the same intangible property value, | 1792 | with the same intangible property value, |
| @@ -1745,16 +1796,16 @@ set_point (position, buffer) | |||
| 1745 | || have_overlays) | 1796 | || have_overlays) |
| 1746 | /* Intangibility never stops us from positioning at the beginning | 1797 | /* Intangibility never stops us from positioning at the beginning |
| 1747 | or end of the buffer, so don't bother checking in that case. */ | 1798 | or end of the buffer, so don't bother checking in that case. */ |
| 1748 | && position != BEGV && position != ZV) | 1799 | && charpos != BEGV && charpos != ZV) |
| 1749 | { | 1800 | { |
| 1750 | Lisp_Object intangible_propval; | 1801 | Lisp_Object intangible_propval; |
| 1751 | Lisp_Object pos; | 1802 | Lisp_Object pos; |
| 1752 | 1803 | ||
| 1753 | XSETINT (pos, position); | 1804 | XSETINT (pos, charpos); |
| 1754 | 1805 | ||
| 1755 | if (backwards) | 1806 | if (backwards) |
| 1756 | { | 1807 | { |
| 1757 | intangible_propval = Fget_char_property (make_number (position), | 1808 | intangible_propval = Fget_char_property (make_number (charpos), |
| 1758 | Qintangible, Qnil); | 1809 | Qintangible, Qnil); |
| 1759 | 1810 | ||
| 1760 | /* If following char is intangible, | 1811 | /* If following char is intangible, |
| @@ -1768,7 +1819,7 @@ set_point (position, buffer) | |||
| 1768 | } | 1819 | } |
| 1769 | else | 1820 | else |
| 1770 | { | 1821 | { |
| 1771 | intangible_propval = Fget_char_property (make_number (position - 1), | 1822 | intangible_propval = Fget_char_property (make_number (charpos - 1), |
| 1772 | Qintangible, Qnil); | 1823 | Qintangible, Qnil); |
| 1773 | 1824 | ||
| 1774 | /* If following char is intangible, | 1825 | /* If following char is intangible, |
| @@ -1781,18 +1832,19 @@ set_point (position, buffer) | |||
| 1781 | 1832 | ||
| 1782 | } | 1833 | } |
| 1783 | 1834 | ||
| 1784 | position = XINT (pos); | 1835 | charpos = XINT (pos); |
| 1836 | bytepos = buf_charpos_to_bytepos (buffer, charpos); | ||
| 1785 | } | 1837 | } |
| 1786 | 1838 | ||
| 1787 | if (position != original_position) | 1839 | if (charpos != original_position) |
| 1788 | { | 1840 | { |
| 1789 | /* Set TO to the interval containing the char after POSITION, | 1841 | /* Set TO to the interval containing the char after CHARPOS, |
| 1790 | and TOPREV to the interval containing the char before POSITION. | 1842 | and TOPREV to the interval containing the char before CHARPOS. |
| 1791 | Either one may be null. They may be equal. */ | 1843 | Either one may be null. They may be equal. */ |
| 1792 | to = find_interval (BUF_INTERVALS (buffer), position); | 1844 | to = find_interval (BUF_INTERVALS (buffer), charpos); |
| 1793 | if (position == BUF_BEGV (buffer)) | 1845 | if (charpos == BUF_BEGV (buffer)) |
| 1794 | toprev = 0; | 1846 | toprev = 0; |
| 1795 | else if (to && to->position == position) | 1847 | else if (to && to->position == charpos) |
| 1796 | toprev = previous_interval (to); | 1848 | toprev = previous_interval (to); |
| 1797 | else | 1849 | else |
| 1798 | toprev = to; | 1850 | toprev = to; |
| @@ -1802,7 +1854,7 @@ set_point (position, buffer) | |||
| 1802 | and TOPREV is the interval before the stopping point. | 1854 | and TOPREV is the interval before the stopping point. |
| 1803 | One or the other may be null. */ | 1855 | One or the other may be null. */ |
| 1804 | 1856 | ||
| 1805 | BUF_PT (buffer) = position; | 1857 | temp_set_point_both (buffer, charpos, bytepos); |
| 1806 | 1858 | ||
| 1807 | /* We run point-left and point-entered hooks here, iff the | 1859 | /* We run point-left and point-entered hooks here, iff the |
| 1808 | two intervals are not equivalent. These hooks take | 1860 | two intervals are not equivalent. These hooks take |
| @@ -1833,29 +1885,19 @@ set_point (position, buffer) | |||
| 1833 | 1885 | ||
| 1834 | if (! EQ (leave_before, enter_before) && !NILP (leave_before)) | 1886 | if (! EQ (leave_before, enter_before) && !NILP (leave_before)) |
| 1835 | call2 (leave_before, make_number (old_position), | 1887 | call2 (leave_before, make_number (old_position), |
| 1836 | make_number (position)); | 1888 | make_number (charpos)); |
| 1837 | if (! EQ (leave_after, enter_after) && !NILP (leave_after)) | 1889 | if (! EQ (leave_after, enter_after) && !NILP (leave_after)) |
| 1838 | call2 (leave_after, make_number (old_position), | 1890 | call2 (leave_after, make_number (old_position), |
| 1839 | make_number (position)); | 1891 | make_number (charpos)); |
| 1840 | 1892 | ||
| 1841 | if (! EQ (enter_before, leave_before) && !NILP (enter_before)) | 1893 | if (! EQ (enter_before, leave_before) && !NILP (enter_before)) |
| 1842 | call2 (enter_before, make_number (old_position), | 1894 | call2 (enter_before, make_number (old_position), |
| 1843 | make_number (position)); | 1895 | make_number (charpos)); |
| 1844 | if (! EQ (enter_after, leave_after) && !NILP (enter_after)) | 1896 | if (! EQ (enter_after, leave_after) && !NILP (enter_after)) |
| 1845 | call2 (enter_after, make_number (old_position), | 1897 | call2 (enter_after, make_number (old_position), |
| 1846 | make_number (position)); | 1898 | make_number (charpos)); |
| 1847 | } | 1899 | } |
| 1848 | } | 1900 | } |
| 1849 | |||
| 1850 | /* Set point temporarily, without checking any text properties. */ | ||
| 1851 | |||
| 1852 | INLINE void | ||
| 1853 | temp_set_point (position, buffer) | ||
| 1854 | int position; | ||
| 1855 | struct buffer *buffer; | ||
| 1856 | { | ||
| 1857 | BUF_PT (buffer) = position; | ||
| 1858 | } | ||
| 1859 | 1901 | ||
| 1860 | /* Move point to POSITION, unless POSITION is inside an intangible | 1902 | /* Move point to POSITION, unless POSITION is inside an intangible |
| 1861 | segment that reaches all the way to point. */ | 1903 | segment that reaches all the way to point. */ |
| @@ -1923,7 +1965,7 @@ get_local_map (position, buffer) | |||
| 1923 | register struct buffer *buffer; | 1965 | register struct buffer *buffer; |
| 1924 | { | 1966 | { |
| 1925 | Lisp_Object prop, tem, lispy_position, lispy_buffer; | 1967 | Lisp_Object prop, tem, lispy_position, lispy_buffer; |
| 1926 | int old_begv, old_zv; | 1968 | int old_begv, old_zv, old_begv_byte, old_zv_byte; |
| 1927 | 1969 | ||
| 1928 | /* Perhaps we should just change `position' to the limit. */ | 1970 | /* Perhaps we should just change `position' to the limit. */ |
| 1929 | if (position > BUF_Z (buffer) || position < BUF_BEG (buffer)) | 1971 | if (position > BUF_Z (buffer) || position < BUF_BEG (buffer)) |
| @@ -1933,8 +1975,12 @@ get_local_map (position, buffer) | |||
| 1933 | the visible region contains no characters and hence no properties. */ | 1975 | the visible region contains no characters and hence no properties. */ |
| 1934 | old_begv = BUF_BEGV (buffer); | 1976 | old_begv = BUF_BEGV (buffer); |
| 1935 | old_zv = BUF_ZV (buffer); | 1977 | old_zv = BUF_ZV (buffer); |
| 1978 | old_begv_byte = BUF_BEGV_BYTE (buffer); | ||
| 1979 | old_zv_byte = BUF_ZV_BYTE (buffer); | ||
| 1936 | BUF_BEGV (buffer) = BUF_BEG (buffer); | 1980 | BUF_BEGV (buffer) = BUF_BEG (buffer); |
| 1937 | BUF_ZV (buffer) = BUF_Z (buffer); | 1981 | BUF_ZV (buffer) = BUF_Z (buffer); |
| 1982 | BUF_BEGV_BYTE (buffer) = BUF_BEG_BYTE (buffer); | ||
| 1983 | BUF_ZV_BYTE (buffer) = BUF_Z_BYTE (buffer); | ||
| 1938 | 1984 | ||
| 1939 | /* There are no properties at the end of the buffer, so in that case | 1985 | /* There are no properties at the end of the buffer, so in that case |
| 1940 | check for a local map on the last character of the buffer instead. */ | 1986 | check for a local map on the last character of the buffer instead. */ |
| @@ -1946,6 +1992,8 @@ get_local_map (position, buffer) | |||
| 1946 | 1992 | ||
| 1947 | BUF_BEGV (buffer) = old_begv; | 1993 | BUF_BEGV (buffer) = old_begv; |
| 1948 | BUF_ZV (buffer) = old_zv; | 1994 | BUF_ZV (buffer) = old_zv; |
| 1995 | BUF_BEGV_BYTE (buffer) = old_begv_byte; | ||
| 1996 | BUF_ZV_BYTE (buffer) = old_zv_byte; | ||
| 1949 | 1997 | ||
| 1950 | /* Use the local map only if it is valid. */ | 1998 | /* Use the local map only if it is valid. */ |
| 1951 | /* Do allow symbols that are defined as keymaps. */ | 1999 | /* Do allow symbols that are defined as keymaps. */ |