aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c186
1 files changed, 95 insertions, 91 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 37d2975c8c7..564dab689cd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -155,7 +155,7 @@ Lisp_Object Qinsert_behind_hooks;
155static void alloc_buffer_text (struct buffer *, ptrdiff_t); 155static void alloc_buffer_text (struct buffer *, ptrdiff_t);
156static void free_buffer_text (struct buffer *b); 156static void free_buffer_text (struct buffer *b);
157static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); 157static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
158static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); 158static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
159static Lisp_Object buffer_lisp_local_variables (struct buffer *); 159static Lisp_Object buffer_lisp_local_variables (struct buffer *);
160 160
161/* For debugging; temporary. See set_buffer_internal. */ 161/* For debugging; temporary. See set_buffer_internal. */
@@ -423,7 +423,7 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
423 for (; list; list = list->next) 423 for (; list; list = list->next)
424 { 424 {
425 Lisp_Object overlay, start, end, old_overlay; 425 Lisp_Object overlay, start, end, old_overlay;
426 EMACS_INT charpos; 426 ptrdiff_t charpos;
427 427
428 XSETMISC (old_overlay, list); 428 XSETMISC (old_overlay, list);
429 charpos = marker_position (OVERLAY_START (old_overlay)); 429 charpos = marker_position (OVERLAY_START (old_overlay));
@@ -724,7 +724,7 @@ reset_buffer (register struct buffer *b)
724 b->prevent_redisplay_optimizations_p = 1; 724 b->prevent_redisplay_optimizations_p = 1;
725 BVAR (b, backed_up) = Qnil; 725 BVAR (b, backed_up) = Qnil;
726 BUF_AUTOSAVE_MODIFF (b) = 0; 726 BUF_AUTOSAVE_MODIFF (b) = 0;
727 b->auto_save_failure_time = -1; 727 b->auto_save_failure_time = 0;
728 BVAR (b, auto_save_file_name) = Qnil; 728 BVAR (b, auto_save_file_name) = Qnil;
729 BVAR (b, read_only) = Qnil; 729 BVAR (b, read_only) = Qnil;
730 b->overlays_before = NULL; 730 b->overlays_before = NULL;
@@ -858,8 +858,8 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
858 (register Lisp_Object name, Lisp_Object ignore) 858 (register Lisp_Object name, Lisp_Object ignore)
859{ 859{
860 register Lisp_Object gentemp, tem; 860 register Lisp_Object gentemp, tem;
861 EMACS_INT count; 861 ptrdiff_t count;
862 char number[INT_BUFSIZE_BOUND (EMACS_INT) + sizeof "<>"]; 862 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
863 863
864 CHECK_STRING (name); 864 CHECK_STRING (name);
865 865
@@ -873,7 +873,7 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
873 count = 1; 873 count = 1;
874 while (1) 874 while (1)
875 { 875 {
876 sprintf (number, "<%"pI"d>", ++count); 876 sprintf (number, "<%"pD"d>", ++count);
877 gentemp = concat2 (name, build_string (number)); 877 gentemp = concat2 (name, build_string (number));
878 tem = Fstring_equal (gentemp, ignore); 878 tem = Fstring_equal (gentemp, ignore);
879 if (!NILP (tem)) 879 if (!NILP (tem))
@@ -1475,7 +1475,7 @@ with SIGHUP. */)
1475 1475
1476 /* Run hooks with the buffer to be killed the current buffer. */ 1476 /* Run hooks with the buffer to be killed the current buffer. */
1477 { 1477 {
1478 int count = SPECPDL_INDEX (); 1478 ptrdiff_t count = SPECPDL_INDEX ();
1479 Lisp_Object arglist[1]; 1479 Lisp_Object arglist[1];
1480 1480
1481 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1481 record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -1746,7 +1746,7 @@ Use this function before selecting the buffer, since it may need to inspect
1746the current buffer's major mode. */) 1746the current buffer's major mode. */)
1747 (Lisp_Object buffer) 1747 (Lisp_Object buffer)
1748{ 1748{
1749 int count; 1749 ptrdiff_t count;
1750 Lisp_Object function; 1750 Lisp_Object function;
1751 1751
1752 CHECK_BUFFER (buffer); 1752 CHECK_BUFFER (buffer);
@@ -1958,16 +1958,15 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1958 tem = *b; *b = *e; *e = tem; 1958 tem = *b; *b = *e; *e = tem;
1959 } 1959 }
1960 1960
1961 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) 1961 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
1962 && XINT (*e) <= ZV))
1963 args_out_of_range (*b, *e); 1962 args_out_of_range (*b, *e);
1964} 1963}
1965 1964
1966/* Advance BYTE_POS up to a character boundary 1965/* Advance BYTE_POS up to a character boundary
1967 and return the adjusted position. */ 1966 and return the adjusted position. */
1968 1967
1969static EMACS_INT 1968static ptrdiff_t
1970advance_to_char_boundary (EMACS_INT byte_pos) 1969advance_to_char_boundary (ptrdiff_t byte_pos)
1971{ 1970{
1972 int c; 1971 int c;
1973 1972
@@ -1980,7 +1979,7 @@ advance_to_char_boundary (EMACS_INT byte_pos)
1980 { 1979 {
1981 /* We should advance BYTE_POS only when C is a constituent of a 1980 /* We should advance BYTE_POS only when C is a constituent of a
1982 multibyte sequence. */ 1981 multibyte sequence. */
1983 EMACS_INT orig_byte_pos = byte_pos; 1982 ptrdiff_t orig_byte_pos = byte_pos;
1984 1983
1985 do 1984 do
1986 { 1985 {
@@ -2056,12 +2055,12 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2056 (POINTER_TYPE **) &current_buffer->own_text.beg); 2055 (POINTER_TYPE **) &current_buffer->own_text.beg);
2057#endif /* REL_ALLOC */ 2056#endif /* REL_ALLOC */
2058 2057
2059 swapfield (pt, EMACS_INT); 2058 swapfield (pt, ptrdiff_t);
2060 swapfield (pt_byte, EMACS_INT); 2059 swapfield (pt_byte, ptrdiff_t);
2061 swapfield (begv, EMACS_INT); 2060 swapfield (begv, ptrdiff_t);
2062 swapfield (begv_byte, EMACS_INT); 2061 swapfield (begv_byte, ptrdiff_t);
2063 swapfield (zv, EMACS_INT); 2062 swapfield (zv, ptrdiff_t);
2064 swapfield (zv_byte, EMACS_INT); 2063 swapfield (zv_byte, ptrdiff_t);
2065 eassert (!current_buffer->base_buffer); 2064 eassert (!current_buffer->base_buffer);
2066 eassert (!other_buffer->base_buffer); 2065 eassert (!other_buffer->base_buffer);
2067 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2066 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
@@ -2071,7 +2070,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2071 other_buffer->prevent_redisplay_optimizations_p = 1; 2070 other_buffer->prevent_redisplay_optimizations_p = 1;
2072 swapfield (overlays_before, struct Lisp_Overlay *); 2071 swapfield (overlays_before, struct Lisp_Overlay *);
2073 swapfield (overlays_after, struct Lisp_Overlay *); 2072 swapfield (overlays_after, struct Lisp_Overlay *);
2074 swapfield (overlay_center, EMACS_INT); 2073 swapfield (overlay_center, ptrdiff_t);
2075 swapfield_ (undo_list, Lisp_Object); 2074 swapfield_ (undo_list, Lisp_Object);
2076 swapfield_ (mark, Lisp_Object); 2075 swapfield_ (mark, Lisp_Object);
2077 swapfield_ (enable_multibyte_characters, Lisp_Object); 2076 swapfield_ (enable_multibyte_characters, Lisp_Object);
@@ -2154,7 +2153,7 @@ current buffer is cleared. */)
2154{ 2153{
2155 struct Lisp_Marker *tail, *markers; 2154 struct Lisp_Marker *tail, *markers;
2156 struct buffer *other; 2155 struct buffer *other;
2157 EMACS_INT begv, zv; 2156 ptrdiff_t begv, zv;
2158 int narrowed = (BEG != BEGV || Z != ZV); 2157 int narrowed = (BEG != BEGV || Z != ZV);
2159 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2158 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2160 Lisp_Object old_undo = BVAR (current_buffer, undo_list); 2159 Lisp_Object old_undo = BVAR (current_buffer, undo_list);
@@ -2186,7 +2185,7 @@ current buffer is cleared. */)
2186 2185
2187 if (NILP (flag)) 2186 if (NILP (flag))
2188 { 2187 {
2189 EMACS_INT pos, stop; 2188 ptrdiff_t pos, stop;
2190 unsigned char *p; 2189 unsigned char *p;
2191 2190
2192 /* Do this first, so it can use CHAR_TO_BYTE 2191 /* Do this first, so it can use CHAR_TO_BYTE
@@ -2250,8 +2249,8 @@ current buffer is cleared. */)
2250 } 2249 }
2251 else 2250 else
2252 { 2251 {
2253 EMACS_INT pt = PT; 2252 ptrdiff_t pt = PT;
2254 EMACS_INT pos, stop; 2253 ptrdiff_t pos, stop;
2255 unsigned char *p, *pend; 2254 unsigned char *p, *pend;
2256 2255
2257 /* Be sure not to have a multibyte sequence striding over the GAP. 2256 /* Be sure not to have a multibyte sequence striding over the GAP.
@@ -2267,7 +2266,7 @@ current buffer is cleared. */)
2267 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--; 2266 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--;
2268 if (LEADING_CODE_P (*q)) 2267 if (LEADING_CODE_P (*q))
2269 { 2268 {
2270 EMACS_INT new_gpt = GPT_BYTE - (GPT_ADDR - q); 2269 ptrdiff_t new_gpt = GPT_BYTE - (GPT_ADDR - q);
2271 2270
2272 move_gap_both (new_gpt, new_gpt); 2271 move_gap_both (new_gpt, new_gpt);
2273 } 2272 }
@@ -2351,8 +2350,8 @@ current buffer is cleared. */)
2351 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 2350 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
2352 2351
2353 { 2352 {
2354 EMACS_INT byte = advance_to_char_boundary (PT_BYTE); 2353 ptrdiff_t byte = advance_to_char_boundary (PT_BYTE);
2355 EMACS_INT position; 2354 ptrdiff_t position;
2356 2355
2357 if (byte > GPT_BYTE) 2356 if (byte > GPT_BYTE)
2358 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT; 2357 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT;
@@ -2516,20 +2515,20 @@ swap_out_buffer_local_variables (struct buffer *b)
2516ptrdiff_t 2515ptrdiff_t
2517overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 2516overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2518 ptrdiff_t *len_ptr, 2517 ptrdiff_t *len_ptr,
2519 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2518 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, int change_req)
2520{ 2519{
2521 Lisp_Object overlay, start, end; 2520 Lisp_Object overlay, start, end;
2522 struct Lisp_Overlay *tail; 2521 struct Lisp_Overlay *tail;
2523 ptrdiff_t idx = 0; 2522 ptrdiff_t idx = 0;
2524 ptrdiff_t len = *len_ptr; 2523 ptrdiff_t len = *len_ptr;
2525 Lisp_Object *vec = *vec_ptr; 2524 Lisp_Object *vec = *vec_ptr;
2526 EMACS_INT next = ZV; 2525 ptrdiff_t next = ZV;
2527 EMACS_INT prev = BEGV; 2526 ptrdiff_t prev = BEGV;
2528 int inhibit_storing = 0; 2527 int inhibit_storing = 0;
2529 2528
2530 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2529 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2531 { 2530 {
2532 EMACS_INT startpos, endpos; 2531 ptrdiff_t startpos, endpos;
2533 2532
2534 XSETMISC (overlay, tail); 2533 XSETMISC (overlay, tail);
2535 2534
@@ -2577,7 +2576,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2577 2576
2578 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2577 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2579 { 2578 {
2580 EMACS_INT startpos, endpos; 2579 ptrdiff_t startpos, endpos;
2581 2580
2582 XSETMISC (overlay, tail); 2581 XSETMISC (overlay, tail);
2583 2582
@@ -2650,21 +2649,21 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2650static ptrdiff_t 2649static ptrdiff_t
2651overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2650overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2652 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, 2651 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2653 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2652 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr)
2654{ 2653{
2655 Lisp_Object overlay, ostart, oend; 2654 Lisp_Object overlay, ostart, oend;
2656 struct Lisp_Overlay *tail; 2655 struct Lisp_Overlay *tail;
2657 ptrdiff_t idx = 0; 2656 ptrdiff_t idx = 0;
2658 ptrdiff_t len = *len_ptr; 2657 ptrdiff_t len = *len_ptr;
2659 Lisp_Object *vec = *vec_ptr; 2658 Lisp_Object *vec = *vec_ptr;
2660 EMACS_INT next = ZV; 2659 ptrdiff_t next = ZV;
2661 EMACS_INT prev = BEGV; 2660 ptrdiff_t prev = BEGV;
2662 int inhibit_storing = 0; 2661 int inhibit_storing = 0;
2663 int end_is_Z = end == Z; 2662 int end_is_Z = end == Z;
2664 2663
2665 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2664 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2666 { 2665 {
2667 EMACS_INT startpos, endpos; 2666 ptrdiff_t startpos, endpos;
2668 2667
2669 XSETMISC (overlay, tail); 2668 XSETMISC (overlay, tail);
2670 2669
@@ -2711,7 +2710,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2711 2710
2712 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2711 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2713 { 2712 {
2714 EMACS_INT startpos, endpos; 2713 ptrdiff_t startpos, endpos;
2715 2714
2716 XSETMISC (overlay, tail); 2715 XSETMISC (overlay, tail);
2717 2716
@@ -2767,8 +2766,8 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2767int 2766int
2768mouse_face_overlay_overlaps (Lisp_Object overlay) 2767mouse_face_overlay_overlaps (Lisp_Object overlay)
2769{ 2768{
2770 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 2769 ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay));
2771 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 2770 ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay));
2772 ptrdiff_t n, i, size; 2771 ptrdiff_t n, i, size;
2773 Lisp_Object *v, tem; 2772 Lisp_Object *v, tem;
2774 2773
@@ -2794,14 +2793,14 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2794 2793
2795/* Fast function to just test if we're at an overlay boundary. */ 2794/* Fast function to just test if we're at an overlay boundary. */
2796int 2795int
2797overlay_touches_p (EMACS_INT pos) 2796overlay_touches_p (ptrdiff_t pos)
2798{ 2797{
2799 Lisp_Object overlay; 2798 Lisp_Object overlay;
2800 struct Lisp_Overlay *tail; 2799 struct Lisp_Overlay *tail;
2801 2800
2802 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2801 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2803 { 2802 {
2804 EMACS_INT endpos; 2803 ptrdiff_t endpos;
2805 2804
2806 XSETMISC (overlay ,tail); 2805 XSETMISC (overlay ,tail);
2807 if (!OVERLAYP (overlay)) 2806 if (!OVERLAYP (overlay))
@@ -2816,7 +2815,7 @@ overlay_touches_p (EMACS_INT pos)
2816 2815
2817 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2816 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2818 { 2817 {
2819 EMACS_INT startpos; 2818 ptrdiff_t startpos;
2820 2819
2821 XSETMISC (overlay, tail); 2820 XSETMISC (overlay, tail);
2822 if (!OVERLAYP (overlay)) 2821 if (!OVERLAYP (overlay))
@@ -2834,7 +2833,7 @@ overlay_touches_p (EMACS_INT pos)
2834struct sortvec 2833struct sortvec
2835{ 2834{
2836 Lisp_Object overlay; 2835 Lisp_Object overlay;
2837 EMACS_INT beg, end; 2836 ptrdiff_t beg, end;
2838 EMACS_INT priority; 2837 EMACS_INT priority;
2839}; 2838};
2840 2839
@@ -2951,7 +2950,7 @@ static void
2951record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, 2950record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2952 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size) 2951 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2953{ 2952{
2954 EMACS_INT nbytes; 2953 ptrdiff_t nbytes;
2955 2954
2956 if (ssl->used == ssl->size) 2955 if (ssl->used == ssl->size)
2957 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); 2956 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
@@ -3001,12 +3000,12 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3001 PSTR, if that variable is non-null. The string may be overwritten by 3000 PSTR, if that variable is non-null. The string may be overwritten by
3002 subsequent calls. */ 3001 subsequent calls. */
3003 3002
3004EMACS_INT 3003ptrdiff_t
3005overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3004overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3006{ 3005{
3007 Lisp_Object overlay, window, str; 3006 Lisp_Object overlay, window, str;
3008 struct Lisp_Overlay *ov; 3007 struct Lisp_Overlay *ov;
3009 EMACS_INT startpos, endpos; 3008 ptrdiff_t startpos, endpos;
3010 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3009 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3011 3010
3012 overlay_heads.used = overlay_heads.bytes = 0; 3011 overlay_heads.used = overlay_heads.bytes = 0;
@@ -3076,7 +3075,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3076 if (overlay_heads.bytes || overlay_tails.bytes) 3075 if (overlay_heads.bytes || overlay_tails.bytes)
3077 { 3076 {
3078 Lisp_Object tem; 3077 Lisp_Object tem;
3079 EMACS_INT i; 3078 ptrdiff_t i;
3080 unsigned char *p; 3079 unsigned char *p;
3081 ptrdiff_t total; 3080 ptrdiff_t total;
3082 3081
@@ -3090,7 +3089,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3090 p = overlay_str_buf; 3089 p = overlay_str_buf;
3091 for (i = overlay_tails.used; --i >= 0;) 3090 for (i = overlay_tails.used; --i >= 0;)
3092 { 3091 {
3093 EMACS_INT nbytes; 3092 ptrdiff_t nbytes;
3094 tem = overlay_tails.buf[i].string; 3093 tem = overlay_tails.buf[i].string;
3095 nbytes = copy_text (SDATA (tem), p, 3094 nbytes = copy_text (SDATA (tem), p,
3096 SBYTES (tem), 3095 SBYTES (tem),
@@ -3099,7 +3098,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3099 } 3098 }
3100 for (i = 0; i < overlay_heads.used; ++i) 3099 for (i = 0; i < overlay_heads.used; ++i)
3101 { 3100 {
3102 EMACS_INT nbytes; 3101 ptrdiff_t nbytes;
3103 tem = overlay_heads.buf[i].string; 3102 tem = overlay_heads.buf[i].string;
3104 nbytes = copy_text (SDATA (tem), p, 3103 nbytes = copy_text (SDATA (tem), p,
3105 SBYTES (tem), 3104 SBYTES (tem),
@@ -3126,7 +3125,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3126/* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3125/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3127 3126
3128void 3127void
3129recenter_overlay_lists (struct buffer *buf, EMACS_INT pos) 3128recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3130{ 3129{
3131 Lisp_Object overlay, beg, end; 3130 Lisp_Object overlay, beg, end;
3132 struct Lisp_Overlay *prev, *tail, *next; 3131 struct Lisp_Overlay *prev, *tail, *next;
@@ -3164,7 +3163,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3164 if (OVERLAY_POSITION (end) > pos) 3163 if (OVERLAY_POSITION (end) > pos)
3165 { 3164 {
3166 /* OVERLAY needs to be moved. */ 3165 /* OVERLAY needs to be moved. */
3167 EMACS_INT where = OVERLAY_POSITION (beg); 3166 ptrdiff_t where = OVERLAY_POSITION (beg);
3168 struct Lisp_Overlay *other, *other_prev; 3167 struct Lisp_Overlay *other, *other_prev;
3169 3168
3170 /* Splice the cons cell TAIL out of overlays_before. */ 3169 /* Splice the cons cell TAIL out of overlays_before. */
@@ -3237,7 +3236,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3237 if (OVERLAY_POSITION (end) <= pos) 3236 if (OVERLAY_POSITION (end) <= pos)
3238 { 3237 {
3239 /* OVERLAY needs to be moved. */ 3238 /* OVERLAY needs to be moved. */
3240 EMACS_INT where = OVERLAY_POSITION (end); 3239 ptrdiff_t where = OVERLAY_POSITION (end);
3241 struct Lisp_Overlay *other, *other_prev; 3240 struct Lisp_Overlay *other, *other_prev;
3242 3241
3243 /* Splice the cons cell TAIL out of overlays_after. */ 3242 /* Splice the cons cell TAIL out of overlays_after. */
@@ -3275,7 +3274,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3275} 3274}
3276 3275
3277void 3276void
3278adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length) 3277adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
3279{ 3278{
3280 /* After an insertion, the lists are still sorted properly, 3279 /* After an insertion, the lists are still sorted properly,
3281 but we may need to update the value of the overlay center. */ 3280 but we may need to update the value of the overlay center. */
@@ -3284,13 +3283,13 @@ adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length)
3284} 3283}
3285 3284
3286void 3285void
3287adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length) 3286adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
3288{ 3287{
3289 if (current_buffer->overlay_center < pos) 3288 if (current_buffer->overlay_center < pos)
3290 /* The deletion was to our right. No change needed; the before- and 3289 /* The deletion was to our right. No change needed; the before- and
3291 after-lists are still consistent. */ 3290 after-lists are still consistent. */
3292 ; 3291 ;
3293 else if (current_buffer->overlay_center > pos + length) 3292 else if (current_buffer->overlay_center - pos > length)
3294 /* The deletion was to our left. We need to adjust the center value 3293 /* The deletion was to our left. We need to adjust the center value
3295 to account for the change in position, but the lists are consistent 3294 to account for the change in position, but the lists are consistent
3296 given the new value. */ 3295 given the new value. */
@@ -3309,7 +3308,7 @@ adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length)
3309 Such an overlay might even have negative size at this point. 3308 Such an overlay might even have negative size at this point.
3310 If so, we'll make the overlay empty. */ 3309 If so, we'll make the overlay empty. */
3311void 3310void
3312fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end) 3311fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3313{ 3312{
3314 Lisp_Object overlay; 3313 Lisp_Object overlay;
3315 struct Lisp_Overlay *before_list IF_LINT (= NULL); 3314 struct Lisp_Overlay *before_list IF_LINT (= NULL);
@@ -3322,7 +3321,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3322 current_buffer->overlays_before or overlays_after, depending 3321 current_buffer->overlays_before or overlays_after, depending
3323 which loop we're in. */ 3322 which loop we're in. */
3324 struct Lisp_Overlay *tail, *parent; 3323 struct Lisp_Overlay *tail, *parent;
3325 EMACS_INT startpos, endpos; 3324 ptrdiff_t startpos, endpos;
3326 3325
3327 /* This algorithm shifts links around instead of consing and GCing. 3326 /* This algorithm shifts links around instead of consing and GCing.
3328 The loop invariant is that before_list (resp. after_list) is a 3327 The loop invariant is that before_list (resp. after_list) is a
@@ -3456,12 +3455,12 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3456 was at PREV, and now is at POS. */ 3455 was at PREV, and now is at POS. */
3457 3456
3458void 3457void
3459fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos) 3458fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3460{ 3459{
3461 /* If parent is nil, replace overlays_before; otherwise, parent->next. */ 3460 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3462 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair; 3461 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3463 Lisp_Object tem; 3462 Lisp_Object tem;
3464 EMACS_INT end IF_LINT (= 0); 3463 ptrdiff_t end IF_LINT (= 0);
3465 3464
3466 /* After the insertion, the several overlays may be in incorrect 3465 /* After the insertion, the several overlays may be in incorrect
3467 order. The possibility is that, in the list `overlays_before', 3466 order. The possibility is that, in the list `overlays_before',
@@ -3619,11 +3618,11 @@ for the rear of the overlay advance when text is inserted there
3619/* Mark a section of BUF as needing redisplay because of overlays changes. */ 3618/* Mark a section of BUF as needing redisplay because of overlays changes. */
3620 3619
3621static void 3620static void
3622modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end) 3621modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3623{ 3622{
3624 if (start > end) 3623 if (start > end)
3625 { 3624 {
3626 EMACS_INT temp = start; 3625 ptrdiff_t temp = start;
3627 start = end; 3626 start = end;
3628 end = temp; 3627 end = temp;
3629 } 3628 }
@@ -3672,7 +3671,7 @@ buffer. */)
3672{ 3671{
3673 struct buffer *b, *ob; 3672 struct buffer *b, *ob;
3674 Lisp_Object obuffer; 3673 Lisp_Object obuffer;
3675 int count = SPECPDL_INDEX (); 3674 ptrdiff_t count = SPECPDL_INDEX ();
3676 3675
3677 CHECK_OVERLAY (overlay); 3676 CHECK_OVERLAY (overlay);
3678 if (NILP (buffer)) 3677 if (NILP (buffer))
@@ -3691,19 +3690,22 @@ buffer. */)
3691 CHECK_NUMBER_COERCE_MARKER (beg); 3690 CHECK_NUMBER_COERCE_MARKER (beg);
3692 CHECK_NUMBER_COERCE_MARKER (end); 3691 CHECK_NUMBER_COERCE_MARKER (end);
3693 3692
3694 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3695 return Fdelete_overlay (overlay);
3696
3697 if (XINT (beg) > XINT (end)) 3693 if (XINT (beg) > XINT (end))
3698 { 3694 {
3699 Lisp_Object temp; 3695 Lisp_Object temp;
3700 temp = beg; beg = end; end = temp; 3696 temp = beg; beg = end; end = temp;
3701 } 3697 }
3702 3698
3699 b = XBUFFER (buffer);
3700 if (! (BUF_BEGV (b) <= XINT (beg) && XINT (end) <= BUF_ZV (b)))
3701 args_out_of_range (beg, end);
3702
3703 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3704 return Fdelete_overlay (overlay);
3705
3703 specbind (Qinhibit_quit, Qt); 3706 specbind (Qinhibit_quit, Qt);
3704 3707
3705 obuffer = Fmarker_buffer (OVERLAY_START (overlay)); 3708 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
3706 b = XBUFFER (buffer);
3707 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; 3709 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0;
3708 3710
3709 /* If the overlay has changed buffers, do a thorough redisplay. */ 3711 /* If the overlay has changed buffers, do a thorough redisplay. */
@@ -3712,8 +3714,8 @@ buffer. */)
3712 /* Redisplay where the overlay was. */ 3714 /* Redisplay where the overlay was. */
3713 if (!NILP (obuffer)) 3715 if (!NILP (obuffer))
3714 { 3716 {
3715 EMACS_INT o_beg; 3717 ptrdiff_t o_beg;
3716 EMACS_INT o_end; 3718 ptrdiff_t o_end;
3717 3719
3718 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3720 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3719 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3721 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
@@ -3727,7 +3729,7 @@ buffer. */)
3727 else 3729 else
3728 /* Redisplay the area the overlay has just left, or just enclosed. */ 3730 /* Redisplay the area the overlay has just left, or just enclosed. */
3729 { 3731 {
3730 EMACS_INT o_beg, o_end; 3732 ptrdiff_t o_beg, o_end;
3731 3733
3732 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3734 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3733 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3735 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
@@ -3781,7 +3783,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3781{ 3783{
3782 Lisp_Object buffer; 3784 Lisp_Object buffer;
3783 struct buffer *b; 3785 struct buffer *b;
3784 int count = SPECPDL_INDEX (); 3786 ptrdiff_t count = SPECPDL_INDEX ();
3785 3787
3786 CHECK_OVERLAY (overlay); 3788 CHECK_OVERLAY (overlay);
3787 3789
@@ -3872,7 +3874,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3872 /* Put all the overlays we want in a vector in overlay_vec. 3874 /* Put all the overlays we want in a vector in overlay_vec.
3873 Store the length in len. */ 3875 Store the length in len. */
3874 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3876 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3875 (EMACS_INT *) 0, (EMACS_INT *) 0, 0); 3877 0, 0, 0);
3876 3878
3877 /* Make a list of them all. */ 3879 /* Make a list of them all. */
3878 result = Flist (noverlays, overlay_vec); 3880 result = Flist (noverlays, overlay_vec);
@@ -3920,7 +3922,7 @@ the value is (point-max). */)
3920 (Lisp_Object pos) 3922 (Lisp_Object pos)
3921{ 3923{
3922 ptrdiff_t i, len, noverlays; 3924 ptrdiff_t i, len, noverlays;
3923 EMACS_INT endpos; 3925 ptrdiff_t endpos;
3924 Lisp_Object *overlay_vec; 3926 Lisp_Object *overlay_vec;
3925 3927
3926 CHECK_NUMBER_COERCE_MARKER (pos); 3928 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3932,14 +3934,14 @@ the value is (point-max). */)
3932 Store the length in len. 3934 Store the length in len.
3933 endpos gets the position where the next overlay starts. */ 3935 endpos gets the position where the next overlay starts. */
3934 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3936 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3935 &endpos, (EMACS_INT *) 0, 1); 3937 &endpos, 0, 1);
3936 3938
3937 /* If any of these overlays ends before endpos, 3939 /* If any of these overlays ends before endpos,
3938 use its ending point instead. */ 3940 use its ending point instead. */
3939 for (i = 0; i < noverlays; i++) 3941 for (i = 0; i < noverlays; i++)
3940 { 3942 {
3941 Lisp_Object oend; 3943 Lisp_Object oend;
3942 EMACS_INT oendpos; 3944 ptrdiff_t oendpos;
3943 3945
3944 oend = OVERLAY_END (overlay_vec[i]); 3946 oend = OVERLAY_END (overlay_vec[i]);
3945 oendpos = OVERLAY_POSITION (oend); 3947 oendpos = OVERLAY_POSITION (oend);
@@ -3958,7 +3960,7 @@ If there are no overlay boundaries from (point-min) to POS,
3958the value is (point-min). */) 3960the value is (point-min). */)
3959 (Lisp_Object pos) 3961 (Lisp_Object pos)
3960{ 3962{
3961 EMACS_INT prevpos; 3963 ptrdiff_t prevpos;
3962 Lisp_Object *overlay_vec; 3964 Lisp_Object *overlay_vec;
3963 ptrdiff_t len; 3965 ptrdiff_t len;
3964 3966
@@ -3976,7 +3978,7 @@ the value is (point-min). */)
3976 Store the length in len. 3978 Store the length in len.
3977 prevpos gets the position of the previous change. */ 3979 prevpos gets the position of the previous change. */
3978 overlays_at (XINT (pos), 1, &overlay_vec, &len, 3980 overlays_at (XINT (pos), 1, &overlay_vec, &len,
3979 (EMACS_INT *) 0, &prevpos, 1); 3981 0, &prevpos, 1);
3980 3982
3981 xfree (overlay_vec); 3983 xfree (overlay_vec);
3982 return make_number (prevpos); 3984 return make_number (prevpos);
@@ -4014,9 +4016,11 @@ That makes overlay lookup faster for positions near POS (but perhaps slower
4014for positions far away from POS). */) 4016for positions far away from POS). */)
4015 (Lisp_Object pos) 4017 (Lisp_Object pos)
4016{ 4018{
4019 ptrdiff_t p;
4017 CHECK_NUMBER_COERCE_MARKER (pos); 4020 CHECK_NUMBER_COERCE_MARKER (pos);
4018 4021
4019 recenter_overlay_lists (current_buffer, XINT (pos)); 4022 p = clip_to_bounds (PTRDIFF_MIN, XINT (pos), PTRDIFF_MAX);
4023 recenter_overlay_lists (current_buffer, p);
4020 return Qnil; 4024 return Qnil;
4021} 4025}
4022 4026
@@ -4083,7 +4087,7 @@ VALUE will be returned.*/)
4083static Lisp_Object last_overlay_modification_hooks; 4087static Lisp_Object last_overlay_modification_hooks;
4084 4088
4085/* Number of elements actually used in last_overlay_modification_hooks. */ 4089/* Number of elements actually used in last_overlay_modification_hooks. */
4086static int last_overlay_modification_hooks_used; 4090static ptrdiff_t last_overlay_modification_hooks_used;
4087 4091
4088/* Add one functionlist/overlay pair 4092/* Add one functionlist/overlay pair
4089 to the end of last_overlay_modification_hooks. */ 4093 to the end of last_overlay_modification_hooks. */
@@ -4091,11 +4095,11 @@ static int last_overlay_modification_hooks_used;
4091static void 4095static void
4092add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) 4096add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4093{ 4097{
4094 int oldsize = ASIZE (last_overlay_modification_hooks); 4098 ptrdiff_t oldsize = ASIZE (last_overlay_modification_hooks);
4095 4099
4096 if (last_overlay_modification_hooks_used == oldsize) 4100 if (oldsize - 1 <= last_overlay_modification_hooks_used)
4097 last_overlay_modification_hooks = larger_vector 4101 last_overlay_modification_hooks =
4098 (last_overlay_modification_hooks, oldsize * 2, Qnil); 4102 larger_vector (last_overlay_modification_hooks, 2, -1);
4099 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4103 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
4100 functionlist); last_overlay_modification_hooks_used++; 4104 functionlist); last_overlay_modification_hooks_used++;
4101 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4105 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
@@ -4144,7 +4148,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4144 last_overlay_modification_hooks_used = 0; 4148 last_overlay_modification_hooks_used = 0;
4145 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4149 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4146 { 4150 {
4147 EMACS_INT startpos, endpos; 4151 ptrdiff_t startpos, endpos;
4148 Lisp_Object ostart, oend; 4152 Lisp_Object ostart, oend;
4149 4153
4150 XSETMISC (overlay, tail); 4154 XSETMISC (overlay, tail);
@@ -4181,7 +4185,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4181 4185
4182 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4186 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4183 { 4187 {
4184 EMACS_INT startpos, endpos; 4188 ptrdiff_t startpos, endpos;
4185 Lisp_Object ostart, oend; 4189 Lisp_Object ostart, oend;
4186 4190
4187 XSETMISC (overlay, tail); 4191 XSETMISC (overlay, tail);
@@ -4222,9 +4226,9 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4222 /* Call the functions recorded in last_overlay_modification_hooks. 4226 /* Call the functions recorded in last_overlay_modification_hooks.
4223 First copy the vector contents, in case some of these hooks 4227 First copy the vector contents, in case some of these hooks
4224 do subsequent modification of the buffer. */ 4228 do subsequent modification of the buffer. */
4225 int size = last_overlay_modification_hooks_used; 4229 ptrdiff_t size = last_overlay_modification_hooks_used;
4226 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4230 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
4227 int i; 4231 ptrdiff_t i;
4228 4232
4229 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4233 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
4230 size * sizeof (Lisp_Object)); 4234 size * sizeof (Lisp_Object));
@@ -4264,7 +4268,7 @@ call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after,
4264/* Delete any zero-sized overlays at position POS, if the `evaporate' 4268/* Delete any zero-sized overlays at position POS, if the `evaporate'
4265 property is set. */ 4269 property is set. */
4266void 4270void
4267evaporate_overlays (EMACS_INT pos) 4271evaporate_overlays (ptrdiff_t pos)
4268{ 4272{
4269 Lisp_Object overlay, hit_list; 4273 Lisp_Object overlay, hit_list;
4270 struct Lisp_Overlay *tail; 4274 struct Lisp_Overlay *tail;
@@ -4273,7 +4277,7 @@ evaporate_overlays (EMACS_INT pos)
4273 if (pos <= current_buffer->overlay_center) 4277 if (pos <= current_buffer->overlay_center)
4274 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4278 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4275 { 4279 {
4276 EMACS_INT endpos; 4280 ptrdiff_t endpos;
4277 XSETMISC (overlay, tail); 4281 XSETMISC (overlay, tail);
4278 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4282 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4279 if (endpos < pos) 4283 if (endpos < pos)
@@ -4285,7 +4289,7 @@ evaporate_overlays (EMACS_INT pos)
4285 else 4289 else
4286 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4290 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4287 { 4291 {
4288 EMACS_INT startpos; 4292 ptrdiff_t startpos;
4289 XSETMISC (overlay, tail); 4293 XSETMISC (overlay, tail);
4290 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4294 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4291 if (startpos > pos) 4295 if (startpos > pos)
@@ -4795,7 +4799,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4795 shrink it. */ 4799 shrink it. */
4796 4800
4797void 4801void
4798enlarge_buffer_text (struct buffer *b, EMACS_INT delta) 4802enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
4799{ 4803{
4800 POINTER_TYPE *p; 4804 POINTER_TYPE *p;
4801 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 4805 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1