comparison src/intervals.c @ 93111:f84051049637

* intervals.c (temp_set_point, temp_set_point_both): Use EMACS_INT. (set_point, set_point_both): Use EMACS_INT. Remove `buffer' arg, work on current_buffer only instead (that was already the case for some of the code anyway). * buffer.h (set_point, set_point_both): Remove buffer arg, use long int. (temp_set_point, temp_set_point_both): Use EMACS_INT. (SET_PT, SET_PT_BOTH): Adjust. * intervals.h (set_point, temp_set_point, set_point_both) (temp_set_point_both): Remove redundant declarations.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 20 Mar 2008 18:38:34 +0000
parents 606f2d163a64
children 8971ddf55736
comparison
equal deleted inserted replaced
93110:6d11337f1ad8 93111:f84051049637
1924 1924
1925 1925
1926 /* Set point "temporarily", without checking any text properties. */ 1926 /* Set point "temporarily", without checking any text properties. */
1927 1927
1928 INLINE void 1928 INLINE void
1929 temp_set_point (buffer, charpos) 1929 temp_set_point (struct buffer *buffer, EMACS_INT charpos)
1930 struct buffer *buffer;
1931 int charpos;
1932 { 1930 {
1933 temp_set_point_both (buffer, charpos, 1931 temp_set_point_both (buffer, charpos,
1934 buf_charpos_to_bytepos (buffer, charpos)); 1932 buf_charpos_to_bytepos (buffer, charpos));
1935 } 1933 }
1936 1934
1937 /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to 1935 /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to
1938 byte position BYTEPOS. */ 1936 byte position BYTEPOS. */
1939 1937
1940 INLINE void 1938 INLINE void
1941 temp_set_point_both (buffer, charpos, bytepos) 1939 temp_set_point_both (struct buffer *buffer,
1942 int charpos, bytepos; 1940 EMACS_INT charpos, EMACS_INT bytepos)
1943 struct buffer *buffer;
1944 { 1941 {
1945 /* In a single-byte buffer, the two positions must be equal. */ 1942 /* In a single-byte buffer, the two positions must be equal. */
1946 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) 1943 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)
1947 && charpos != bytepos) 1944 && charpos != bytepos)
1948 abort (); 1945 abort ();
1959 1956
1960 /* Set point in BUFFER to CHARPOS. If the target position is 1957 /* Set point in BUFFER to CHARPOS. If the target position is
1961 before an intangible character, move to an ok place. */ 1958 before an intangible character, move to an ok place. */
1962 1959
1963 void 1960 void
1964 set_point (buffer, charpos) 1961 set_point (EMACS_INT charpos)
1965 register struct buffer *buffer; 1962 {
1966 register int charpos; 1963 set_point_both (charpos, buf_charpos_to_bytepos (current_buffer, charpos));
1967 {
1968 set_point_both (buffer, charpos, buf_charpos_to_bytepos (buffer, charpos));
1969 } 1964 }
1970 1965
1971 /* If there's an invisible character at position POS + TEST_OFFS in the 1966 /* If there's an invisible character at position POS + TEST_OFFS in the
1972 current buffer, and the invisible property has a `stickiness' such that 1967 current buffer, and the invisible property has a `stickiness' such that
1973 inserting a character at position POS would inherit the property it, 1968 inserting a character at position POS would inherit the property it,
2017 /* Set point in BUFFER to CHARPOS, which corresponds to byte 2012 /* Set point in BUFFER to CHARPOS, which corresponds to byte
2018 position BYTEPOS. If the target position is 2013 position BYTEPOS. If the target position is
2019 before an intangible character, move to an ok place. */ 2014 before an intangible character, move to an ok place. */
2020 2015
2021 void 2016 void
2022 set_point_both (buffer, charpos, bytepos) 2017 set_point_both (EMACS_INT charpos, EMACS_INT bytepos)
2023 register struct buffer *buffer;
2024 register int charpos, bytepos;
2025 { 2018 {
2026 register INTERVAL to, from, toprev, fromprev; 2019 register INTERVAL to, from, toprev, fromprev;
2027 int buffer_point; 2020 EMACS_INT buffer_point;
2028 int old_position = BUF_PT (buffer); 2021 EMACS_INT old_position = PT;
2029 /* This ensures that we move forward past intangible text when the 2022 /* This ensures that we move forward past intangible text when the
2030 initial position is the same as the destination, in the rare 2023 initial position is the same as the destination, in the rare
2031 instances where this is important, e.g. in line-move-finish 2024 instances where this is important, e.g. in line-move-finish
2032 (simple.el). */ 2025 (simple.el). */
2033 int backwards = (charpos < old_position ? 1 : 0); 2026 int backwards = (charpos < old_position ? 1 : 0);
2034 int have_overlays; 2027 int have_overlays;
2035 int original_position; 2028 EMACS_INT original_position;
2036 2029
2037 buffer->point_before_scroll = Qnil; 2030 current_buffer->point_before_scroll = Qnil;
2038 2031
2039 if (charpos == BUF_PT (buffer)) 2032 if (charpos == PT)
2040 return; 2033 return;
2041 2034
2042 /* In a single-byte buffer, the two positions must be equal. */ 2035 /* In a single-byte buffer, the two positions must be equal. */
2043 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) 2036 eassert (ZV != ZV_BYTE || charpos == bytepos);
2044 && charpos != bytepos)
2045 abort ();
2046 2037
2047 /* Check this now, before checking if the buffer has any intervals. 2038 /* Check this now, before checking if the buffer has any intervals.
2048 That way, we can catch conditions which break this sanity check 2039 That way, we can catch conditions which break this sanity check
2049 whether or not there are intervals in the buffer. */ 2040 whether or not there are intervals in the buffer. */
2050 if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) 2041 eassert (charpos <= ZV && charpos >= BEGV);
2051 abort (); 2042
2052 2043 have_overlays = (current_buffer->overlays_before
2053 have_overlays = (buffer->overlays_before || buffer->overlays_after); 2044 || current_buffer->overlays_after);
2054 2045
2055 /* If we have no text properties and overlays, 2046 /* If we have no text properties and overlays,
2056 then we can do it quickly. */ 2047 then we can do it quickly. */
2057 if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays) 2048 if (NULL_INTERVAL_P (BUF_INTERVALS (current_buffer)) && ! have_overlays)
2058 { 2049 {
2059 temp_set_point_both (buffer, charpos, bytepos); 2050 temp_set_point_both (current_buffer, charpos, bytepos);
2060 return; 2051 return;
2061 } 2052 }
2062 2053
2063 /* Set TO to the interval containing the char after CHARPOS, 2054 /* Set TO to the interval containing the char after CHARPOS,
2064 and TOPREV to the interval containing the char before CHARPOS. 2055 and TOPREV to the interval containing the char before CHARPOS.
2065 Either one may be null. They may be equal. */ 2056 Either one may be null. They may be equal. */
2066 to = find_interval (BUF_INTERVALS (buffer), charpos); 2057 to = find_interval (BUF_INTERVALS (current_buffer), charpos);
2067 if (charpos == BUF_BEGV (buffer)) 2058 if (charpos == BEGV)
2068 toprev = 0; 2059 toprev = 0;
2069 else if (to && to->position == charpos) 2060 else if (to && to->position == charpos)
2070 toprev = previous_interval (to); 2061 toprev = previous_interval (to);
2071 else 2062 else
2072 toprev = to; 2063 toprev = to;
2073 2064
2074 buffer_point = (BUF_PT (buffer) == BUF_ZV (buffer) 2065 buffer_point = (PT == ZV ? ZV - 1 : PT);
2075 ? BUF_ZV (buffer) - 1
2076 : BUF_PT (buffer));
2077 2066
2078 /* Set FROM to the interval containing the char after PT, 2067 /* Set FROM to the interval containing the char after PT,
2079 and FROMPREV to the interval containing the char before PT. 2068 and FROMPREV to the interval containing the char before PT.
2080 Either one may be null. They may be equal. */ 2069 Either one may be null. They may be equal. */
2081 /* We could cache this and save time. */ 2070 /* We could cache this and save time. */
2082 from = find_interval (BUF_INTERVALS (buffer), buffer_point); 2071 from = find_interval (BUF_INTERVALS (current_buffer), buffer_point);
2083 if (buffer_point == BUF_BEGV (buffer)) 2072 if (buffer_point == BEGV)
2084 fromprev = 0; 2073 fromprev = 0;
2085 else if (from && from->position == BUF_PT (buffer)) 2074 else if (from && from->position == PT)
2086 fromprev = previous_interval (from); 2075 fromprev = previous_interval (from);
2087 else if (buffer_point != BUF_PT (buffer)) 2076 else if (buffer_point != PT)
2088 fromprev = from, from = 0; 2077 fromprev = from, from = 0;
2089 else 2078 else
2090 fromprev = from; 2079 fromprev = from;
2091 2080
2092 /* Moving within an interval. */ 2081 /* Moving within an interval. */
2093 if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to) 2082 if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to)
2094 && ! have_overlays) 2083 && ! have_overlays)
2095 { 2084 {
2096 temp_set_point_both (buffer, charpos, bytepos); 2085 temp_set_point_both (current_buffer, charpos, bytepos);
2097 return; 2086 return;
2098 } 2087 }
2099 2088
2100 original_position = charpos; 2089 original_position = charpos;
2101 2090
2128 2117
2129 intangible_propval = Fget_char_property (pos, Qintangible, Qnil); 2118 intangible_propval = Fget_char_property (pos, Qintangible, Qnil);
2130 2119
2131 if (! NILP (intangible_propval)) 2120 if (! NILP (intangible_propval))
2132 { 2121 {
2133 while (XINT (pos) > BUF_BEGV (buffer) 2122 while (XINT (pos) > BEGV
2134 && EQ (Fget_char_property (make_number (XINT (pos) - 1), 2123 && EQ (Fget_char_property (make_number (XINT (pos) - 1),
2135 Qintangible, Qnil), 2124 Qintangible, Qnil),
2136 intangible_propval)) 2125 intangible_propval))
2137 pos = Fprevious_char_property_change (pos, Qnil); 2126 pos = Fprevious_char_property_change (pos, Qnil);
2138 2127
2161 intangible_propval = Fget_char_property (make_number (charpos - 1), 2150 intangible_propval = Fget_char_property (make_number (charpos - 1),
2162 Qintangible, Qnil); 2151 Qintangible, Qnil);
2163 2152
2164 if (! NILP (intangible_propval)) 2153 if (! NILP (intangible_propval))
2165 { 2154 {
2166 while (XINT (pos) < BUF_ZV (buffer) 2155 while (XINT (pos) < ZV
2167 && EQ (Fget_char_property (pos, Qintangible, Qnil), 2156 && EQ (Fget_char_property (pos, Qintangible, Qnil),
2168 intangible_propval)) 2157 intangible_propval))
2169 pos = Fnext_char_property_change (pos, Qnil); 2158 pos = Fnext_char_property_change (pos, Qnil);
2170 2159
2171 /* Set CHARPOS from POS, and if the final intangible character 2160 /* Set CHARPOS from POS, and if the final intangible character
2175 end of an invisible/intangible/rear-sticky region. */ 2164 end of an invisible/intangible/rear-sticky region. */
2176 charpos = adjust_for_invis_intang (XINT (pos), -1, 1, 0); 2165 charpos = adjust_for_invis_intang (XINT (pos), -1, 1, 0);
2177 } 2166 }
2178 } 2167 }
2179 2168
2180 bytepos = buf_charpos_to_bytepos (buffer, charpos); 2169 bytepos = buf_charpos_to_bytepos (current_buffer, charpos);
2181 } 2170 }
2182 2171
2183 if (charpos != original_position) 2172 if (charpos != original_position)
2184 { 2173 {
2185 /* Set TO to the interval containing the char after CHARPOS, 2174 /* Set TO to the interval containing the char after CHARPOS,
2186 and TOPREV to the interval containing the char before CHARPOS. 2175 and TOPREV to the interval containing the char before CHARPOS.
2187 Either one may be null. They may be equal. */ 2176 Either one may be null. They may be equal. */
2188 to = find_interval (BUF_INTERVALS (buffer), charpos); 2177 to = find_interval (BUF_INTERVALS (current_buffer), charpos);
2189 if (charpos == BUF_BEGV (buffer)) 2178 if (charpos == BEGV)
2190 toprev = 0; 2179 toprev = 0;
2191 else if (to && to->position == charpos) 2180 else if (to && to->position == charpos)
2192 toprev = previous_interval (to); 2181 toprev = previous_interval (to);
2193 else 2182 else
2194 toprev = to; 2183 toprev = to;
2196 2185
2197 /* Here TO is the interval after the stopping point 2186 /* Here TO is the interval after the stopping point
2198 and TOPREV is the interval before the stopping point. 2187 and TOPREV is the interval before the stopping point.
2199 One or the other may be null. */ 2188 One or the other may be null. */
2200 2189
2201 temp_set_point_both (buffer, charpos, bytepos); 2190 temp_set_point_both (current_buffer, charpos, bytepos);
2202 2191
2203 /* We run point-left and point-entered hooks here, if the 2192 /* We run point-left and point-entered hooks here, if the
2204 two intervals are not equivalent. These hooks take 2193 two intervals are not equivalent. These hooks take
2205 (old_point, new_point) as arguments. */ 2194 (old_point, new_point) as arguments. */
2206 if (NILP (Vinhibit_point_motion_hooks) 2195 if (NILP (Vinhibit_point_motion_hooks)