Mercurial > emacs
comparison src/intervals.c @ 20557:b1edf278ca98
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 01 Jan 1998 07:08:33 +0000 |
parents | f62a4f83537e |
children | 3cb3da7382f5 |
comparison
equal
deleted
inserted
replaced
20556:8f6f64cc1f08 | 20557:b1edf278ca98 |
---|---|
881 | 881 |
882 pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist; | 882 pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist; |
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 { |
890 i = split_interval_left (i, length); | 890 i = split_interval_left (i, length); |
891 i->plist = newi.plist; | 891 i->plist = newi.plist; |
1658 return Fplist_get (Vdefault_text_properties, prop); | 1658 return Fplist_get (Vdefault_text_properties, prop); |
1659 return Qnil; | 1659 return Qnil; |
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; |
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 (); | |
1683 | 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) |
1691 || ! NILP (buffer->overlays_after)); | 1742 || ! NILP (buffer->overlays_after)); |
1692 | 1743 |
1693 /* If we have no text properties and overlays, | 1744 /* If we have no text properties and overlays, |
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; |
1711 | 1762 |
1712 buffer_point = (BUF_PT (buffer) == BUF_ZV (buffer) | 1763 buffer_point = (BUF_PT (buffer) == BUF_ZV (buffer) |
1729 | 1780 |
1730 /* Moving within an interval. */ | 1781 /* Moving within an interval. */ |
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, |
1742 move forward or backward until a change in that property. */ | 1793 move forward or backward until a change in that property. */ |
1743 if (NILP (Vinhibit_point_motion_hooks) | 1794 if (NILP (Vinhibit_point_motion_hooks) |
1744 && ((! NULL_INTERVAL_P (to) && ! NULL_INTERVAL_P (toprev)) | 1795 && ((! NULL_INTERVAL_P (to) && ! NULL_INTERVAL_P (toprev)) |
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, |
1761 skip back over all chars with matching intangible property. */ | 1812 skip back over all chars with matching intangible property. */ |
1762 if (! NILP (intangible_propval)) | 1813 if (! NILP (intangible_propval)) |
1766 intangible_propval)) | 1817 intangible_propval)) |
1767 pos = Fprevious_char_property_change (pos, Qnil); | 1818 pos = Fprevious_char_property_change (pos, Qnil); |
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, |
1775 skip back over all chars with matching intangible property. */ | 1826 skip back over all chars with matching intangible property. */ |
1776 if (! NILP (intangible_propval)) | 1827 if (! NILP (intangible_propval)) |
1779 intangible_propval)) | 1830 intangible_propval)) |
1780 pos = Fnext_char_property_change (pos, Qnil); | 1831 pos = Fnext_char_property_change (pos, Qnil); |
1781 | 1832 |
1782 } | 1833 } |
1783 | 1834 |
1784 position = XINT (pos); | 1835 charpos = XINT (pos); |
1785 } | 1836 bytepos = buf_charpos_to_bytepos (buffer, charpos); |
1786 | 1837 } |
1787 if (position != original_position) | 1838 |
1788 { | 1839 if (charpos != original_position) |
1789 /* Set TO to the interval containing the char after POSITION, | 1840 { |
1790 and TOPREV to the interval containing the char before POSITION. | 1841 /* Set TO to the interval containing the char after CHARPOS, |
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; |
1799 } | 1851 } |
1800 | 1852 |
1801 /* Here TO is the interval after the stopping point | 1853 /* Here TO is the interval after the stopping point |
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 |
1809 (old_point, new_point) as arguments. */ | 1861 (old_point, new_point) as arguments. */ |
1810 if (NILP (Vinhibit_point_motion_hooks) | 1862 if (NILP (Vinhibit_point_motion_hooks) |
1831 else | 1883 else |
1832 enter_before = Qnil; | 1884 enter_before = Qnil; |
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 } | |
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 } | 1900 } |
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. */ |
1862 | 1904 |
1921 get_local_map (position, buffer) | 1963 get_local_map (position, buffer) |
1922 register int position; | 1964 register int position; |
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)) |
1930 abort (); | 1972 abort (); |
1931 | 1973 |
1932 /* Ignore narrowing, so that a local map continues to be valid even if | 1974 /* Ignore narrowing, so that a local map continues to be valid even if |
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. */ |
1941 if (position == BUF_Z (buffer) && BUF_Z (buffer) > BUF_BEG (buffer)) | 1987 if (position == BUF_Z (buffer) && BUF_Z (buffer) > BUF_BEG (buffer)) |
1942 --position; | 1988 --position; |
1944 XSETBUFFER (lispy_buffer, buffer); | 1990 XSETBUFFER (lispy_buffer, buffer); |
1945 prop = Fget_char_property (lispy_position, Qlocal_map, lispy_buffer); | 1991 prop = Fget_char_property (lispy_position, Qlocal_map, lispy_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. */ |
1952 if (SYMBOLP (prop) && !NILP (prop)) | 2000 if (SYMBOLP (prop) && !NILP (prop)) |
1953 prop = Findirect_function (prop); | 2001 prop = Findirect_function (prop); |