Mercurial > hg > xemacs-beta
comparison src/insdel.c @ 373:6240c7796c7a r21-2b2
Import from CVS: tag r21-2b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:04:06 +0200 |
parents | 57709be46d1b |
children | d883f39b8495 |
comparison
equal
deleted
inserted
replaced
372:49e1ed2d7ed8 | 373:6240c7796c7a |
---|---|
1655 gap_left (struct buffer *buf, Bytind pos) | 1655 gap_left (struct buffer *buf, Bytind pos) |
1656 { | 1656 { |
1657 Bufbyte *to, *from; | 1657 Bufbyte *to, *from; |
1658 Bytecount i; | 1658 Bytecount i; |
1659 Bytind new_s1; | 1659 Bytind new_s1; |
1660 struct buffer *mbuf; | |
1661 Lisp_Object bufcons; | |
1660 | 1662 |
1661 from = BUF_GPT_ADDR (buf); | 1663 from = BUF_GPT_ADDR (buf); |
1662 to = from + BUF_GAP_SIZE (buf); | 1664 to = from + BUF_GAP_SIZE (buf); |
1663 new_s1 = BI_BUF_GPT (buf); | 1665 new_s1 = BI_BUF_GPT (buf); |
1664 | 1666 |
1706 } | 1708 } |
1707 | 1709 |
1708 /* Adjust markers, and buffer data structure, to put the gap at POS. | 1710 /* Adjust markers, and buffer data structure, to put the gap at POS. |
1709 POS is where the loop above stopped, which may be what was specified | 1711 POS is where the loop above stopped, which may be what was specified |
1710 or may be where a quit was detected. */ | 1712 or may be where a quit was detected. */ |
1711 adjust_markers (buf, pos, BI_BUF_GPT (buf), BUF_GAP_SIZE (buf)); | 1713 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
1712 adjust_extents (make_buffer (buf), pos, BI_BUF_GPT (buf), | 1714 { |
1713 BUF_GAP_SIZE (buf)); | 1715 adjust_markers (mbuf, pos, BI_BUF_GPT (mbuf), BUF_GAP_SIZE (mbuf)); |
1716 } | |
1717 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
1718 { | |
1719 adjust_extents (make_buffer (mbuf), pos, BI_BUF_GPT (mbuf), | |
1720 BUF_GAP_SIZE (mbuf)); | |
1721 } | |
1714 SET_BI_BUF_GPT (buf, pos); | 1722 SET_BI_BUF_GPT (buf, pos); |
1715 SET_GAP_SENTINEL (buf); | 1723 SET_GAP_SENTINEL (buf); |
1716 #ifdef ERROR_CHECK_EXTENTS | 1724 #ifdef ERROR_CHECK_EXTENTS |
1717 sledgehammer_extent_check (make_buffer (buf)); | 1725 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
1726 { | |
1727 sledgehammer_extent_check (make_buffer (mbuf)); | |
1728 } | |
1718 #endif | 1729 #endif |
1719 QUIT; | 1730 QUIT; |
1720 } | 1731 } |
1721 | 1732 |
1722 static void | 1733 static void |
1723 gap_right (struct buffer *buf, Bytind pos) | 1734 gap_right (struct buffer *buf, Bytind pos) |
1724 { | 1735 { |
1725 Bufbyte *to, *from; | 1736 Bufbyte *to, *from; |
1726 Bytecount i; | 1737 Bytecount i; |
1727 Bytind new_s1; | 1738 Bytind new_s1; |
1739 struct buffer *mbuf; | |
1740 Lisp_Object bufcons; | |
1728 | 1741 |
1729 to = BUF_GPT_ADDR (buf); | 1742 to = BUF_GPT_ADDR (buf); |
1730 from = to + BUF_GAP_SIZE (buf); | 1743 from = to + BUF_GAP_SIZE (buf); |
1731 new_s1 = BI_BUF_GPT (buf); | 1744 new_s1 = BI_BUF_GPT (buf); |
1732 | 1745 |
1773 } | 1786 } |
1774 } | 1787 } |
1775 | 1788 |
1776 { | 1789 { |
1777 int gsize = BUF_GAP_SIZE (buf); | 1790 int gsize = BUF_GAP_SIZE (buf); |
1778 adjust_markers (buf, BI_BUF_GPT (buf) + gsize, pos + gsize, - gsize); | 1791 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
1779 adjust_extents (make_buffer (buf), BI_BUF_GPT (buf) + gsize, pos + gsize, | 1792 { |
1780 - gsize); | 1793 adjust_markers (mbuf, BI_BUF_GPT (mbuf) + gsize, pos + gsize, - gsize); |
1794 } | |
1795 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
1796 { | |
1797 adjust_extents (make_buffer (mbuf), BI_BUF_GPT (mbuf) + gsize, | |
1798 pos + gsize, - gsize); | |
1799 } | |
1781 SET_BI_BUF_GPT (buf, pos); | 1800 SET_BI_BUF_GPT (buf, pos); |
1782 SET_GAP_SENTINEL (buf); | 1801 SET_GAP_SENTINEL (buf); |
1783 #ifdef ERROR_CHECK_EXTENTS | 1802 #ifdef ERROR_CHECK_EXTENTS |
1784 sledgehammer_extent_check (make_buffer (buf)); | 1803 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
1804 { | |
1805 sledgehammer_extent_check (make_buffer (mbuf)); | |
1806 } | |
1785 #endif | 1807 #endif |
1786 } | 1808 } |
1787 if (pos == BI_BUF_Z (buf)) | 1809 if (pos == BI_BUF_Z (buf)) |
1788 { | 1810 { |
1789 /* merge gap with end gap */ | 1811 /* merge gap with end gap */ |
2078 static int inside_change_hook; | 2100 static int inside_change_hook; |
2079 | 2101 |
2080 static Lisp_Object | 2102 static Lisp_Object |
2081 change_function_restore (Lisp_Object buffer) | 2103 change_function_restore (Lisp_Object buffer) |
2082 { | 2104 { |
2105 /* We should first reset the variable and then change the buffer, | |
2106 because Fset_buffer() can throw. */ | |
2107 inside_change_hook = 0; | |
2083 Fset_buffer (buffer); | 2108 Fset_buffer (buffer); |
2084 inside_change_hook = 0; | |
2085 return Qnil; | 2109 return Qnil; |
2086 } | 2110 } |
2087 | 2111 |
2088 static int in_first_change; | 2112 static int in_first_change; |
2089 | 2113 |
2090 static Lisp_Object | 2114 static Lisp_Object |
2091 first_change_hook_restore (Lisp_Object buffer) | 2115 first_change_hook_restore (Lisp_Object buffer) |
2092 { | 2116 { |
2117 in_first_change = 0; | |
2093 Fset_buffer (buffer); | 2118 Fset_buffer (buffer); |
2094 in_first_change = 0; | |
2095 return Qnil; | 2119 return Qnil; |
2096 } | 2120 } |
2097 | 2121 |
2098 /* Signal an initial modification to the buffer. */ | 2122 /* Signal an initial modification to the buffer. */ |
2099 | 2123 |
2104 Lisp_Object buffer; | 2128 Lisp_Object buffer; |
2105 XSETBUFFER (buffer, current_buffer); | 2129 XSETBUFFER (buffer, current_buffer); |
2106 | 2130 |
2107 if (!in_first_change) | 2131 if (!in_first_change) |
2108 { | 2132 { |
2109 if (!preparing_for_armageddon && | 2133 if (!NILP (symbol_value_in_buffer (Qfirst_change_hook, buffer))) |
2110 !NILP (symbol_value_in_buffer (Qfirst_change_hook, buffer))) | |
2111 { | 2134 { |
2112 int speccount = specpdl_depth (); | 2135 int speccount = specpdl_depth (); |
2113 record_unwind_protect (first_change_hook_restore, buffer); | 2136 record_unwind_protect (first_change_hook_restore, buffer); |
2114 set_buffer_internal (buf); | 2137 set_buffer_internal (buf); |
2115 in_first_change = 1; | 2138 in_first_change = 1; |
2124 | 2147 |
2125 static void | 2148 static void |
2126 signal_before_change (struct buffer *buf, Bufpos start, Bufpos end) | 2149 signal_before_change (struct buffer *buf, Bufpos start, Bufpos end) |
2127 { | 2150 { |
2128 /* This function can GC */ | 2151 /* This function can GC */ |
2129 Lisp_Object buffer; | 2152 struct buffer *mbuf; |
2130 XSETBUFFER (buffer, buf); | 2153 Lisp_Object bufcons; |
2131 | 2154 |
2132 if (!inside_change_hook) | 2155 if (!inside_change_hook) |
2133 { | 2156 { |
2157 Lisp_Object buffer; | |
2158 | |
2134 /* Are we in a multiple-change session? */ | 2159 /* Are we in a multiple-change session? */ |
2135 if (buf->text->changes->in_multiple_change && | 2160 if (buf->text->changes->in_multiple_change && |
2136 buf->text->changes->mc_begin != 0) | 2161 buf->text->changes->mc_begin != 0) |
2137 { | 2162 { |
2138 /* If we're violating the constraints of the session, | 2163 /* If we're violating the constraints of the session, |
2157 } | 2182 } |
2158 } | 2183 } |
2159 | 2184 |
2160 /* If buffer is unmodified, run a special hook for that case. */ | 2185 /* If buffer is unmodified, run a special hook for that case. */ |
2161 if (BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf)) | 2186 if (BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf)) |
2162 signal_first_change (buf); | 2187 { |
2188 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2189 { | |
2190 signal_first_change (mbuf); | |
2191 } | |
2192 } | |
2163 | 2193 |
2164 /* Now in any case run the before-change-functions if any. */ | 2194 /* Now in any case run the before-change-functions if any. */ |
2165 | 2195 |
2166 if (!preparing_for_armageddon && | 2196 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2167 (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer)) || | 2197 { |
2168 /* Obsolete, for compatibility */ | 2198 XSETBUFFER (buffer, mbuf); |
2169 !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer)))) | 2199 if (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer)) |
2170 { | 2200 /* Obsolete, for compatibility */ |
2171 int speccount = specpdl_depth (); | 2201 || !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer))) |
2172 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | 2202 { |
2173 set_buffer_internal (buf); | 2203 int speccount = specpdl_depth (); |
2174 inside_change_hook = 1; | 2204 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); |
2175 va_run_hook_with_args (Qbefore_change_functions, 2, | 2205 set_buffer_internal (buf); |
2176 make_int (start), make_int (end)); | 2206 inside_change_hook = 1; |
2177 /* Obsolete, for compatibility */ | 2207 va_run_hook_with_args (Qbefore_change_functions, 2, |
2178 va_run_hook_with_args (Qbefore_change_function, 2, | 2208 make_int (start), make_int (end)); |
2179 make_int (start), make_int (end)); | 2209 /* Obsolete, for compatibility */ |
2180 unbind_to (speccount, Qnil); | 2210 va_run_hook_with_args (Qbefore_change_function, 2, |
2211 make_int (start), make_int (end)); | |
2212 unbind_to (speccount, Qnil); | |
2213 } | |
2214 } | |
2215 | |
2216 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2217 { | |
2218 XSETBUFFER (buffer, mbuf); | |
2219 report_extent_modification (buffer, start, end, | |
2220 &inside_change_hook, 0); | |
2181 } | 2221 } |
2182 | 2222 |
2183 /* Only now do we indicate that the before-change-functions have | 2223 /* Only now do we indicate that the before-change-functions have |
2184 been called, in case some function throws out. */ | 2224 been called, in case some function throws out. */ |
2185 buf->text->changes->mc_begin_signaled = 1; | 2225 buf->text->changes->mc_begin_signaled = 1; |
2186 } | 2226 } |
2187 | |
2188 /* #### At this point we should map over extents calling | |
2189 modification-hooks, insert-before-hooks and insert-after-hooks | |
2190 of relevant extents */ | |
2191 } | 2227 } |
2192 | 2228 |
2193 /* Signal a change immediately after it happens. | 2229 /* Signal a change immediately after it happens. |
2194 START is the bufpos of the start of the changed text. | 2230 START is the bufpos of the start of the changed text. |
2195 ORIG_END is the bufpos of the end of the before-changed text. | 2231 ORIG_END is the bufpos of the end of the before-changed text. |
2199 static void | 2235 static void |
2200 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end, | 2236 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end, |
2201 Bufpos new_end) | 2237 Bufpos new_end) |
2202 { | 2238 { |
2203 /* This function can GC */ | 2239 /* This function can GC */ |
2204 Lisp_Object buffer; | 2240 struct buffer *mbuf; |
2205 XSETBUFFER (buffer, buf); | 2241 Lisp_Object bufcons; |
2206 | 2242 |
2207 /* always do this. */ | 2243 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2208 buffer_signal_changed_region (buf, start, new_end); | 2244 { |
2209 font_lock_maybe_update_syntactic_caches (buf, start, orig_end, new_end); | 2245 /* always do this. */ |
2246 buffer_signal_changed_region (mbuf, start, new_end); | |
2247 } | |
2248 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2249 { | |
2250 /* #### This seems inefficient. Wouldn't it be better to just | |
2251 keep one cache per base buffer? */ | |
2252 font_lock_maybe_update_syntactic_caches (mbuf, start, orig_end, new_end); | |
2253 } | |
2210 | 2254 |
2211 if (!inside_change_hook) | 2255 if (!inside_change_hook) |
2212 { | 2256 { |
2257 Lisp_Object buffer; | |
2258 | |
2213 if (buf->text->changes->in_multiple_change && | 2259 if (buf->text->changes->in_multiple_change && |
2214 buf->text->changes->mc_begin != 0) | 2260 buf->text->changes->mc_begin != 0) |
2215 { | 2261 { |
2216 assert (start >= buf->text->changes->mc_begin && | 2262 assert (start >= buf->text->changes->mc_begin && |
2217 start <= buf->text->changes->mc_new_end); | 2263 start <= buf->text->changes->mc_new_end); |
2219 orig_end <= buf->text->changes->mc_new_end); | 2265 orig_end <= buf->text->changes->mc_new_end); |
2220 buf->text->changes->mc_new_end += new_end - orig_end; | 2266 buf->text->changes->mc_new_end += new_end - orig_end; |
2221 return; /* after-change-functions signalled when all changes done */ | 2267 return; /* after-change-functions signalled when all changes done */ |
2222 } | 2268 } |
2223 | 2269 |
2224 if (!preparing_for_armageddon && | 2270 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2225 (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer)) || | 2271 { |
2226 /* Obsolete, for compatibility */ | 2272 XSETBUFFER (buffer, mbuf); |
2227 !NILP (symbol_value_in_buffer (Qafter_change_function, buffer)))) | 2273 |
2228 { | 2274 if (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer)) |
2229 int speccount = specpdl_depth (); | 2275 /* Obsolete, for compatibility */ |
2230 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | 2276 || !NILP (symbol_value_in_buffer (Qafter_change_function, buffer))) |
2231 set_buffer_internal (buf); | 2277 { |
2232 inside_change_hook = 1; | 2278 int speccount = specpdl_depth (); |
2233 /* The actual after-change functions take slightly | 2279 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); |
2234 different arguments than what we were passed. */ | 2280 set_buffer_internal (buf); |
2235 va_run_hook_with_args (Qafter_change_functions, 3, | 2281 inside_change_hook = 1; |
2236 make_int (start), make_int (new_end), | 2282 /* The actual after-change functions take slightly |
2237 make_int (orig_end - start)); | 2283 different arguments than what we were passed. */ |
2238 /* Obsolete, for compatibility */ | 2284 va_run_hook_with_args (Qafter_change_functions, 3, |
2239 va_run_hook_with_args (Qafter_change_function, 3, | 2285 make_int (start), make_int (new_end), |
2240 make_int (start), make_int (new_end), | 2286 make_int (orig_end - start)); |
2241 make_int (orig_end - start)); | 2287 /* Obsolete, for compatibility */ |
2242 unbind_to (speccount, Qnil); | 2288 va_run_hook_with_args (Qafter_change_function, 3, |
2243 } | 2289 make_int (start), make_int (new_end), |
2244 } | 2290 make_int (orig_end - start)); |
2245 | 2291 unbind_to (speccount, Qnil); |
2246 /* #### At this point we should map over extents calling | 2292 } |
2247 some sort of modification hooks of relevant extents */ | 2293 } |
2294 | |
2295 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2296 { | |
2297 XSETBUFFER (buffer, mbuf); | |
2298 report_extent_modification (buffer, start, new_end, | |
2299 &inside_change_hook, 1); | |
2300 } | |
2301 } | |
2248 } | 2302 } |
2249 | 2303 |
2250 /* Call this if you're about to change the region of BUFFER from START | 2304 /* Call this if you're about to change the region of BUFFER from START |
2251 to END. This checks the read-only properties of the region, calls | 2305 to END. This checks the read-only properties of the region, calls |
2252 the necessary modification hooks, and warns the next redisplay that | 2306 the necessary modification hooks, and warns the next redisplay that |
2258 { | 2312 { |
2259 /* This function can GC */ | 2313 /* This function can GC */ |
2260 /* dmoore - This function can also kill the buffer buf, the current | 2314 /* dmoore - This function can also kill the buffer buf, the current |
2261 buffer, and do anything it pleases. So if you call it, be | 2315 buffer, and do anything it pleases. So if you call it, be |
2262 careful. */ | 2316 careful. */ |
2263 Lisp_Object buffer; | 2317 struct buffer *mbuf; |
2318 Lisp_Object buffer, bufcons; | |
2264 struct gcpro gcpro1; | 2319 struct gcpro gcpro1; |
2265 | 2320 |
2266 barf_if_buffer_read_only (buf, start, end); | 2321 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2322 { | |
2323 barf_if_buffer_read_only (mbuf, start, end); | |
2324 } | |
2267 | 2325 |
2268 /* if this is the first modification, see about locking the buffer's | 2326 /* if this is the first modification, see about locking the buffer's |
2269 file */ | 2327 file */ |
2270 XSETBUFFER (buffer, buf); | 2328 XSETBUFFER (buffer, buf); |
2271 GCPRO1 (buffer); | 2329 GCPRO1 (buffer); |
2305 | 2363 |
2306 #if 0 /* FSFmacs */ | 2364 #if 0 /* FSFmacs */ |
2307 Vdeactivate_mark = Qt; | 2365 Vdeactivate_mark = Qt; |
2308 #endif | 2366 #endif |
2309 | 2367 |
2310 buf->point_before_scroll = Qnil; | 2368 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2369 { | |
2370 mbuf->point_before_scroll = Qnil; | |
2371 } | |
2311 } | 2372 } |
2312 | 2373 |
2313 | 2374 |
2314 /************************************************************************/ | 2375 /************************************************************************/ |
2315 /* Insertion of strings */ | 2376 /* Insertion of strings */ |
2365 /* This function can GC */ | 2426 /* This function can GC */ |
2366 struct gcpro gcpro1; | 2427 struct gcpro gcpro1; |
2367 Bytind ind; | 2428 Bytind ind; |
2368 Charcount cclen; | 2429 Charcount cclen; |
2369 int move_point = 0; | 2430 int move_point = 0; |
2431 struct buffer *mbuf; | |
2432 Lisp_Object bufcons; | |
2370 | 2433 |
2371 /* Defensive steps just in case a buffer gets deleted and a calling | 2434 /* Defensive steps just in case a buffer gets deleted and a calling |
2372 function doesn't notice it. */ | 2435 function doesn't notice it. */ |
2373 if (!BUFFER_LIVE_P (buf)) | 2436 if (!BUFFER_LIVE_P (buf)) |
2374 return 0; | 2437 return 0; |
2389 | 2452 |
2390 /* Make sure that point-max won't exceed the size of an emacs int. */ | 2453 /* Make sure that point-max won't exceed the size of an emacs int. */ |
2391 if ((length + BUF_Z (buf)) > EMACS_INT_MAX) | 2454 if ((length + BUF_Z (buf)) > EMACS_INT_MAX) |
2392 error ("Maximum buffer size exceeded"); | 2455 error ("Maximum buffer size exceeded"); |
2393 | 2456 |
2394 /* theoretically not necessary -- caller should GCPRO */ | 2457 /* theoretically not necessary -- caller should GCPRO. |
2458 #### buffer_insert_from_buffer_1() doesn't! */ | |
2395 GCPRO1 (reloc); | 2459 GCPRO1 (reloc); |
2396 | 2460 |
2397 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING)); | 2461 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING)); |
2398 | 2462 |
2399 /* Defensive steps in case the before-change-functions fuck around */ | 2463 /* Defensive steps in case the before-change-functions fuck around */ |
2431 make_gap (buf, length - BUF_GAP_SIZE (buf)); | 2495 make_gap (buf, length - BUF_GAP_SIZE (buf)); |
2432 } | 2496 } |
2433 | 2497 |
2434 insert_invalidate_line_number_cache (buf, pos, nonreloc + offset, length); | 2498 insert_invalidate_line_number_cache (buf, pos, nonreloc + offset, length); |
2435 | 2499 |
2436 record_insert (buf, pos, cclen); | 2500 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2501 { | |
2502 record_insert (mbuf, pos, cclen); | |
2503 } | |
2504 | |
2437 BUF_MODIFF (buf)++; | 2505 BUF_MODIFF (buf)++; |
2438 MARK_BUFFERS_CHANGED; | 2506 MARK_BUFFERS_CHANGED; |
2439 | 2507 |
2440 /* string may have been relocated up to this point */ | 2508 /* string may have been relocated up to this point */ |
2441 if (STRINGP (reloc)) | 2509 if (STRINGP (reloc)) |
2443 | 2511 |
2444 memcpy (BUF_GPT_ADDR (buf), nonreloc + offset, length); | 2512 memcpy (BUF_GPT_ADDR (buf), nonreloc + offset, length); |
2445 | 2513 |
2446 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length); | 2514 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length); |
2447 SET_BI_BUF_GPT (buf, BI_BUF_GPT (buf) + length); | 2515 SET_BI_BUF_GPT (buf, BI_BUF_GPT (buf) + length); |
2448 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) + cclen, BI_BUF_ZV (buf) + length); | 2516 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2517 { | |
2518 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) + cclen, BI_BUF_ZV (mbuf) + length); | |
2519 } | |
2449 SET_BOTH_BUF_Z (buf, BUF_Z (buf) + cclen, BI_BUF_Z (buf) + length); | 2520 SET_BOTH_BUF_Z (buf, BUF_Z (buf) + cclen, BI_BUF_Z (buf) + length); |
2450 SET_GAP_SENTINEL (buf); | 2521 SET_GAP_SENTINEL (buf); |
2451 | 2522 |
2452 #ifdef MULE | 2523 #ifdef MULE |
2453 buffer_mule_signal_inserted_region (buf, pos, length, cclen); | 2524 buffer_mule_signal_inserted_region (buf, pos, length, cclen); |
2454 #endif | 2525 #endif |
2455 | 2526 |
2456 process_extents_for_insertion (make_buffer (buf), ind, length); | 2527 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2457 /* We know the gap is at IND so the cast is OK. */ | 2528 { |
2458 adjust_markers_for_insert (buf, (Memind) ind, length); | 2529 process_extents_for_insertion (make_buffer (mbuf), ind, length); |
2530 } | |
2531 | |
2532 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2533 { | |
2534 /* We know the gap is at IND so the cast is OK. */ | |
2535 adjust_markers_for_insert (mbuf, (Memind) ind, length); | |
2536 } | |
2459 | 2537 |
2460 /* Point logically doesn't move, but may need to be adjusted because | 2538 /* Point logically doesn't move, but may need to be adjusted because |
2461 it's a byte index. point-marker doesn't change because it's a | 2539 it's a byte index. point-marker doesn't change because it's a |
2462 memory index. */ | 2540 memory index. */ |
2463 if (BI_BUF_PT (buf) > ind) | 2541 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2464 JUST_SET_POINT (buf, BUF_PT (buf) + cclen, BI_BUF_PT (buf) + length); | 2542 { |
2543 if (BI_BUF_PT (mbuf) > ind) | |
2544 JUST_SET_POINT (mbuf, BUF_PT (mbuf) + cclen, | |
2545 BI_BUF_PT (mbuf) + length); | |
2546 } | |
2465 | 2547 |
2466 /* Well, point might move. */ | 2548 /* Well, point might move. */ |
2467 if (move_point) | 2549 if (move_point) |
2468 BI_BUF_SET_PT (buf, ind + length); | 2550 BI_BUF_SET_PT (buf, ind + length); |
2469 | 2551 |
2470 if (STRINGP (reloc)) | 2552 if (STRINGP (reloc)) |
2471 splice_in_string_extents (reloc, buf, ind, length, offset); | 2553 { |
2554 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2555 { | |
2556 splice_in_string_extents (reloc, mbuf, ind, length, offset); | |
2557 } | |
2558 } | |
2472 | 2559 |
2473 if (flags & INSDEL_BEFORE_MARKERS) | 2560 if (flags & INSDEL_BEFORE_MARKERS) |
2474 { | 2561 { |
2475 /* ind - 1 is correct because the FROM argument is exclusive. | 2562 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2476 I formerly used DEC_BYTIND() but that caused problems at the | 2563 { |
2477 beginning of the buffer. */ | 2564 /* ind - 1 is correct because the FROM argument is exclusive. |
2478 adjust_markers (buf, ind - 1, ind, length); | 2565 I formerly used DEC_BYTIND() but that caused problems at the |
2566 beginning of the buffer. */ | |
2567 adjust_markers (mbuf, ind - 1, ind, length); | |
2568 } | |
2479 } | 2569 } |
2480 | 2570 |
2481 signal_after_change (buf, pos, pos, pos + cclen); | 2571 signal_after_change (buf, pos, pos, pos + cclen); |
2482 | 2572 |
2483 UNGCPRO; | 2573 UNGCPRO; |
2505 Charcount | 2595 Charcount |
2506 buffer_insert_lisp_string_1 (struct buffer *buf, Bufpos pos, Lisp_Object str, | 2596 buffer_insert_lisp_string_1 (struct buffer *buf, Bufpos pos, Lisp_Object str, |
2507 int flags) | 2597 int flags) |
2508 { | 2598 { |
2509 /* This function can GC */ | 2599 /* This function can GC */ |
2600 #ifdef ERROR_CHECK_TYPECHECK | |
2510 assert (STRINGP (str)); | 2601 assert (STRINGP (str)); |
2602 #endif | |
2511 return buffer_insert_string_1 (buf, pos, 0, str, 0, | 2603 return buffer_insert_string_1 (buf, pos, 0, str, 0, |
2512 XSTRING_LENGTH (str), | 2604 XSTRING_LENGTH (str), |
2513 flags); | 2605 flags); |
2514 } | 2606 } |
2515 | 2607 |
2518 Charcount | 2610 Charcount |
2519 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s, | 2611 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s, |
2520 int flags) | 2612 int flags) |
2521 { | 2613 { |
2522 /* This function can GC */ | 2614 /* This function can GC */ |
2523 | |
2524 CONST char *translated = GETTEXT (s); | 2615 CONST char *translated = GETTEXT (s); |
2525 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil, | 2616 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil, |
2526 0, strlen (translated), flags); | 2617 0, strlen (translated), flags); |
2527 } | 2618 } |
2528 | 2619 |
2530 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch, | 2621 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch, |
2531 int flags) | 2622 int flags) |
2532 { | 2623 { |
2533 /* This function can GC */ | 2624 /* This function can GC */ |
2534 Bufbyte str[MAX_EMCHAR_LEN]; | 2625 Bufbyte str[MAX_EMCHAR_LEN]; |
2535 Bytecount len; | 2626 Bytecount len = set_charptr_emchar (str, ch); |
2536 | |
2537 len = set_charptr_emchar (str, ch); | |
2538 return buffer_insert_string_1 (buf, pos, str, Qnil, 0, len, flags); | 2627 return buffer_insert_string_1 (buf, pos, str, Qnil, 0, len, flags); |
2539 } | 2628 } |
2540 | 2629 |
2541 Charcount | 2630 Charcount |
2542 buffer_insert_c_char_1 (struct buffer *buf, Bufpos pos, char c, | 2631 buffer_insert_c_char_1 (struct buffer *buf, Bufpos pos, char c, |
2571 /* This function can GC */ | 2660 /* This function can GC */ |
2572 Charcount numdel; | 2661 Charcount numdel; |
2573 Bytind bi_from, bi_to; | 2662 Bytind bi_from, bi_to; |
2574 Bytecount bc_numdel; | 2663 Bytecount bc_numdel; |
2575 EMACS_INT shortage; | 2664 EMACS_INT shortage; |
2576 Lisp_Object bufobj; | 2665 struct buffer *mbuf; |
2666 Lisp_Object bufcons; | |
2577 | 2667 |
2578 /* Defensive steps just in case a buffer gets deleted and a calling | 2668 /* Defensive steps just in case a buffer gets deleted and a calling |
2579 function doesn't notice it. */ | 2669 function doesn't notice it. */ |
2580 if (!BUFFER_LIVE_P (buf)) | 2670 if (!BUFFER_LIVE_P (buf)) |
2581 return; | 2671 return; |
2602 if (to > BUF_ZV (buf)) | 2692 if (to > BUF_ZV (buf)) |
2603 to = BUF_ZV (buf); | 2693 to = BUF_ZV (buf); |
2604 if ((numdel = to - from) <= 0) | 2694 if ((numdel = to - from) <= 0) |
2605 return; | 2695 return; |
2606 | 2696 |
2607 XSETBUFFER (bufobj, buf); | |
2608 | |
2609 /* Redisplay needs to know if a newline was in the deleted region. | 2697 /* Redisplay needs to know if a newline was in the deleted region. |
2610 If we've already marked the changed region as having a deleted | 2698 If we've already marked the changed region as having a deleted |
2611 newline there is no use in performing the check. */ | 2699 newline there is no use in performing the check. */ |
2612 if (!buf->changes->newline_was_deleted) | 2700 if (!buf->changes->newline_was_deleted) |
2613 { | 2701 { |
2614 scan_buffer (buf, '\n', from, to, 1, &shortage, 1); | 2702 scan_buffer (buf, '\n', from, to, 1, &shortage, 1); |
2615 if (!shortage) | 2703 if (!shortage) |
2616 buf->changes->newline_was_deleted = 1; | 2704 { |
2705 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2706 { | |
2707 mbuf->changes->newline_was_deleted = 1; | |
2708 } | |
2709 } | |
2617 } | 2710 } |
2618 | 2711 |
2619 bi_from = bufpos_to_bytind (buf, from); | 2712 bi_from = bufpos_to_bytind (buf, from); |
2620 bi_to = bufpos_to_bytind (buf, to); | 2713 bi_to = bufpos_to_bytind (buf, to); |
2621 bc_numdel = bi_to - bi_from; | 2714 bc_numdel = bi_to - bi_from; |
2625 if (to == BUF_Z (buf) && | 2718 if (to == BUF_Z (buf) && |
2626 bi_from > BI_BUF_GPT (buf)) | 2719 bi_from > BI_BUF_GPT (buf)) |
2627 { | 2720 { |
2628 /* avoid moving the gap just to delete from the bottom. */ | 2721 /* avoid moving the gap just to delete from the bottom. */ |
2629 | 2722 |
2630 record_delete (buf, from, numdel); | 2723 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2724 { | |
2725 record_delete (mbuf, from, numdel); | |
2726 } | |
2631 BUF_MODIFF (buf)++; | 2727 BUF_MODIFF (buf)++; |
2632 MARK_BUFFERS_CHANGED; | 2728 MARK_BUFFERS_CHANGED; |
2633 | 2729 |
2634 /* ### Point used to be modified here, but this causes problems with MULE, | 2730 /* #### Point used to be modified here, but this causes problems |
2635 as point is used to calculate bytinds, and if the offset in bc_numdel causes | 2731 with MULE, as point is used to calculate bytinds, and if the |
2636 point to move to a non first-byte location, causing some other function to | 2732 offset in bc_numdel causes point to move to a non first-byte |
2637 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after | 2733 location, causing some other function to throw an assertion |
2638 the other movements and adjustments, but before the gap is moved. | 2734 in ASSERT_VALID_BYTIND. I've moved the code to right after |
2639 -- jh 970813 */ | 2735 the other movements and adjustments, but before the gap is |
2736 moved. -- jh 970813 */ | |
2640 | 2737 |
2641 /* Detach any extents that are completely within the range [FROM, TO], | 2738 /* Detach any extents that are completely within the range [FROM, TO], |
2642 if the extents are detachable. | 2739 if the extents are detachable. |
2643 | 2740 |
2644 This must come AFTER record_delete(), so that the appropriate extents | 2741 This must come AFTER record_delete(), so that the appropriate |
2645 will be present to be recorded, and BEFORE the gap size is increased, | 2742 extents will be present to be recorded, and BEFORE the gap |
2646 as otherwise we will be confused about where the extents end. */ | 2743 size is increased, as otherwise we will be confused about |
2647 process_extents_for_deletion (bufobj, bi_from, bi_to, 0); | 2744 where the extents end. */ |
2648 | 2745 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2649 /* Relocate all markers pointing into the new, larger gap | 2746 { |
2650 to point at the end of the text before the gap. */ | 2747 process_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, 0); |
2651 adjust_markers (buf, | 2748 } |
2652 (bi_to + BUF_GAP_SIZE (buf)), | 2749 |
2653 (bi_to + BUF_GAP_SIZE (buf)), | 2750 /* Relocate all markers pointing into the new, larger gap to |
2654 (- bc_numdel)); | 2751 point at the end of the text before the gap. */ |
2655 | 2752 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2656 /* Relocate any extent endpoints just like markers. */ | 2753 { |
2657 adjust_extents_for_deletion (bufobj, bi_from, bi_to, | 2754 adjust_markers (mbuf, |
2658 BUF_GAP_SIZE (buf), bc_numdel, 0); | 2755 (bi_to + BUF_GAP_SIZE (mbuf)), |
2659 | 2756 (bi_to + BUF_GAP_SIZE (mbuf)), |
2660 /* Relocate point as if it were a marker. */ | 2757 (- bc_numdel)); |
2661 if (bi_from < BI_BUF_PT (buf)) | 2758 } |
2662 { | 2759 |
2663 if (BI_BUF_PT (buf) < bi_to) | 2760 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2664 JUST_SET_POINT (buf, from, bi_from); | 2761 { |
2665 else | 2762 /* Relocate any extent endpoints just like markers. */ |
2666 JUST_SET_POINT (buf, BUF_PT (buf) - numdel, | 2763 adjust_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, |
2667 BI_BUF_PT (buf) - bc_numdel); | 2764 BUF_GAP_SIZE (mbuf), bc_numdel, 0); |
2765 } | |
2766 | |
2767 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2768 { | |
2769 /* Relocate point as if it were a marker. */ | |
2770 if (bi_from < BI_BUF_PT (mbuf)) | |
2771 { | |
2772 if (BI_BUF_PT (mbuf) < bi_to) | |
2773 JUST_SET_POINT (mbuf, from, bi_from); | |
2774 else | |
2775 JUST_SET_POINT (mbuf, BUF_PT (mbuf) - numdel, | |
2776 BI_BUF_PT (mbuf) - bc_numdel); | |
2777 } | |
2668 } | 2778 } |
2669 | 2779 |
2670 SET_BUF_END_GAP_SIZE (buf, BUF_END_GAP_SIZE (buf) + bc_numdel); | 2780 SET_BUF_END_GAP_SIZE (buf, BUF_END_GAP_SIZE (buf) + bc_numdel); |
2671 | 2781 |
2672 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel); | 2782 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2783 { | |
2784 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel, | |
2785 BI_BUF_ZV (mbuf) - bc_numdel); | |
2786 } | |
2673 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel); | 2787 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel); |
2674 SET_GAP_SENTINEL (buf); | 2788 SET_GAP_SENTINEL (buf); |
2675 } | 2789 } |
2676 else | 2790 else |
2677 { | 2791 { |
2679 if (bi_to < BI_BUF_GPT (buf)) | 2793 if (bi_to < BI_BUF_GPT (buf)) |
2680 gap_left (buf, bi_to); | 2794 gap_left (buf, bi_to); |
2681 if (bi_from > BI_BUF_GPT (buf)) | 2795 if (bi_from > BI_BUF_GPT (buf)) |
2682 gap_right (buf, bi_from); | 2796 gap_right (buf, bi_from); |
2683 | 2797 |
2684 record_delete (buf, from, numdel); | 2798 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2799 { | |
2800 record_delete (mbuf, from, numdel); | |
2801 } | |
2685 BUF_MODIFF (buf)++; | 2802 BUF_MODIFF (buf)++; |
2686 MARK_BUFFERS_CHANGED; | 2803 MARK_BUFFERS_CHANGED; |
2687 | 2804 |
2688 /* ### Point used to be modified here, but this causes problems with MULE, | 2805 /* #### Point used to be modified here, but this causes problems |
2689 as point is used to calculate bytinds, and if the offset in bc_numdel causes | 2806 with MULE, as point is used to calculate bytinds, and if the |
2690 point to move to a non first-byte location, causing some other function to | 2807 offset in bc_numdel causes point to move to a non first-byte |
2691 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after | 2808 location, causing some other function to throw an assertion |
2692 the other movements and adjustments, but before the gap is moved. | 2809 in ASSERT_VALID_BYTIND. I've moved the code to right after |
2693 -- jh 970813 */ | 2810 the other movements and adjustments, but before the gap is |
2811 moved. -- jh 970813 */ | |
2694 | 2812 |
2695 /* Detach any extents that are completely within the range [FROM, TO], | 2813 /* Detach any extents that are completely within the range [FROM, TO], |
2696 if the extents are detachable. | 2814 if the extents are detachable. |
2697 | 2815 |
2698 This must come AFTER record_delete(), so that the appropriate extents | 2816 This must come AFTER record_delete(), so that the appropriate extents |
2699 will be present to be recorded, and BEFORE the gap size is increased, | 2817 will be present to be recorded, and BEFORE the gap size is increased, |
2700 as otherwise we will be confused about where the extents end. */ | 2818 as otherwise we will be confused about where the extents end. */ |
2701 process_extents_for_deletion (bufobj, bi_from, bi_to, 0); | 2819 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2702 | 2820 { |
2703 /* Relocate all markers pointing into the new, larger gap | 2821 process_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, 0); |
2704 to point at the end of the text before the gap. */ | 2822 } |
2705 adjust_markers (buf, | 2823 |
2706 (bi_to + BUF_GAP_SIZE (buf)), | 2824 /* Relocate all markers pointing into the new, larger gap to |
2707 (bi_to + BUF_GAP_SIZE (buf)), | 2825 point at the end of the text before the gap. */ |
2708 (- bc_numdel - BUF_GAP_SIZE (buf))); | 2826 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2827 { | |
2828 adjust_markers (mbuf, | |
2829 (bi_to + BUF_GAP_SIZE (mbuf)), | |
2830 (bi_to + BUF_GAP_SIZE (mbuf)), | |
2831 (- bc_numdel - BUF_GAP_SIZE (mbuf))); | |
2832 } | |
2709 | 2833 |
2710 /* Relocate any extent endpoints just like markers. */ | 2834 /* Relocate any extent endpoints just like markers. */ |
2711 adjust_extents_for_deletion (bufobj, bi_from, bi_to, BUF_GAP_SIZE (buf), | 2835 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2712 bc_numdel, BUF_GAP_SIZE (buf)); | 2836 { |
2713 | 2837 adjust_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, |
2714 /* Relocate point as if it were a marker. */ | 2838 BUF_GAP_SIZE (mbuf), |
2715 if (bi_from < BI_BUF_PT (buf)) | 2839 bc_numdel, BUF_GAP_SIZE (mbuf)); |
2716 { | 2840 } |
2717 if (BI_BUF_PT (buf) < bi_to) | 2841 |
2718 JUST_SET_POINT (buf, from, bi_from); | 2842 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2719 else | 2843 { |
2720 JUST_SET_POINT (buf, BUF_PT (buf) - numdel, | 2844 /* Relocate point as if it were a marker. */ |
2721 BI_BUF_PT (buf) - bc_numdel); | 2845 if (bi_from < BI_BUF_PT (mbuf)) |
2846 { | |
2847 if (BI_BUF_PT (mbuf) < bi_to) | |
2848 JUST_SET_POINT (mbuf, from, bi_from); | |
2849 else | |
2850 JUST_SET_POINT (mbuf, BUF_PT (mbuf) - numdel, | |
2851 BI_BUF_PT (mbuf) - bc_numdel); | |
2852 } | |
2722 } | 2853 } |
2723 | 2854 |
2724 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + bc_numdel); | 2855 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + bc_numdel); |
2725 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel); | 2856 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2857 { | |
2858 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel, | |
2859 BI_BUF_ZV (mbuf) - bc_numdel); | |
2860 } | |
2726 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel); | 2861 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel); |
2727 SET_BI_BUF_GPT (buf, bi_from); | 2862 SET_BI_BUF_GPT (buf, bi_from); |
2728 SET_GAP_SENTINEL (buf); | 2863 SET_GAP_SENTINEL (buf); |
2729 } | 2864 } |
2730 | 2865 |
2731 #ifdef MULE | 2866 #ifdef MULE |
2732 buffer_mule_signal_deleted_region (buf, from, to, bi_from, bi_to); | 2867 buffer_mule_signal_deleted_region (buf, from, to, bi_from, bi_to); |
2733 #endif | 2868 #endif |
2734 | 2869 |
2735 #ifdef ERROR_CHECK_EXTENTS | 2870 #ifdef ERROR_CHECK_EXTENTS |
2736 sledgehammer_extent_check (bufobj); | 2871 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2872 { | |
2873 sledgehammer_extent_check (make_buffer (mbuf)); | |
2874 } | |
2737 #endif | 2875 #endif |
2738 | 2876 |
2739 signal_after_change (buf, from, to, from); | 2877 signal_after_change (buf, from, to, from); |
2740 } | 2878 } |
2741 | 2879 |
2745 /************************************************************************/ | 2883 /************************************************************************/ |
2746 | 2884 |
2747 /* Replace the character at POS in buffer B with CH. */ | 2885 /* Replace the character at POS in buffer B with CH. */ |
2748 | 2886 |
2749 void | 2887 void |
2750 buffer_replace_char (struct buffer *b, Bufpos pos, Emchar ch, | 2888 buffer_replace_char (struct buffer *buf, Bufpos pos, Emchar ch, |
2751 int not_real_change, int force_lock_check) | 2889 int not_real_change, int force_lock_check) |
2752 { | 2890 { |
2753 /* This function can GC */ | 2891 /* This function can GC */ |
2754 Bufbyte curstr[MAX_EMCHAR_LEN]; | 2892 Bufbyte curstr[MAX_EMCHAR_LEN]; |
2755 Bufbyte newstr[MAX_EMCHAR_LEN]; | 2893 Bufbyte newstr[MAX_EMCHAR_LEN]; |
2756 Bytecount curlen, newlen; | 2894 Bytecount curlen, newlen; |
2757 | 2895 |
2758 /* Defensive steps just in case a buffer gets deleted and a calling | 2896 /* Defensive steps just in case a buffer gets deleted and a calling |
2759 function doesn't notice it. */ | 2897 function doesn't notice it. */ |
2760 if (!BUFFER_LIVE_P (b)) | 2898 if (!BUFFER_LIVE_P (buf)) |
2761 return; | 2899 return; |
2762 | 2900 |
2763 curlen = BUF_CHARPTR_COPY_CHAR (b, pos, curstr); | 2901 curlen = BUF_CHARPTR_COPY_CHAR (buf, pos, curstr); |
2764 newlen = set_charptr_emchar (newstr, ch); | 2902 newlen = set_charptr_emchar (newstr, ch); |
2765 | 2903 |
2766 if (curlen == newlen) | 2904 if (curlen == newlen) |
2767 { | 2905 { |
2906 struct buffer *mbuf; | |
2907 Lisp_Object bufcons; | |
2908 | |
2768 /* then we can just replace the text. */ | 2909 /* then we can just replace the text. */ |
2769 prepare_to_modify_buffer (b, pos, pos + 1, | 2910 prepare_to_modify_buffer (buf, pos, pos + 1, |
2770 !not_real_change || force_lock_check); | 2911 !not_real_change || force_lock_check); |
2771 /* Defensive steps in case the before-change-functions fuck around */ | 2912 /* Defensive steps in case the before-change-functions fuck around */ |
2772 if (!BUFFER_LIVE_P (b)) | 2913 if (!BUFFER_LIVE_P (buf)) |
2773 /* Bad bad pre-change function. */ | 2914 /* Bad bad pre-change function. */ |
2774 return; | 2915 return; |
2775 | 2916 |
2776 /* Make args be valid again. prepare_to_modify_buffer() might have | 2917 /* Make args be valid again. prepare_to_modify_buffer() might have |
2777 modified the buffer. */ | 2918 modified the buffer. */ |
2778 if (pos < BUF_BEGV (b)) | 2919 if (pos < BUF_BEGV (buf)) |
2779 pos = BUF_BEGV (b); | 2920 pos = BUF_BEGV (buf); |
2780 if (pos >= BUF_ZV (b)) | 2921 if (pos >= BUF_ZV (buf)) |
2781 pos = BUF_ZV (b) - 1; | 2922 pos = BUF_ZV (buf) - 1; |
2782 if (pos < BUF_BEGV (b)) | 2923 if (pos < BUF_BEGV (buf)) |
2783 /* no more characters in buffer! */ | 2924 /* no more characters in buffer! */ |
2784 return; | 2925 return; |
2785 | 2926 |
2786 if (BUF_FETCH_CHAR (b, pos) == '\n') | 2927 if (BUF_FETCH_CHAR (buf, pos) == '\n') |
2787 b->changes->newline_was_deleted = 1; | 2928 { |
2929 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | |
2930 { | |
2931 mbuf->changes->newline_was_deleted = 1; | |
2932 } | |
2933 } | |
2788 MARK_BUFFERS_CHANGED; | 2934 MARK_BUFFERS_CHANGED; |
2789 if (!not_real_change) | 2935 if (!not_real_change) |
2790 { | 2936 { |
2791 record_change (b, pos, 1); | 2937 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2792 BUF_MODIFF (b)++; | 2938 { |
2793 } | 2939 record_change (mbuf, pos, 1); |
2794 memcpy (BUF_BYTE_ADDRESS (b, pos), newstr, newlen); | 2940 } |
2795 signal_after_change (b, pos, pos + 1, pos + 1); | 2941 BUF_MODIFF (buf)++; |
2942 } | |
2943 memcpy (BUF_BYTE_ADDRESS (buf, pos), newstr, newlen); | |
2944 | |
2945 signal_after_change (buf, pos, pos + 1, pos + 1); | |
2796 | 2946 |
2797 /* We do not have to adjust the Mule data; we just replaced a | 2947 /* We do not have to adjust the Mule data; we just replaced a |
2798 character with another of the same number of bytes. */ | 2948 character with another of the same number of bytes. */ |
2799 } | 2949 } |
2800 else | 2950 else |
2805 * Make a note to move point forward later in the one situation | 2955 * Make a note to move point forward later in the one situation |
2806 * where it is needed, a delete/insert one position behind | 2956 * where it is needed, a delete/insert one position behind |
2807 * point. Point will drift backward by one position and stay | 2957 * point. Point will drift backward by one position and stay |
2808 * there otherwise. | 2958 * there otherwise. |
2809 */ | 2959 */ |
2810 int movepoint = (pos == BUF_PT (b) - 1); | 2960 int movepoint = (pos == BUF_PT (buf) - 1); |
2811 | 2961 |
2812 buffer_delete_range (b, pos, pos + 1, 0); | 2962 buffer_delete_range (buf, pos, pos + 1, 0); |
2813 /* Defensive steps in case the before-change-functions fuck around */ | 2963 /* Defensive steps in case the before-change-functions fuck around */ |
2814 if (!BUFFER_LIVE_P (b)) | 2964 if (!BUFFER_LIVE_P (buf)) |
2815 /* Bad bad pre-change function. */ | 2965 /* Bad bad pre-change function. */ |
2816 return; | 2966 return; |
2817 | 2967 |
2818 /* Make args be valid again. prepare_to_modify_buffer() might have | 2968 /* Make args be valid again. prepare_to_modify_buffer() might have |
2819 modified the buffer. */ | 2969 modified the buffer. */ |
2820 if (pos < BUF_BEGV (b)) | 2970 if (pos < BUF_BEGV (buf)) |
2821 pos = BUF_BEGV (b); | 2971 pos = BUF_BEGV (buf); |
2822 if (pos >= BUF_ZV (b)) | 2972 if (pos >= BUF_ZV (buf)) |
2823 pos = BUF_ZV (b) - 1; | 2973 pos = BUF_ZV (buf) - 1; |
2824 if (pos < BUF_BEGV (b)) | 2974 if (pos < BUF_BEGV (buf)) |
2825 /* no more characters in buffer! */ | 2975 /* no more characters in buffer! */ |
2826 return; | 2976 return; |
2827 /* | 2977 /* |
2828 * -1 as the pos argument means to move point forward with the | 2978 * -1 as the pos argument means to move point forward with the |
2829 * insertion, which we must do if the deletion moved point | 2979 * insertion, which we must do if the deletion moved point |
2830 * backward so that it now equals the insertion point. | 2980 * backward so that it now equals the insertion point. |
2831 */ | 2981 */ |
2832 buffer_insert_string_1 (b, (movepoint ? -1 : pos), | 2982 buffer_insert_string_1 (buf, (movepoint ? -1 : pos), |
2833 newstr, Qnil, 0, newlen, 0); | 2983 newstr, Qnil, 0, newlen, 0); |
2834 } | 2984 } |
2835 } | 2985 } |
2836 | 2986 |
2837 | 2987 |
3083 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++) | 3233 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++) |
3084 three_to_one_table[i] = i / 3; | 3234 three_to_one_table[i] = i / 3; |
3085 } | 3235 } |
3086 | 3236 |
3087 void | 3237 void |
3088 init_buffer_text (struct buffer *b, int indirect_p) | 3238 init_buffer_text (struct buffer *b) |
3089 { | 3239 { |
3090 if (!indirect_p) | 3240 if (!b->base_buffer) |
3091 { | 3241 { |
3092 SET_BUF_GAP_SIZE (b, 20); | 3242 SET_BUF_GAP_SIZE (b, 20); |
3093 BUFFER_ALLOC (b->text->beg, BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE); | 3243 BUFFER_ALLOC (b->text->beg, BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE); |
3094 if (! BUF_BEG_ADDR (b)) | 3244 if (! BUF_BEG_ADDR (b)) |
3095 memory_full (); | 3245 memory_full (); |
3113 b->text->mule_bufpos_cache[i] = 1; | 3263 b->text->mule_bufpos_cache[i] = 1; |
3114 b->text->mule_bytind_cache[i] = 1; | 3264 b->text->mule_bytind_cache[i] = 1; |
3115 } | 3265 } |
3116 } | 3266 } |
3117 #endif /* MULE */ | 3267 #endif /* MULE */ |
3268 b->text->line_number_cache = Qnil; | |
3118 | 3269 |
3119 BUF_MODIFF (b) = 1; | 3270 BUF_MODIFF (b) = 1; |
3120 BUF_SAVE_MODIFF (b) = 1; | 3271 BUF_SAVE_MODIFF (b) = 1; |
3121 | 3272 |
3122 JUST_SET_POINT (b, 1, 1); | 3273 JUST_SET_POINT (b, 1, 1); |
3143 b->width_table = Qnil; | 3294 b->width_table = Qnil; |
3144 #endif | 3295 #endif |
3145 } | 3296 } |
3146 | 3297 |
3147 void | 3298 void |
3148 uninit_buffer_text (struct buffer *b, int indirect_p) | 3299 uninit_buffer_text (struct buffer *b) |
3149 { | 3300 { |
3150 if (!indirect_p) | 3301 if (!b->base_buffer) |
3151 { | 3302 { |
3152 BUFFER_FREE (b->text->beg); | 3303 BUFFER_FREE (b->text->beg); |
3153 xfree (b->text->changes); | 3304 xfree (b->text->changes); |
3154 } | 3305 } |
3155 xfree (b->changes); | 3306 xfree (b->changes); |