comparison src/insdel.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents e121b013d1f0
children 850242ba4a81
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
28 28
29 /* 29 /*
30 There are three possible ways to specify positions in a buffer. All 30 There are three possible ways to specify positions in a buffer. All
31 of these are one-based: the beginning of the buffer is position or 31 of these are one-based: the beginning of the buffer is position or
32 index 1, and 0 is not a valid position. 32 index 1, and 0 is not a valid position.
33 33
34 As a "buffer position" (typedef Bufpos): 34 As a "buffer position" (typedef Bufpos):
35 35
36 This is an index specifying an offset in characters from the 36 This is an index specifying an offset in characters from the
37 beginning of the buffer. Note that buffer positions are 37 beginning of the buffer. Note that buffer positions are
38 logically *between* characters, not on a character. The 38 logically *between* characters, not on a character. The
159 Bytecount: 159 Bytecount:
160 ---------- 160 ----------
161 Similar to a Charcount but represents a count of bytes. 161 Similar to a Charcount but represents a count of bytes.
162 The difference between two Bytind's is a Bytecount. 162 The difference between two Bytind's is a Bytecount.
163 163
164 164
165 Usage of the various representations: 165 Usage of the various representations:
166 ===================================== 166 =====================================
167 167
168 Memory indices are used in low-level functions in insdel.c and for 168 Memory indices are used in low-level functions in insdel.c and for
169 extent endpoints and marker positions. The reason for this is that 169 extent endpoints and marker positions. The reason for this is that
192 except for code that needs to be fast, which used Bytecounts. 192 except for code that needs to be fast, which used Bytecounts.
193 193
194 Strings are always passed around internally using internal format. 194 Strings are always passed around internally using internal format.
195 Conversions between external format are performed at the time 195 Conversions between external format are performed at the time
196 that the data goes in or out of Emacs. 196 that the data goes in or out of Emacs.
197 197
198 Working with the various representations: 198 Working with the various representations:
199 ========================================= */ 199 ========================================= */
200 200
201 #include <config.h> 201 #include <config.h>
202 #include "lisp.h" 202 #include "lisp.h"
237 #define SET_BUF_GAP_SIZE(buf, value) \ 237 #define SET_BUF_GAP_SIZE(buf, value) \
238 do { (buf)->text->gap_size = (value); } while (0) 238 do { (buf)->text->gap_size = (value); } while (0)
239 #define SET_BUF_END_GAP_SIZE(buf, value) \ 239 #define SET_BUF_END_GAP_SIZE(buf, value) \
240 do { (buf)->text->end_gap_size = (value); } while (0) 240 do { (buf)->text->end_gap_size = (value); } while (0)
241 241
242 /* Gap location. */ 242 /* Gap location. */
243 #define BI_BUF_GPT(buf) ((buf)->text->gpt + 0) 243 #define BI_BUF_GPT(buf) ((buf)->text->gpt + 0)
244 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BI_BUF_GPT (buf) - 1) 244 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BI_BUF_GPT (buf) - 1)
245 245
246 /* Set gap location. */ 246 /* Set gap location. */
247 #define SET_BI_BUF_GPT(buf, value) do { (buf)->text->gpt = (value); } while (0) 247 #define SET_BI_BUF_GPT(buf, value) do { (buf)->text->gpt = (value); } while (0)
248 248
249 /* Set end of buffer. */ 249 /* Set end of buffer. */
250 #define SET_BOTH_BUF_Z(buf, val, bival) \ 250 #define SET_BOTH_BUF_Z(buf, val, bival) \
251 do \ 251 do \
252 { \ 252 { \
253 (buf)->text->z = (bival); \ 253 (buf)->text->z = (bival); \
254 (buf)->text->bufz = (val); \ 254 (buf)->text->bufz = (val); \
266 call SET_GAP_SENTINEL(). 266 call SET_GAP_SENTINEL().
267 267
268 Every time we change the total size (characters plus gap) 268 Every time we change the total size (characters plus gap)
269 of the buffer, we have to call SET_END_SENTINEL(). 269 of the buffer, we have to call SET_END_SENTINEL().
270 */ 270 */
271 271
272 272
273 #ifdef MULE 273 #ifdef MULE
274 # define GAP_CAN_HOLD_SIZE_P(buf, len) (BUF_GAP_SIZE (buf) >= (len) + 1) 274 # define GAP_CAN_HOLD_SIZE_P(buf, len) (BUF_GAP_SIZE (buf) >= (len) + 1)
275 # define SET_GAP_SENTINEL(buf) (*BUF_GPT_ADDR (buf) = 0) 275 # define SET_GAP_SENTINEL(buf) (*BUF_GPT_ADDR (buf) = 0)
276 # define BUF_END_SENTINEL_SIZE 1 276 # define BUF_END_SENTINEL_SIZE 1
343 count++, ptr++; 343 count++, ptr++;
344 } 344 }
345 /* Now do it. */ 345 /* Now do it. */
346 while (ptr < aligned_end) 346 while (ptr < aligned_end)
347 { 347 {
348 348
349 if ((* (unsigned long *) ptr) & HIGH_BIT_MASK) 349 if ((* (unsigned long *) ptr) & HIGH_BIT_MASK)
350 goto bail; 350 goto bail;
351 ptr += LONG_BYTES; 351 ptr += LONG_BYTES;
352 count += LONG_BYTES; 352 count += LONG_BYTES;
353 } 353 }
396 function in all of XEmacs. Therefore, it must be FAST FAST FAST. 396 function in all of XEmacs. Therefore, it must be FAST FAST FAST.
397 This is the reason why so much of the code is duplicated. 397 This is the reason why so much of the code is duplicated.
398 398
399 Similar considerations apply to bytind_to_bufpos_func(), although 399 Similar considerations apply to bytind_to_bufpos_func(), although
400 less so because the function is not called so often. 400 less so because the function is not called so often.
401 401
402 #### At some point this should use a more sophisticated method; 402 #### At some point this should use a more sophisticated method;
403 see buffer.h. */ 403 see buffer.h. */
404 404
405 static int not_very_random_number; 405 static int not_very_random_number;
406 406
451 /* #### This value could stand some more exploration. */ 451 /* #### This value could stand some more exploration. */
452 Charcount heuristic_hack = (bufmax - bufmin) >> 2; 452 Charcount heuristic_hack = (bufmax - bufmin) >> 2;
453 453
454 /* Check if the position is closer to PT or ZV than to the 454 /* Check if the position is closer to PT or ZV than to the
455 end of the known region. */ 455 end of the known region. */
456 456
457 if (diffpt < 0) 457 if (diffpt < 0)
458 diffpt = -diffpt; 458 diffpt = -diffpt;
459 if (diffzv < 0) 459 if (diffzv < 0)
460 diffzv = -diffzv; 460 diffzv = -diffzv;
461 461
463 over PT or ZV. The reason for this is that switching to 463 over PT or ZV. The reason for this is that switching to
464 PT or ZV will wipe out the knowledge in the known region, 464 PT or ZV will wipe out the knowledge in the known region,
465 which might be annoying if the known region is large and 465 which might be annoying if the known region is large and
466 PT or ZV is not that much closer than the end of the known 466 PT or ZV is not that much closer than the end of the known
467 region. */ 467 region. */
468 468
469 diffzv += heuristic_hack; 469 diffzv += heuristic_hack;
470 diffpt += heuristic_hack; 470 diffpt += heuristic_hack;
471 if (diffpt < diffmax && diffpt <= diffzv) 471 if (diffpt < diffmax && diffpt <= diffzv)
472 { 472 {
473 bufmax = bufmin = BUF_PT (buf); 473 bufmax = bufmin = BUF_PT (buf);
504 if (diffbegv < 0) 504 if (diffbegv < 0)
505 diffbegv = -diffbegv; 505 diffbegv = -diffbegv;
506 506
507 /* But also implement a heuristic that favors the known region -- 507 /* But also implement a heuristic that favors the known region --
508 see above. */ 508 see above. */
509 509
510 diffbegv += heuristic_hack; 510 diffbegv += heuristic_hack;
511 diffpt += heuristic_hack; 511 diffpt += heuristic_hack;
512 512
513 if (diffpt < diffmin && diffpt <= diffbegv) 513 if (diffpt < diffmin && diffpt <= diffbegv)
514 { 514 {
573 573
574 forward_p = 1; 574 forward_p = 1;
575 while (x > bufmax) 575 while (x > bufmax)
576 { 576 {
577 newmax = bytmax; 577 newmax = bytmax;
578 578
579 INC_BYTIND (buf, newmax); 579 INC_BYTIND (buf, newmax);
580 newsize = newmax - bytmax; 580 newsize = newmax - bytmax;
581 if (newsize != size) 581 if (newsize != size)
582 { 582 {
583 bufmin = bufmax; 583 bufmin = bufmax;
599 599
600 forward_p = 0; 600 forward_p = 0;
601 while (x < bufmin) 601 while (x < bufmin)
602 { 602 {
603 newmin = bytmin; 603 newmin = bytmin;
604 604
605 DEC_BYTIND (buf, newmin); 605 DEC_BYTIND (buf, newmin);
606 newsize = bytmin - newmin; 606 newsize = bytmin - newmin;
607 if (newsize != size) 607 if (newsize != size)
608 { 608 {
609 bufmax = bufmin; 609 bufmax = bufmin;
728 /* #### This value could stand some more exploration. */ 728 /* #### This value could stand some more exploration. */
729 Bytecount heuristic_hack = (bytmax - bytmin) >> 2; 729 Bytecount heuristic_hack = (bytmax - bytmin) >> 2;
730 730
731 /* Check if the position is closer to PT or ZV than to the 731 /* Check if the position is closer to PT or ZV than to the
732 end of the known region. */ 732 end of the known region. */
733 733
734 if (diffpt < 0) 734 if (diffpt < 0)
735 diffpt = -diffpt; 735 diffpt = -diffpt;
736 if (diffzv < 0) 736 if (diffzv < 0)
737 diffzv = -diffzv; 737 diffzv = -diffzv;
738 738
740 over BI_PT or BI_ZV. The reason for this is that switching to 740 over BI_PT or BI_ZV. The reason for this is that switching to
741 BI_PT or BI_ZV will wipe out the knowledge in the known region, 741 BI_PT or BI_ZV will wipe out the knowledge in the known region,
742 which might be annoying if the known region is large and 742 which might be annoying if the known region is large and
743 BI_PT or BI_ZV is not that much closer than the end of the known 743 BI_PT or BI_ZV is not that much closer than the end of the known
744 region. */ 744 region. */
745 745
746 diffzv += heuristic_hack; 746 diffzv += heuristic_hack;
747 diffpt += heuristic_hack; 747 diffpt += heuristic_hack;
748 if (diffpt < diffmax && diffpt <= diffzv) 748 if (diffpt < diffmax && diffpt <= diffzv)
749 { 749 {
750 bufmax = bufmin = BUF_PT (buf); 750 bufmax = bufmin = BUF_PT (buf);
781 if (diffbegv < 0) 781 if (diffbegv < 0)
782 diffbegv = -diffbegv; 782 diffbegv = -diffbegv;
783 783
784 /* But also implement a heuristic that favors the known region -- 784 /* But also implement a heuristic that favors the known region --
785 see above. */ 785 see above. */
786 786
787 diffbegv += heuristic_hack; 787 diffbegv += heuristic_hack;
788 diffpt += heuristic_hack; 788 diffpt += heuristic_hack;
789 789
790 if (diffpt < diffmin && diffpt <= diffbegv) 790 if (diffpt < diffmin && diffpt <= diffbegv)
791 { 791 {
850 850
851 forward_p = 1; 851 forward_p = 1;
852 while (x > bytmax) 852 while (x > bytmax)
853 { 853 {
854 newmax = bytmax; 854 newmax = bytmax;
855 855
856 INC_BYTIND (buf, newmax); 856 INC_BYTIND (buf, newmax);
857 newsize = newmax - bytmax; 857 newsize = newmax - bytmax;
858 if (newsize != size) 858 if (newsize != size)
859 { 859 {
860 bufmin = bufmax; 860 bufmin = bufmax;
876 876
877 forward_p = 0; 877 forward_p = 0;
878 while (x < bytmin) 878 while (x < bytmin)
879 { 879 {
880 newmin = bytmin; 880 newmin = bytmin;
881 881
882 DEC_BYTIND (buf, newmin); 882 DEC_BYTIND (buf, newmin);
883 newsize = bytmin - newmin; 883 newsize = bytmin - newmin;
884 if (newsize != size) 884 if (newsize != size)
885 { 885 {
886 bufmax = bufmin; 886 bufmax = bufmin;
967 int i; 967 int i;
968 968
969 /* Adjust the cache of known positions. */ 969 /* Adjust the cache of known positions. */
970 for (i = 0; i < 16; i++) 970 for (i = 0; i < 16; i++)
971 { 971 {
972
972 if (buf->text->mule_bufpos_cache[i] > start) 973 if (buf->text->mule_bufpos_cache[i] > start)
973 { 974 {
974 buf->text->mule_bufpos_cache[i] += charlength; 975 buf->text->mule_bufpos_cache[i] += charlength;
975 buf->text->mule_bytind_cache[i] += bytelength; 976 buf->text->mule_bytind_cache[i] += bytelength;
976 } 977 }
1198 1199
1199 CHECK_INT_COERCE_MARKER (pos); 1200 CHECK_INT_COERCE_MARKER (pos);
1200 ind = XINT (pos); 1201 ind = XINT (pos);
1201 min_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_BEG (b) : BUF_BEGV (b); 1202 min_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_BEG (b) : BUF_BEGV (b);
1202 max_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_Z (b) : BUF_ZV (b); 1203 max_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_Z (b) : BUF_ZV (b);
1203 1204
1204 if (ind < min_allowed || ind > max_allowed) 1205 if (ind < min_allowed || ind > max_allowed)
1205 { 1206 {
1206 if (flags & GB_COERCE_RANGE) 1207 if (flags & GB_COERCE_RANGE)
1207 ind = ind < min_allowed ? min_allowed : max_allowed; 1208 ind = ind < min_allowed ? min_allowed : max_allowed;
1208 else if (flags & GB_NO_ERROR_IF_BAD) 1209 else if (flags & GB_NO_ERROR_IF_BAD)
1574 mpos = from + amount; 1575 mpos = from + amount;
1575 } 1576 }
1576 if (mpos > from && mpos <= to) 1577 if (mpos > from && mpos <= to)
1577 mpos += amount; 1578 mpos += amount;
1578 return mpos; 1579 return mpos;
1579 } 1580 }
1580 1581
1581 /* Do the following: 1582 /* Do the following:
1582 1583
1583 (1) Add `amount' to the position of every marker in the current buffer 1584 (1) Add `amount' to the position of every marker in the current buffer
1584 whose current position is between `from' (exclusive) and `to' (inclusive). 1585 whose current position is between `from' (exclusive) and `to' (inclusive).
1595 or when a region of characters adjacent to the gap is wiped out, 1596 or when a region of characters adjacent to the gap is wiped out,
1596 causing the gap to increase to include the region (in this case, 1597 causing the gap to increase to include the region (in this case,
1597 `from' and `to' are the same, both pointing to the boundary 1598 `from' and `to' are the same, both pointing to the boundary
1598 between the gap and the deleted region, and there are no markers 1599 between the gap and the deleted region, and there are no markers
1599 affected by (1)). 1600 affected by (1)).
1600 1601
1601 The reason for the use of exclusive and inclusive is that markers at 1602 The reason for the use of exclusive and inclusive is that markers at
1602 the gap always sit at the beginning, not at the end. 1603 the gap always sit at the beginning, not at the end.
1603 */ 1604 */
1604 1605
1605 static void 1606 static void
1791 1792
1792 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + BUF_END_GAP_SIZE (buf)); 1793 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + BUF_END_GAP_SIZE (buf));
1793 SET_BUF_END_GAP_SIZE (buf, 0); 1794 SET_BUF_END_GAP_SIZE (buf, 0);
1794 SET_END_SENTINEL (buf); 1795 SET_END_SENTINEL (buf);
1795 } 1796 }
1796 1797
1797 QUIT; 1798 QUIT;
1798 } 1799 }
1799 1800
1800 /* Move gap to position `pos'. 1801 /* Move gap to position `pos'.
1801 Note that this can quit! */ 1802 Note that this can quit! */
1821 Bytecount old_gap_size; 1822 Bytecount old_gap_size;
1822 Bytecount increment; 1823 Bytecount increment;
1823 1824
1824 increment = BUF_END_GAP_SIZE (buf); 1825 increment = BUF_END_GAP_SIZE (buf);
1825 SET_BUF_END_GAP_SIZE (buf, 0); 1826 SET_BUF_END_GAP_SIZE (buf, 0);
1826 1827
1827 if (increment > 0) 1828 if (increment > 0)
1828 { 1829 {
1829 /* Prevent quitting in move_gap. */ 1830 /* Prevent quitting in move_gap. */
1830 tem = Vinhibit_quit; 1831 tem = Vinhibit_quit;
1831 Vinhibit_quit = Qt; 1832 Vinhibit_quit = Qt;
1871 if (increment > BUF_END_GAP_SIZE (buf)) 1872 if (increment > BUF_END_GAP_SIZE (buf))
1872 { 1873 {
1873 /* Don't allow a buffer size that won't fit in an int 1874 /* Don't allow a buffer size that won't fit in an int
1874 even if it will fit in a Lisp integer. 1875 even if it will fit in a Lisp integer.
1875 That won't work because so many places use `int'. */ 1876 That won't work because so many places use `int'. */
1876 1877
1877 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment 1878 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment
1878 >= ((unsigned) 1 << (min (INTBITS, VALBITS) - 1))) 1879 >= ((unsigned) 1 << (min (INTBITS, VALBITS) - 1)))
1879 error ("Buffer exceeds maximum size"); 1880 error ("Buffer exceeds maximum size");
1880 1881
1881 result = BUFFER_REALLOC (buf->text->beg, 1882 result = BUFFER_REALLOC (buf->text->beg,
1882 BI_BUF_Z (buf) - BI_BUF_BEG (buf) + 1883 BI_BUF_Z (buf) - BI_BUF_BEG (buf) +
1883 BUF_GAP_SIZE (buf) + increment + 1884 BUF_GAP_SIZE (buf) + increment +
1884 BUF_END_SENTINEL_SIZE); 1885 BUF_END_SENTINEL_SIZE);
1885 if (result == 0) 1886 if (result == 0)
1886 memory_full (); 1887 memory_full ();
1887 1888
1888 SET_BUF_BEG_ADDR (buf, result); 1889 SET_BUF_BEG_ADDR (buf, result);
1889 } 1890 }
1890 else 1891 else
1891 increment = BUF_END_GAP_SIZE (buf); 1892 increment = BUF_END_GAP_SIZE (buf);
1892 1893
1893 /* Prevent quitting in move_gap. */ 1894 /* Prevent quitting in move_gap. */
1894 tem = Vinhibit_quit; 1895 tem = Vinhibit_quit;
1895 Vinhibit_quit = Qt; 1896 Vinhibit_quit = Qt;
1896 1897
1897 real_gap_loc = BI_BUF_GPT (buf); 1898 real_gap_loc = BI_BUF_GPT (buf);
1967 1968
1968 static void 1969 static void
1969 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end, 1970 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end,
1970 Bufpos new_end); 1971 Bufpos new_end);
1971 1972
1973
1972 /* Call the after-change-functions according to the changes made so far 1974 /* Call the after-change-functions according to the changes made so far
1973 and treat all further changes as single until the outermost 1975 and treat all further changes as single until the outermost
1974 multiple change exits. This is called when the outermost multiple 1976 multiple change exits. This is called when the outermost multiple
1975 change exits and when someone is trying to make a change that violates 1977 change exits and when someone is trying to make a change that violates
1976 the constraints specified in begin_multiple_change(), typically 1978 the constraints specified in begin_multiple_change(), typically
2034 automatically, however, and if changes somehow or other happen outside 2036 automatically, however, and if changes somehow or other happen outside
2035 of the specified region, that will also be handled correctly. 2037 of the specified region, that will also be handled correctly.
2036 2038
2037 begin_multiple_change() returns a number (actually a specpdl depth) 2039 begin_multiple_change() returns a number (actually a specpdl depth)
2038 that you must pass to end_multiple_change() when you are done. */ 2040 that you must pass to end_multiple_change() when you are done. */
2039 2041
2040 int 2042 int
2041 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end) 2043 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end)
2042 { 2044 {
2043 /* This function can GC */ 2045 /* This function can GC */
2044 int count = -1; 2046 int count = -1;
2388 #endif 2390 #endif
2389 2391
2390 /* Make sure that point-max won't exceed the size of an emacs int. */ 2392 /* Make sure that point-max won't exceed the size of an emacs int. */
2391 { 2393 {
2392 Lisp_Object temp; 2394 Lisp_Object temp;
2393 2395
2394 XSETINT (temp, (int) (length + BUF_Z (buf))); 2396 XSETINT (temp, (int) (length + BUF_Z (buf)));
2395 if ((int) (length + BUF_Z (buf)) != XINT (temp)) 2397 if ((int) (length + BUF_Z (buf)) != XINT (temp))
2396 error ("maximum buffer size exceeded"); 2398 error ("maximum buffer size exceeded");
2397 } 2399 }
2398 2400
2521 Charcount 2523 Charcount
2522 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s, 2524 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s,
2523 int flags) 2525 int flags)
2524 { 2526 {
2525 /* This function can GC */ 2527 /* This function can GC */
2526 2528
2527 CONST char *translated = GETTEXT (s); 2529 CONST char *translated = GETTEXT (s);
2528 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil, 2530 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil,
2529 0, strlen (translated), flags); 2531 0, strlen (translated), flags);
2530 } 2532 }
2531 2533
2547 { 2549 {
2548 /* This function can GC */ 2550 /* This function can GC */
2549 return buffer_insert_emacs_char_1 (buf, pos, (Emchar) (unsigned char) c, 2551 return buffer_insert_emacs_char_1 (buf, pos, (Emchar) (unsigned char) c,
2550 flags); 2552 flags);
2551 } 2553 }
2552 2554
2553 Charcount 2555 Charcount
2554 buffer_insert_from_buffer_1 (struct buffer *buf, Bufpos pos, 2556 buffer_insert_from_buffer_1 (struct buffer *buf, Bufpos pos,
2555 struct buffer *buf2, Bufpos pos2, 2557 struct buffer *buf2, Bufpos pos2,
2556 Charcount length, int flags) 2558 Charcount length, int flags)
2557 { 2559 {
2625 2627
2626 if (to == BUF_Z (buf) && 2628 if (to == BUF_Z (buf) &&
2627 bi_from > BI_BUF_GPT (buf)) 2629 bi_from > BI_BUF_GPT (buf))
2628 { 2630 {
2629 /* avoid moving the gap just to delete from the bottom. */ 2631 /* avoid moving the gap just to delete from the bottom. */
2630 2632
2631 record_delete (buf, from, numdel); 2633 record_delete (buf, from, numdel);
2632 BUF_MODIFF (buf)++; 2634 BUF_MODIFF (buf)++;
2633 MARK_BUFFERS_CHANGED; 2635 MARK_BUFFERS_CHANGED;
2634 2636
2635 /* Relocate point as if it were a marker. */ 2637 /* ### Point used to be modified here, but this causes problems with MULE,
2636 if (bi_from < BI_BUF_PT (buf)) 2638 as point is used to calculate bytinds, and if the offset in bc_numdel causes
2637 { 2639 point to move to a non first-byte location, causing some other function to
2638 if (BI_BUF_PT (buf) < bi_to) 2640 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after
2639 JUST_SET_POINT (buf, from, bi_from); 2641 the other movements and adjustments, but before the gap is moved.
2640 else 2642 -- jh 970813 */
2641 JUST_SET_POINT (buf, BUF_PT (buf) - numdel,
2642 BI_BUF_PT (buf) - bc_numdel);
2643 }
2644 2643
2645 /* Detach any extents that are completely within the range [FROM, TO], 2644 /* Detach any extents that are completely within the range [FROM, TO],
2646 if the extents are detachable. 2645 if the extents are detachable.
2647 2646
2648 This must come AFTER record_delete(), so that the appropriate extents 2647 This must come AFTER record_delete(), so that the appropriate extents
2658 (- bc_numdel)); 2657 (- bc_numdel));
2659 2658
2660 /* Relocate any extent endpoints just like markers. */ 2659 /* Relocate any extent endpoints just like markers. */
2661 adjust_extents_for_deletion (bufobj, bi_from, bi_to, 2660 adjust_extents_for_deletion (bufobj, bi_from, bi_to,
2662 BUF_GAP_SIZE (buf), bc_numdel, 0); 2661 BUF_GAP_SIZE (buf), bc_numdel, 0);
2662
2663 /* Relocate point as if it were a marker. */
2664 if (bi_from < BI_BUF_PT (buf))
2665 {
2666 if (BI_BUF_PT (buf) < bi_to)
2667 JUST_SET_POINT (buf, from, bi_from);
2668 else
2669 JUST_SET_POINT (buf, BUF_PT (buf) - numdel,
2670 BI_BUF_PT (buf) - bc_numdel);
2671 }
2672
2663 SET_BUF_END_GAP_SIZE (buf, BUF_END_GAP_SIZE (buf) + bc_numdel); 2673 SET_BUF_END_GAP_SIZE (buf, BUF_END_GAP_SIZE (buf) + bc_numdel);
2664 2674
2665 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel); 2675 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel);
2666 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel); 2676 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel);
2667 SET_GAP_SENTINEL (buf); 2677 SET_GAP_SENTINEL (buf);
2668 } 2678 }
2669 else 2679 else
2678 BUF_MODIFF (buf)++; 2688 BUF_MODIFF (buf)++;
2679 MARK_BUFFERS_CHANGED; 2689 MARK_BUFFERS_CHANGED;
2680 2690
2681 /* ### Point used to be modified here, but this causes problems with MULE, 2691 /* ### Point used to be modified here, but this causes problems with MULE,
2682 as point is used to calculate bytinds, and if the offset in bc_numdel causes 2692 as point is used to calculate bytinds, and if the offset in bc_numdel causes
2683 point to move to a non first-byte location, causing some other function to 2693 point to move to a non first-byte location, causing some other function to
2684 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after 2694 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after
2685 the other movements and adjustments, but before the gap is moved. 2695 the other movements and adjustments, but before the gap is moved.
2686 -- jh 970813 */ 2696 -- jh 970813 */
2687 2697
2688 /* Detach any extents that are completely within the range [FROM, TO], 2698 /* Detach any extents that are completely within the range [FROM, TO],
2957 { 2967 {
2958 int cols = 0; 2968 int cols = 0;
2959 int i; 2969 int i;
2960 2970
2961 for (i = 0; i < len; i++) 2971 for (i = 0; i < len; i++)
2972
2962 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i])); 2973 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i]));
2963 2974
2964 return cols; 2975 return cols;
2965 } 2976 }
2966 2977
2967 /* NOTE: Does not reset the Dynarr. */ 2978 /* NOTE: Does not reset the Dynarr. */
2968 2979
2969 void 2980 void
2970 convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, Bytecount len, 2981 convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, Bytecount len,
2971 emchar_dynarr *dyn) 2982 Emchar_dynarr *dyn)
2972 { 2983 {
2973 CONST Bufbyte *strend = str + len; 2984 CONST Bufbyte *strend = str + len;
2974 2985
2975 while (str < strend) 2986 while (str < strend)
2976 { 2987 {
2999 Store into the given Bufbyte dynarr. Does not reset the dynarr. 3010 Store into the given Bufbyte dynarr. Does not reset the dynarr.
3000 Does not add a terminating zero. */ 3011 Does not add a terminating zero. */
3001 3012
3002 void 3013 void
3003 convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, 3014 convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
3004 bufbyte_dynarr *dyn) 3015 Bufbyte_dynarr *dyn)
3005 { 3016 {
3006 Bufbyte str[MAX_EMCHAR_LEN]; 3017 Bufbyte str[MAX_EMCHAR_LEN];
3007 int i; 3018 int i;
3008 3019
3009 for (i = 0; i < nels; i++) 3020 for (i = 0; i < nels; i++)
3025 { 3036 {
3026 /* Damn zero-termination. */ 3037 /* Damn zero-termination. */
3027 Bufbyte *str = (Bufbyte *) alloca (nels * MAX_EMCHAR_LEN + 1); 3038 Bufbyte *str = (Bufbyte *) alloca (nels * MAX_EMCHAR_LEN + 1);
3028 Bufbyte *strorig = str; 3039 Bufbyte *strorig = str;
3029 Bytecount len; 3040 Bytecount len;
3030 3041
3031 int i; 3042 int i;
3032 3043
3033 for (i = 0; i < nels; i++) 3044 for (i = 0; i < nels; i++)
3034 str += set_charptr_emchar (str, arr[i]); 3045 str += set_charptr_emchar (str, arr[i]);
3035 *str = '\0'; 3046 *str = '\0';
3036 len = str - strorig; 3047 len = str - strorig;
3037 str = xmalloc (1 + len); 3048 str = (Bufbyte *) xmalloc (1 + len);
3038 memcpy (str, strorig, 1 + len); 3049 memcpy (str, strorig, 1 + len);
3039 if (len_out) 3050 if (len_out)
3040 *len_out = len; 3051 *len_out = len;
3041 return str; 3052 return str;
3042 } 3053 }
3074 SET_GAP_SENTINEL (b); 3085 SET_GAP_SENTINEL (b);
3075 SET_END_SENTINEL (b); 3086 SET_END_SENTINEL (b);
3076 #ifdef MULE 3087 #ifdef MULE
3077 { 3088 {
3078 int i; 3089 int i;
3079 3090
3080 b->text->mule_bufmin = b->text->mule_bufmax = 1; 3091 b->text->mule_bufmin = b->text->mule_bufmax = 1;
3081 b->text->mule_bytmin = b->text->mule_bytmax = 1; 3092 b->text->mule_bytmin = b->text->mule_bytmax = 1;
3082 b->text->mule_shifter = 0; 3093 b->text->mule_shifter = 0;
3083 b->text->mule_three_p = 0; 3094 b->text->mule_three_p = 0;
3084 3095
3085 for (i = 0; i < 16; i++) 3096 for (i = 0; i < 16; i++)
3086 { 3097 {
3087 b->text->mule_bufpos_cache[i] = 1; 3098 b->text->mule_bufpos_cache[i] = 1;
3088 b->text->mule_bytind_cache[i] = 1; 3099 b->text->mule_bytind_cache[i] = 1;
3089 } 3100 }
3095 3106
3096 JUST_SET_POINT (b, 1, 1); 3107 JUST_SET_POINT (b, 1, 1);
3097 SET_BOTH_BUF_BEGV (b, 1, 1); 3108 SET_BOTH_BUF_BEGV (b, 1, 1);
3098 SET_BOTH_BUF_ZV (b, 1, 1); 3109 SET_BOTH_BUF_ZV (b, 1, 1);
3099 3110
3100 b->text->changes = 3111 b->text->changes = xnew_and_zero (struct buffer_text_change_data);
3101 (struct buffer_text_change_data *)
3102 xmalloc (sizeof (*b->text->changes));
3103 memset (b->text->changes, 0, sizeof (*b->text->changes));
3104 } 3112 }
3105 else 3113 else
3106 { 3114 {
3107 JUST_SET_POINT (b, BUF_PT (b->base_buffer), BI_BUF_PT (b->base_buffer)); 3115 JUST_SET_POINT (b, BUF_PT (b->base_buffer), BI_BUF_PT (b->base_buffer));
3108 SET_BOTH_BUF_BEGV (b, BUF_BEGV (b->base_buffer), 3116 SET_BOTH_BUF_BEGV (b, BUF_BEGV (b->base_buffer),
3109 BI_BUF_BEGV (b->base_buffer)); 3117 BI_BUF_BEGV (b->base_buffer));
3110 SET_BOTH_BUF_ZV (b, BUF_ZV (b->base_buffer), 3118 SET_BOTH_BUF_ZV (b, BUF_ZV (b->base_buffer),
3111 BI_BUF_ZV (b->base_buffer)); 3119 BI_BUF_ZV (b->base_buffer));
3112 } 3120 }
3113 3121
3114 b->changes = 3122 b->changes = xnew_and_zero (struct each_buffer_change_data);
3115 (struct each_buffer_change_data *) xmalloc (sizeof (*b->changes));
3116 memset (b->changes, 0, sizeof (*b->changes));
3117 BUF_FACECHANGE (b) = 1; 3123 BUF_FACECHANGE (b) = 1;
3118 3124
3119 #ifdef REGION_CACHE_NEEDS_WORK 3125 #ifdef REGION_CACHE_NEEDS_WORK
3120 b->newline_cache = 0; 3126 b->newline_cache = 0;
3121 b->width_run_cache = 0; 3127 b->width_run_cache = 0;