aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c1863
1 files changed, 1062 insertions, 801 deletions
diff --git a/src/buffer.c b/src/buffer.c
index a482493fac7..619a729a859 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,6 +1,6 @@
1/* Buffer manipulation primitives for GNU Emacs. 1/* Buffer manipulation primitives for GNU Emacs.
2 2
3Copyright (C) 1985-1989, 1993-1995, 1997-2011 Free Software Foundation, Inc. 3Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -19,12 +19,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20#include <config.h> 20#include <config.h>
21 21
22#define BUFFER_INLINE EXTERN_INLINE
23
22#include <sys/types.h> 24#include <sys/types.h>
23#include <sys/stat.h> 25#include <sys/stat.h>
24#include <sys/param.h> 26#include <sys/param.h>
25#include <errno.h> 27#include <errno.h>
26#include <stdio.h> 28#include <stdio.h>
27#include <setjmp.h>
28#include <unistd.h> 29#include <unistd.h>
29 30
30#include <verify.h> 31#include <verify.h>
@@ -33,8 +34,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "intervals.h" 34#include "intervals.h"
34#include "window.h" 35#include "window.h"
35#include "commands.h" 36#include "commands.h"
36#include "buffer.h"
37#include "character.h" 37#include "character.h"
38#include "buffer.h"
38#include "region-cache.h" 39#include "region-cache.h"
39#include "indent.h" 40#include "indent.h"
40#include "blockinput.h" 41#include "blockinput.h"
@@ -42,7 +43,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
42#include "keymap.h" 43#include "keymap.h"
43#include "frame.h" 44#include "frame.h"
44 45
45struct buffer *current_buffer; /* the current buffer */ 46struct buffer *current_buffer; /* The current buffer. */
46 47
47/* First buffer in chain of all buffers (in reverse order of creation). 48/* First buffer in chain of all buffers (in reverse order of creation).
48 Threaded through ->header.next.buffer. */ 49 Threaded through ->header.next.buffer. */
@@ -56,11 +57,7 @@ struct buffer *all_buffers;
56 Setting the default value also goes through the alist of buffers 57 Setting the default value also goes through the alist of buffers
57 and stores into each buffer that does not say it has a local value. */ 58 and stores into each buffer that does not say it has a local value. */
58 59
59DECL_ALIGN (struct buffer, buffer_defaults); 60struct buffer alignas (GCALIGNMENT) buffer_defaults;
60
61/* A Lisp_Object pointer to the above, used for staticpro */
62
63static Lisp_Object Vbuffer_defaults;
64 61
65/* This structure marks which slots in a buffer have corresponding 62/* This structure marks which slots in a buffer have corresponding
66 default values in buffer_defaults. 63 default values in buffer_defaults.
@@ -76,17 +73,14 @@ static Lisp_Object Vbuffer_defaults;
76 and the corresponding slot in buffer_defaults is not used. 73 and the corresponding slot in buffer_defaults is not used.
77 74
78 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is 75 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
79 zero, that is a bug */ 76 zero, that is a bug. */
80 77
81struct buffer buffer_local_flags; 78struct buffer buffer_local_flags;
82 79
83/* This structure holds the names of symbols whose values may be 80/* This structure holds the names of symbols whose values may be
84 buffer-local. It is indexed and accessed in the same way as the above. */ 81 buffer-local. It is indexed and accessed in the same way as the above. */
85
86DECL_ALIGN (struct buffer, buffer_local_symbols);
87 82
88/* A Lisp_Object pointer to the above, used for staticpro */ 83struct buffer alignas (GCALIGNMENT) buffer_local_symbols;
89static Lisp_Object Vbuffer_local_symbols;
90 84
91/* Return the symbol of the per-buffer variable at offset OFFSET in 85/* Return the symbol of the per-buffer variable at offset OFFSET in
92 the buffer structure. */ 86 the buffer structure. */
@@ -97,7 +91,7 @@ static Lisp_Object Vbuffer_local_symbols;
97/* Maximum length of an overlay vector. */ 91/* Maximum length of an overlay vector. */
98#define OVERLAY_COUNT_MAX \ 92#define OVERLAY_COUNT_MAX \
99 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \ 93 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \
100 min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object))) 94 min (PTRDIFF_MAX, SIZE_MAX) / word_size))
101 95
102/* Flags indicating which built-in buffer-local variables 96/* Flags indicating which built-in buffer-local variables
103 are permanent locals. */ 97 are permanent locals. */
@@ -107,15 +101,13 @@ static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS];
107 101
108int last_per_buffer_idx; 102int last_per_buffer_idx;
109 103
110static Lisp_Object Fset_buffer_major_mode (Lisp_Object);
111static Lisp_Object Fdelete_overlay (Lisp_Object);
112static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, 104static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
113 int after, Lisp_Object arg1, 105 bool after, Lisp_Object arg1,
114 Lisp_Object arg2, Lisp_Object arg3); 106 Lisp_Object arg2, Lisp_Object arg3);
115static void swap_out_buffer_local_variables (struct buffer *b); 107static void swap_out_buffer_local_variables (struct buffer *b);
116static void reset_buffer_local_variables (struct buffer *b, int permanent_too); 108static void reset_buffer_local_variables (struct buffer *, bool);
117 109
118/* Alist of all buffer names vs the buffers. */ 110/* Alist of all buffer names vs the buffers. */
119/* This used to be a variable, but is no longer, 111/* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */ 112 to prevent lossage due to user rplac'ing this alist or its elements. */
121Lisp_Object Vbuffer_alist; 113Lisp_Object Vbuffer_alist;
@@ -128,14 +120,13 @@ static Lisp_Object Qchange_major_mode_hook;
128Lisp_Object Qfirst_change_hook; 120Lisp_Object Qfirst_change_hook;
129Lisp_Object Qbefore_change_functions; 121Lisp_Object Qbefore_change_functions;
130Lisp_Object Qafter_change_functions; 122Lisp_Object Qafter_change_functions;
131static Lisp_Object Qucs_set_table_for_input;
132 123
133static Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local; 124static Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local;
134static Lisp_Object Qpermanent_local_hook; 125static Lisp_Object Qpermanent_local_hook;
135 126
136static Lisp_Object Qprotected_field; 127static Lisp_Object Qprotected_field;
137 128
138static Lisp_Object QSFundamental; /* A string "Fundamental" */ 129static Lisp_Object QSFundamental; /* A string "Fundamental". */
139 130
140static Lisp_Object Qkill_buffer_hook; 131static Lisp_Object Qkill_buffer_hook;
141static Lisp_Object Qbuffer_list_update_hook; 132static Lisp_Object Qbuffer_list_update_hook;
@@ -155,8 +146,230 @@ Lisp_Object Qinsert_behind_hooks;
155static void alloc_buffer_text (struct buffer *, ptrdiff_t); 146static void alloc_buffer_text (struct buffer *, ptrdiff_t);
156static void free_buffer_text (struct buffer *b); 147static void free_buffer_text (struct buffer *b);
157static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); 148static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
158static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); 149static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
159static Lisp_Object buffer_lisp_local_variables (struct buffer *); 150static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool);
151
152/* These setters are used only in this file, so they can be private. */
153static void
154bset_abbrev_mode (struct buffer *b, Lisp_Object val)
155{
156 b->INTERNAL_FIELD (abbrev_mode) = val;
157}
158static void
159bset_abbrev_table (struct buffer *b, Lisp_Object val)
160{
161 b->INTERNAL_FIELD (abbrev_table) = val;
162}
163static void
164bset_auto_fill_function (struct buffer *b, Lisp_Object val)
165{
166 b->INTERNAL_FIELD (auto_fill_function) = val;
167}
168static void
169bset_auto_save_file_format (struct buffer *b, Lisp_Object val)
170{
171 b->INTERNAL_FIELD (auto_save_file_format) = val;
172}
173static void
174bset_auto_save_file_name (struct buffer *b, Lisp_Object val)
175{
176 b->INTERNAL_FIELD (auto_save_file_name) = val;
177}
178static void
179bset_backed_up (struct buffer *b, Lisp_Object val)
180{
181 b->INTERNAL_FIELD (backed_up) = val;
182}
183static void
184bset_begv_marker (struct buffer *b, Lisp_Object val)
185{
186 b->INTERNAL_FIELD (begv_marker) = val;
187}
188static void
189bset_bidi_display_reordering (struct buffer *b, Lisp_Object val)
190{
191 b->INTERNAL_FIELD (bidi_display_reordering) = val;
192}
193static void
194bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
195{
196 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
197}
198static void
199bset_cache_long_line_scans (struct buffer *b, Lisp_Object val)
200{
201 b->INTERNAL_FIELD (cache_long_line_scans) = val;
202}
203static void
204bset_case_fold_search (struct buffer *b, Lisp_Object val)
205{
206 b->INTERNAL_FIELD (case_fold_search) = val;
207}
208static void
209bset_ctl_arrow (struct buffer *b, Lisp_Object val)
210{
211 b->INTERNAL_FIELD (ctl_arrow) = val;
212}
213static void
214bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val)
215{
216 b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val;
217}
218static void
219bset_cursor_type (struct buffer *b, Lisp_Object val)
220{
221 b->INTERNAL_FIELD (cursor_type) = val;
222}
223static void
224bset_display_table (struct buffer *b, Lisp_Object val)
225{
226 b->INTERNAL_FIELD (display_table) = val;
227}
228static void
229bset_extra_line_spacing (struct buffer *b, Lisp_Object val)
230{
231 b->INTERNAL_FIELD (extra_line_spacing) = val;
232}
233static void
234bset_file_format (struct buffer *b, Lisp_Object val)
235{
236 b->INTERNAL_FIELD (file_format) = val;
237}
238static void
239bset_file_truename (struct buffer *b, Lisp_Object val)
240{
241 b->INTERNAL_FIELD (file_truename) = val;
242}
243static void
244bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val)
245{
246 b->INTERNAL_FIELD (fringe_cursor_alist) = val;
247}
248static void
249bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val)
250{
251 b->INTERNAL_FIELD (fringe_indicator_alist) = val;
252}
253static void
254bset_fringes_outside_margins (struct buffer *b, Lisp_Object val)
255{
256 b->INTERNAL_FIELD (fringes_outside_margins) = val;
257}
258static void
259bset_header_line_format (struct buffer *b, Lisp_Object val)
260{
261 b->INTERNAL_FIELD (header_line_format) = val;
262}
263static void
264bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val)
265{
266 b->INTERNAL_FIELD (indicate_buffer_boundaries) = val;
267}
268static void
269bset_indicate_empty_lines (struct buffer *b, Lisp_Object val)
270{
271 b->INTERNAL_FIELD (indicate_empty_lines) = val;
272}
273static void
274bset_invisibility_spec (struct buffer *b, Lisp_Object val)
275{
276 b->INTERNAL_FIELD (invisibility_spec) = val;
277}
278static void
279bset_left_fringe_width (struct buffer *b, Lisp_Object val)
280{
281 b->INTERNAL_FIELD (left_fringe_width) = val;
282}
283static void
284bset_major_mode (struct buffer *b, Lisp_Object val)
285{
286 b->INTERNAL_FIELD (major_mode) = val;
287}
288static void
289bset_mark (struct buffer *b, Lisp_Object val)
290{
291 b->INTERNAL_FIELD (mark) = val;
292}
293static void
294bset_minor_modes (struct buffer *b, Lisp_Object val)
295{
296 b->INTERNAL_FIELD (minor_modes) = val;
297}
298static void
299bset_mode_line_format (struct buffer *b, Lisp_Object val)
300{
301 b->INTERNAL_FIELD (mode_line_format) = val;
302}
303static void
304bset_mode_name (struct buffer *b, Lisp_Object val)
305{
306 b->INTERNAL_FIELD (mode_name) = val;
307}
308static void
309bset_name (struct buffer *b, Lisp_Object val)
310{
311 b->INTERNAL_FIELD (name) = val;
312}
313static void
314bset_overwrite_mode (struct buffer *b, Lisp_Object val)
315{
316 b->INTERNAL_FIELD (overwrite_mode) = val;
317}
318static void
319bset_pt_marker (struct buffer *b, Lisp_Object val)
320{
321 b->INTERNAL_FIELD (pt_marker) = val;
322}
323static void
324bset_right_fringe_width (struct buffer *b, Lisp_Object val)
325{
326 b->INTERNAL_FIELD (right_fringe_width) = val;
327}
328static void
329bset_save_length (struct buffer *b, Lisp_Object val)
330{
331 b->INTERNAL_FIELD (save_length) = val;
332}
333static void
334bset_scroll_bar_width (struct buffer *b, Lisp_Object val)
335{
336 b->INTERNAL_FIELD (scroll_bar_width) = val;
337}
338static void
339bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val)
340{
341 b->INTERNAL_FIELD (scroll_down_aggressively) = val;
342}
343static void
344bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val)
345{
346 b->INTERNAL_FIELD (scroll_up_aggressively) = val;
347}
348static void
349bset_selective_display (struct buffer *b, Lisp_Object val)
350{
351 b->INTERNAL_FIELD (selective_display) = val;
352}
353static void
354bset_selective_display_ellipses (struct buffer *b, Lisp_Object val)
355{
356 b->INTERNAL_FIELD (selective_display_ellipses) = val;
357}
358static void
359bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val)
360{
361 b->INTERNAL_FIELD (vertical_scroll_bar_type) = val;
362}
363static void
364bset_word_wrap (struct buffer *b, Lisp_Object val)
365{
366 b->INTERNAL_FIELD (word_wrap) = val;
367}
368static void
369bset_zv_marker (struct buffer *b, Lisp_Object val)
370{
371 b->INTERNAL_FIELD (zv_marker) = val;
372}
160 373
161/* For debugging; temporary. See set_buffer_internal. */ 374/* For debugging; temporary. See set_buffer_internal. */
162/* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 375/* Lisp_Object Qlisp_mode, Vcheck_symbol; */
@@ -174,7 +387,7 @@ DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
174Value is nil if OBJECT is not a buffer or if it has been killed. */) 387Value is nil if OBJECT is not a buffer or if it has been killed. */)
175 (Lisp_Object object) 388 (Lisp_Object object)
176{ 389{
177 return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name))) 390 return ((BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
178 ? Qt : Qnil); 391 ? Qt : Qnil);
179} 392}
180 393
@@ -193,7 +406,6 @@ followed by the rest of the buffers. */)
193 Lisp_Object framelist, prevlist, tail; 406 Lisp_Object framelist, prevlist, tail;
194 Lisp_Object args[3]; 407 Lisp_Object args[3];
195 408
196 CHECK_FRAME (frame);
197 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); 409 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list);
198 prevlist = Fnreverse (Fcopy_sequence 410 prevlist = Fnreverse (Fcopy_sequence
199 (XFRAME (frame)->buried_buffer_list)); 411 (XFRAME (frame)->buried_buffer_list));
@@ -272,7 +484,11 @@ See also `find-buffer-visiting'. */)
272 call the corresponding file handler. */ 484 call the corresponding file handler. */
273 handler = Ffind_file_name_handler (filename, Qget_file_buffer); 485 handler = Ffind_file_name_handler (filename, Qget_file_buffer);
274 if (!NILP (handler)) 486 if (!NILP (handler))
275 return call2 (handler, Qget_file_buffer, filename); 487 {
488 Lisp_Object handled_buf = call2 (handler, Qget_file_buffer,
489 filename);
490 return BUFFERP (handled_buf) ? handled_buf : Qnil;
491 }
276 492
277 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 493 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
278 { 494 {
@@ -328,14 +544,16 @@ even if it is dead. The return value is never nil. */)
328 544
329 /* An ordinary buffer uses its own struct buffer_text. */ 545 /* An ordinary buffer uses its own struct buffer_text. */
330 b->text = &b->own_text; 546 b->text = &b->own_text;
331 b->base_buffer = 0; 547 b->base_buffer = NULL;
548 /* No one shares the text with us now. */
549 b->indirections = 0;
332 550
333 BUF_GAP_SIZE (b) = 20; 551 BUF_GAP_SIZE (b) = 20;
334 BLOCK_INPUT; 552 block_input ();
335 /* We allocate extra 1-byte at the tail and keep it always '\0' for 553 /* We allocate extra 1-byte at the tail and keep it always '\0' for
336 anchoring a search. */ 554 anchoring a search. */
337 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); 555 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1);
338 UNBLOCK_INPUT; 556 unblock_input ();
339 if (! BUF_BEG_ADDR (b)) 557 if (! BUF_BEG_ADDR (b))
340 buffer_memory_full (BUF_GAP_SIZE (b) + 1); 558 buffer_memory_full (BUF_GAP_SIZE (b) + 1);
341 559
@@ -355,7 +573,7 @@ even if it is dead. The return value is never nil. */)
355 BUF_CHARS_MODIFF (b) = 1; 573 BUF_CHARS_MODIFF (b) = 1;
356 BUF_OVERLAY_MODIFF (b) = 1; 574 BUF_OVERLAY_MODIFF (b) = 1;
357 BUF_SAVE_MODIFF (b) = 1; 575 BUF_SAVE_MODIFF (b) = 1;
358 BUF_INTERVALS (b) = 0; 576 set_buffer_intervals (b, NULL);
359 BUF_UNCHANGED_MODIFIED (b) = 1; 577 BUF_UNCHANGED_MODIFIED (b) = 1;
360 BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1; 578 BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
361 BUF_END_UNCHANGED (b) = 0; 579 BUF_END_UNCHANGED (b) = 0;
@@ -365,31 +583,26 @@ even if it is dead. The return value is never nil. */)
365 583
366 b->newline_cache = 0; 584 b->newline_cache = 0;
367 b->width_run_cache = 0; 585 b->width_run_cache = 0;
368 BVAR (b, width_table) = Qnil; 586 bset_width_table (b, Qnil);
369 b->prevent_redisplay_optimizations_p = 1; 587 b->prevent_redisplay_optimizations_p = 1;
370 588
371 /* Put this on the chain of all buffers including killed ones. */
372 b->header.next.buffer = all_buffers;
373 all_buffers = b;
374
375 /* An ordinary buffer normally doesn't need markers 589 /* An ordinary buffer normally doesn't need markers
376 to handle BEGV and ZV. */ 590 to handle BEGV and ZV. */
377 BVAR (b, pt_marker) = Qnil; 591 bset_pt_marker (b, Qnil);
378 BVAR (b, begv_marker) = Qnil; 592 bset_begv_marker (b, Qnil);
379 BVAR (b, zv_marker) = Qnil; 593 bset_zv_marker (b, Qnil);
380 594
381 name = Fcopy_sequence (buffer_or_name); 595 name = Fcopy_sequence (buffer_or_name);
382 STRING_SET_INTERVALS (name, NULL_INTERVAL); 596 set_string_intervals (name, NULL);
383 BVAR (b, name) = name; 597 bset_name (b, name);
384 598
385 BVAR (b, undo_list) = (SREF (name, 0) != ' ') ? Qnil : Qt; 599 bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
386 600
387 reset_buffer (b); 601 reset_buffer (b);
388 reset_buffer_local_variables (b, 1); 602 reset_buffer_local_variables (b, 1);
389 603
390 BVAR (b, mark) = Fmake_marker (); 604 bset_mark (b, Fmake_marker ());
391 BUF_MARKERS (b) = NULL; 605 BUF_MARKERS (b) = NULL;
392 BVAR (b, name) = name;
393 606
394 /* Put this in the alist of all live buffers. */ 607 /* Put this in the alist of all live buffers. */
395 XSETBUFFER (buffer, b); 608 XSETBUFFER (buffer, b);
@@ -398,13 +611,6 @@ even if it is dead. The return value is never nil. */)
398 if (!NILP (Vrun_hooks)) 611 if (!NILP (Vrun_hooks))
399 call1 (Vrun_hooks, Qbuffer_list_update_hook); 612 call1 (Vrun_hooks, Qbuffer_list_update_hook);
400 613
401 /* An error in calling the function here (should someone redefine it)
402 can lead to infinite regress until you run out of stack. rms
403 says that's not worth protecting against. */
404 if (!NILP (Ffboundp (Qucs_set_table_for_input)))
405 /* buffer is on buffer-alist, so no gcpro. */
406 call1 (Qucs_set_table_for_input, buffer);
407
408 return buffer; 614 return buffer;
409} 615}
410 616
@@ -415,36 +621,24 @@ even if it is dead. The return value is never nil. */)
415static struct Lisp_Overlay * 621static struct Lisp_Overlay *
416copy_overlays (struct buffer *b, struct Lisp_Overlay *list) 622copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
417{ 623{
418 Lisp_Object buffer;
419 struct Lisp_Overlay *result = NULL, *tail = NULL; 624 struct Lisp_Overlay *result = NULL, *tail = NULL;
420 625
421 XSETBUFFER (buffer, b);
422
423 for (; list; list = list->next) 626 for (; list; list = list->next)
424 { 627 {
425 Lisp_Object overlay, start, end, old_overlay; 628 Lisp_Object overlay, start, end;
426 EMACS_INT charpos; 629 struct Lisp_Marker *m;
427 630
428 XSETMISC (old_overlay, list); 631 eassert (MARKERP (list->start));
429 charpos = marker_position (OVERLAY_START (old_overlay)); 632 m = XMARKER (list->start);
430 start = Fmake_marker (); 633 start = build_marker (b, m->charpos, m->bytepos);
431 Fset_marker (start, make_number (charpos), buffer); 634 XMARKER (start)->insertion_type = m->insertion_type;
432 XMARKER (start)->insertion_type 635
433 = XMARKER (OVERLAY_START (old_overlay))->insertion_type; 636 eassert (MARKERP (list->end));
434 637 m = XMARKER (list->end);
435 charpos = marker_position (OVERLAY_END (old_overlay)); 638 end = build_marker (b, m->charpos, m->bytepos);
436 end = Fmake_marker (); 639 XMARKER (end)->insertion_type = m->insertion_type;
437 Fset_marker (end, make_number (charpos), buffer);
438 XMARKER (end)->insertion_type
439 = XMARKER (OVERLAY_END (old_overlay))->insertion_type;
440
441 overlay = allocate_misc ();
442 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
443 OVERLAY_START (overlay) = start;
444 OVERLAY_END (overlay) = end;
445 OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay));
446 XOVERLAY (overlay)->next = NULL;
447 640
641 overlay = build_overlay (start, end, Fcopy_sequence (list->plist));
448 if (tail) 642 if (tail)
449 tail = tail->next = XOVERLAY (overlay); 643 tail = tail->next = XOVERLAY (overlay);
450 else 644 else
@@ -454,6 +648,19 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
454 return result; 648 return result;
455} 649}
456 650
651/* Set an appropriate overlay of B. */
652
653static void
654set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o)
655{
656 b->overlays_before = o;
657}
658
659static void
660set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o)
661{
662 b->overlays_after = o;
663}
457 664
458/* Clone per-buffer values of buffer FROM. 665/* Clone per-buffer values of buffer FROM.
459 666
@@ -465,16 +672,9 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
465static void 672static void
466clone_per_buffer_values (struct buffer *from, struct buffer *to) 673clone_per_buffer_values (struct buffer *from, struct buffer *to)
467{ 674{
468 Lisp_Object to_buffer;
469 int offset; 675 int offset;
470 676
471 XSETBUFFER (to_buffer, to); 677 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
472
473 /* buffer-local Lisp variables start at `undo_list',
474 tho only the ones from `name' on are GC'd normally. */
475 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
476 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
477 offset += sizeof (Lisp_Object))
478 { 678 {
479 Lisp_Object obj; 679 Lisp_Object obj;
480 680
@@ -482,26 +682,26 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
482 if (offset == PER_BUFFER_VAR_OFFSET (name)) 682 if (offset == PER_BUFFER_VAR_OFFSET (name))
483 continue; 683 continue;
484 684
485 obj = PER_BUFFER_VALUE (from, offset); 685 obj = per_buffer_value (from, offset);
486 if (MARKERP (obj) && XMARKER (obj)->buffer == from) 686 if (MARKERP (obj) && XMARKER (obj)->buffer == from)
487 { 687 {
488 struct Lisp_Marker *m = XMARKER (obj); 688 struct Lisp_Marker *m = XMARKER (obj);
489 obj = Fmake_marker (); 689
690 obj = build_marker (to, m->charpos, m->bytepos);
490 XMARKER (obj)->insertion_type = m->insertion_type; 691 XMARKER (obj)->insertion_type = m->insertion_type;
491 set_marker_both (obj, to_buffer, m->charpos, m->bytepos);
492 } 692 }
493 693
494 PER_BUFFER_VALUE (to, offset) = obj; 694 set_per_buffer_value (to, offset, obj);
495 } 695 }
496 696
497 memcpy (to->local_flags, from->local_flags, sizeof to->local_flags); 697 memcpy (to->local_flags, from->local_flags, sizeof to->local_flags);
498 698
499 to->overlays_before = copy_overlays (to, from->overlays_before); 699 set_buffer_overlays_before (to, copy_overlays (to, from->overlays_before));
500 to->overlays_after = copy_overlays (to, from->overlays_after); 700 set_buffer_overlays_after (to, copy_overlays (to, from->overlays_after));
501 701
502 /* Get (a copy of) the alist of Lisp-level local variables of FROM 702 /* Get (a copy of) the alist of Lisp-level local variables of FROM
503 and install that in TO. */ 703 and install that in TO. */
504 BVAR (to, local_var_alist) = buffer_lisp_local_variables (from); 704 bset_local_var_alist (to, buffer_lisp_local_variables (from, 1));
505} 705}
506 706
507 707
@@ -574,7 +774,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
574 base_buffer = Fget_buffer (base_buffer); 774 base_buffer = Fget_buffer (base_buffer);
575 if (NILP (base_buffer)) 775 if (NILP (base_buffer))
576 error ("No such buffer: `%s'", SDATA (tem)); 776 error ("No such buffer: `%s'", SDATA (tem));
577 if (NILP (BVAR (XBUFFER (base_buffer), name))) 777 if (!BUFFER_LIVE_P (XBUFFER (base_buffer)))
578 error ("Base buffer has been killed"); 778 error ("Base buffer has been killed");
579 779
580 if (SCHARS (name) == 0) 780 if (SCHARS (name) == 0)
@@ -582,12 +782,18 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
582 782
583 b = allocate_buffer (); 783 b = allocate_buffer ();
584 784
785 /* No double indirection - if base buffer is indirect,
786 new buffer becomes an indirect to base's base. */
585 b->base_buffer = (XBUFFER (base_buffer)->base_buffer 787 b->base_buffer = (XBUFFER (base_buffer)->base_buffer
586 ? XBUFFER (base_buffer)->base_buffer 788 ? XBUFFER (base_buffer)->base_buffer
587 : XBUFFER (base_buffer)); 789 : XBUFFER (base_buffer));
588 790
589 /* Use the base buffer's text object. */ 791 /* Use the base buffer's text object. */
590 b->text = b->base_buffer->text; 792 b->text = b->base_buffer->text;
793 /* We have no own text. */
794 b->indirections = -1;
795 /* Notify base buffer that we share the text now. */
796 b->base_buffer->indirections++;
591 797
592 b->pt = b->base_buffer->pt; 798 b->pt = b->base_buffer->pt;
593 b->begv = b->base_buffer->begv; 799 b->begv = b->base_buffer->begv;
@@ -598,15 +804,11 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
598 804
599 b->newline_cache = 0; 805 b->newline_cache = 0;
600 b->width_run_cache = 0; 806 b->width_run_cache = 0;
601 BVAR (b, width_table) = Qnil; 807 bset_width_table (b, Qnil);
602
603 /* Put this on the chain of all buffers including killed ones. */
604 b->header.next.buffer = all_buffers;
605 all_buffers = b;
606 808
607 name = Fcopy_sequence (name); 809 name = Fcopy_sequence (name);
608 STRING_SET_INTERVALS (name, NULL_INTERVAL); 810 set_string_intervals (name, NULL);
609 BVAR (b, name) = name; 811 bset_name (b, name);
610 812
611 reset_buffer (b); 813 reset_buffer (b);
612 reset_buffer_local_variables (b, 1); 814 reset_buffer_local_variables (b, 1);
@@ -615,11 +817,11 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
615 XSETBUFFER (buf, b); 817 XSETBUFFER (buf, b);
616 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); 818 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
617 819
618 BVAR (b, mark) = Fmake_marker (); 820 bset_mark (b, Fmake_marker ());
619 BVAR (b, name) = name;
620 821
621 /* The multibyte status belongs to the base buffer. */ 822 /* The multibyte status belongs to the base buffer. */
622 BVAR (b, enable_multibyte_characters) = BVAR (b->base_buffer, enable_multibyte_characters); 823 bset_enable_multibyte_characters
824 (b, BVAR (b->base_buffer, enable_multibyte_characters));
623 825
624 /* Make sure the base buffer has markers for its narrowing. */ 826 /* Make sure the base buffer has markers for its narrowing. */
625 if (NILP (BVAR (b->base_buffer, pt_marker))) 827 if (NILP (BVAR (b->base_buffer, pt_marker)))
@@ -627,32 +829,27 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
627 eassert (NILP (BVAR (b->base_buffer, begv_marker))); 829 eassert (NILP (BVAR (b->base_buffer, begv_marker)));
628 eassert (NILP (BVAR (b->base_buffer, zv_marker))); 830 eassert (NILP (BVAR (b->base_buffer, zv_marker)));
629 831
630 BVAR (b->base_buffer, pt_marker) = Fmake_marker (); 832 bset_pt_marker (b->base_buffer,
631 set_marker_both (BVAR (b->base_buffer, pt_marker), base_buffer, 833 build_marker (b->base_buffer, b->base_buffer->pt,
632 b->base_buffer->pt, 834 b->base_buffer->pt_byte));
633 b->base_buffer->pt_byte);
634 835
635 BVAR (b->base_buffer, begv_marker) = Fmake_marker (); 836 bset_begv_marker (b->base_buffer,
636 set_marker_both (BVAR (b->base_buffer, begv_marker), base_buffer, 837 build_marker (b->base_buffer, b->base_buffer->begv,
637 b->base_buffer->begv, 838 b->base_buffer->begv_byte));
638 b->base_buffer->begv_byte); 839
840 bset_zv_marker (b->base_buffer,
841 build_marker (b->base_buffer, b->base_buffer->zv,
842 b->base_buffer->zv_byte));
639 843
640 BVAR (b->base_buffer, zv_marker) = Fmake_marker ();
641 set_marker_both (BVAR (b->base_buffer, zv_marker), base_buffer,
642 b->base_buffer->zv,
643 b->base_buffer->zv_byte);
644 XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1; 844 XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1;
645 } 845 }
646 846
647 if (NILP (clone)) 847 if (NILP (clone))
648 { 848 {
649 /* Give the indirect buffer markers for its narrowing. */ 849 /* Give the indirect buffer markers for its narrowing. */
650 BVAR (b, pt_marker) = Fmake_marker (); 850 bset_pt_marker (b, build_marker (b, b->pt, b->pt_byte));
651 set_marker_both (BVAR (b, pt_marker), buf, b->pt, b->pt_byte); 851 bset_begv_marker (b, build_marker (b, b->begv, b->begv_byte));
652 BVAR (b, begv_marker) = Fmake_marker (); 852 bset_zv_marker (b, build_marker (b, b->zv, b->zv_byte));
653 set_marker_both (BVAR (b, begv_marker), buf, b->begv, b->begv_byte);
654 BVAR (b, zv_marker) = Fmake_marker ();
655 set_marker_both (BVAR (b, zv_marker), buf, b->zv, b->zv_byte);
656 XMARKER (BVAR (b, zv_marker))->insertion_type = 1; 853 XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
657 } 854 }
658 else 855 else
@@ -660,11 +857,11 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
660 struct buffer *old_b = current_buffer; 857 struct buffer *old_b = current_buffer;
661 858
662 clone_per_buffer_values (b->base_buffer, b); 859 clone_per_buffer_values (b->base_buffer, b);
663 BVAR (b, filename) = Qnil; 860 bset_filename (b, Qnil);
664 BVAR (b, file_truename) = Qnil; 861 bset_file_truename (b, Qnil);
665 BVAR (b, display_count) = make_number (0); 862 bset_display_count (b, make_number (0));
666 BVAR (b, backed_up) = Qnil; 863 bset_backed_up (b, Qnil);
667 BVAR (b, auto_save_file_name) = Qnil; 864 bset_auto_save_file_name (b, Qnil);
668 set_buffer_internal_1 (b); 865 set_buffer_internal_1 (b);
669 Fset (intern ("buffer-save-without-query"), Qnil); 866 Fset (intern ("buffer-save-without-query"), Qnil);
670 Fset (intern ("buffer-file-number"), Qnil); 867 Fset (intern ("buffer-file-number"), Qnil);
@@ -679,27 +876,44 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
679 return buf; 876 return buf;
680} 877}
681 878
879/* Mark OV as no longer associated with B. */
880
881static void
882drop_overlay (struct buffer *b, struct Lisp_Overlay *ov)
883{
884 eassert (b == XBUFFER (Fmarker_buffer (ov->start)));
885 modify_overlay (b, marker_position (ov->start),
886 marker_position (ov->end));
887 Fset_marker (ov->start, Qnil, Qnil);
888 Fset_marker (ov->end, Qnil, Qnil);
889
890}
891
892/* Delete all overlays of B and reset it's overlay lists. */
893
682void 894void
683delete_all_overlays (struct buffer *b) 895delete_all_overlays (struct buffer *b)
684{ 896{
685 Lisp_Object overlay; 897 struct Lisp_Overlay *ov, *next;
686 898
687 /* `reset_buffer' blindly sets the list of overlays to NULL, so we 899 /* FIXME: Since each drop_overlay will scan BUF_MARKERS to unlink its
688 have to empty the list, otherwise we end up with overlays that 900 markers, we have an unneeded O(N^2) behavior here. */
689 think they belong to this buffer while the buffer doesn't know about 901 for (ov = b->overlays_before; ov; ov = next)
690 them any more. */
691 while (b->overlays_before)
692 { 902 {
693 XSETMISC (overlay, b->overlays_before); 903 drop_overlay (b, ov);
694 Fdelete_overlay (overlay); 904 next = ov->next;
905 ov->next = NULL;
695 } 906 }
696 while (b->overlays_after) 907
908 for (ov = b->overlays_after; ov; ov = next)
697 { 909 {
698 XSETMISC (overlay, b->overlays_after); 910 drop_overlay (b, ov);
699 Fdelete_overlay (overlay); 911 next = ov->next;
912 ov->next = NULL;
700 } 913 }
701 eassert (b->overlays_before == NULL); 914
702 eassert (b->overlays_after == NULL); 915 set_buffer_overlays_before (b, NULL);
916 set_buffer_overlays_after (b, NULL);
703} 917}
704 918
705/* Reinitialize everything about a buffer except its name and contents 919/* Reinitialize everything about a buffer except its name and contents
@@ -712,34 +926,35 @@ delete_all_overlays (struct buffer *b)
712void 926void
713reset_buffer (register struct buffer *b) 927reset_buffer (register struct buffer *b)
714{ 928{
715 BVAR (b, filename) = Qnil; 929 bset_filename (b, Qnil);
716 BVAR (b, file_truename) = Qnil; 930 bset_file_truename (b, Qnil);
717 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil; 931 bset_directory (b, current_buffer ? BVAR (current_buffer, directory) : Qnil);
718 b->modtime = 0; 932 b->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS);
719 b->modtime_size = -1; 933 b->modtime_size = -1;
720 XSETFASTINT (BVAR (b, save_length), 0); 934 XSETFASTINT (BVAR (b, save_length), 0);
721 b->last_window_start = 1; 935 b->last_window_start = 1;
722 /* It is more conservative to start out "changed" than "unchanged". */ 936 /* It is more conservative to start out "changed" than "unchanged". */
723 b->clip_changed = 0; 937 b->clip_changed = 0;
724 b->prevent_redisplay_optimizations_p = 1; 938 b->prevent_redisplay_optimizations_p = 1;
725 BVAR (b, backed_up) = Qnil; 939 bset_backed_up (b, Qnil);
726 BUF_AUTOSAVE_MODIFF (b) = 0; 940 BUF_AUTOSAVE_MODIFF (b) = 0;
727 b->auto_save_failure_time = 0; 941 b->auto_save_failure_time = 0;
728 BVAR (b, auto_save_file_name) = Qnil; 942 bset_auto_save_file_name (b, Qnil);
729 BVAR (b, read_only) = Qnil; 943 bset_read_only (b, Qnil);
730 b->overlays_before = NULL; 944 set_buffer_overlays_before (b, NULL);
731 b->overlays_after = NULL; 945 set_buffer_overlays_after (b, NULL);
732 b->overlay_center = BEG; 946 b->overlay_center = BEG;
733 BVAR (b, mark_active) = Qnil; 947 bset_mark_active (b, Qnil);
734 BVAR (b, point_before_scroll) = Qnil; 948 bset_point_before_scroll (b, Qnil);
735 BVAR (b, file_format) = Qnil; 949 bset_file_format (b, Qnil);
736 BVAR (b, auto_save_file_format) = Qt; 950 bset_auto_save_file_format (b, Qt);
737 BVAR (b, last_selected_window) = Qnil; 951 bset_last_selected_window (b, Qnil);
738 XSETINT (BVAR (b, display_count), 0); 952 bset_display_count (b, make_number (0));
739 BVAR (b, display_time) = Qnil; 953 bset_display_time (b, Qnil);
740 BVAR (b, enable_multibyte_characters) = BVAR (&buffer_defaults, enable_multibyte_characters); 954 bset_enable_multibyte_characters
741 BVAR (b, cursor_type) = BVAR (&buffer_defaults, cursor_type); 955 (b, BVAR (&buffer_defaults, enable_multibyte_characters));
742 BVAR (b, extra_line_spacing) = BVAR (&buffer_defaults, extra_line_spacing); 956 bset_cursor_type (b, BVAR (&buffer_defaults, cursor_type));
957 bset_extra_line_spacing (b, BVAR (&buffer_defaults, extra_line_spacing));
743 958
744 b->display_error_modiff = 0; 959 b->display_error_modiff = 0;
745} 960}
@@ -749,24 +964,22 @@ reset_buffer (register struct buffer *b)
749 it does not treat permanent locals consistently. 964 it does not treat permanent locals consistently.
750 Instead, use Fkill_all_local_variables. 965 Instead, use Fkill_all_local_variables.
751 966
752 If PERMANENT_TOO is 1, then we reset permanent 967 If PERMANENT_TOO, reset permanent buffer-local variables.
753 buffer-local variables. If PERMANENT_TOO is 0, 968 If not, preserve those. */
754 we preserve those. */
755 969
756static void 970static void
757reset_buffer_local_variables (register struct buffer *b, int permanent_too) 971reset_buffer_local_variables (struct buffer *b, bool permanent_too)
758{ 972{
759 register int offset; 973 int offset, i;
760 int i;
761 974
762 /* Reset the major mode to Fundamental, together with all the 975 /* Reset the major mode to Fundamental, together with all the
763 things that depend on the major mode. 976 things that depend on the major mode.
764 default-major-mode is handled at a higher level. 977 default-major-mode is handled at a higher level.
765 We ignore it here. */ 978 We ignore it here. */
766 BVAR (b, major_mode) = Qfundamental_mode; 979 bset_major_mode (b, Qfundamental_mode);
767 BVAR (b, keymap) = Qnil; 980 bset_keymap (b, Qnil);
768 BVAR (b, mode_name) = QSFundamental; 981 bset_mode_name (b, QSFundamental);
769 BVAR (b, minor_modes) = Qnil; 982 bset_minor_modes (b, Qnil);
770 983
771 /* If the standard case table has been altered and invalidated, 984 /* If the standard case table has been altered and invalidated,
772 fix up its insides first. */ 985 fix up its insides first. */
@@ -775,15 +988,15 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
775 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[2]))) 988 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[2])))
776 Fset_standard_case_table (Vascii_downcase_table); 989 Fset_standard_case_table (Vascii_downcase_table);
777 990
778 BVAR (b, downcase_table) = Vascii_downcase_table; 991 bset_downcase_table (b, Vascii_downcase_table);
779 BVAR (b, upcase_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[0]; 992 bset_upcase_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[0]);
780 BVAR (b, case_canon_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[1]; 993 bset_case_canon_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[1]);
781 BVAR (b, case_eqv_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[2]; 994 bset_case_eqv_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[2]);
782 BVAR (b, invisibility_spec) = Qt; 995 bset_invisibility_spec (b, Qt);
783 996
784 /* Reset all (or most) per-buffer variables to their defaults. */ 997 /* Reset all (or most) per-buffer variables to their defaults. */
785 if (permanent_too) 998 if (permanent_too)
786 BVAR (b, local_var_alist) = Qnil; 999 bset_local_var_alist (b, Qnil);
787 else 1000 else
788 { 1001 {
789 Lisp_Object tmp, prop, last = Qnil; 1002 Lisp_Object tmp, prop, last = Qnil;
@@ -817,7 +1030,7 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
817 } 1030 }
818 /* Delete this local variable. */ 1031 /* Delete this local variable. */
819 else if (NILP (last)) 1032 else if (NILP (last))
820 BVAR (b, local_var_alist) = XCDR (tmp); 1033 bset_local_var_alist (b, XCDR (tmp));
821 else 1034 else
822 XSETCDR (last, XCDR (tmp)); 1035 XSETCDR (last, XCDR (tmp));
823 } 1036 }
@@ -826,20 +1039,14 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
826 if (permanent_too || buffer_permanent_local_flags[i] == 0) 1039 if (permanent_too || buffer_permanent_local_flags[i] == 0)
827 SET_PER_BUFFER_VALUE_P (b, i, 0); 1040 SET_PER_BUFFER_VALUE_P (b, i, 0);
828 1041
829 /* For each slot that has a default value, 1042 /* For each slot that has a default value, copy that into the slot. */
830 copy that into the slot. */ 1043 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
831
832 /* buffer-local Lisp variables start at `undo_list',
833 tho only the ones from `name' on are GC'd normally. */
834 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
835 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
836 offset += sizeof (Lisp_Object))
837 { 1044 {
838 int idx = PER_BUFFER_IDX (offset); 1045 int idx = PER_BUFFER_IDX (offset);
839 if ((idx > 0 1046 if ((idx > 0
840 && (permanent_too 1047 && (permanent_too
841 || buffer_permanent_local_flags[idx] == 0))) 1048 || buffer_permanent_local_flags[idx] == 0)))
842 PER_BUFFER_VALUE (b, offset) = PER_BUFFER_DEFAULT (offset); 1049 set_per_buffer_value (b, offset, per_buffer_default (offset));
843 } 1050 }
844} 1051}
845 1052
@@ -854,12 +1061,16 @@ If there is no live buffer named NAME, then return NAME.
854Otherwise modify name by appending `<NUMBER>', incrementing NUMBER 1061Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
855\(starting at 2) until an unused name is found, and then return that name. 1062\(starting at 2) until an unused name is found, and then return that name.
856Optional second argument IGNORE specifies a name that is okay to use (if 1063Optional second argument IGNORE specifies a name that is okay to use (if
857it is in the sequence to be tried) even if a buffer with that name exists. */) 1064it is in the sequence to be tried) even if a buffer with that name exists.
1065
1066If NAME begins with a space (i.e., a buffer that is not normally
1067visible to users), then if buffer NAME already exists a random number
1068is first appended to NAME, to speed up finding a non-existent buffer. */)
858 (register Lisp_Object name, Lisp_Object ignore) 1069 (register Lisp_Object name, Lisp_Object ignore)
859{ 1070{
860 register Lisp_Object gentemp, tem; 1071 register Lisp_Object gentemp, tem, tem2;
861 EMACS_INT count; 1072 ptrdiff_t count;
862 char number[INT_BUFSIZE_BOUND (EMACS_INT) + sizeof "<>"]; 1073 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
863 1074
864 CHECK_STRING (name); 1075 CHECK_STRING (name);
865 1076
@@ -870,11 +1081,24 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
870 if (NILP (tem)) 1081 if (NILP (tem))
871 return name; 1082 return name;
872 1083
1084 if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
1085 {
1086 /* Note fileio.c:make_temp_name does random differently. */
1087 tem2 = concat2 (name, make_formatted_string
1088 (number, "-%"pI"d",
1089 XFASTINT (Frandom (make_number (999999)))));
1090 tem = Fget_buffer (tem2);
1091 if (NILP (tem))
1092 return tem2;
1093 }
1094 else
1095 tem2 = name;
1096
873 count = 1; 1097 count = 1;
874 while (1) 1098 while (1)
875 { 1099 {
876 sprintf (number, "<%"pI"d>", ++count); 1100 gentemp = concat2 (tem2, make_formatted_string
877 gentemp = concat2 (name, build_string (number)); 1101 (number, "<%"pD"d>", ++count));
878 tem = Fstring_equal (gentemp, ignore); 1102 tem = Fstring_equal (gentemp, ignore);
879 if (!NILP (tem)) 1103 if (!NILP (tem))
880 return gentemp; 1104 return gentemp;
@@ -939,6 +1163,21 @@ If VARIABLE does not have a buffer-local binding in BUFFER, the value
939is the default binding of the variable. */) 1163is the default binding of the variable. */)
940 (register Lisp_Object variable, register Lisp_Object buffer) 1164 (register Lisp_Object variable, register Lisp_Object buffer)
941{ 1165{
1166 register Lisp_Object result = buffer_local_value_1 (variable, buffer);
1167
1168 if (EQ (result, Qunbound))
1169 xsignal1 (Qvoid_variable, variable);
1170
1171 return result;
1172}
1173
1174
1175/* Like Fbuffer_local_value, but return Qunbound if the variable is
1176 locally unbound. */
1177
1178Lisp_Object
1179buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer)
1180{
942 register struct buffer *buf; 1181 register struct buffer *buf;
943 register Lisp_Object result; 1182 register Lisp_Object result;
944 struct Lisp_Symbol *sym; 1183 struct Lisp_Symbol *sym;
@@ -983,29 +1222,28 @@ is the default binding of the variable. */)
983 { 1222 {
984 union Lisp_Fwd *fwd = SYMBOL_FWD (sym); 1223 union Lisp_Fwd *fwd = SYMBOL_FWD (sym);
985 if (BUFFER_OBJFWDP (fwd)) 1224 if (BUFFER_OBJFWDP (fwd))
986 result = PER_BUFFER_VALUE (buf, XBUFFER_OBJFWD (fwd)->offset); 1225 result = per_buffer_value (buf, XBUFFER_OBJFWD (fwd)->offset);
987 else 1226 else
988 result = Fdefault_value (variable); 1227 result = Fdefault_value (variable);
989 break; 1228 break;
990 } 1229 }
991 default: abort (); 1230 default: emacs_abort ();
992 } 1231 }
993 1232
994 if (!EQ (result, Qunbound)) 1233 return result;
995 return result;
996
997 xsignal1 (Qvoid_variable, variable);
998} 1234}
999 1235
1000/* Return an alist of the Lisp-level buffer-local bindings of 1236/* Return an alist of the Lisp-level buffer-local bindings of
1001 buffer BUF. That is, don't include the variables maintained 1237 buffer BUF. That is, don't include the variables maintained
1002 in special slots in the buffer object. */ 1238 in special slots in the buffer object.
1239 If not CLONE, replace elements of the form (VAR . unbound)
1240 by VAR. */
1003 1241
1004static Lisp_Object 1242static Lisp_Object
1005buffer_lisp_local_variables (struct buffer *buf) 1243buffer_lisp_local_variables (struct buffer *buf, bool clone)
1006{ 1244{
1007 Lisp_Object result = Qnil; 1245 Lisp_Object result = Qnil;
1008 register Lisp_Object tail; 1246 Lisp_Object tail;
1009 for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail)) 1247 for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail))
1010 { 1248 {
1011 Lisp_Object val, elt; 1249 Lisp_Object val, elt;
@@ -1022,7 +1260,10 @@ buffer_lisp_local_variables (struct buffer *buf)
1022 if (buf != current_buffer) 1260 if (buf != current_buffer)
1023 val = XCDR (elt); 1261 val = XCDR (elt);
1024 1262
1025 result = Fcons (Fcons (XCAR (elt), val), result); 1263 result = Fcons (!clone && EQ (val, Qunbound)
1264 ? XCAR (elt)
1265 : Fcons (XCAR (elt), val),
1266 result);
1026 } 1267 }
1027 1268
1028 return result; 1269 return result;
@@ -1048,25 +1289,23 @@ No argument or nil as argument means use current buffer as BUFFER. */)
1048 buf = XBUFFER (buffer); 1289 buf = XBUFFER (buffer);
1049 } 1290 }
1050 1291
1051 result = buffer_lisp_local_variables (buf); 1292 result = buffer_lisp_local_variables (buf, 0);
1052 1293
1053 /* Add on all the variables stored in special slots. */ 1294 /* Add on all the variables stored in special slots. */
1054 { 1295 {
1055 int offset, idx; 1296 int offset, idx;
1056 1297
1057 /* buffer-local Lisp variables start at `undo_list', 1298 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
1058 tho only the ones from `name' on are GC'd normally. */
1059 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
1060 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
1061 /* sizeof EMACS_INT == sizeof Lisp_Object */
1062 offset += (sizeof (EMACS_INT)))
1063 { 1299 {
1064 idx = PER_BUFFER_IDX (offset); 1300 idx = PER_BUFFER_IDX (offset);
1065 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) 1301 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1066 && SYMBOLP (PER_BUFFER_SYMBOL (offset))) 1302 && SYMBOLP (PER_BUFFER_SYMBOL (offset)))
1067 result = Fcons (Fcons (PER_BUFFER_SYMBOL (offset), 1303 {
1068 PER_BUFFER_VALUE (buf, offset)), 1304 Lisp_Object sym = PER_BUFFER_SYMBOL (offset);
1069 result); 1305 Lisp_Object val = per_buffer_value (buf, offset);
1306 result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val),
1307 result);
1308 }
1070 } 1309 }
1071 } 1310 }
1072 1311
@@ -1095,21 +1334,23 @@ DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p,
1095 1, 1, 0, 1334 1, 1, 0,
1096 doc: /* Mark current buffer as modified or unmodified according to FLAG. 1335 doc: /* Mark current buffer as modified or unmodified according to FLAG.
1097A non-nil FLAG means mark the buffer modified. */) 1336A non-nil FLAG means mark the buffer modified. */)
1098 (register Lisp_Object flag) 1337 (Lisp_Object flag)
1099{ 1338{
1100 register int already; 1339 Lisp_Object fn, buffer, window;
1101 register Lisp_Object fn;
1102 Lisp_Object buffer, window;
1103 1340
1104#ifdef CLASH_DETECTION 1341#ifdef CLASH_DETECTION
1105 /* If buffer becoming modified, lock the file. 1342 /* If buffer becoming modified, lock the file.
1106 If buffer becoming unmodified, unlock the file. */ 1343 If buffer becoming unmodified, unlock the file. */
1107 1344
1108 fn = BVAR (current_buffer, file_truename); 1345 struct buffer *b = current_buffer->base_buffer
1346 ? current_buffer->base_buffer
1347 : current_buffer;
1348
1349 fn = BVAR (b, file_truename);
1109 /* Test buffer-file-name so that binding it to nil is effective. */ 1350 /* Test buffer-file-name so that binding it to nil is effective. */
1110 if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) 1351 if (!NILP (fn) && ! NILP (BVAR (b, filename)))
1111 { 1352 {
1112 already = SAVE_MODIFF < MODIFF; 1353 bool already = SAVE_MODIFF < MODIFF;
1113 if (!already && !NILP (flag)) 1354 if (!already && !NILP (flag))
1114 lock_file (fn); 1355 lock_file (fn);
1115 else if (already && NILP (flag)) 1356 else if (already && NILP (flag))
@@ -1176,7 +1417,7 @@ state of the current buffer. Use with care. */)
1176 /* Test buffer-file-name so that binding it to nil is effective. */ 1417 /* Test buffer-file-name so that binding it to nil is effective. */
1177 if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) 1418 if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename)))
1178 { 1419 {
1179 int already = SAVE_MODIFF < MODIFF; 1420 bool already = SAVE_MODIFF < MODIFF;
1180 if (!already && !NILP (flag)) 1421 if (!already && !NILP (flag))
1181 lock_file (fn); 1422 lock_file (fn);
1182 else if (already && NILP (flag)) 1423 else if (already && NILP (flag))
@@ -1268,7 +1509,7 @@ This does not change the name of the visited file (if any). */)
1268 error ("Buffer name `%s' is in use", SDATA (newname)); 1509 error ("Buffer name `%s' is in use", SDATA (newname));
1269 } 1510 }
1270 1511
1271 BVAR (current_buffer, name) = newname; 1512 bset_name (current_buffer, newname);
1272 1513
1273 /* Catch redisplay's attention. Unless we do this, the mode lines for 1514 /* Catch redisplay's attention. Unless we do this, the mode lines for
1274 any windows displaying current_buffer will stay unchanged. */ 1515 any windows displaying current_buffer will stay unchanged. */
@@ -1301,23 +1542,16 @@ list first, followed by the list of all buffers. If no other buffer
1301exists, return the buffer `*scratch*' (creating it if necessary). */) 1542exists, return the buffer `*scratch*' (creating it if necessary). */)
1302 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) 1543 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
1303{ 1544{
1304 Lisp_Object Fset_buffer_major_mode (Lisp_Object buffer); 1545 struct frame *f = decode_any_frame (frame);
1305 Lisp_Object tail, buf, pred; 1546 Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
1306 Lisp_Object notsogood = Qnil; 1547 Lisp_Object buf, notsogood = Qnil;
1307
1308 if (NILP (frame))
1309 frame = selected_frame;
1310
1311 CHECK_FRAME (frame);
1312 1548
1313 pred = frame_buffer_predicate (frame);
1314 /* Consider buffers that have been seen in the frame first. */ 1549 /* Consider buffers that have been seen in the frame first. */
1315 tail = XFRAME (frame)->buffer_list;
1316 for (; CONSP (tail); tail = XCDR (tail)) 1550 for (; CONSP (tail); tail = XCDR (tail))
1317 { 1551 {
1318 buf = XCAR (tail); 1552 buf = XCAR (tail);
1319 if (BUFFERP (buf) && !EQ (buf, buffer) 1553 if (BUFFERP (buf) && !EQ (buf, buffer)
1320 && !NILP (BVAR (XBUFFER (buf), name)) 1554 && BUFFER_LIVE_P (XBUFFER (buf))
1321 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') 1555 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1322 /* If the frame has a buffer_predicate, disregard buffers that 1556 /* If the frame has a buffer_predicate, disregard buffers that
1323 don't fit the predicate. */ 1557 don't fit the predicate. */
@@ -1337,7 +1571,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1337 { 1571 {
1338 buf = Fcdr (XCAR (tail)); 1572 buf = Fcdr (XCAR (tail));
1339 if (BUFFERP (buf) && !EQ (buf, buffer) 1573 if (BUFFERP (buf) && !EQ (buf, buffer)
1340 && !NILP (BVAR (XBUFFER (buf), name)) 1574 && BUFFER_LIVE_P (XBUFFER (buf))
1341 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') 1575 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1342 /* If the frame has a buffer_predicate, disregard buffers that 1576 /* If the frame has a buffer_predicate, disregard buffers that
1343 don't fit the predicate. */ 1577 don't fit the predicate. */
@@ -1372,7 +1606,6 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1372Lisp_Object 1606Lisp_Object
1373other_buffer_safely (Lisp_Object buffer) 1607other_buffer_safely (Lisp_Object buffer)
1374{ 1608{
1375 Lisp_Object Fset_buffer_major_mode (Lisp_Object buffer);
1376 Lisp_Object tail, buf; 1609 Lisp_Object tail, buf;
1377 1610
1378 tail = Vbuffer_alist; 1611 tail = Vbuffer_alist;
@@ -1380,7 +1613,7 @@ other_buffer_safely (Lisp_Object buffer)
1380 { 1613 {
1381 buf = Fcdr (XCAR (tail)); 1614 buf = Fcdr (XCAR (tail));
1382 if (BUFFERP (buf) && !EQ (buf, buffer) 1615 if (BUFFERP (buf) && !EQ (buf, buffer)
1383 && !NILP (BVAR (XBUFFER (buf), name)) 1616 && BUFFER_LIVE_P (XBUFFER (buf))
1384 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')) 1617 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' '))
1385 return buf; 1618 return buf;
1386 } 1619 }
@@ -1413,33 +1646,67 @@ No argument or nil as argument means do this for the current buffer. */)
1413 } 1646 }
1414 1647
1415 if (EQ (BVAR (XBUFFER (real_buffer), undo_list), Qt)) 1648 if (EQ (BVAR (XBUFFER (real_buffer), undo_list), Qt))
1416 BVAR (XBUFFER (real_buffer), undo_list) = Qnil; 1649 bset_undo_list (XBUFFER (real_buffer), Qnil);
1417 1650
1418 return Qnil; 1651 return Qnil;
1419} 1652}
1420 1653
1421/* 1654/* Truncate undo list and shrink the gap of BUFFER. */
1422 DEFVAR_LISP ("kill-buffer-hook", ..., "\ 1655
1423Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ 1656void
1424The buffer being killed will be current while the hook is running.\n\ 1657compact_buffer (struct buffer *buffer)
1425See `kill-buffer'." 1658{
1426 */ 1659 BUFFER_CHECK_INDIRECTION (buffer);
1660
1661 /* Skip dead buffers, indirect buffers and buffers
1662 which aren't changed since last compaction. */
1663 if (BUFFER_LIVE_P (buffer)
1664 && (buffer->base_buffer == NULL)
1665 && (buffer->text->compact != buffer->text->modiff))
1666 {
1667 /* If a buffer's undo list is Qt, that means that undo is
1668 turned off in that buffer. Calling truncate_undo_list on
1669 Qt tends to return NULL, which effectively turns undo back on.
1670 So don't call truncate_undo_list if undo_list is Qt. */
1671 if (!EQ (buffer->INTERNAL_FIELD (undo_list), Qt))
1672 truncate_undo_list (buffer);
1673
1674 /* Shrink buffer gaps. */
1675 if (!buffer->text->inhibit_shrinking)
1676 {
1677 /* If a buffer's gap size is more than 10% of the buffer
1678 size, or larger than 2000 bytes, then shrink it
1679 accordingly. Keep a minimum size of 20 bytes. */
1680 int size = min (2000, max (20, (buffer->text->z_byte / 10)));
1681
1682 if (buffer->text->gap_size > size)
1683 {
1684 struct buffer *save_current = current_buffer;
1685 current_buffer = buffer;
1686 make_gap (-(buffer->text->gap_size - size));
1687 current_buffer = save_current;
1688 }
1689 }
1690 buffer->text->compact = buffer->text->modiff;
1691 }
1692}
1693
1427DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ", 1694DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
1428 doc: /* Kill buffer BUFFER-OR-NAME. 1695 doc: /* Kill the buffer specified by BUFFER-OR-NAME.
1429The argument may be a buffer or the name of an existing buffer. 1696The argument may be a buffer or the name of an existing buffer.
1430Argument nil or omitted means kill the current buffer. Return t if the 1697Argument nil or omitted means kill the current buffer. Return t if the
1431buffer is actually killed, nil otherwise. 1698buffer is actually killed, nil otherwise.
1432 1699
1433This function calls `replace-buffer-in-windows' for cleaning up all 1700The functions in `kill-buffer-query-functions' are called with the
1434windows currently displaying the buffer to be killed. The functions in 1701buffer to be killed as the current buffer. If any of them returns nil,
1435`kill-buffer-query-functions' are called with the buffer to be killed as 1702the buffer is not killed. The hook `kill-buffer-hook' is run before the
1436the current buffer. If any of them returns nil, the buffer is not 1703buffer is actually killed. The buffer being killed will be current
1437killed. The hook `kill-buffer-hook' is run before the buffer is 1704while the hook is running. Functions called by any of these hooks are
1438actually killed. The buffer being killed will be current while the hook 1705supposed to not change the current buffer.
1439is running.
1440 1706
1441Any processes that have this buffer as the `process-buffer' are killed 1707Any processes that have this buffer as the `process-buffer' are killed
1442with SIGHUP. */) 1708with SIGHUP. This function calls `replace-buffer-in-windows' for
1709cleaning up all windows currently displaying the buffer to be killed. */)
1443 (Lisp_Object buffer_or_name) 1710 (Lisp_Object buffer_or_name)
1444{ 1711{
1445 Lisp_Object buffer; 1712 Lisp_Object buffer;
@@ -1458,7 +1725,7 @@ with SIGHUP. */)
1458 b = XBUFFER (buffer); 1725 b = XBUFFER (buffer);
1459 1726
1460 /* Avoid trouble for buffer already dead. */ 1727 /* Avoid trouble for buffer already dead. */
1461 if (NILP (BVAR (b, name))) 1728 if (!BUFFER_LIVE_P (b))
1462 return Qnil; 1729 return Qnil;
1463 1730
1464 /* Query if the buffer is still modified. */ 1731 /* Query if the buffer is still modified. */
@@ -1475,7 +1742,7 @@ with SIGHUP. */)
1475 1742
1476 /* Run hooks with the buffer to be killed the current buffer. */ 1743 /* Run hooks with the buffer to be killed the current buffer. */
1477 { 1744 {
1478 int count = SPECPDL_INDEX (); 1745 ptrdiff_t count = SPECPDL_INDEX ();
1479 Lisp_Object arglist[1]; 1746 Lisp_Object arglist[1];
1480 1747
1481 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1748 record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -1493,6 +1760,10 @@ with SIGHUP. */)
1493 unbind_to (count, Qnil); 1760 unbind_to (count, Qnil);
1494 } 1761 }
1495 1762
1763 /* If the hooks have killed the buffer, exit now. */
1764 if (!BUFFER_LIVE_P (b))
1765 return Qt;
1766
1496 /* We have no more questions to ask. Verify that it is valid 1767 /* We have no more questions to ask. Verify that it is valid
1497 to kill the buffer. This must be done after the questions 1768 to kill the buffer. This must be done after the questions
1498 since anything can happen within do_yes_or_no_p. */ 1769 since anything can happen within do_yes_or_no_p. */
@@ -1501,22 +1772,18 @@ with SIGHUP. */)
1501 if (EQ (buffer, XWINDOW (minibuf_window)->buffer)) 1772 if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
1502 return Qnil; 1773 return Qnil;
1503 1774
1504 if (NILP (BVAR (b, name))) 1775 /* When we kill an ordinary buffer which shares it's buffer text
1505 return Qnil; 1776 with indirect buffer(s), we must kill indirect buffer(s) too.
1506
1507 /* When we kill a base buffer, kill all its indirect buffers.
1508 We do it at this stage so nothing terrible happens if they 1777 We do it at this stage so nothing terrible happens if they
1509 ask questions or their hooks get errors. */ 1778 ask questions or their hooks get errors. */
1510 if (! b->base_buffer) 1779 if (!b->base_buffer && b->indirections > 0)
1511 { 1780 {
1512 struct buffer *other; 1781 struct buffer *other;
1513 1782
1514 GCPRO1 (buffer); 1783 GCPRO1 (buffer);
1515 1784
1516 for (other = all_buffers; other; other = other->header.next.buffer) 1785 FOR_EACH_BUFFER (other)
1517 /* all_buffers contains dead buffers too; 1786 if (other->base_buffer == b)
1518 don't re-kill them. */
1519 if (other->base_buffer == b && !NILP (BVAR (other, name)))
1520 { 1787 {
1521 Lisp_Object buf; 1788 Lisp_Object buf;
1522 XSETBUFFER (buf, other); 1789 XSETBUFFER (buf, other);
@@ -1524,6 +1791,10 @@ with SIGHUP. */)
1524 } 1791 }
1525 1792
1526 UNGCPRO; 1793 UNGCPRO;
1794
1795 /* Exit if we now have killed the base buffer (Bug#11665). */
1796 if (!BUFFER_LIVE_P (b))
1797 return Qt;
1527 } 1798 }
1528 1799
1529 /* Run replace_buffer_in_windows before making another buffer current 1800 /* Run replace_buffer_in_windows before making another buffer current
@@ -1532,9 +1803,12 @@ with SIGHUP. */)
1532 buffer. (Bug#10114) */ 1803 buffer. (Bug#10114) */
1533 replace_buffer_in_windows (buffer); 1804 replace_buffer_in_windows (buffer);
1534 1805
1535 /* Make this buffer not be current. 1806 /* Exit if replacing the buffer in windows has killed our buffer. */
1536 In the process, notice if this is the sole visible buffer 1807 if (!BUFFER_LIVE_P (b))
1537 and give up if so. */ 1808 return Qt;
1809
1810 /* Make this buffer not be current. Exit if it is the sole visible
1811 buffer. */
1538 if (b == current_buffer) 1812 if (b == current_buffer)
1539 { 1813 {
1540 tem = Fother_buffer (buffer, Qnil, Qnil); 1814 tem = Fother_buffer (buffer, Qnil, Qnil);
@@ -1543,15 +1817,12 @@ with SIGHUP. */)
1543 return Qnil; 1817 return Qnil;
1544 } 1818 }
1545 1819
1546 /* Notice if the buffer to kill is the sole visible buffer 1820 /* If the buffer now current is shown in the minibuffer and our buffer
1547 when we're currently in the mini-buffer, and give up if so. */ 1821 is the sole other buffer give up. */
1548 XSETBUFFER (tem, current_buffer); 1822 XSETBUFFER (tem, current_buffer);
1549 if (EQ (tem, XWINDOW (minibuf_window)->buffer)) 1823 if (EQ (tem, XWINDOW (minibuf_window)->buffer)
1550 { 1824 && EQ (buffer, Fother_buffer (buffer, Qnil, Qnil)))
1551 tem = Fother_buffer (buffer, Qnil, Qnil); 1825 return Qnil;
1552 if (EQ (buffer, tem))
1553 return Qnil;
1554 }
1555 1826
1556 /* Now there is no question: we can kill the buffer. */ 1827 /* Now there is no question: we can kill the buffer. */
1557 1828
@@ -1564,11 +1835,10 @@ with SIGHUP. */)
1564 kill_buffer_processes (buffer); 1835 kill_buffer_processes (buffer);
1565 UNGCPRO; 1836 UNGCPRO;
1566 1837
1567 /* Killing buffer processes may run sentinels which may 1838 /* Killing buffer processes may run sentinels which may have killed
1568 have called kill-buffer. */ 1839 our buffer. */
1569 1840 if (!BUFFER_LIVE_P (b))
1570 if (NILP (BVAR (b, name))) 1841 return Qt;
1571 return Qnil;
1572 1842
1573 /* These may run Lisp code and into infinite loops (if someone 1843 /* These may run Lisp code and into infinite loops (if someone
1574 insisted on circular lists) so allow quitting here. */ 1844 insisted on circular lists) so allow quitting here. */
@@ -1580,8 +1850,7 @@ with SIGHUP. */)
1580 Vinhibit_quit = Qt; 1850 Vinhibit_quit = Qt;
1581 /* Remove the buffer from the list of all buffers. */ 1851 /* Remove the buffer from the list of all buffers. */
1582 Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist); 1852 Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist);
1583 /* If replace_buffer_in_windows didn't do its job correctly fix that 1853 /* If replace_buffer_in_windows didn't do its job fix that now. */
1584 now. */
1585 replace_buffer_in_windows_safely (buffer); 1854 replace_buffer_in_windows_safely (buffer);
1586 Vinhibit_quit = tem; 1855 Vinhibit_quit = tem;
1587 1856
@@ -1599,17 +1868,25 @@ with SIGHUP. */)
1599 internal_delete_file (BVAR (b, auto_save_file_name)); 1868 internal_delete_file (BVAR (b, auto_save_file_name));
1600 } 1869 }
1601 1870
1871 /* Deleting an auto-save file could have killed our buffer. */
1872 if (!BUFFER_LIVE_P (b))
1873 return Qt;
1874
1602 if (b->base_buffer) 1875 if (b->base_buffer)
1603 { 1876 {
1604 /* Unchain all markers that belong to this indirect buffer. 1877 /* Unchain all markers that belong to this indirect buffer.
1605 Don't unchain the markers that belong to the base buffer 1878 Don't unchain the markers that belong to the base buffer
1606 or its other indirect buffers. */ 1879 or its other indirect buffers. */
1607 for (m = BUF_MARKERS (b); m; ) 1880 struct Lisp_Marker **mp = &BUF_MARKERS (b);
1881 while ((m = *mp))
1608 { 1882 {
1609 struct Lisp_Marker *next = m->next;
1610 if (m->buffer == b) 1883 if (m->buffer == b)
1611 unchain_marker (m); 1884 {
1612 m = next; 1885 m->buffer = NULL;
1886 *mp = m->next;
1887 }
1888 else
1889 mp = &m->next;
1613 } 1890 }
1614 } 1891 }
1615 else 1892 else
@@ -1624,10 +1901,14 @@ with SIGHUP. */)
1624 m = next; 1901 m = next;
1625 } 1902 }
1626 BUF_MARKERS (b) = NULL; 1903 BUF_MARKERS (b) = NULL;
1627 BUF_INTERVALS (b) = NULL_INTERVAL; 1904 set_buffer_intervals (b, NULL);
1628 1905
1629 /* Perhaps we should explicitly free the interval tree here... */ 1906 /* Perhaps we should explicitly free the interval tree here... */
1630 } 1907 }
1908 /* Since we've unlinked the markers, the overlays can't be here any more
1909 either. */
1910 b->overlays_before = NULL;
1911 b->overlays_after = NULL;
1631 1912
1632 /* Reset the local variables, so that this buffer's local values 1913 /* Reset the local variables, so that this buffer's local values
1633 won't be protected from GC. They would be protected 1914 won't be protected from GC. They would be protected
@@ -1636,10 +1917,18 @@ with SIGHUP. */)
1636 swap_out_buffer_local_variables (b); 1917 swap_out_buffer_local_variables (b);
1637 reset_buffer_local_variables (b, 1); 1918 reset_buffer_local_variables (b, 1);
1638 1919
1639 BVAR (b, name) = Qnil; 1920 bset_name (b, Qnil);
1640 1921
1641 BLOCK_INPUT; 1922 block_input ();
1642 if (! b->base_buffer) 1923 if (b->base_buffer)
1924 {
1925 /* Notify our base buffer that we don't share the text anymore. */
1926 eassert (b->indirections == -1);
1927 b->base_buffer->indirections--;
1928 eassert (b->base_buffer->indirections >= 0);
1929 }
1930 else
1931 /* No one shares our buffer text, can free it. */
1643 free_buffer_text (b); 1932 free_buffer_text (b);
1644 1933
1645 if (b->newline_cache) 1934 if (b->newline_cache)
@@ -1652,9 +1941,9 @@ with SIGHUP. */)
1652 free_region_cache (b->width_run_cache); 1941 free_region_cache (b->width_run_cache);
1653 b->width_run_cache = 0; 1942 b->width_run_cache = 0;
1654 } 1943 }
1655 BVAR (b, width_table) = Qnil; 1944 bset_width_table (b, Qnil);
1656 UNBLOCK_INPUT; 1945 unblock_input ();
1657 BVAR (b, undo_list) = Qnil; 1946 bset_undo_list (b, Qnil);
1658 1947
1659 /* Run buffer-list-update-hook. */ 1948 /* Run buffer-list-update-hook. */
1660 if (!NILP (Vrun_hooks)) 1949 if (!NILP (Vrun_hooks))
@@ -1695,8 +1984,8 @@ record_buffer (Lisp_Object buffer)
1695 Vinhibit_quit = tem; 1984 Vinhibit_quit = tem;
1696 1985
1697 /* Update buffer list of selected frame. */ 1986 /* Update buffer list of selected frame. */
1698 f->buffer_list = Fcons (buffer, Fdelq (buffer, f->buffer_list)); 1987 fset_buffer_list (f, Fcons (buffer, Fdelq (buffer, f->buffer_list)));
1699 f->buried_buffer_list = Fdelq (buffer, f->buried_buffer_list); 1988 fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list));
1700 1989
1701 /* Run buffer-list-update-hook. */ 1990 /* Run buffer-list-update-hook. */
1702 if (!NILP (Vrun_hooks)) 1991 if (!NILP (Vrun_hooks))
@@ -1707,7 +1996,7 @@ record_buffer (Lisp_Object buffer)
1707/* Move BUFFER to the end of the buffer (a)lists. Do nothing if the 1996/* Move BUFFER to the end of the buffer (a)lists. Do nothing if the
1708 buffer is killed. For the selected frame's buffer list this moves 1997 buffer is killed. For the selected frame's buffer list this moves
1709 BUFFER to its end even if it was never shown in that frame. If 1998 BUFFER to its end even if it was never shown in that frame. If
1710 this happens we have a feature, hence `unrecord-buffer' should be 1999 this happens we have a feature, hence `bury-buffer-internal' should be
1711 called only when BUFFER was shown in the selected frame. */ 2000 called only when BUFFER was shown in the selected frame. */
1712 2001
1713DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, 2002DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
@@ -1733,8 +2022,9 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
1733 Vinhibit_quit = tem; 2022 Vinhibit_quit = tem;
1734 2023
1735 /* Update buffer lists of selected frame. */ 2024 /* Update buffer lists of selected frame. */
1736 f->buffer_list = Fdelq (buffer, f->buffer_list); 2025 fset_buffer_list (f, Fdelq (buffer, f->buffer_list));
1737 f->buried_buffer_list = Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)); 2026 fset_buried_buffer_list
2027 (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
1738 2028
1739 /* Run buffer-list-update-hook. */ 2029 /* Run buffer-list-update-hook. */
1740 if (!NILP (Vrun_hooks)) 2030 if (!NILP (Vrun_hooks))
@@ -1751,13 +2041,15 @@ Use this function before selecting the buffer, since it may need to inspect
1751the current buffer's major mode. */) 2041the current buffer's major mode. */)
1752 (Lisp_Object buffer) 2042 (Lisp_Object buffer)
1753{ 2043{
1754 int count; 2044 ptrdiff_t count;
1755 Lisp_Object function; 2045 Lisp_Object function;
1756 2046
1757 CHECK_BUFFER (buffer); 2047 CHECK_BUFFER (buffer);
1758 2048
1759 if (STRINGP (BVAR (XBUFFER (buffer), name)) 2049 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
1760 && strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0) 2050 error ("Attempt to set major mode for a dead buffer");
2051
2052 if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0)
1761 function = find_symbol_value (intern ("initial-major-mode")); 2053 function = find_symbol_value (intern ("initial-major-mode"));
1762 else 2054 else
1763 { 2055 {
@@ -1791,22 +2083,6 @@ DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
1791 XSETBUFFER (buf, current_buffer); 2083 XSETBUFFER (buf, current_buffer);
1792 return buf; 2084 return buf;
1793} 2085}
1794
1795/* Set the current buffer to B.
1796
1797 We previously set windows_or_buffers_changed here to invalidate
1798 global unchanged information in beg_unchanged and end_unchanged.
1799 This is no longer necessary because we now compute unchanged
1800 information on a buffer-basis. Every action affecting other
1801 windows than the selected one requires a select_window at some
1802 time, and that increments windows_or_buffers_changed. */
1803
1804void
1805set_buffer_internal (register struct buffer *b)
1806{
1807 if (current_buffer != b)
1808 set_buffer_internal_1 (b);
1809}
1810 2086
1811/* Set the current buffer to B, and do not set windows_or_buffers_changed. 2087/* Set the current buffer to B, and do not set windows_or_buffers_changed.
1812 This is used by redisplay. */ 2088 This is used by redisplay. */
@@ -1825,6 +2101,8 @@ set_buffer_internal_1 (register struct buffer *b)
1825 if (current_buffer == b) 2101 if (current_buffer == b)
1826 return; 2102 return;
1827 2103
2104 BUFFER_CHECK_INDIRECTION (b);
2105
1828 old_buf = current_buffer; 2106 old_buf = current_buffer;
1829 current_buffer = b; 2107 current_buffer = b;
1830 last_known_column_point = -1; /* invalidate indentation cache */ 2108 last_known_column_point = -1; /* invalidate indentation cache */
@@ -1834,7 +2112,7 @@ set_buffer_internal_1 (register struct buffer *b)
1834 /* Put the undo list back in the base buffer, so that it appears 2112 /* Put the undo list back in the base buffer, so that it appears
1835 that an indirect buffer shares the undo list of its base. */ 2113 that an indirect buffer shares the undo list of its base. */
1836 if (old_buf->base_buffer) 2114 if (old_buf->base_buffer)
1837 BVAR (old_buf->base_buffer, undo_list) = BVAR (old_buf, undo_list); 2115 bset_undo_list (old_buf->base_buffer, BVAR (old_buf, undo_list));
1838 2116
1839 /* If the old current buffer has markers to record PT, BEGV and ZV 2117 /* If the old current buffer has markers to record PT, BEGV and ZV
1840 when it is not current, update them now. */ 2118 when it is not current, update them now. */
@@ -1844,7 +2122,7 @@ set_buffer_internal_1 (register struct buffer *b)
1844 /* Get the undo list from the base buffer, so that it appears 2122 /* Get the undo list from the base buffer, so that it appears
1845 that an indirect buffer shares the undo list of its base. */ 2123 that an indirect buffer shares the undo list of its base. */
1846 if (b->base_buffer) 2124 if (b->base_buffer)
1847 BVAR (b, undo_list) = BVAR (b->base_buffer, undo_list); 2125 bset_undo_list (b, BVAR (b->base_buffer, undo_list));
1848 2126
1849 /* If the new current buffer has markers to record PT, BEGV and ZV 2127 /* If the new current buffer has markers to record PT, BEGV and ZV
1850 when it is not current, fetch them now. */ 2128 when it is not current, fetch them now. */
@@ -1896,7 +2174,7 @@ set_buffer_temp (struct buffer *b)
1896DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, 2174DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
1897 doc: /* Make buffer BUFFER-OR-NAME current for editing operations. 2175 doc: /* Make buffer BUFFER-OR-NAME current for editing operations.
1898BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See 2176BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See
1899also `save-excursion' when you want to make a buffer current 2177also `with-current-buffer' when you want to make a buffer current
1900temporarily. This function does not display the buffer, so its effect 2178temporarily. This function does not display the buffer, so its effect
1901ends when the current command terminates. Use `switch-to-buffer' or 2179ends when the current command terminates. Use `switch-to-buffer' or
1902`pop-to-buffer' to switch buffers permanently. */) 2180`pop-to-buffer' to switch buffers permanently. */)
@@ -1906,19 +2184,19 @@ ends when the current command terminates. Use `switch-to-buffer' or
1906 buffer = Fget_buffer (buffer_or_name); 2184 buffer = Fget_buffer (buffer_or_name);
1907 if (NILP (buffer)) 2185 if (NILP (buffer))
1908 nsberror (buffer_or_name); 2186 nsberror (buffer_or_name);
1909 if (NILP (BVAR (XBUFFER (buffer), name))) 2187 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
1910 error ("Selecting deleted buffer"); 2188 error ("Selecting deleted buffer");
1911 set_buffer_internal (XBUFFER (buffer)); 2189 set_buffer_internal (XBUFFER (buffer));
1912 return buffer; 2190 return buffer;
1913} 2191}
1914 2192
1915/* Set the current buffer to BUFFER provided it is alive. */ 2193/* Set the current buffer to BUFFER provided if it is alive. */
1916 2194
1917Lisp_Object 2195Lisp_Object
1918set_buffer_if_live (Lisp_Object buffer) 2196set_buffer_if_live (Lisp_Object buffer)
1919{ 2197{
1920 if (! NILP (BVAR (XBUFFER (buffer), name))) 2198 if (BUFFER_LIVE_P (XBUFFER (buffer)))
1921 Fset_buffer (buffer); 2199 set_buffer_internal (XBUFFER (buffer));
1922 return Qnil; 2200 return Qnil;
1923} 2201}
1924 2202
@@ -1963,16 +2241,15 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1963 tem = *b; *b = *e; *e = tem; 2241 tem = *b; *b = *e; *e = tem;
1964 } 2242 }
1965 2243
1966 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) 2244 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
1967 && XINT (*e) <= ZV))
1968 args_out_of_range (*b, *e); 2245 args_out_of_range (*b, *e);
1969} 2246}
1970 2247
1971/* Advance BYTE_POS up to a character boundary 2248/* Advance BYTE_POS up to a character boundary
1972 and return the adjusted position. */ 2249 and return the adjusted position. */
1973 2250
1974static EMACS_INT 2251static ptrdiff_t
1975advance_to_char_boundary (EMACS_INT byte_pos) 2252advance_to_char_boundary (ptrdiff_t byte_pos)
1976{ 2253{
1977 int c; 2254 int c;
1978 2255
@@ -1985,7 +2262,7 @@ advance_to_char_boundary (EMACS_INT byte_pos)
1985 { 2262 {
1986 /* We should advance BYTE_POS only when C is a constituent of a 2263 /* We should advance BYTE_POS only when C is a constituent of a
1987 multibyte sequence. */ 2264 multibyte sequence. */
1988 EMACS_INT orig_byte_pos = byte_pos; 2265 ptrdiff_t orig_byte_pos = byte_pos;
1989 2266
1990 do 2267 do
1991 { 2268 {
@@ -2004,10 +2281,6 @@ advance_to_char_boundary (EMACS_INT byte_pos)
2004 return byte_pos; 2281 return byte_pos;
2005} 2282}
2006 2283
2007#ifdef REL_ALLOC
2008extern void r_alloc_reset_variable (POINTER_TYPE *, POINTER_TYPE *);
2009#endif /* REL_ALLOC */
2010
2011DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, 2284DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2012 1, 1, 0, 2285 1, 1, 0,
2013 doc: /* Swap the text between current buffer and BUFFER. */) 2286 doc: /* Swap the text between current buffer and BUFFER. */)
@@ -2017,7 +2290,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2017 CHECK_BUFFER (buffer); 2290 CHECK_BUFFER (buffer);
2018 other_buffer = XBUFFER (buffer); 2291 other_buffer = XBUFFER (buffer);
2019 2292
2020 if (NILP (BVAR (other_buffer, name))) 2293 if (!BUFFER_LIVE_P (other_buffer))
2021 error ("Cannot swap a dead buffer's text"); 2294 error ("Cannot swap a dead buffer's text");
2022 2295
2023 /* Actually, it probably works just fine. 2296 /* Actually, it probably works just fine.
@@ -2032,7 +2305,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2032 2305
2033 { /* This is probably harder to make work. */ 2306 { /* This is probably harder to make work. */
2034 struct buffer *other; 2307 struct buffer *other;
2035 for (other = all_buffers; other; other = other->header.next.buffer) 2308 FOR_EACH_BUFFER (other)
2036 if (other->base_buffer == other_buffer 2309 if (other->base_buffer == other_buffer
2037 || other->base_buffer == current_buffer) 2310 || other->base_buffer == current_buffer)
2038 error ("One of the buffers to swap has indirect buffers"); 2311 error ("One of the buffers to swap has indirect buffers");
@@ -2047,28 +2320,29 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2047#define swapfield_(field, type) \ 2320#define swapfield_(field, type) \
2048 do { \ 2321 do { \
2049 type tmp##field = BVAR (other_buffer, field); \ 2322 type tmp##field = BVAR (other_buffer, field); \
2050 BVAR (other_buffer, field) = BVAR (current_buffer, field); \ 2323 bset_##field (other_buffer, BVAR (current_buffer, field)); \
2051 BVAR (current_buffer, field) = tmp##field; \ 2324 bset_##field (current_buffer, tmp##field); \
2052 } while (0) 2325 } while (0)
2053 2326
2054 swapfield (own_text, struct buffer_text); 2327 swapfield (own_text, struct buffer_text);
2055 eassert (current_buffer->text == &current_buffer->own_text); 2328 eassert (current_buffer->text == &current_buffer->own_text);
2056 eassert (other_buffer->text == &other_buffer->own_text); 2329 eassert (other_buffer->text == &other_buffer->own_text);
2057#ifdef REL_ALLOC 2330#ifdef REL_ALLOC
2058 r_alloc_reset_variable ((POINTER_TYPE **) &current_buffer->own_text.beg, 2331 r_alloc_reset_variable ((void **) &current_buffer->own_text.beg,
2059 (POINTER_TYPE **) &other_buffer->own_text.beg); 2332 (void **) &other_buffer->own_text.beg);
2060 r_alloc_reset_variable ((POINTER_TYPE **) &other_buffer->own_text.beg, 2333 r_alloc_reset_variable ((void **) &other_buffer->own_text.beg,
2061 (POINTER_TYPE **) &current_buffer->own_text.beg); 2334 (void **) &current_buffer->own_text.beg);
2062#endif /* REL_ALLOC */ 2335#endif /* REL_ALLOC */
2063 2336
2064 swapfield (pt, EMACS_INT); 2337 swapfield (pt, ptrdiff_t);
2065 swapfield (pt_byte, EMACS_INT); 2338 swapfield (pt_byte, ptrdiff_t);
2066 swapfield (begv, EMACS_INT); 2339 swapfield (begv, ptrdiff_t);
2067 swapfield (begv_byte, EMACS_INT); 2340 swapfield (begv_byte, ptrdiff_t);
2068 swapfield (zv, EMACS_INT); 2341 swapfield (zv, ptrdiff_t);
2069 swapfield (zv_byte, EMACS_INT); 2342 swapfield (zv_byte, ptrdiff_t);
2070 eassert (!current_buffer->base_buffer); 2343 eassert (!current_buffer->base_buffer);
2071 eassert (!other_buffer->base_buffer); 2344 eassert (!other_buffer->base_buffer);
2345 swapfield (indirections, ptrdiff_t);
2072 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2346 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
2073 swapfield (newline_cache, struct region_cache *); 2347 swapfield (newline_cache, struct region_cache *);
2074 swapfield (width_run_cache, struct region_cache *); 2348 swapfield (width_run_cache, struct region_cache *);
@@ -2076,7 +2350,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2076 other_buffer->prevent_redisplay_optimizations_p = 1; 2350 other_buffer->prevent_redisplay_optimizations_p = 1;
2077 swapfield (overlays_before, struct Lisp_Overlay *); 2351 swapfield (overlays_before, struct Lisp_Overlay *);
2078 swapfield (overlays_after, struct Lisp_Overlay *); 2352 swapfield (overlays_after, struct Lisp_Overlay *);
2079 swapfield (overlay_center, EMACS_INT); 2353 swapfield (overlay_center, ptrdiff_t);
2080 swapfield_ (undo_list, Lisp_Object); 2354 swapfield_ (undo_list, Lisp_Object);
2081 swapfield_ (mark, Lisp_Object); 2355 swapfield_ (mark, Lisp_Object);
2082 swapfield_ (enable_multibyte_characters, Lisp_Object); 2356 swapfield_ (enable_multibyte_characters, Lisp_Object);
@@ -2087,8 +2361,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2087 swapfield_ (pt_marker, Lisp_Object); 2361 swapfield_ (pt_marker, Lisp_Object);
2088 swapfield_ (begv_marker, Lisp_Object); 2362 swapfield_ (begv_marker, Lisp_Object);
2089 swapfield_ (zv_marker, Lisp_Object); 2363 swapfield_ (zv_marker, Lisp_Object);
2090 BVAR (current_buffer, point_before_scroll) = Qnil; 2364 bset_point_before_scroll (current_buffer, Qnil);
2091 BVAR (other_buffer, point_before_scroll) = Qnil; 2365 bset_point_before_scroll (other_buffer, Qnil);
2092 2366
2093 current_buffer->text->modiff++; other_buffer->text->modiff++; 2367 current_buffer->text->modiff++; other_buffer->text->modiff++;
2094 current_buffer->text->chars_modiff++; other_buffer->text->chars_modiff++; 2368 current_buffer->text->chars_modiff++; other_buffer->text->chars_modiff++;
@@ -2128,7 +2402,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2128 && (EQ (XWINDOW (w)->buffer, buf1) 2402 && (EQ (XWINDOW (w)->buffer, buf1)
2129 || EQ (XWINDOW (w)->buffer, buf2))) 2403 || EQ (XWINDOW (w)->buffer, buf2)))
2130 Fset_marker (XWINDOW (w)->pointm, 2404 Fset_marker (XWINDOW (w)->pointm,
2131 make_number (BUF_BEGV (XBUFFER (XWINDOW (w)->buffer))), 2405 make_number
2406 (BUF_BEGV (XBUFFER (XWINDOW (w)->buffer))),
2132 XWINDOW (w)->buffer); 2407 XWINDOW (w)->buffer);
2133 w = Fnext_window (w, Qt, Qt); 2408 w = Fnext_window (w, Qt, Qt);
2134 } 2409 }
@@ -2159,9 +2434,9 @@ current buffer is cleared. */)
2159{ 2434{
2160 struct Lisp_Marker *tail, *markers; 2435 struct Lisp_Marker *tail, *markers;
2161 struct buffer *other; 2436 struct buffer *other;
2162 EMACS_INT begv, zv; 2437 ptrdiff_t begv, zv;
2163 int narrowed = (BEG != BEGV || Z != ZV); 2438 bool narrowed = (BEG != BEGV || Z != ZV);
2164 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2439 bool modified_p = !NILP (Fbuffer_modified_p (Qnil));
2165 Lisp_Object old_undo = BVAR (current_buffer, undo_list); 2440 Lisp_Object old_undo = BVAR (current_buffer, undo_list);
2166 struct gcpro gcpro1; 2441 struct gcpro gcpro1;
2167 2442
@@ -2176,7 +2451,7 @@ current buffer is cleared. */)
2176 2451
2177 /* Don't record these buffer changes. We will put a special undo entry 2452 /* Don't record these buffer changes. We will put a special undo entry
2178 instead. */ 2453 instead. */
2179 BVAR (current_buffer, undo_list) = Qt; 2454 bset_undo_list (current_buffer, Qt);
2180 2455
2181 /* If the cached position is for this buffer, clear it out. */ 2456 /* If the cached position is for this buffer, clear it out. */
2182 clear_charpos_cache (current_buffer); 2457 clear_charpos_cache (current_buffer);
@@ -2187,18 +2462,18 @@ current buffer is cleared. */)
2187 begv = BEGV, zv = ZV; 2462 begv = BEGV, zv = ZV;
2188 2463
2189 if (narrowed) 2464 if (narrowed)
2190 Fwiden (); 2465 error ("Changing multibyteness in a narrowed buffer");
2191 2466
2192 if (NILP (flag)) 2467 if (NILP (flag))
2193 { 2468 {
2194 EMACS_INT pos, stop; 2469 ptrdiff_t pos, stop;
2195 unsigned char *p; 2470 unsigned char *p;
2196 2471
2197 /* Do this first, so it can use CHAR_TO_BYTE 2472 /* Do this first, so it can use CHAR_TO_BYTE
2198 to calculate the old correspondences. */ 2473 to calculate the old correspondences. */
2199 set_intervals_multibyte (0); 2474 set_intervals_multibyte (0);
2200 2475
2201 BVAR (current_buffer, enable_multibyte_characters) = Qnil; 2476 bset_enable_multibyte_characters (current_buffer, Qnil);
2202 2477
2203 Z = Z_BYTE; 2478 Z = Z_BYTE;
2204 BEGV = BEGV_BYTE; 2479 BEGV = BEGV_BYTE;
@@ -2255,8 +2530,8 @@ current buffer is cleared. */)
2255 } 2530 }
2256 else 2531 else
2257 { 2532 {
2258 EMACS_INT pt = PT; 2533 ptrdiff_t pt = PT;
2259 EMACS_INT pos, stop; 2534 ptrdiff_t pos, stop;
2260 unsigned char *p, *pend; 2535 unsigned char *p, *pend;
2261 2536
2262 /* Be sure not to have a multibyte sequence striding over the GAP. 2537 /* Be sure not to have a multibyte sequence striding over the GAP.
@@ -2272,7 +2547,7 @@ current buffer is cleared. */)
2272 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--; 2547 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--;
2273 if (LEADING_CODE_P (*q)) 2548 if (LEADING_CODE_P (*q))
2274 { 2549 {
2275 EMACS_INT new_gpt = GPT_BYTE - (GPT_ADDR - q); 2550 ptrdiff_t new_gpt = GPT_BYTE - (GPT_ADDR - q);
2276 2551
2277 move_gap_both (new_gpt, new_gpt); 2552 move_gap_both (new_gpt, new_gpt);
2278 } 2553 }
@@ -2336,7 +2611,7 @@ current buffer is cleared. */)
2336 2611
2337 /* Do this first, so that chars_in_text asks the right question. 2612 /* Do this first, so that chars_in_text asks the right question.
2338 set_intervals_multibyte needs it too. */ 2613 set_intervals_multibyte needs it too. */
2339 BVAR (current_buffer, enable_multibyte_characters) = Qt; 2614 bset_enable_multibyte_characters (current_buffer, Qt);
2340 2615
2341 GPT_BYTE = advance_to_char_boundary (GPT_BYTE); 2616 GPT_BYTE = advance_to_char_boundary (GPT_BYTE);
2342 GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG; 2617 GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG;
@@ -2356,8 +2631,8 @@ current buffer is cleared. */)
2356 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 2631 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
2357 2632
2358 { 2633 {
2359 EMACS_INT byte = advance_to_char_boundary (PT_BYTE); 2634 ptrdiff_t byte = advance_to_char_boundary (PT_BYTE);
2360 EMACS_INT position; 2635 ptrdiff_t position;
2361 2636
2362 if (byte > GPT_BYTE) 2637 if (byte > GPT_BYTE)
2363 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT; 2638 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT;
@@ -2382,7 +2657,7 @@ current buffer is cleared. */)
2382 /* Make sure no markers were put on the chain 2657 /* Make sure no markers were put on the chain
2383 while the chain value was incorrect. */ 2658 while the chain value was incorrect. */
2384 if (BUF_MARKERS (current_buffer)) 2659 if (BUF_MARKERS (current_buffer))
2385 abort (); 2660 emacs_abort ();
2386 2661
2387 BUF_MARKERS (current_buffer) = markers; 2662 BUF_MARKERS (current_buffer) = markers;
2388 2663
@@ -2394,10 +2669,11 @@ current buffer is cleared. */)
2394 if (!EQ (old_undo, Qt)) 2669 if (!EQ (old_undo, Qt))
2395 { 2670 {
2396 /* Represent all the above changes by a special undo entry. */ 2671 /* Represent all the above changes by a special undo entry. */
2397 BVAR (current_buffer, undo_list) = Fcons (list3 (Qapply, 2672 bset_undo_list (current_buffer,
2398 intern ("set-buffer-multibyte"), 2673 Fcons (list3 (Qapply,
2399 NILP (flag) ? Qt : Qnil), 2674 intern ("set-buffer-multibyte"),
2400 old_undo); 2675 NILP (flag) ? Qt : Qnil),
2676 old_undo));
2401 } 2677 }
2402 2678
2403 UNGCPRO; 2679 UNGCPRO;
@@ -2409,8 +2685,8 @@ current buffer is cleared. */)
2409 2685
2410 /* Copy this buffer's new multibyte status 2686 /* Copy this buffer's new multibyte status
2411 into all of its indirect buffers. */ 2687 into all of its indirect buffers. */
2412 for (other = all_buffers; other; other = other->header.next.buffer) 2688 FOR_EACH_BUFFER (other)
2413 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) 2689 if (other->base_buffer == current_buffer && BUFFER_LIVE_P (other))
2414 { 2690 {
2415 BVAR (other, enable_multibyte_characters) 2691 BVAR (other, enable_multibyte_characters)
2416 = BVAR (current_buffer, enable_multibyte_characters); 2692 = BVAR (current_buffer, enable_multibyte_characters);
@@ -2509,32 +2785,32 @@ swap_out_buffer_local_variables (struct buffer *b)
2509 *VEC_PTR and *LEN_PTR should contain a valid vector and size 2785 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2510 when this function is called. 2786 when this function is called.
2511 2787
2512 If EXTEND is non-zero, we make the vector bigger if necessary. 2788 If EXTEND, make the vector bigger if necessary.
2513 If EXTEND is zero, we never extend the vector, 2789 If not, never extend the vector,
2514 and we store only as many overlays as will fit. 2790 and store only as many overlays as will fit.
2515 But we still return the total number of overlays. 2791 But still return the total number of overlays.
2516 2792
2517 If CHANGE_REQ is true, then any position written into *PREV_PTR or 2793 If CHANGE_REQ, any position written into *PREV_PTR or
2518 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the 2794 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2519 default (BEGV or ZV). */ 2795 default (BEGV or ZV). */
2520 2796
2521ptrdiff_t 2797ptrdiff_t
2522overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 2798overlays_at (EMACS_INT pos, bool extend, Lisp_Object **vec_ptr,
2523 ptrdiff_t *len_ptr, 2799 ptrdiff_t *len_ptr,
2524 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2800 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, bool change_req)
2525{ 2801{
2526 Lisp_Object overlay, start, end; 2802 Lisp_Object overlay, start, end;
2527 struct Lisp_Overlay *tail; 2803 struct Lisp_Overlay *tail;
2528 ptrdiff_t idx = 0; 2804 ptrdiff_t idx = 0;
2529 ptrdiff_t len = *len_ptr; 2805 ptrdiff_t len = *len_ptr;
2530 Lisp_Object *vec = *vec_ptr; 2806 Lisp_Object *vec = *vec_ptr;
2531 EMACS_INT next = ZV; 2807 ptrdiff_t next = ZV;
2532 EMACS_INT prev = BEGV; 2808 ptrdiff_t prev = BEGV;
2533 int inhibit_storing = 0; 2809 bool inhibit_storing = 0;
2534 2810
2535 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2811 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2536 { 2812 {
2537 EMACS_INT startpos, endpos; 2813 ptrdiff_t startpos, endpos;
2538 2814
2539 XSETMISC (overlay, tail); 2815 XSETMISC (overlay, tail);
2540 2816
@@ -2582,7 +2858,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2582 2858
2583 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2859 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2584 { 2860 {
2585 EMACS_INT startpos, endpos; 2861 ptrdiff_t startpos, endpos;
2586 2862
2587 XSETMISC (overlay, tail); 2863 XSETMISC (overlay, tail);
2588 2864
@@ -2647,29 +2923,29 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2647 *VEC_PTR and *LEN_PTR should contain a valid vector and size 2923 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2648 when this function is called. 2924 when this function is called.
2649 2925
2650 If EXTEND is non-zero, we make the vector bigger if necessary. 2926 If EXTEND, make the vector bigger if necessary.
2651 If EXTEND is zero, we never extend the vector, 2927 If not, never extend the vector,
2652 and we store only as many overlays as will fit. 2928 and store only as many overlays as will fit.
2653 But we still return the total number of overlays. */ 2929 But still return the total number of overlays. */
2654 2930
2655static ptrdiff_t 2931static ptrdiff_t
2656overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2932overlays_in (EMACS_INT beg, EMACS_INT end, bool extend,
2657 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, 2933 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2658 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2934 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr)
2659{ 2935{
2660 Lisp_Object overlay, ostart, oend; 2936 Lisp_Object overlay, ostart, oend;
2661 struct Lisp_Overlay *tail; 2937 struct Lisp_Overlay *tail;
2662 ptrdiff_t idx = 0; 2938 ptrdiff_t idx = 0;
2663 ptrdiff_t len = *len_ptr; 2939 ptrdiff_t len = *len_ptr;
2664 Lisp_Object *vec = *vec_ptr; 2940 Lisp_Object *vec = *vec_ptr;
2665 EMACS_INT next = ZV; 2941 ptrdiff_t next = ZV;
2666 EMACS_INT prev = BEGV; 2942 ptrdiff_t prev = BEGV;
2667 int inhibit_storing = 0; 2943 bool inhibit_storing = 0;
2668 int end_is_Z = end == Z; 2944 bool end_is_Z = end == Z;
2669 2945
2670 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2946 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2671 { 2947 {
2672 EMACS_INT startpos, endpos; 2948 ptrdiff_t startpos, endpos;
2673 2949
2674 XSETMISC (overlay, tail); 2950 XSETMISC (overlay, tail);
2675 2951
@@ -2716,7 +2992,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2716 2992
2717 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2993 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2718 { 2994 {
2719 EMACS_INT startpos, endpos; 2995 ptrdiff_t startpos, endpos;
2720 2996
2721 XSETMISC (overlay, tail); 2997 XSETMISC (overlay, tail);
2722 2998
@@ -2766,23 +3042,23 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2766} 3042}
2767 3043
2768 3044
2769/* Return non-zero if there exists an overlay with a non-nil 3045/* Return true if there exists an overlay with a non-nil
2770 `mouse-face' property overlapping OVERLAY. */ 3046 `mouse-face' property overlapping OVERLAY. */
2771 3047
2772int 3048bool
2773mouse_face_overlay_overlaps (Lisp_Object overlay) 3049mouse_face_overlay_overlaps (Lisp_Object overlay)
2774{ 3050{
2775 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 3051 ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay));
2776 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3052 ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay));
2777 ptrdiff_t n, i, size; 3053 ptrdiff_t n, i, size;
2778 Lisp_Object *v, tem; 3054 Lisp_Object *v, tem;
2779 3055
2780 size = 10; 3056 size = 10;
2781 v = (Lisp_Object *) alloca (size * sizeof *v); 3057 v = alloca (size * sizeof *v);
2782 n = overlays_in (start, end, 0, &v, &size, NULL, NULL); 3058 n = overlays_in (start, end, 0, &v, &size, NULL, NULL);
2783 if (n > size) 3059 if (n > size)
2784 { 3060 {
2785 v = (Lisp_Object *) alloca (n * sizeof *v); 3061 v = alloca (n * sizeof *v);
2786 overlays_in (start, end, 0, &v, &n, NULL, NULL); 3062 overlays_in (start, end, 0, &v, &n, NULL, NULL);
2787 } 3063 }
2788 3064
@@ -2798,19 +3074,18 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2798 3074
2799 3075
2800/* Fast function to just test if we're at an overlay boundary. */ 3076/* Fast function to just test if we're at an overlay boundary. */
2801int 3077bool
2802overlay_touches_p (EMACS_INT pos) 3078overlay_touches_p (ptrdiff_t pos)
2803{ 3079{
2804 Lisp_Object overlay; 3080 Lisp_Object overlay;
2805 struct Lisp_Overlay *tail; 3081 struct Lisp_Overlay *tail;
2806 3082
2807 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 3083 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2808 { 3084 {
2809 EMACS_INT endpos; 3085 ptrdiff_t endpos;
2810 3086
2811 XSETMISC (overlay ,tail); 3087 XSETMISC (overlay ,tail);
2812 if (!OVERLAYP (overlay)) 3088 eassert (OVERLAYP (overlay));
2813 abort ();
2814 3089
2815 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 3090 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2816 if (endpos < pos) 3091 if (endpos < pos)
@@ -2821,11 +3096,10 @@ overlay_touches_p (EMACS_INT pos)
2821 3096
2822 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 3097 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2823 { 3098 {
2824 EMACS_INT startpos; 3099 ptrdiff_t startpos;
2825 3100
2826 XSETMISC (overlay, tail); 3101 XSETMISC (overlay, tail);
2827 if (!OVERLAYP (overlay)) 3102 eassert (OVERLAYP (overlay));
2828 abort ();
2829 3103
2830 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 3104 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2831 if (pos < startpos) 3105 if (pos < startpos)
@@ -2839,7 +3113,7 @@ overlay_touches_p (EMACS_INT pos)
2839struct sortvec 3113struct sortvec
2840{ 3114{
2841 Lisp_Object overlay; 3115 Lisp_Object overlay;
2842 EMACS_INT beg, end; 3116 ptrdiff_t beg, end;
2843 EMACS_INT priority; 3117 EMACS_INT priority;
2844}; 3118};
2845 3119
@@ -2854,6 +3128,12 @@ compare_overlays (const void *v1, const void *v2)
2854 return s1->beg < s2->beg ? -1 : 1; 3128 return s1->beg < s2->beg ? -1 : 1;
2855 if (s1->end != s2->end) 3129 if (s1->end != s2->end)
2856 return s2->end < s1->end ? -1 : 1; 3130 return s2->end < s1->end ? -1 : 1;
3131 /* Avoid the non-determinism of qsort by choosing an arbitrary ordering
3132 between "equal" overlays. The result can still change between
3133 invocations of Emacs, but it won't change in the middle of
3134 `find_field' (bug#6830). */
3135 if (!EQ (s1->overlay, s2->overlay))
3136 return XLI (s1->overlay) < XLI (s2->overlay) ? -1 : 1;
2857 return 0; 3137 return 0;
2858} 3138}
2859 3139
@@ -2864,8 +3144,7 @@ ptrdiff_t
2864sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) 3144sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2865{ 3145{
2866 ptrdiff_t i, j; 3146 ptrdiff_t i, j;
2867 struct sortvec *sortvec; 3147 struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec);
2868 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2869 3148
2870 /* Put the valid and relevant overlays into sortvec. */ 3149 /* Put the valid and relevant overlays into sortvec. */
2871 3150
@@ -2875,7 +3154,7 @@ sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2875 Lisp_Object overlay; 3154 Lisp_Object overlay;
2876 3155
2877 overlay = overlay_vec[i]; 3156 overlay = overlay_vec[i];
2878 if (OVERLAY_VALID (overlay) 3157 if (OVERLAYP (overlay)
2879 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0 3158 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
2880 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0) 3159 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
2881 { 3160 {
@@ -2956,7 +3235,7 @@ static void
2956record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, 3235record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2957 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size) 3236 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2958{ 3237{
2959 EMACS_INT nbytes; 3238 ptrdiff_t nbytes;
2960 3239
2961 if (ssl->used == ssl->size) 3240 if (ssl->used == ssl->size)
2962 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); 3241 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
@@ -3006,13 +3285,13 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3006 PSTR, if that variable is non-null. The string may be overwritten by 3285 PSTR, if that variable is non-null. The string may be overwritten by
3007 subsequent calls. */ 3286 subsequent calls. */
3008 3287
3009EMACS_INT 3288ptrdiff_t
3010overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3289overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3011{ 3290{
3012 Lisp_Object overlay, window, str; 3291 Lisp_Object overlay, window, str;
3013 struct Lisp_Overlay *ov; 3292 struct Lisp_Overlay *ov;
3014 EMACS_INT startpos, endpos; 3293 ptrdiff_t startpos, endpos;
3015 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3294 bool multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3016 3295
3017 overlay_heads.used = overlay_heads.bytes = 0; 3296 overlay_heads.used = overlay_heads.bytes = 0;
3018 overlay_tails.used = overlay_tails.bytes = 0; 3297 overlay_tails.used = overlay_tails.bytes = 0;
@@ -3081,7 +3360,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3081 if (overlay_heads.bytes || overlay_tails.bytes) 3360 if (overlay_heads.bytes || overlay_tails.bytes)
3082 { 3361 {
3083 Lisp_Object tem; 3362 Lisp_Object tem;
3084 EMACS_INT i; 3363 ptrdiff_t i;
3085 unsigned char *p; 3364 unsigned char *p;
3086 ptrdiff_t total; 3365 ptrdiff_t total;
3087 3366
@@ -3095,7 +3374,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3095 p = overlay_str_buf; 3374 p = overlay_str_buf;
3096 for (i = overlay_tails.used; --i >= 0;) 3375 for (i = overlay_tails.used; --i >= 0;)
3097 { 3376 {
3098 EMACS_INT nbytes; 3377 ptrdiff_t nbytes;
3099 tem = overlay_tails.buf[i].string; 3378 tem = overlay_tails.buf[i].string;
3100 nbytes = copy_text (SDATA (tem), p, 3379 nbytes = copy_text (SDATA (tem), p,
3101 SBYTES (tem), 3380 SBYTES (tem),
@@ -3104,7 +3383,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3104 } 3383 }
3105 for (i = 0; i < overlay_heads.used; ++i) 3384 for (i = 0; i < overlay_heads.used; ++i)
3106 { 3385 {
3107 EMACS_INT nbytes; 3386 ptrdiff_t nbytes;
3108 tem = overlay_heads.buf[i].string; 3387 tem = overlay_heads.buf[i].string;
3109 nbytes = copy_text (SDATA (tem), p, 3388 nbytes = copy_text (SDATA (tem), p,
3110 SBYTES (tem), 3389 SBYTES (tem),
@@ -3120,7 +3399,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3120 } 3399 }
3121 } 3400 }
3122 if (p != overlay_str_buf + total) 3401 if (p != overlay_str_buf + total)
3123 abort (); 3402 emacs_abort ();
3124 if (pstr) 3403 if (pstr)
3125 *pstr = overlay_str_buf; 3404 *pstr = overlay_str_buf;
3126 return total; 3405 return total;
@@ -3131,7 +3410,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3131/* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3410/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3132 3411
3133void 3412void
3134recenter_overlay_lists (struct buffer *buf, EMACS_INT pos) 3413recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3135{ 3414{
3136 Lisp_Object overlay, beg, end; 3415 Lisp_Object overlay, beg, end;
3137 struct Lisp_Overlay *prev, *tail, *next; 3416 struct Lisp_Overlay *prev, *tail, *next;
@@ -3146,22 +3425,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3146 { 3425 {
3147 next = tail->next; 3426 next = tail->next;
3148 XSETMISC (overlay, tail); 3427 XSETMISC (overlay, tail);
3149 3428 eassert (OVERLAYP (overlay));
3150 /* If the overlay is not valid, get rid of it. */
3151 if (!OVERLAY_VALID (overlay))
3152#if 1
3153 abort ();
3154#else
3155 {
3156 /* Splice the cons cell TAIL out of overlays_before. */
3157 if (!NILP (prev))
3158 XCDR (prev) = next;
3159 else
3160 buf->overlays_before = next;
3161 tail = prev;
3162 continue;
3163 }
3164#endif
3165 3429
3166 beg = OVERLAY_START (overlay); 3430 beg = OVERLAY_START (overlay);
3167 end = OVERLAY_END (overlay); 3431 end = OVERLAY_END (overlay);
@@ -3169,14 +3433,14 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3169 if (OVERLAY_POSITION (end) > pos) 3433 if (OVERLAY_POSITION (end) > pos)
3170 { 3434 {
3171 /* OVERLAY needs to be moved. */ 3435 /* OVERLAY needs to be moved. */
3172 EMACS_INT where = OVERLAY_POSITION (beg); 3436 ptrdiff_t where = OVERLAY_POSITION (beg);
3173 struct Lisp_Overlay *other, *other_prev; 3437 struct Lisp_Overlay *other, *other_prev;
3174 3438
3175 /* Splice the cons cell TAIL out of overlays_before. */ 3439 /* Splice the cons cell TAIL out of overlays_before. */
3176 if (prev) 3440 if (prev)
3177 prev->next = next; 3441 prev->next = next;
3178 else 3442 else
3179 buf->overlays_before = next; 3443 set_buffer_overlays_before (buf, next);
3180 3444
3181 /* Search thru overlays_after for where to put it. */ 3445 /* Search thru overlays_after for where to put it. */
3182 other_prev = NULL; 3446 other_prev = NULL;
@@ -3186,7 +3450,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3186 Lisp_Object otherbeg, otheroverlay; 3450 Lisp_Object otherbeg, otheroverlay;
3187 3451
3188 XSETMISC (otheroverlay, other); 3452 XSETMISC (otheroverlay, other);
3189 eassert (OVERLAY_VALID (otheroverlay)); 3453 eassert (OVERLAYP (otheroverlay));
3190 3454
3191 otherbeg = OVERLAY_START (otheroverlay); 3455 otherbeg = OVERLAY_START (otheroverlay);
3192 if (OVERLAY_POSITION (otherbeg) >= where) 3456 if (OVERLAY_POSITION (otherbeg) >= where)
@@ -3198,7 +3462,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3198 if (other_prev) 3462 if (other_prev)
3199 other_prev->next = tail; 3463 other_prev->next = tail;
3200 else 3464 else
3201 buf->overlays_after = tail; 3465 set_buffer_overlays_after (buf, tail);
3202 tail = prev; 3466 tail = prev;
3203 } 3467 }
3204 else 3468 else
@@ -3214,22 +3478,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3214 { 3478 {
3215 next = tail->next; 3479 next = tail->next;
3216 XSETMISC (overlay, tail); 3480 XSETMISC (overlay, tail);
3217 3481 eassert (OVERLAYP (overlay));
3218 /* If the overlay is not valid, get rid of it. */
3219 if (!OVERLAY_VALID (overlay))
3220#if 1
3221 abort ();
3222#else
3223 {
3224 /* Splice the cons cell TAIL out of overlays_after. */
3225 if (!NILP (prev))
3226 XCDR (prev) = next;
3227 else
3228 buf->overlays_after = next;
3229 tail = prev;
3230 continue;
3231 }
3232#endif
3233 3482
3234 beg = OVERLAY_START (overlay); 3483 beg = OVERLAY_START (overlay);
3235 end = OVERLAY_END (overlay); 3484 end = OVERLAY_END (overlay);
@@ -3242,14 +3491,14 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3242 if (OVERLAY_POSITION (end) <= pos) 3491 if (OVERLAY_POSITION (end) <= pos)
3243 { 3492 {
3244 /* OVERLAY needs to be moved. */ 3493 /* OVERLAY needs to be moved. */
3245 EMACS_INT where = OVERLAY_POSITION (end); 3494 ptrdiff_t where = OVERLAY_POSITION (end);
3246 struct Lisp_Overlay *other, *other_prev; 3495 struct Lisp_Overlay *other, *other_prev;
3247 3496
3248 /* Splice the cons cell TAIL out of overlays_after. */ 3497 /* Splice the cons cell TAIL out of overlays_after. */
3249 if (prev) 3498 if (prev)
3250 prev->next = next; 3499 prev->next = next;
3251 else 3500 else
3252 buf->overlays_after = next; 3501 set_buffer_overlays_after (buf, next);
3253 3502
3254 /* Search thru overlays_before for where to put it. */ 3503 /* Search thru overlays_before for where to put it. */
3255 other_prev = NULL; 3504 other_prev = NULL;
@@ -3259,7 +3508,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3259 Lisp_Object otherend, otheroverlay; 3508 Lisp_Object otherend, otheroverlay;
3260 3509
3261 XSETMISC (otheroverlay, other); 3510 XSETMISC (otheroverlay, other);
3262 eassert (OVERLAY_VALID (otheroverlay)); 3511 eassert (OVERLAYP (otheroverlay));
3263 3512
3264 otherend = OVERLAY_END (otheroverlay); 3513 otherend = OVERLAY_END (otheroverlay);
3265 if (OVERLAY_POSITION (otherend) <= where) 3514 if (OVERLAY_POSITION (otherend) <= where)
@@ -3271,7 +3520,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3271 if (other_prev) 3520 if (other_prev)
3272 other_prev->next = tail; 3521 other_prev->next = tail;
3273 else 3522 else
3274 buf->overlays_before = tail; 3523 set_buffer_overlays_before (buf, tail);
3275 tail = prev; 3524 tail = prev;
3276 } 3525 }
3277 } 3526 }
@@ -3280,7 +3529,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3280} 3529}
3281 3530
3282void 3531void
3283adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length) 3532adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
3284{ 3533{
3285 /* After an insertion, the lists are still sorted properly, 3534 /* After an insertion, the lists are still sorted properly,
3286 but we may need to update the value of the overlay center. */ 3535 but we may need to update the value of the overlay center. */
@@ -3289,13 +3538,13 @@ adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length)
3289} 3538}
3290 3539
3291void 3540void
3292adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length) 3541adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
3293{ 3542{
3294 if (current_buffer->overlay_center < pos) 3543 if (current_buffer->overlay_center < pos)
3295 /* The deletion was to our right. No change needed; the before- and 3544 /* The deletion was to our right. No change needed; the before- and
3296 after-lists are still consistent. */ 3545 after-lists are still consistent. */
3297 ; 3546 ;
3298 else if (current_buffer->overlay_center > pos + length) 3547 else if (current_buffer->overlay_center - pos > length)
3299 /* The deletion was to our left. We need to adjust the center value 3548 /* The deletion was to our left. We need to adjust the center value
3300 to account for the change in position, but the lists are consistent 3549 to account for the change in position, but the lists are consistent
3301 given the new value. */ 3550 given the new value. */
@@ -3314,7 +3563,7 @@ adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length)
3314 Such an overlay might even have negative size at this point. 3563 Such an overlay might even have negative size at this point.
3315 If so, we'll make the overlay empty. */ 3564 If so, we'll make the overlay empty. */
3316void 3565void
3317fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end) 3566fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3318{ 3567{
3319 Lisp_Object overlay; 3568 Lisp_Object overlay;
3320 struct Lisp_Overlay *before_list IF_LINT (= NULL); 3569 struct Lisp_Overlay *before_list IF_LINT (= NULL);
@@ -3327,7 +3576,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3327 current_buffer->overlays_before or overlays_after, depending 3576 current_buffer->overlays_before or overlays_after, depending
3328 which loop we're in. */ 3577 which loop we're in. */
3329 struct Lisp_Overlay *tail, *parent; 3578 struct Lisp_Overlay *tail, *parent;
3330 EMACS_INT startpos, endpos; 3579 ptrdiff_t startpos, endpos;
3331 3580
3332 /* This algorithm shifts links around instead of consing and GCing. 3581 /* This algorithm shifts links around instead of consing and GCing.
3333 The loop invariant is that before_list (resp. after_list) is a 3582 The loop invariant is that before_list (resp. after_list) is a
@@ -3376,7 +3625,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3376 beforep = tail; 3625 beforep = tail;
3377 } 3626 }
3378 if (!parent) 3627 if (!parent)
3379 current_buffer->overlays_before = tail->next; 3628 set_buffer_overlays_before (current_buffer, tail->next);
3380 else 3629 else
3381 parent->next = tail->next; 3630 parent->next = tail->next;
3382 tail = tail->next; 3631 tail = tail->next;
@@ -3422,7 +3671,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3422 beforep = tail; 3671 beforep = tail;
3423 } 3672 }
3424 if (!parent) 3673 if (!parent)
3425 current_buffer->overlays_after = tail->next; 3674 set_buffer_overlays_after (current_buffer, tail->next);
3426 else 3675 else
3427 parent->next = tail->next; 3676 parent->next = tail->next;
3428 tail = tail->next; 3677 tail = tail->next;
@@ -3436,14 +3685,13 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3436 if (beforep) 3685 if (beforep)
3437 { 3686 {
3438 beforep->next = current_buffer->overlays_before; 3687 beforep->next = current_buffer->overlays_before;
3439 current_buffer->overlays_before = before_list; 3688 set_buffer_overlays_before (current_buffer, before_list);
3440 } 3689 }
3441 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3442 3690
3443 if (afterp) 3691 if (afterp)
3444 { 3692 {
3445 afterp->next = current_buffer->overlays_after; 3693 afterp->next = current_buffer->overlays_after;
3446 current_buffer->overlays_after = after_list; 3694 set_buffer_overlays_after (current_buffer, after_list);
3447 } 3695 }
3448 recenter_overlay_lists (current_buffer, current_buffer->overlay_center); 3696 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3449} 3697}
@@ -3461,12 +3709,12 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3461 was at PREV, and now is at POS. */ 3709 was at PREV, and now is at POS. */
3462 3710
3463void 3711void
3464fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos) 3712fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3465{ 3713{
3466 /* If parent is nil, replace overlays_before; otherwise, parent->next. */ 3714 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3467 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair; 3715 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3468 Lisp_Object tem; 3716 Lisp_Object tem;
3469 EMACS_INT end IF_LINT (= 0); 3717 ptrdiff_t end IF_LINT (= 0);
3470 3718
3471 /* After the insertion, the several overlays may be in incorrect 3719 /* After the insertion, the several overlays may be in incorrect
3472 order. The possibility is that, in the list `overlays_before', 3720 order. The possibility is that, in the list `overlays_before',
@@ -3520,7 +3768,7 @@ fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos)
3520 if (!right_pair) 3768 if (!right_pair)
3521 { 3769 {
3522 found->next = bp->overlays_before; 3770 found->next = bp->overlays_before;
3523 bp->overlays_before = found; 3771 set_buffer_overlays_before (bp, found);
3524 } 3772 }
3525 else 3773 else
3526 { 3774 {
@@ -3590,28 +3838,22 @@ for the rear of the overlay advance when text is inserted there
3590 if (!NILP (rear_advance)) 3838 if (!NILP (rear_advance))
3591 XMARKER (end)->insertion_type = 1; 3839 XMARKER (end)->insertion_type = 1;
3592 3840
3593 overlay = allocate_misc (); 3841 overlay = build_overlay (beg, end, Qnil);
3594 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
3595 XOVERLAY (overlay)->start = beg;
3596 XOVERLAY (overlay)->end = end;
3597 XOVERLAY (overlay)->plist = Qnil;
3598 XOVERLAY (overlay)->next = NULL;
3599 3842
3600 /* Put the new overlay on the wrong list. */ 3843 /* Put the new overlay on the wrong list. */
3601 end = OVERLAY_END (overlay); 3844 end = OVERLAY_END (overlay);
3602 if (OVERLAY_POSITION (end) < b->overlay_center) 3845 if (OVERLAY_POSITION (end) < b->overlay_center)
3603 { 3846 {
3604 if (b->overlays_after) 3847 eassert (b->overlays_after || (XOVERLAY (overlay)->next == NULL));
3605 XOVERLAY (overlay)->next = b->overlays_after; 3848 XOVERLAY (overlay)->next = b->overlays_after;
3606 b->overlays_after = XOVERLAY (overlay); 3849 set_buffer_overlays_after (b, XOVERLAY (overlay));
3607 } 3850 }
3608 else 3851 else
3609 { 3852 {
3610 if (b->overlays_before) 3853 eassert (b->overlays_before || (XOVERLAY (overlay)->next == NULL));
3611 XOVERLAY (overlay)->next = b->overlays_before; 3854 XOVERLAY (overlay)->next = b->overlays_before;
3612 b->overlays_before = XOVERLAY (overlay); 3855 set_buffer_overlays_before (b, XOVERLAY (overlay));
3613 } 3856 }
3614
3615 /* This puts it in the right list, and in the right order. */ 3857 /* This puts it in the right list, and in the right order. */
3616 recenter_overlay_lists (b, b->overlay_center); 3858 recenter_overlay_lists (b, b->overlay_center);
3617 3859
@@ -3624,11 +3866,11 @@ for the rear of the overlay advance when text is inserted there
3624/* Mark a section of BUF as needing redisplay because of overlays changes. */ 3866/* Mark a section of BUF as needing redisplay because of overlays changes. */
3625 3867
3626static void 3868static void
3627modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end) 3869modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3628{ 3870{
3629 if (start > end) 3871 if (start > end)
3630 { 3872 {
3631 EMACS_INT temp = start; 3873 ptrdiff_t temp = start;
3632 start = end; 3874 start = end;
3633 end = temp; 3875 end = temp;
3634 } 3876 }
@@ -3650,24 +3892,35 @@ modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end)
3650 ++BUF_OVERLAY_MODIFF (buf); 3892 ++BUF_OVERLAY_MODIFF (buf);
3651} 3893}
3652 3894
3653 3895/* Remove OVERLAY from LIST. */
3896
3654static struct Lisp_Overlay * 3897static struct Lisp_Overlay *
3655unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay) 3898unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay)
3656{ 3899{
3657 struct Lisp_Overlay *tmp, *prev; 3900 register struct Lisp_Overlay *tail, **prev = &list;
3658 for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next) 3901
3659 if (tmp == overlay) 3902 for (tail = list; tail; prev = &tail->next, tail = *prev)
3903 if (tail == overlay)
3660 { 3904 {
3661 if (prev) 3905 *prev = overlay->next;
3662 prev->next = tmp->next;
3663 else
3664 list = tmp->next;
3665 overlay->next = NULL; 3906 overlay->next = NULL;
3666 break; 3907 break;
3667 } 3908 }
3668 return list; 3909 return list;
3669} 3910}
3670 3911
3912/* Remove OVERLAY from both overlay lists of B. */
3913
3914static void
3915unchain_both (struct buffer *b, Lisp_Object overlay)
3916{
3917 struct Lisp_Overlay *ov = XOVERLAY (overlay);
3918
3919 set_buffer_overlays_before (b, unchain_overlay (b->overlays_before, ov));
3920 set_buffer_overlays_after (b, unchain_overlay (b->overlays_after, ov));
3921 eassert (XOVERLAY (overlay)->next == NULL);
3922}
3923
3671DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, 3924DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,
3672 doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER. 3925 doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3673If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now. 3926If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
@@ -3675,9 +3928,10 @@ If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3675buffer. */) 3928buffer. */)
3676 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer) 3929 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer)
3677{ 3930{
3678 struct buffer *b, *ob; 3931 struct buffer *b, *ob = 0;
3679 Lisp_Object obuffer; 3932 Lisp_Object obuffer;
3680 int count = SPECPDL_INDEX (); 3933 ptrdiff_t count = SPECPDL_INDEX ();
3934 ptrdiff_t n_beg, n_end, o_beg IF_LINT (= 0), o_end IF_LINT (= 0);
3681 3935
3682 CHECK_OVERLAY (overlay); 3936 CHECK_OVERLAY (overlay);
3683 if (NILP (buffer)) 3937 if (NILP (buffer))
@@ -3686,6 +3940,9 @@ buffer. */)
3686 XSETBUFFER (buffer, current_buffer); 3940 XSETBUFFER (buffer, current_buffer);
3687 CHECK_BUFFER (buffer); 3941 CHECK_BUFFER (buffer);
3688 3942
3943 if (NILP (Fbuffer_live_p (buffer)))
3944 error ("Attempt to move overlay to a dead buffer");
3945
3689 if (MARKERP (beg) 3946 if (MARKERP (beg)
3690 && ! EQ (Fmarker_buffer (beg), buffer)) 3947 && ! EQ (Fmarker_buffer (beg), buffer))
3691 error ("Marker points into wrong buffer"); 3948 error ("Marker points into wrong buffer");
@@ -3696,9 +3953,6 @@ buffer. */)
3696 CHECK_NUMBER_COERCE_MARKER (beg); 3953 CHECK_NUMBER_COERCE_MARKER (beg);
3697 CHECK_NUMBER_COERCE_MARKER (end); 3954 CHECK_NUMBER_COERCE_MARKER (end);
3698 3955
3699 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3700 return Fdelete_overlay (overlay);
3701
3702 if (XINT (beg) > XINT (end)) 3956 if (XINT (beg) > XINT (end))
3703 { 3957 {
3704 Lisp_Object temp; 3958 Lisp_Object temp;
@@ -3709,69 +3963,61 @@ buffer. */)
3709 3963
3710 obuffer = Fmarker_buffer (OVERLAY_START (overlay)); 3964 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
3711 b = XBUFFER (buffer); 3965 b = XBUFFER (buffer);
3712 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; 3966
3967 if (!NILP (obuffer))
3968 {
3969 ob = XBUFFER (obuffer);
3970
3971 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3972 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
3973
3974 unchain_both (ob, overlay);
3975 }
3976
3977 /* Set the overlay boundaries, which may clip them. */
3978 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3979 Fset_marker (OVERLAY_END (overlay), end, buffer);
3980
3981 n_beg = marker_position (OVERLAY_START (overlay));
3982 n_end = marker_position (OVERLAY_END (overlay));
3713 3983
3714 /* If the overlay has changed buffers, do a thorough redisplay. */ 3984 /* If the overlay has changed buffers, do a thorough redisplay. */
3715 if (!EQ (buffer, obuffer)) 3985 if (!EQ (buffer, obuffer))
3716 { 3986 {
3717 /* Redisplay where the overlay was. */ 3987 /* Redisplay where the overlay was. */
3718 if (!NILP (obuffer)) 3988 if (ob)
3719 { 3989 modify_overlay (ob, o_beg, o_end);
3720 EMACS_INT o_beg;
3721 EMACS_INT o_end;
3722
3723 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3724 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
3725
3726 modify_overlay (ob, o_beg, o_end);
3727 }
3728 3990
3729 /* Redisplay where the overlay is going to be. */ 3991 /* Redisplay where the overlay is going to be. */
3730 modify_overlay (b, XINT (beg), XINT (end)); 3992 modify_overlay (b, n_beg, n_end);
3731 } 3993 }
3732 else 3994 else
3733 /* Redisplay the area the overlay has just left, or just enclosed. */ 3995 /* Redisplay the area the overlay has just left, or just enclosed. */
3734 { 3996 {
3735 EMACS_INT o_beg, o_end; 3997 if (o_beg == n_beg)
3736 3998 modify_overlay (b, o_end, n_end);
3737 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3999 else if (o_end == n_end)
3738 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 4000 modify_overlay (b, o_beg, n_beg);
3739
3740 if (o_beg == XINT (beg))
3741 modify_overlay (b, o_end, XINT (end));
3742 else if (o_end == XINT (end))
3743 modify_overlay (b, o_beg, XINT (beg));
3744 else 4001 else
3745 { 4002 modify_overlay (b, min (o_beg, n_beg), max (o_end, n_end));
3746 if (XINT (beg) < o_beg) o_beg = XINT (beg);
3747 if (XINT (end) > o_end) o_end = XINT (end);
3748 modify_overlay (b, o_beg, o_end);
3749 }
3750 } 4003 }
3751 4004
3752 if (!NILP (obuffer)) 4005 /* Delete the overlay if it is empty after clipping and has the
3753 { 4006 evaporate property. */
3754 ob->overlays_before 4007 if (n_beg == n_end && !NILP (Foverlay_get (overlay, Qevaporate)))
3755 = unchain_overlay (ob->overlays_before, XOVERLAY (overlay)); 4008 return unbind_to (count, Fdelete_overlay (overlay));
3756 ob->overlays_after
3757 = unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3758 eassert (XOVERLAY (overlay)->next == NULL);
3759 }
3760 4009
3761 Fset_marker (OVERLAY_START (overlay), beg, buffer); 4010 /* Put the overlay into the new buffer's overlay lists, first on the
3762 Fset_marker (OVERLAY_END (overlay), end, buffer); 4011 wrong list. */
3763 4012 if (n_end < b->overlay_center)
3764 /* Put the overlay on the wrong list. */
3765 end = OVERLAY_END (overlay);
3766 if (OVERLAY_POSITION (end) < b->overlay_center)
3767 { 4013 {
3768 XOVERLAY (overlay)->next = b->overlays_after; 4014 XOVERLAY (overlay)->next = b->overlays_after;
3769 b->overlays_after = XOVERLAY (overlay); 4015 set_buffer_overlays_after (b, XOVERLAY (overlay));
3770 } 4016 }
3771 else 4017 else
3772 { 4018 {
3773 XOVERLAY (overlay)->next = b->overlays_before; 4019 XOVERLAY (overlay)->next = b->overlays_before;
3774 b->overlays_before = XOVERLAY (overlay); 4020 set_buffer_overlays_before (b, XOVERLAY (overlay));
3775 } 4021 }
3776 4022
3777 /* This puts it in the right list, and in the right order. */ 4023 /* This puts it in the right list, and in the right order. */
@@ -3786,7 +4032,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3786{ 4032{
3787 Lisp_Object buffer; 4033 Lisp_Object buffer;
3788 struct buffer *b; 4034 struct buffer *b;
3789 int count = SPECPDL_INDEX (); 4035 ptrdiff_t count = SPECPDL_INDEX ();
3790 4036
3791 CHECK_OVERLAY (overlay); 4037 CHECK_OVERLAY (overlay);
3792 4038
@@ -3797,14 +4043,8 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3797 b = XBUFFER (buffer); 4043 b = XBUFFER (buffer);
3798 specbind (Qinhibit_quit, Qt); 4044 specbind (Qinhibit_quit, Qt);
3799 4045
3800 b->overlays_before = unchain_overlay (b->overlays_before,XOVERLAY (overlay)); 4046 unchain_both (b, overlay);
3801 b->overlays_after = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); 4047 drop_overlay (b, XOVERLAY (overlay));
3802 eassert (XOVERLAY (overlay)->next == NULL);
3803 modify_overlay (b,
3804 marker_position (OVERLAY_START (overlay)),
3805 marker_position (OVERLAY_END (overlay)));
3806 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
3807 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
3808 4048
3809 /* When deleting an overlay with before or after strings, turn off 4049 /* When deleting an overlay with before or after strings, turn off
3810 display optimizations for the affected buffer, on the basis that 4050 display optimizations for the affected buffer, on the basis that
@@ -3817,6 +4057,26 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3817 4057
3818 return unbind_to (count, Qnil); 4058 return unbind_to (count, Qnil);
3819} 4059}
4060
4061DEFUN ("delete-all-overlays", Fdelete_all_overlays, Sdelete_all_overlays, 0, 1, 0,
4062 doc: /* Delete all overlays of BUFFER.
4063BUFFER omitted or nil means delete all overlays of the current
4064buffer. */)
4065 (Lisp_Object buffer)
4066{
4067 register struct buffer *buf;
4068
4069 if (NILP (buffer))
4070 buf = current_buffer;
4071 else
4072 {
4073 CHECK_BUFFER (buffer);
4074 buf = XBUFFER (buffer);
4075 }
4076
4077 delete_all_overlays (buf);
4078 return Qnil;
4079}
3820 4080
3821/* Overlay dissection functions. */ 4081/* Overlay dissection functions. */
3822 4082
@@ -3872,12 +4132,12 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3872 4132
3873 len = 10; 4133 len = 10;
3874 /* We can't use alloca here because overlays_at can call xrealloc. */ 4134 /* We can't use alloca here because overlays_at can call xrealloc. */
3875 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 4135 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3876 4136
3877 /* Put all the overlays we want in a vector in overlay_vec. 4137 /* Put all the overlays we want in a vector in overlay_vec.
3878 Store the length in len. */ 4138 Store the length in len. */
3879 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 4139 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3880 (EMACS_INT *) 0, (EMACS_INT *) 0, 0); 4140 NULL, NULL, 0);
3881 4141
3882 /* Make a list of them all. */ 4142 /* Make a list of them all. */
3883 result = Flist (noverlays, overlay_vec); 4143 result = Flist (noverlays, overlay_vec);
@@ -3903,7 +4163,7 @@ end of the buffer. */)
3903 CHECK_NUMBER_COERCE_MARKER (end); 4163 CHECK_NUMBER_COERCE_MARKER (end);
3904 4164
3905 len = 10; 4165 len = 10;
3906 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 4166 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3907 4167
3908 /* Put all the overlays we want in a vector in overlay_vec. 4168 /* Put all the overlays we want in a vector in overlay_vec.
3909 Store the length in len. */ 4169 Store the length in len. */
@@ -3925,26 +4185,26 @@ the value is (point-max). */)
3925 (Lisp_Object pos) 4185 (Lisp_Object pos)
3926{ 4186{
3927 ptrdiff_t i, len, noverlays; 4187 ptrdiff_t i, len, noverlays;
3928 EMACS_INT endpos; 4188 ptrdiff_t endpos;
3929 Lisp_Object *overlay_vec; 4189 Lisp_Object *overlay_vec;
3930 4190
3931 CHECK_NUMBER_COERCE_MARKER (pos); 4191 CHECK_NUMBER_COERCE_MARKER (pos);
3932 4192
3933 len = 10; 4193 len = 10;
3934 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 4194 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3935 4195
3936 /* Put all the overlays we want in a vector in overlay_vec. 4196 /* Put all the overlays we want in a vector in overlay_vec.
3937 Store the length in len. 4197 Store the length in len.
3938 endpos gets the position where the next overlay starts. */ 4198 endpos gets the position where the next overlay starts. */
3939 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 4199 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3940 &endpos, (EMACS_INT *) 0, 1); 4200 &endpos, 0, 1);
3941 4201
3942 /* If any of these overlays ends before endpos, 4202 /* If any of these overlays ends before endpos,
3943 use its ending point instead. */ 4203 use its ending point instead. */
3944 for (i = 0; i < noverlays; i++) 4204 for (i = 0; i < noverlays; i++)
3945 { 4205 {
3946 Lisp_Object oend; 4206 Lisp_Object oend;
3947 EMACS_INT oendpos; 4207 ptrdiff_t oendpos;
3948 4208
3949 oend = OVERLAY_END (overlay_vec[i]); 4209 oend = OVERLAY_END (overlay_vec[i]);
3950 oendpos = OVERLAY_POSITION (oend); 4210 oendpos = OVERLAY_POSITION (oend);
@@ -3963,7 +4223,7 @@ If there are no overlay boundaries from (point-min) to POS,
3963the value is (point-min). */) 4223the value is (point-min). */)
3964 (Lisp_Object pos) 4224 (Lisp_Object pos)
3965{ 4225{
3966 EMACS_INT prevpos; 4226 ptrdiff_t prevpos;
3967 Lisp_Object *overlay_vec; 4227 Lisp_Object *overlay_vec;
3968 ptrdiff_t len; 4228 ptrdiff_t len;
3969 4229
@@ -3975,13 +4235,13 @@ the value is (point-min). */)
3975 return pos; 4235 return pos;
3976 4236
3977 len = 10; 4237 len = 10;
3978 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 4238 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3979 4239
3980 /* Put all the overlays we want in a vector in overlay_vec. 4240 /* Put all the overlays we want in a vector in overlay_vec.
3981 Store the length in len. 4241 Store the length in len.
3982 prevpos gets the position of the previous change. */ 4242 prevpos gets the position of the previous change. */
3983 overlays_at (XINT (pos), 1, &overlay_vec, &len, 4243 overlays_at (XINT (pos), 1, &overlay_vec, &len,
3984 (EMACS_INT *) 0, &prevpos, 1); 4244 0, &prevpos, 1);
3985 4245
3986 xfree (overlay_vec); 4246 xfree (overlay_vec);
3987 return make_number (prevpos); 4247 return make_number (prevpos);
@@ -4000,6 +4260,7 @@ However, the overlays you get are the real objects that the buffer uses. */)
4000{ 4260{
4001 struct Lisp_Overlay *ol; 4261 struct Lisp_Overlay *ol;
4002 Lisp_Object before = Qnil, after = Qnil, tmp; 4262 Lisp_Object before = Qnil, after = Qnil, tmp;
4263
4003 for (ol = current_buffer->overlays_before; ol; ol = ol->next) 4264 for (ol = current_buffer->overlays_before; ol; ol = ol->next)
4004 { 4265 {
4005 XSETMISC (tmp, ol); 4266 XSETMISC (tmp, ol);
@@ -4010,6 +4271,7 @@ However, the overlays you get are the real objects that the buffer uses. */)
4010 XSETMISC (tmp, ol); 4271 XSETMISC (tmp, ol);
4011 after = Fcons (tmp, after); 4272 after = Fcons (tmp, after);
4012 } 4273 }
4274
4013 return Fcons (Fnreverse (before), Fnreverse (after)); 4275 return Fcons (Fnreverse (before), Fnreverse (after));
4014} 4276}
4015 4277
@@ -4019,9 +4281,11 @@ That makes overlay lookup faster for positions near POS (but perhaps slower
4019for positions far away from POS). */) 4281for positions far away from POS). */)
4020 (Lisp_Object pos) 4282 (Lisp_Object pos)
4021{ 4283{
4284 ptrdiff_t p;
4022 CHECK_NUMBER_COERCE_MARKER (pos); 4285 CHECK_NUMBER_COERCE_MARKER (pos);
4023 4286
4024 recenter_overlay_lists (current_buffer, XINT (pos)); 4287 p = clip_to_bounds (PTRDIFF_MIN, XINT (pos), PTRDIFF_MAX);
4288 recenter_overlay_lists (current_buffer, p);
4025 return Qnil; 4289 return Qnil;
4026} 4290}
4027 4291
@@ -4039,7 +4303,7 @@ VALUE will be returned.*/)
4039 (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value) 4303 (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value)
4040{ 4304{
4041 Lisp_Object tail, buffer; 4305 Lisp_Object tail, buffer;
4042 int changed; 4306 bool changed;
4043 4307
4044 CHECK_OVERLAY (overlay); 4308 CHECK_OVERLAY (overlay);
4045 4309
@@ -4056,8 +4320,8 @@ VALUE will be returned.*/)
4056 } 4320 }
4057 /* It wasn't in the list, so add it to the front. */ 4321 /* It wasn't in the list, so add it to the front. */
4058 changed = !NILP (value); 4322 changed = !NILP (value);
4059 XOVERLAY (overlay)->plist 4323 set_overlay_plist
4060 = Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist)); 4324 (overlay, Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist)));
4061 found: 4325 found:
4062 if (! NILP (buffer)) 4326 if (! NILP (buffer))
4063 { 4327 {
@@ -4088,7 +4352,7 @@ VALUE will be returned.*/)
4088static Lisp_Object last_overlay_modification_hooks; 4352static Lisp_Object last_overlay_modification_hooks;
4089 4353
4090/* Number of elements actually used in last_overlay_modification_hooks. */ 4354/* Number of elements actually used in last_overlay_modification_hooks. */
4091static int last_overlay_modification_hooks_used; 4355static ptrdiff_t last_overlay_modification_hooks_used;
4092 4356
4093/* Add one functionlist/overlay pair 4357/* Add one functionlist/overlay pair
4094 to the end of last_overlay_modification_hooks. */ 4358 to the end of last_overlay_modification_hooks. */
@@ -4096,11 +4360,11 @@ static int last_overlay_modification_hooks_used;
4096static void 4360static void
4097add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) 4361add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4098{ 4362{
4099 int oldsize = ASIZE (last_overlay_modification_hooks); 4363 ptrdiff_t oldsize = ASIZE (last_overlay_modification_hooks);
4100 4364
4101 if (last_overlay_modification_hooks_used == oldsize) 4365 if (oldsize - 1 <= last_overlay_modification_hooks_used)
4102 last_overlay_modification_hooks = larger_vector 4366 last_overlay_modification_hooks =
4103 (last_overlay_modification_hooks, oldsize * 2, Qnil); 4367 larger_vector (last_overlay_modification_hooks, 2, -1);
4104 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4368 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
4105 functionlist); last_overlay_modification_hooks_used++; 4369 functionlist); last_overlay_modification_hooks_used++;
4106 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4370 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
@@ -4114,7 +4378,7 @@ add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4114 and the insert-after-hooks of overlay ending at START. 4378 and the insert-after-hooks of overlay ending at START.
4115 4379
4116 This is called both before and after the modification. 4380 This is called both before and after the modification.
4117 AFTER is nonzero when we call after the modification. 4381 AFTER is true when we call after the modification.
4118 4382
4119 ARG1, ARG2, ARG3 are arguments to pass to the hook functions. 4383 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
4120 When AFTER is nonzero, they are the start position, 4384 When AFTER is nonzero, they are the start position,
@@ -4122,13 +4386,13 @@ add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4122 and the length of deleted or replaced old text. */ 4386 and the length of deleted or replaced old text. */
4123 4387
4124void 4388void
4125report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, 4389report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after,
4126 Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) 4390 Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
4127{ 4391{
4128 Lisp_Object prop, overlay; 4392 Lisp_Object prop, overlay;
4129 struct Lisp_Overlay *tail; 4393 struct Lisp_Overlay *tail;
4130 /* 1 if this change is an insertion. */ 4394 /* True if this change is an insertion. */
4131 int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end)); 4395 bool insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end));
4132 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4396 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4133 4397
4134 overlay = Qnil; 4398 overlay = Qnil;
@@ -4149,7 +4413,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4149 last_overlay_modification_hooks_used = 0; 4413 last_overlay_modification_hooks_used = 0;
4150 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4414 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4151 { 4415 {
4152 EMACS_INT startpos, endpos; 4416 ptrdiff_t startpos, endpos;
4153 Lisp_Object ostart, oend; 4417 Lisp_Object ostart, oend;
4154 4418
4155 XSETMISC (overlay, tail); 4419 XSETMISC (overlay, tail);
@@ -4186,7 +4450,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4186 4450
4187 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4451 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4188 { 4452 {
4189 EMACS_INT startpos, endpos; 4453 ptrdiff_t startpos, endpos;
4190 Lisp_Object ostart, oend; 4454 Lisp_Object ostart, oend;
4191 4455
4192 XSETMISC (overlay, tail); 4456 XSETMISC (overlay, tail);
@@ -4227,12 +4491,12 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4227 /* Call the functions recorded in last_overlay_modification_hooks. 4491 /* Call the functions recorded in last_overlay_modification_hooks.
4228 First copy the vector contents, in case some of these hooks 4492 First copy the vector contents, in case some of these hooks
4229 do subsequent modification of the buffer. */ 4493 do subsequent modification of the buffer. */
4230 int size = last_overlay_modification_hooks_used; 4494 ptrdiff_t size = last_overlay_modification_hooks_used;
4231 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4495 Lisp_Object *copy = alloca (size * sizeof *copy);
4232 int i; 4496 ptrdiff_t i;
4233 4497
4234 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4498 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
4235 size * sizeof (Lisp_Object)); 4499 size * word_size);
4236 gcpro1.var = copy; 4500 gcpro1.var = copy;
4237 gcpro1.nvars = size; 4501 gcpro1.nvars = size;
4238 4502
@@ -4248,7 +4512,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4248} 4512}
4249 4513
4250static void 4514static void
4251call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after, 4515call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, bool after,
4252 Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) 4516 Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
4253{ 4517{
4254 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4518 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
@@ -4269,7 +4533,7 @@ call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after,
4269/* Delete any zero-sized overlays at position POS, if the `evaporate' 4533/* Delete any zero-sized overlays at position POS, if the `evaporate'
4270 property is set. */ 4534 property is set. */
4271void 4535void
4272evaporate_overlays (EMACS_INT pos) 4536evaporate_overlays (ptrdiff_t pos)
4273{ 4537{
4274 Lisp_Object overlay, hit_list; 4538 Lisp_Object overlay, hit_list;
4275 struct Lisp_Overlay *tail; 4539 struct Lisp_Overlay *tail;
@@ -4278,7 +4542,7 @@ evaporate_overlays (EMACS_INT pos)
4278 if (pos <= current_buffer->overlay_center) 4542 if (pos <= current_buffer->overlay_center)
4279 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4543 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4280 { 4544 {
4281 EMACS_INT endpos; 4545 ptrdiff_t endpos;
4282 XSETMISC (overlay, tail); 4546 XSETMISC (overlay, tail);
4283 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4547 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4284 if (endpos < pos) 4548 if (endpos < pos)
@@ -4290,7 +4554,7 @@ evaporate_overlays (EMACS_INT pos)
4290 else 4554 else
4291 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4555 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4292 { 4556 {
4293 EMACS_INT startpos; 4557 ptrdiff_t startpos;
4294 XSETMISC (overlay, tail); 4558 XSETMISC (overlay, tail);
4295 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4559 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4296 if (startpos > pos) 4560 if (startpos > pos)
@@ -4316,7 +4580,7 @@ buffer_slot_type_mismatch (Lisp_Object newval, int type)
4316 case_Lisp_Int: predicate = Qintegerp; break; 4580 case_Lisp_Int: predicate = Qintegerp; break;
4317 case Lisp_String: predicate = Qstringp; break; 4581 case Lisp_String: predicate = Qstringp; break;
4318 case Lisp_Symbol: predicate = Qsymbolp; break; 4582 case Lisp_Symbol: predicate = Qsymbolp; break;
4319 default: abort (); 4583 default: emacs_abort ();
4320 } 4584 }
4321 4585
4322 wrong_type_argument (predicate, newval); 4586 wrong_type_argument (predicate, newval);
@@ -4381,7 +4645,7 @@ struct mmap_region
4381 /* Pointer to the location holding the address of the memory 4645 /* Pointer to the location holding the address of the memory
4382 allocated with the mmap'd block. The variable actually points 4646 allocated with the mmap'd block. The variable actually points
4383 after this structure. */ 4647 after this structure. */
4384 POINTER_TYPE **var; 4648 void **var;
4385 4649
4386 /* Next and previous in list of all mmap'd regions. */ 4650 /* Next and previous in list of all mmap'd regions. */
4387 struct mmap_region *next, *prev; 4651 struct mmap_region *next, *prev;
@@ -4407,7 +4671,7 @@ static int mmap_page_size;
4407 4671
4408/* 1 means mmap has been initialized. */ 4672/* 1 means mmap has been initialized. */
4409 4673
4410static int mmap_initialized_p; 4674static bool mmap_initialized_p;
4411 4675
4412/* Value is X rounded up to the next multiple of N. */ 4676/* Value is X rounded up to the next multiple of N. */
4413 4677
@@ -4428,7 +4692,7 @@ static int mmap_initialized_p;
4428 to the start of the user-visible part of the region. */ 4692 to the start of the user-visible part of the region. */
4429 4693
4430#define MMAP_USER_AREA(P) \ 4694#define MMAP_USER_AREA(P) \
4431 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE)) 4695 ((void *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4432 4696
4433#define MEM_ALIGN sizeof (double) 4697#define MEM_ALIGN sizeof (double)
4434 4698
@@ -4477,7 +4741,7 @@ mmap_init (void)
4477 is at END - 1. */ 4741 is at END - 1. */
4478 4742
4479static struct mmap_region * 4743static struct mmap_region *
4480mmap_find (POINTER_TYPE *start, POINTER_TYPE *end) 4744mmap_find (void *start, void *end)
4481{ 4745{
4482 struct mmap_region *r; 4746 struct mmap_region *r;
4483 char *s = (char *) start, *e = (char *) end; 4747 char *s = (char *) start, *e = (char *) end;
@@ -4503,9 +4767,9 @@ mmap_find (POINTER_TYPE *start, POINTER_TYPE *end)
4503 4767
4504 4768
4505/* Unmap a region. P is a pointer to the start of the user-araa of 4769/* Unmap a region. P is a pointer to the start of the user-araa of
4506 the region. Value is non-zero if successful. */ 4770 the region. */
4507 4771
4508static int 4772static void
4509mmap_free_1 (struct mmap_region *r) 4773mmap_free_1 (struct mmap_region *r)
4510{ 4774{
4511 if (r->next) 4775 if (r->next)
@@ -4515,25 +4779,20 @@ mmap_free_1 (struct mmap_region *r)
4515 else 4779 else
4516 mmap_regions = r->next; 4780 mmap_regions = r->next;
4517 4781
4518 if (munmap ((POINTER_TYPE *) r, r->nbytes_mapped) == -1) 4782 if (munmap (r, r->nbytes_mapped) == -1)
4519 { 4783 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
4520 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
4521 return 0;
4522 }
4523
4524 return 1;
4525} 4784}
4526 4785
4527 4786
4528/* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R. 4787/* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R.
4529 Value is non-zero if successful. */ 4788 Value is true if successful. */
4530 4789
4531static int 4790static bool
4532mmap_enlarge (struct mmap_region *r, int npages) 4791mmap_enlarge (struct mmap_region *r, int npages)
4533{ 4792{
4534 char *region_end = (char *) r + r->nbytes_mapped; 4793 char *region_end = (char *) r + r->nbytes_mapped;
4535 size_t nbytes; 4794 size_t nbytes;
4536 int success = 0; 4795 bool success = 0;
4537 4796
4538 if (npages < 0) 4797 if (npages < 0)
4539 { 4798 {
@@ -4557,13 +4816,13 @@ mmap_enlarge (struct mmap_region *r, int npages)
4557 I'm not sure this is worth doing, let's see. */ 4816 I'm not sure this is worth doing, let's see. */
4558 if (!MMAP_ALLOCATED_P (region_end, region_end + nbytes)) 4817 if (!MMAP_ALLOCATED_P (region_end, region_end + nbytes))
4559 { 4818 {
4560 POINTER_TYPE *p; 4819 void *p;
4561 4820
4562 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, 4821 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
4563 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0); 4822 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0);
4564 if (p == MAP_FAILED) 4823 if (p == MAP_FAILED)
4565 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */ 4824 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4566 else if (p != (POINTER_TYPE *) region_end) 4825 else if (p != region_end)
4567 { 4826 {
4568 /* Kernels are free to choose a different address. In 4827 /* Kernels are free to choose a different address. In
4569 that case, unmap what we've mapped above; we have 4828 that case, unmap what we've mapped above; we have
@@ -4583,17 +4842,16 @@ mmap_enlarge (struct mmap_region *r, int npages)
4583} 4842}
4584 4843
4585 4844
4586/* Set or reset variables holding references to mapped regions. If 4845/* Set or reset variables holding references to mapped regions.
4587 RESTORE_P is zero, set all variables to null. If RESTORE_P is 4846 If not RESTORE_P, set all variables to null. If RESTORE_P, set all
4588 non-zero, set all variables to the start of the user-areas 4847 variables to the start of the user-areas of mapped regions.
4589 of mapped regions.
4590 4848
4591 This function is called from Fdump_emacs to ensure that the dumped 4849 This function is called from Fdump_emacs to ensure that the dumped
4592 Emacs doesn't contain references to memory that won't be mapped 4850 Emacs doesn't contain references to memory that won't be mapped
4593 when Emacs starts. */ 4851 when Emacs starts. */
4594 4852
4595void 4853void
4596mmap_set_vars (int restore_p) 4854mmap_set_vars (bool restore_p)
4597{ 4855{
4598 struct mmap_region *r; 4856 struct mmap_region *r;
4599 4857
@@ -4625,8 +4883,8 @@ mmap_set_vars (int restore_p)
4625 If we can't allocate the necessary memory, set *VAR to null, and 4883 If we can't allocate the necessary memory, set *VAR to null, and
4626 return null. */ 4884 return null. */
4627 4885
4628static POINTER_TYPE * 4886static void *
4629mmap_alloc (POINTER_TYPE **var, size_t nbytes) 4887mmap_alloc (void **var, size_t nbytes)
4630{ 4888{
4631 void *p; 4889 void *p;
4632 size_t map; 4890 size_t map;
@@ -4667,7 +4925,7 @@ mmap_alloc (POINTER_TYPE **var, size_t nbytes)
4667 PTR. Store 0 in *PTR to show there's no block allocated. */ 4925 PTR. Store 0 in *PTR to show there's no block allocated. */
4668 4926
4669static void 4927static void
4670mmap_free (POINTER_TYPE **var) 4928mmap_free (void **var)
4671{ 4929{
4672 mmap_init (); 4930 mmap_init ();
4673 4931
@@ -4684,10 +4942,10 @@ mmap_free (POINTER_TYPE **var)
4684 and return this value. If more memory cannot be allocated, then 4942 and return this value. If more memory cannot be allocated, then
4685 leave *VAR unchanged, and return null. */ 4943 leave *VAR unchanged, and return null. */
4686 4944
4687static POINTER_TYPE * 4945static void *
4688mmap_realloc (POINTER_TYPE **var, size_t nbytes) 4946mmap_realloc (void **var, size_t nbytes)
4689{ 4947{
4690 POINTER_TYPE *result; 4948 void *result;
4691 4949
4692 mmap_init (); 4950 mmap_init ();
4693 4951
@@ -4706,7 +4964,7 @@ mmap_realloc (POINTER_TYPE **var, size_t nbytes)
4706 if (room < nbytes) 4964 if (room < nbytes)
4707 { 4965 {
4708 /* Must enlarge. */ 4966 /* Must enlarge. */
4709 POINTER_TYPE *old_ptr = *var; 4967 void *old_ptr = *var;
4710 4968
4711 /* Try to map additional pages at the end of the region. 4969 /* Try to map additional pages at the end of the region.
4712 If that fails, allocate a new region, copy data 4970 If that fails, allocate a new region, copy data
@@ -4763,65 +5021,58 @@ mmap_realloc (POINTER_TYPE **var, size_t nbytes)
4763 Buffer-text Allocation 5021 Buffer-text Allocation
4764 ***********************************************************************/ 5022 ***********************************************************************/
4765 5023
4766#ifdef REL_ALLOC
4767extern POINTER_TYPE *r_alloc (POINTER_TYPE **, size_t);
4768extern POINTER_TYPE *r_re_alloc (POINTER_TYPE **, size_t);
4769extern void r_alloc_free (POINTER_TYPE **ptr);
4770#endif /* REL_ALLOC */
4771
4772
4773/* Allocate NBYTES bytes for buffer B's text buffer. */ 5024/* Allocate NBYTES bytes for buffer B's text buffer. */
4774 5025
4775static void 5026static void
4776alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) 5027alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4777{ 5028{
4778 POINTER_TYPE *p; 5029 void *p;
4779 5030
4780 BLOCK_INPUT; 5031 block_input ();
4781#if defined USE_MMAP_FOR_BUFFERS 5032#if defined USE_MMAP_FOR_BUFFERS
4782 p = mmap_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 5033 p = mmap_alloc ((void **) &b->text->beg, nbytes);
4783#elif defined REL_ALLOC 5034#elif defined REL_ALLOC
4784 p = r_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 5035 p = r_alloc ((void **) &b->text->beg, nbytes);
4785#else 5036#else
4786 p = xmalloc (nbytes); 5037 p = xmalloc (nbytes);
4787#endif 5038#endif
4788 5039
4789 if (p == NULL) 5040 if (p == NULL)
4790 { 5041 {
4791 UNBLOCK_INPUT; 5042 unblock_input ();
4792 memory_full (nbytes); 5043 memory_full (nbytes);
4793 } 5044 }
4794 5045
4795 b->text->beg = (unsigned char *) p; 5046 b->text->beg = (unsigned char *) p;
4796 UNBLOCK_INPUT; 5047 unblock_input ();
4797} 5048}
4798 5049
4799/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means 5050/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
4800 shrink it. */ 5051 shrink it. */
4801 5052
4802void 5053void
4803enlarge_buffer_text (struct buffer *b, EMACS_INT delta) 5054enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
4804{ 5055{
4805 POINTER_TYPE *p; 5056 void *p;
4806 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 5057 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
4807 + delta); 5058 + delta);
4808 BLOCK_INPUT; 5059 block_input ();
4809#if defined USE_MMAP_FOR_BUFFERS 5060#if defined USE_MMAP_FOR_BUFFERS
4810 p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); 5061 p = mmap_realloc ((void **) &b->text->beg, nbytes);
4811#elif defined REL_ALLOC 5062#elif defined REL_ALLOC
4812 p = r_re_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 5063 p = r_re_alloc ((void **) &b->text->beg, nbytes);
4813#else 5064#else
4814 p = xrealloc (b->text->beg, nbytes); 5065 p = xrealloc (b->text->beg, nbytes);
4815#endif 5066#endif
4816 5067
4817 if (p == NULL) 5068 if (p == NULL)
4818 { 5069 {
4819 UNBLOCK_INPUT; 5070 unblock_input ();
4820 memory_full (nbytes); 5071 memory_full (nbytes);
4821 } 5072 }
4822 5073
4823 BUF_BEG_ADDR (b) = (unsigned char *) p; 5074 BUF_BEG_ADDR (b) = (unsigned char *) p;
4824 UNBLOCK_INPUT; 5075 unblock_input ();
4825} 5076}
4826 5077
4827 5078
@@ -4830,18 +5081,18 @@ enlarge_buffer_text (struct buffer *b, EMACS_INT delta)
4830static void 5081static void
4831free_buffer_text (struct buffer *b) 5082free_buffer_text (struct buffer *b)
4832{ 5083{
4833 BLOCK_INPUT; 5084 block_input ();
4834 5085
4835#if defined USE_MMAP_FOR_BUFFERS 5086#if defined USE_MMAP_FOR_BUFFERS
4836 mmap_free ((POINTER_TYPE **) &b->text->beg); 5087 mmap_free ((void **) &b->text->beg);
4837#elif defined REL_ALLOC 5088#elif defined REL_ALLOC
4838 r_alloc_free ((POINTER_TYPE **) &b->text->beg); 5089 r_alloc_free ((void **) &b->text->beg);
4839#else 5090#else
4840 xfree (b->text->beg); 5091 xfree (b->text->beg);
4841#endif 5092#endif
4842 5093
4843 BUF_BEG_ADDR (b) = NULL; 5094 BUF_BEG_ADDR (b) = NULL;
4844 UNBLOCK_INPUT; 5095 unblock_input ();
4845} 5096}
4846 5097
4847 5098
@@ -4868,68 +5119,70 @@ init_buffer_once (void)
4868 /* Prevent GC from getting confused. */ 5119 /* Prevent GC from getting confused. */
4869 buffer_defaults.text = &buffer_defaults.own_text; 5120 buffer_defaults.text = &buffer_defaults.own_text;
4870 buffer_local_symbols.text = &buffer_local_symbols.own_text; 5121 buffer_local_symbols.text = &buffer_local_symbols.own_text;
4871 BUF_INTERVALS (&buffer_defaults) = 0; 5122 /* No one will share the text with these buffers, but let's play it safe. */
4872 BUF_INTERVALS (&buffer_local_symbols) = 0; 5123 buffer_defaults.indirections = 0;
4873 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, 0); 5124 buffer_local_symbols.indirections = 0;
4874 XSETBUFFER (Vbuffer_defaults, &buffer_defaults); 5125 set_buffer_intervals (&buffer_defaults, NULL);
4875 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, 0); 5126 set_buffer_intervals (&buffer_local_symbols, NULL);
4876 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); 5127 /* This is not strictly necessary, but let's make them initialized. */
5128 bset_name (&buffer_defaults, build_pure_c_string (" *buffer-defaults*"));
5129 bset_name (&buffer_local_symbols, build_pure_c_string (" *buffer-local-symbols*"));
5130 BUFFER_PVEC_INIT (&buffer_defaults);
5131 BUFFER_PVEC_INIT (&buffer_local_symbols);
4877 5132
4878 /* Set up the default values of various buffer slots. */ 5133 /* Set up the default values of various buffer slots. */
4879 /* Must do these before making the first buffer! */ 5134 /* Must do these before making the first buffer! */
4880 5135
4881 /* real setup is done in bindings.el */ 5136 /* real setup is done in bindings.el */
4882 BVAR (&buffer_defaults, mode_line_format) = make_pure_c_string ("%-"); 5137 bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-"));
4883 BVAR (&buffer_defaults, header_line_format) = Qnil; 5138 bset_header_line_format (&buffer_defaults, Qnil);
4884 BVAR (&buffer_defaults, abbrev_mode) = Qnil; 5139 bset_abbrev_mode (&buffer_defaults, Qnil);
4885 BVAR (&buffer_defaults, overwrite_mode) = Qnil; 5140 bset_overwrite_mode (&buffer_defaults, Qnil);
4886 BVAR (&buffer_defaults, case_fold_search) = Qt; 5141 bset_case_fold_search (&buffer_defaults, Qt);
4887 BVAR (&buffer_defaults, auto_fill_function) = Qnil; 5142 bset_auto_fill_function (&buffer_defaults, Qnil);
4888 BVAR (&buffer_defaults, selective_display) = Qnil; 5143 bset_selective_display (&buffer_defaults, Qnil);
4889#ifndef old 5144 bset_selective_display_ellipses (&buffer_defaults, Qt);
4890 BVAR (&buffer_defaults, selective_display_ellipses) = Qt; 5145 bset_abbrev_table (&buffer_defaults, Qnil);
4891#endif 5146 bset_display_table (&buffer_defaults, Qnil);
4892 BVAR (&buffer_defaults, abbrev_table) = Qnil; 5147 bset_undo_list (&buffer_defaults, Qnil);
4893 BVAR (&buffer_defaults, display_table) = Qnil; 5148 bset_mark_active (&buffer_defaults, Qnil);
4894 BVAR (&buffer_defaults, undo_list) = Qnil; 5149 bset_file_format (&buffer_defaults, Qnil);
4895 BVAR (&buffer_defaults, mark_active) = Qnil; 5150 bset_auto_save_file_format (&buffer_defaults, Qt);
4896 BVAR (&buffer_defaults, file_format) = Qnil; 5151 set_buffer_overlays_before (&buffer_defaults, NULL);
4897 BVAR (&buffer_defaults, auto_save_file_format) = Qt; 5152 set_buffer_overlays_after (&buffer_defaults, NULL);
4898 buffer_defaults.overlays_before = NULL;
4899 buffer_defaults.overlays_after = NULL;
4900 buffer_defaults.overlay_center = BEG; 5153 buffer_defaults.overlay_center = BEG;
4901 5154
4902 XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8); 5155 XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8);
4903 BVAR (&buffer_defaults, truncate_lines) = Qnil; 5156 bset_truncate_lines (&buffer_defaults, Qnil);
4904 BVAR (&buffer_defaults, word_wrap) = Qnil; 5157 bset_word_wrap (&buffer_defaults, Qnil);
4905 BVAR (&buffer_defaults, ctl_arrow) = Qt; 5158 bset_ctl_arrow (&buffer_defaults, Qt);
4906 BVAR (&buffer_defaults, bidi_display_reordering) = Qt; 5159 bset_bidi_display_reordering (&buffer_defaults, Qt);
4907 BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; 5160 bset_bidi_paragraph_direction (&buffer_defaults, Qnil);
4908 BVAR (&buffer_defaults, cursor_type) = Qt; 5161 bset_cursor_type (&buffer_defaults, Qt);
4909 BVAR (&buffer_defaults, extra_line_spacing) = Qnil; 5162 bset_extra_line_spacing (&buffer_defaults, Qnil);
4910 BVAR (&buffer_defaults, cursor_in_non_selected_windows) = Qt; 5163 bset_cursor_in_non_selected_windows (&buffer_defaults, Qt);
4911 5164
4912 BVAR (&buffer_defaults, enable_multibyte_characters) = Qt; 5165 bset_enable_multibyte_characters (&buffer_defaults, Qt);
4913 BVAR (&buffer_defaults, buffer_file_coding_system) = Qnil; 5166 bset_buffer_file_coding_system (&buffer_defaults, Qnil);
4914 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); 5167 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70);
4915 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); 5168 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0);
4916 BVAR (&buffer_defaults, cache_long_line_scans) = Qnil; 5169 bset_cache_long_line_scans (&buffer_defaults, Qnil);
4917 BVAR (&buffer_defaults, file_truename) = Qnil; 5170 bset_file_truename (&buffer_defaults, Qnil);
4918 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); 5171 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0);
4919 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); 5172 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0);
4920 XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0); 5173 XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0);
4921 BVAR (&buffer_defaults, left_fringe_width) = Qnil; 5174 bset_left_fringe_width (&buffer_defaults, Qnil);
4922 BVAR (&buffer_defaults, right_fringe_width) = Qnil; 5175 bset_right_fringe_width (&buffer_defaults, Qnil);
4923 BVAR (&buffer_defaults, fringes_outside_margins) = Qnil; 5176 bset_fringes_outside_margins (&buffer_defaults, Qnil);
4924 BVAR (&buffer_defaults, scroll_bar_width) = Qnil; 5177 bset_scroll_bar_width (&buffer_defaults, Qnil);
4925 BVAR (&buffer_defaults, vertical_scroll_bar_type) = Qt; 5178 bset_vertical_scroll_bar_type (&buffer_defaults, Qt);
4926 BVAR (&buffer_defaults, indicate_empty_lines) = Qnil; 5179 bset_indicate_empty_lines (&buffer_defaults, Qnil);
4927 BVAR (&buffer_defaults, indicate_buffer_boundaries) = Qnil; 5180 bset_indicate_buffer_boundaries (&buffer_defaults, Qnil);
4928 BVAR (&buffer_defaults, fringe_indicator_alist) = Qnil; 5181 bset_fringe_indicator_alist (&buffer_defaults, Qnil);
4929 BVAR (&buffer_defaults, fringe_cursor_alist) = Qnil; 5182 bset_fringe_cursor_alist (&buffer_defaults, Qnil);
4930 BVAR (&buffer_defaults, scroll_up_aggressively) = Qnil; 5183 bset_scroll_up_aggressively (&buffer_defaults, Qnil);
4931 BVAR (&buffer_defaults, scroll_down_aggressively) = Qnil; 5184 bset_scroll_down_aggressively (&buffer_defaults, Qnil);
4932 BVAR (&buffer_defaults, display_time) = Qnil; 5185 bset_display_time (&buffer_defaults, Qnil);
4933 5186
4934 /* Assign the local-flags to the slots that have default values. 5187 /* Assign the local-flags to the slots that have default values.
4935 The local flag is a bit that is used in the buffer 5188 The local flag is a bit that is used in the buffer
@@ -4937,28 +5190,28 @@ init_buffer_once (void)
4937 The local flag bits are in the local_var_flags slot of the buffer. */ 5190 The local flag bits are in the local_var_flags slot of the buffer. */
4938 5191
4939 /* Nothing can work if this isn't true */ 5192 /* Nothing can work if this isn't true */
4940 { verify (sizeof (EMACS_INT) == sizeof (Lisp_Object)); } 5193 { verify (sizeof (EMACS_INT) == word_size); }
4941 5194
4942 /* 0 means not a lisp var, -1 means always local, else mask */ 5195 /* 0 means not a lisp var, -1 means always local, else mask */
4943 memset (&buffer_local_flags, 0, sizeof buffer_local_flags); 5196 memset (&buffer_local_flags, 0, sizeof buffer_local_flags);
4944 XSETINT (BVAR (&buffer_local_flags, filename), -1); 5197 bset_filename (&buffer_local_flags, make_number (-1));
4945 XSETINT (BVAR (&buffer_local_flags, directory), -1); 5198 bset_directory (&buffer_local_flags, make_number (-1));
4946 XSETINT (BVAR (&buffer_local_flags, backed_up), -1); 5199 bset_backed_up (&buffer_local_flags, make_number (-1));
4947 XSETINT (BVAR (&buffer_local_flags, save_length), -1); 5200 bset_save_length (&buffer_local_flags, make_number (-1));
4948 XSETINT (BVAR (&buffer_local_flags, auto_save_file_name), -1); 5201 bset_auto_save_file_name (&buffer_local_flags, make_number (-1));
4949 XSETINT (BVAR (&buffer_local_flags, read_only), -1); 5202 bset_read_only (&buffer_local_flags, make_number (-1));
4950 XSETINT (BVAR (&buffer_local_flags, major_mode), -1); 5203 bset_major_mode (&buffer_local_flags, make_number (-1));
4951 XSETINT (BVAR (&buffer_local_flags, mode_name), -1); 5204 bset_mode_name (&buffer_local_flags, make_number (-1));
4952 XSETINT (BVAR (&buffer_local_flags, undo_list), -1); 5205 bset_undo_list (&buffer_local_flags, make_number (-1));
4953 XSETINT (BVAR (&buffer_local_flags, mark_active), -1); 5206 bset_mark_active (&buffer_local_flags, make_number (-1));
4954 XSETINT (BVAR (&buffer_local_flags, point_before_scroll), -1); 5207 bset_point_before_scroll (&buffer_local_flags, make_number (-1));
4955 XSETINT (BVAR (&buffer_local_flags, file_truename), -1); 5208 bset_file_truename (&buffer_local_flags, make_number (-1));
4956 XSETINT (BVAR (&buffer_local_flags, invisibility_spec), -1); 5209 bset_invisibility_spec (&buffer_local_flags, make_number (-1));
4957 XSETINT (BVAR (&buffer_local_flags, file_format), -1); 5210 bset_file_format (&buffer_local_flags, make_number (-1));
4958 XSETINT (BVAR (&buffer_local_flags, auto_save_file_format), -1); 5211 bset_auto_save_file_format (&buffer_local_flags, make_number (-1));
4959 XSETINT (BVAR (&buffer_local_flags, display_count), -1); 5212 bset_display_count (&buffer_local_flags, make_number (-1));
4960 XSETINT (BVAR (&buffer_local_flags, display_time), -1); 5213 bset_display_time (&buffer_local_flags, make_number (-1));
4961 XSETINT (BVAR (&buffer_local_flags, enable_multibyte_characters), -1); 5214 bset_enable_multibyte_characters (&buffer_local_flags, make_number (-1));
4962 5215
4963 idx = 1; 5216 idx = 1;
4964 XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx; 5217 XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx;
@@ -4967,9 +5220,7 @@ init_buffer_once (void)
4967 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; 5220 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx;
4968 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; 5221 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx;
4969 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; 5222 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx;
4970#ifndef old
4971 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; 5223 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx;
4972#endif
4973 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx; 5224 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx;
4974 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx; 5225 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx;
4975 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx; 5226 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx;
@@ -5006,17 +5257,17 @@ init_buffer_once (void)
5006 5257
5007 /* Need more room? */ 5258 /* Need more room? */
5008 if (idx >= MAX_PER_BUFFER_VARS) 5259 if (idx >= MAX_PER_BUFFER_VARS)
5009 abort (); 5260 emacs_abort ();
5010 last_per_buffer_idx = idx; 5261 last_per_buffer_idx = idx;
5011 5262
5012 Vbuffer_alist = Qnil; 5263 Vbuffer_alist = Qnil;
5013 current_buffer = 0; 5264 current_buffer = 0;
5014 all_buffers = 0; 5265 all_buffers = 0;
5015 5266
5016 QSFundamental = make_pure_c_string ("Fundamental"); 5267 QSFundamental = build_pure_c_string ("Fundamental");
5017 5268
5018 Qfundamental_mode = intern_c_string ("fundamental-mode"); 5269 Qfundamental_mode = intern_c_string ("fundamental-mode");
5019 BVAR (&buffer_defaults, major_mode) = Qfundamental_mode; 5270 bset_major_mode (&buffer_defaults, Qfundamental_mode);
5020 5271
5021 Qmode_class = intern_c_string ("mode-class"); 5272 Qmode_class = intern_c_string ("mode-class");
5022 5273
@@ -5027,13 +5278,11 @@ init_buffer_once (void)
5027 Qkill_buffer_hook = intern_c_string ("kill-buffer-hook"); 5278 Qkill_buffer_hook = intern_c_string ("kill-buffer-hook");
5028 Fput (Qkill_buffer_hook, Qpermanent_local, Qt); 5279 Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
5029 5280
5030 Qucs_set_table_for_input = intern_c_string ("ucs-set-table-for-input");
5031
5032 /* super-magic invisible buffer */ 5281 /* super-magic invisible buffer */
5033 Vprin1_to_string_buffer = Fget_buffer_create (make_pure_c_string (" prin1")); 5282 Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"));
5034 Vbuffer_alist = Qnil; 5283 Vbuffer_alist = Qnil;
5035 5284
5036 Fset_buffer (Fget_buffer_create (make_pure_c_string ("*scratch*"))); 5285 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
5037 5286
5038 inhibit_modification_hooks = 0; 5287 inhibit_modification_hooks = 0;
5039} 5288}
@@ -5052,7 +5301,7 @@ init_buffer (void)
5052 Map new memory. */ 5301 Map new memory. */
5053 struct buffer *b; 5302 struct buffer *b;
5054 5303
5055 for (b = all_buffers; b; b = b->header.next.buffer) 5304 FOR_EACH_BUFFER (b)
5056 if (b->text->beg == NULL) 5305 if (b->text->beg == NULL)
5057 enlarge_buffer_text (b, 0); 5306 enlarge_buffer_text (b, 0);
5058 } 5307 }
@@ -5073,20 +5322,21 @@ init_buffer (void)
5073 if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) 5322 if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
5074 { 5323 {
5075 /* Grow buffer to add directory separator and '\0'. */ 5324 /* Grow buffer to add directory separator and '\0'. */
5076 pwd = (char *) realloc (pwd, len + 2); 5325 pwd = realloc (pwd, len + 2);
5077 if (!pwd) 5326 if (!pwd)
5078 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); 5327 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
5079 pwd[len] = DIRECTORY_SEP; 5328 pwd[len] = DIRECTORY_SEP;
5080 pwd[len + 1] = '\0'; 5329 pwd[len + 1] = '\0';
5330 len++;
5081 } 5331 }
5082 5332
5083 BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd)); 5333 bset_directory (current_buffer, make_unibyte_string (pwd, len));
5084 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) 5334 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
5085 /* At this moment, we still don't know how to decode the 5335 /* At this moment, we still don't know how to decode the
5086 directory name. So, we keep the bytes in multibyte form so 5336 directory name. So, we keep the bytes in multibyte form so
5087 that ENCODE_FILE correctly gets the original bytes. */ 5337 that ENCODE_FILE correctly gets the original bytes. */
5088 BVAR (current_buffer, directory) 5338 bset_directory
5089 = string_to_multibyte (BVAR (current_buffer, directory)); 5339 (current_buffer, string_to_multibyte (BVAR (current_buffer, directory)));
5090 5340
5091 /* Add /: to the front of the name 5341 /* Add /: to the front of the name
5092 if it would otherwise be treated as magic. */ 5342 if it would otherwise be treated as magic. */
@@ -5097,11 +5347,12 @@ init_buffer (void)
5097 However, it is not necessary to turn / into /:/. 5347 However, it is not necessary to turn / into /:/.
5098 So avoid doing that. */ 5348 So avoid doing that. */
5099 && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) 5349 && strcmp ("/", SSDATA (BVAR (current_buffer, directory))))
5100 BVAR (current_buffer, directory) 5350 bset_directory
5101 = concat2 (build_string ("/:"), BVAR (current_buffer, directory)); 5351 (current_buffer,
5352 concat2 (build_string ("/:"), BVAR (current_buffer, directory)));
5102 5353
5103 temp = get_minibuffer (0); 5354 temp = get_minibuffer (0);
5104 BVAR (XBUFFER (temp), directory) = BVAR (current_buffer, directory); 5355 bset_directory (XBUFFER (temp), BVAR (current_buffer, directory));
5105 5356
5106 free (pwd); 5357 free (pwd);
5107} 5358}
@@ -5147,7 +5398,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5147 if (PER_BUFFER_IDX (offset) == 0) 5398 if (PER_BUFFER_IDX (offset) == 0)
5148 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding 5399 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
5149 slot of buffer_local_flags */ 5400 slot of buffer_local_flags */
5150 abort (); 5401 emacs_abort ();
5151} 5402}
5152 5403
5153 5404
@@ -5159,8 +5410,6 @@ syms_of_buffer (void)
5159 last_overlay_modification_hooks 5410 last_overlay_modification_hooks
5160 = Fmake_vector (make_number (10), Qnil); 5411 = Fmake_vector (make_number (10), Qnil);
5161 5412
5162 staticpro (&Vbuffer_defaults);
5163 staticpro (&Vbuffer_local_symbols);
5164 staticpro (&Qfundamental_mode); 5413 staticpro (&Qfundamental_mode);
5165 staticpro (&Qmode_class); 5414 staticpro (&Qmode_class);
5166 staticpro (&QSFundamental); 5415 staticpro (&QSFundamental);
@@ -5184,13 +5433,10 @@ syms_of_buffer (void)
5184 DEFSYM (Qafter_change_functions, "after-change-functions"); 5433 DEFSYM (Qafter_change_functions, "after-change-functions");
5185 DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions"); 5434 DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions");
5186 5435
5187 /* The next one is initialized in init_buffer_once. */
5188 staticpro (&Qucs_set_table_for_input);
5189
5190 Fput (Qprotected_field, Qerror_conditions, 5436 Fput (Qprotected_field, Qerror_conditions,
5191 pure_cons (Qprotected_field, pure_cons (Qerror, Qnil))); 5437 listn (CONSTYPE_PURE, 2, Qprotected_field, Qerror));
5192 Fput (Qprotected_field, Qerror_message, 5438 Fput (Qprotected_field, Qerror_message,
5193 make_pure_c_string ("Attempt to modify a protected field")); 5439 build_pure_c_string ("Attempt to modify a protected field"));
5194 5440
5195 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format", 5441 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format",
5196 mode_line_format, 5442 mode_line_format,
@@ -5228,7 +5474,7 @@ This is the same as (default-value 'ctl-arrow). */);
5228 5474
5229 DEFVAR_BUFFER_DEFAULTS ("default-enable-multibyte-characters", 5475 DEFVAR_BUFFER_DEFAULTS ("default-enable-multibyte-characters",
5230 enable_multibyte_characters, 5476 enable_multibyte_characters,
5231 doc: /* *Default value of `enable-multibyte-characters' for buffers not overriding it. 5477 doc: /* Default value of `enable-multibyte-characters' for buffers not overriding it.
5232This is the same as (default-value 'enable-multibyte-characters). */); 5478This is the same as (default-value 'enable-multibyte-characters). */);
5233 5479
5234 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system", 5480 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system",
@@ -5338,31 +5584,40 @@ the mode line appears at the bottom. */);
5338 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), 5584 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format),
5339 Qnil, 5585 Qnil,
5340 doc: /* Template for displaying mode line for current buffer. 5586 doc: /* Template for displaying mode line for current buffer.
5341Each buffer has its own value of this variable. 5587
5342Value may be nil, a string, a symbol or a list or cons cell. 5588The value may be nil, a string, a symbol or a list.
5589
5343A value of nil means don't display a mode line. 5590A value of nil means don't display a mode line.
5344For a symbol, its value is used (but it is ignored if t or nil). 5591
5345 A string appearing directly as the value of a symbol is processed verbatim 5592For any symbol other than t or nil, the symbol's value is processed as
5346 in that the %-constructs below are not recognized. 5593 a mode line construct. As a special exception, if that value is a
5347 Note that unless the symbol is marked as a `risky-local-variable', all 5594 string, the string is processed verbatim, without handling any
5348 properties in any strings, as well as all :eval and :propertize forms 5595 %-constructs (see below). Also, unless the symbol has a non-nil
5349 in the value of that symbol will be ignored. 5596 `risky-local-variable' property, all properties in any strings, as
5350For a list of the form `(:eval FORM)', FORM is evaluated and the result 5597 well as all :eval and :propertize forms in the value, are ignored.
5351 is used as a mode line element. Be careful--FORM should not load any files, 5598
5352 because that can cause an infinite recursion. 5599A list whose car is a string or list is processed by processing each
5353For a list of the form `(:propertize ELT PROPS...)', ELT is displayed 5600 of the list elements recursively, as separate mode line constructs,
5354 with the specified properties PROPS applied. 5601 and concatenating the results.
5355For a list whose car is a symbol, the symbol's value is taken, 5602
5356 and if that is non-nil, the cadr of the list is processed recursively. 5603A list of the form `(:eval FORM)' is processed by evaluating FORM and
5357 Otherwise, the caddr of the list (if there is one) is processed. 5604 using the result as a mode line construct. Be careful--FORM should
5358For a list whose car is a string or list, each element is processed 5605 not load any files, because that can cause an infinite recursion.
5359 recursively and the results are effectively concatenated. 5606
5360For a list whose car is an integer, the cdr of the list is processed 5607A list of the form `(:propertize ELT PROPS...)' is processed by
5361 and padded (if the number is positive) or truncated (if negative) 5608 processing ELT as the mode line construct, and adding the text
5362 to the width specified by that number. 5609 properties PROPS to the result.
5610
5611A list whose car is a symbol is processed by examining the symbol's
5612 value, and, if that value is non-nil, processing the cadr of the list
5613 recursively; and if that value is nil, processing the caddr of the
5614 list recursively.
5615
5616A list whose car is an integer is processed by processing the cadr of
5617 the list, and padding (if the number is positive) or truncating (if
5618 negative) to the width specified by that number.
5619
5363A string is printed verbatim in the mode line except for %-constructs: 5620A string is printed verbatim in the mode line except for %-constructs:
5364 (%-constructs are allowed when the string is the entire mode-line-format
5365 or when it is found in a cons-cell or a list)
5366 %b -- print buffer name. %f -- print visited file name. 5621 %b -- print buffer name. %f -- print visited file name.
5367 %F -- print frame name. 5622 %F -- print frame name.
5368 %* -- print %, * or hyphen. %+ -- print *, % or hyphen. 5623 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
@@ -5390,7 +5645,7 @@ A string is printed verbatim in the mode line except for %-constructs:
5390Decimal digits after the % specify field width to which to pad. */); 5645Decimal digits after the % specify field width to which to pad. */);
5391 5646
5392 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode, 5647 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode,
5393 doc: /* *Value of `major-mode' for new buffers. */); 5648 doc: /* Value of `major-mode' for new buffers. */);
5394 5649
5395 DEFVAR_PER_BUFFER ("major-mode", &BVAR (current_buffer, major_mode), 5650 DEFVAR_PER_BUFFER ("major-mode", &BVAR (current_buffer, major_mode),
5396 make_number (Lisp_Symbol), 5651 make_number (Lisp_Symbol),
@@ -5421,25 +5676,25 @@ Use the command `abbrev-mode' to change this variable. */);
5421 5676
5422 DEFVAR_PER_BUFFER ("case-fold-search", &BVAR (current_buffer, case_fold_search), 5677 DEFVAR_PER_BUFFER ("case-fold-search", &BVAR (current_buffer, case_fold_search),
5423 Qnil, 5678 Qnil,
5424 doc: /* *Non-nil if searches and matches should ignore case. */); 5679 doc: /* Non-nil if searches and matches should ignore case. */);
5425 5680
5426 DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column), 5681 DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column),
5427 make_number (LISP_INT_TAG), 5682 make_number (Lisp_Int0),
5428 doc: /* *Column beyond which automatic line-wrapping should happen. 5683 doc: /* Column beyond which automatic line-wrapping should happen.
5429Interactively, you can set the buffer local value using \\[set-fill-column]. */); 5684Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5430 5685
5431 DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer, left_margin), 5686 DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer, left_margin),
5432 make_number (LISP_INT_TAG), 5687 make_number (Lisp_Int0),
5433 doc: /* *Column for the default `indent-line-function' to indent to. 5688 doc: /* Column for the default `indent-line-function' to indent to.
5434Linefeed indents to this column in Fundamental mode. */); 5689Linefeed indents to this column in Fundamental mode. */);
5435 5690
5436 DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer, tab_width), 5691 DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer, tab_width),
5437 make_number (LISP_INT_TAG), 5692 make_number (Lisp_Int0),
5438 doc: /* *Distance between tab stops (for display of tab characters), in columns. 5693 doc: /* Distance between tab stops (for display of tab characters), in columns.
5439This should be an integer greater than zero. */); 5694This should be an integer greater than zero. */);
5440 5695
5441 DEFVAR_PER_BUFFER ("ctl-arrow", &BVAR (current_buffer, ctl_arrow), Qnil, 5696 DEFVAR_PER_BUFFER ("ctl-arrow", &BVAR (current_buffer, ctl_arrow), Qnil,
5442 doc: /* *Non-nil means display control chars with uparrow. 5697 doc: /* Non-nil means display control chars with uparrow.
5443A value of nil means use backslash and octal digits. 5698A value of nil means use backslash and octal digits.
5444This variable does not apply to characters whose display is specified 5699This variable does not apply to characters whose display is specified
5445in the current display table (if there is one). */); 5700in the current display table (if there is one). */);
@@ -5480,7 +5735,7 @@ This variable is never applied to a way of decoding a file while reading it. */
5480 5735
5481 DEFVAR_PER_BUFFER ("bidi-paragraph-direction", 5736 DEFVAR_PER_BUFFER ("bidi-paragraph-direction",
5482 &BVAR (current_buffer, bidi_paragraph_direction), Qnil, 5737 &BVAR (current_buffer, bidi_paragraph_direction), Qnil,
5483 doc: /* *If non-nil, forces directionality of text paragraphs in the buffer. 5738 doc: /* If non-nil, forces directionality of text paragraphs in the buffer.
5484 5739
5485If this is nil (the default), the direction of each paragraph is 5740If this is nil (the default), the direction of each paragraph is
5486determined by the first strong directional character of its text. 5741determined by the first strong directional character of its text.
@@ -5491,7 +5746,7 @@ This variable has no effect unless the buffer's value of
5491\`bidi-display-reordering' is non-nil. */); 5746\`bidi-display-reordering' is non-nil. */);
5492 5747
5493 DEFVAR_PER_BUFFER ("truncate-lines", &BVAR (current_buffer, truncate_lines), Qnil, 5748 DEFVAR_PER_BUFFER ("truncate-lines", &BVAR (current_buffer, truncate_lines), Qnil,
5494 doc: /* *Non-nil means do not display continuation lines. 5749 doc: /* Non-nil means do not display continuation lines.
5495Instead, give each line of text just one screen line. 5750Instead, give each line of text just one screen line.
5496 5751
5497Note that this is overridden by the variable 5752Note that this is overridden by the variable
@@ -5501,7 +5756,7 @@ and this buffer is not full-frame width.
5501Minibuffers set this variable to nil. */); 5756Minibuffers set this variable to nil. */);
5502 5757
5503 DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil, 5758 DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil,
5504 doc: /* *Non-nil means to use word-wrapping for continuation lines. 5759 doc: /* Non-nil means to use word-wrapping for continuation lines.
5505When word-wrapping is on, continuation lines are wrapped at the space 5760When word-wrapping is on, continuation lines are wrapped at the space
5506or tab character nearest to the right window edge. 5761or tab character nearest to the right window edge.
5507If nil, continuation lines are wrapped at the right screen edge. 5762If nil, continuation lines are wrapped at the right screen edge.
@@ -5510,7 +5765,13 @@ This variable has no effect if long lines are truncated (see
5510`truncate-lines' and `truncate-partial-width-windows'). If you use 5765`truncate-lines' and `truncate-partial-width-windows'). If you use
5511word-wrapping, you might want to reduce the value of 5766word-wrapping, you might want to reduce the value of
5512`truncate-partial-width-windows', since wrapping can make text readable 5767`truncate-partial-width-windows', since wrapping can make text readable
5513in narrower windows. */); 5768in narrower windows.
5769
5770Instead of setting this variable directly, most users should use
5771Visual Line mode . Visual Line mode, when enabled, sets `word-wrap'
5772to t, and additionally redefines simple editing commands to act on
5773visual lines rather than logical lines. See the documentation of
5774`visual-line-mode'. */);
5514 5775
5515 DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory), 5776 DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory),
5516 make_number (Lisp_String), 5777 make_number (Lisp_String),
@@ -5549,7 +5810,7 @@ If it is nil, that means don't auto-save this buffer. */);
5549Backing up is done before the first time the file is saved. */); 5810Backing up is done before the first time the file is saved. */);
5550 5811
5551 DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer, save_length), 5812 DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer, save_length),
5552 make_number (LISP_INT_TAG), 5813 make_number (Lisp_Int0),
5553 doc: /* Length of current buffer when last read in, saved or auto-saved. 5814 doc: /* Length of current buffer when last read in, saved or auto-saved.
55540 initially. 58150 initially.
5555-1 means auto-saving turned off until next real save. 5816-1 means auto-saving turned off until next real save.
@@ -5567,12 +5828,10 @@ A value of t means that the character ^M makes itself and
5567all the rest of the line invisible; also, when saving the buffer 5828all the rest of the line invisible; also, when saving the buffer
5568in a file, save the ^M as a newline. */); 5829in a file, save the ^M as a newline. */);
5569 5830
5570#ifndef old
5571 DEFVAR_PER_BUFFER ("selective-display-ellipses", 5831 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5572 &BVAR (current_buffer, selective_display_ellipses), 5832 &BVAR (current_buffer, selective_display_ellipses),
5573 Qnil, 5833 Qnil,
5574 doc: /* Non-nil means display ... on previous line when a line is invisible. */); 5834 doc: /* Non-nil means display ... on previous line when a line is invisible. */);
5575#endif
5576 5835
5577 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil, 5836 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil,
5578 doc: /* Non-nil if self-insertion should replace existing text. 5837 doc: /* Non-nil if self-insertion should replace existing text.
@@ -5622,39 +5881,39 @@ See also the functions `display-table-slot' and `set-display-table-slot'. */);
5622 5881
5623 DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols), 5882 DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols),
5624 Qnil, 5883 Qnil,
5625 doc: /* *Width of left marginal area for display of a buffer. 5884 doc: /* Width of left marginal area for display of a buffer.
5626A value of nil means no marginal area. */); 5885A value of nil means no marginal area. */);
5627 5886
5628 DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols), 5887 DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols),
5629 Qnil, 5888 Qnil,
5630 doc: /* *Width of right marginal area for display of a buffer. 5889 doc: /* Width of right marginal area for display of a buffer.
5631A value of nil means no marginal area. */); 5890A value of nil means no marginal area. */);
5632 5891
5633 DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width), 5892 DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width),
5634 Qnil, 5893 Qnil,
5635 doc: /* *Width of this buffer's left fringe (in pixels). 5894 doc: /* Width of this buffer's left fringe (in pixels).
5636A value of 0 means no left fringe is shown in this buffer's window. 5895A value of 0 means no left fringe is shown in this buffer's window.
5637A value of nil means to use the left fringe width from the window's frame. */); 5896A value of nil means to use the left fringe width from the window's frame. */);
5638 5897
5639 DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width), 5898 DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width),
5640 Qnil, 5899 Qnil,
5641 doc: /* *Width of this buffer's right fringe (in pixels). 5900 doc: /* Width of this buffer's right fringe (in pixels).
5642A value of 0 means no right fringe is shown in this buffer's window. 5901A value of 0 means no right fringe is shown in this buffer's window.
5643A value of nil means to use the right fringe width from the window's frame. */); 5902A value of nil means to use the right fringe width from the window's frame. */);
5644 5903
5645 DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins), 5904 DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins),
5646 Qnil, 5905 Qnil,
5647 doc: /* *Non-nil means to display fringes outside display margins. 5906 doc: /* Non-nil means to display fringes outside display margins.
5648A value of nil means to display fringes between margins and buffer text. */); 5907A value of nil means to display fringes between margins and buffer text. */);
5649 5908
5650 DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), 5909 DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width),
5651 Qnil, 5910 Qnil,
5652 doc: /* *Width of this buffer's scroll bars in pixels. 5911 doc: /* Width of this buffer's scroll bars in pixels.
5653A value of nil means to use the scroll bar width from the window's frame. */); 5912A value of nil means to use the scroll bar width from the window's frame. */);
5654 5913
5655 DEFVAR_PER_BUFFER ("vertical-scroll-bar", &BVAR (current_buffer, vertical_scroll_bar_type), 5914 DEFVAR_PER_BUFFER ("vertical-scroll-bar", &BVAR (current_buffer, vertical_scroll_bar_type),
5656 Qnil, 5915 Qnil,
5657 doc: /* *Position of this buffer's vertical scroll bar. 5916 doc: /* Position of this buffer's vertical scroll bar.
5658The value takes effect whenever you tell a window to display this buffer; 5917The value takes effect whenever you tell a window to display this buffer;
5659for instance, with `set-window-buffer' or when `display-buffer' displays it. 5918for instance, with `set-window-buffer' or when `display-buffer' displays it.
5660 5919
@@ -5664,13 +5923,13 @@ A value of t (the default) means do whatever the window's frame specifies. */);
5664 5923
5665 DEFVAR_PER_BUFFER ("indicate-empty-lines", 5924 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5666 &BVAR (current_buffer, indicate_empty_lines), Qnil, 5925 &BVAR (current_buffer, indicate_empty_lines), Qnil,
5667 doc: /* *Visually indicate empty lines after the buffer end. 5926 doc: /* Visually indicate empty lines after the buffer end.
5668If non-nil, a bitmap is displayed in the left fringe of a window on 5927If non-nil, a bitmap is displayed in the left fringe of a window on
5669window-systems. */); 5928window-systems. */);
5670 5929
5671 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries", 5930 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5672 &BVAR (current_buffer, indicate_buffer_boundaries), Qnil, 5931 &BVAR (current_buffer, indicate_buffer_boundaries), Qnil,
5673 doc: /* *Visually indicate buffer boundaries and scrolling. 5932 doc: /* Visually indicate buffer boundaries and scrolling.
5674If non-nil, the first and last line of the buffer are marked in the fringe 5933If non-nil, the first and last line of the buffer are marked in the fringe
5675of a window on window-systems with angle bitmaps, or if the window can be 5934of a window on window-systems with angle bitmaps, or if the window can be
5676scrolled, the top and bottom line of the window are marked with up and down 5935scrolled, the top and bottom line of the window are marked with up and down
@@ -5695,7 +5954,7 @@ fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5695 5954
5696 DEFVAR_PER_BUFFER ("fringe-indicator-alist", 5955 DEFVAR_PER_BUFFER ("fringe-indicator-alist",
5697 &BVAR (current_buffer, fringe_indicator_alist), Qnil, 5956 &BVAR (current_buffer, fringe_indicator_alist), Qnil,
5698 doc: /* *Mapping from logical to physical fringe indicator bitmaps. 5957 doc: /* Mapping from logical to physical fringe indicator bitmaps.
5699The value is an alist where each element (INDICATOR . BITMAPS) 5958The value is an alist where each element (INDICATOR . BITMAPS)
5700specifies the fringe bitmaps used to display a specific logical 5959specifies the fringe bitmaps used to display a specific logical
5701fringe indicator. 5960fringe indicator.
@@ -5714,7 +5973,7 @@ symbol which is used in both left and right fringes. */);
5714 5973
5715 DEFVAR_PER_BUFFER ("fringe-cursor-alist", 5974 DEFVAR_PER_BUFFER ("fringe-cursor-alist",
5716 &BVAR (current_buffer, fringe_cursor_alist), Qnil, 5975 &BVAR (current_buffer, fringe_cursor_alist), Qnil,
5717 doc: /* *Mapping from logical to physical fringe cursor bitmaps. 5976 doc: /* Mapping from logical to physical fringe cursor bitmaps.
5718The value is an alist where each element (CURSOR . BITMAP) 5977The value is an alist where each element (CURSOR . BITMAP)
5719specifies the fringe bitmaps used to display a specific logical 5978specifies the fringe bitmaps used to display a specific logical
5720cursor type in the fringe. 5979cursor type in the fringe.
@@ -5807,9 +6066,9 @@ An entry (TEXT . POSITION) represents the deletion of the string TEXT
5807from (abs POSITION). If POSITION is positive, point was at the front 6066from (abs POSITION). If POSITION is positive, point was at the front
5808of the text being deleted; if negative, point was at the end. 6067of the text being deleted; if negative, point was at the end.
5809 6068
5810An entry (t HIGH . LOW) indicates that the buffer previously had 6069An entry (t HIGH LOW USEC PSEC) indicates that the buffer was previously
5811\"unmodified\" status. HIGH and LOW are the high and low 16-bit portions 6070unmodified; (HIGH LOW USEC PSEC) is in the same style as (current-time)
5812of the visited file's modification time, as of that time. If the 6071and is the visited file's modification time, as of that time. If the
5813modification time of the most recent save is different, this entry is 6072modification time of the most recent save is different, this entry is
5814obsolete. 6073obsolete.
5815 6074
@@ -5878,7 +6137,7 @@ set when a file is visited. */);
5878 6137
5879 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format", 6138 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
5880 &BVAR (current_buffer, auto_save_file_format), Qnil, 6139 &BVAR (current_buffer, auto_save_file_format), Qnil,
5881 doc: /* *Format in which to write auto-save files. 6140 doc: /* Format in which to write auto-save files.
5882Should be a list of symbols naming formats that are defined in `format-alist'. 6141Should be a list of symbols naming formats that are defined in `format-alist'.
5883If it is t, which is the default, auto-save files are written in the 6142If it is t, which is the default, auto-save files are written in the
5884same format as a regular save would use. */); 6143same format as a regular save would use. */);
@@ -5928,7 +6187,7 @@ Lisp programs may give this variable certain special values:
5928 Vtransient_mark_mode = Qnil; 6187 Vtransient_mark_mode = Qnil;
5929 6188
5930 DEFVAR_LISP ("inhibit-read-only", Vinhibit_read_only, 6189 DEFVAR_LISP ("inhibit-read-only", Vinhibit_read_only,
5931 doc: /* *Non-nil means disregard read-only status of buffers or characters. 6190 doc: /* Non-nil means disregard read-only status of buffers or characters.
5932If the value is t, disregard `buffer-read-only' and all `read-only' 6191If the value is t, disregard `buffer-read-only' and all `read-only'
5933text properties. If the value is a list, disregard `buffer-read-only' 6192text properties. If the value is a list, disregard `buffer-read-only'
5934and disregard a `read-only' text property if the property value 6193and disregard a `read-only' text property if the property value
@@ -5939,15 +6198,15 @@ is a member of the list. */);
5939 doc: /* Cursor to use when this buffer is in the selected window. 6198 doc: /* Cursor to use when this buffer is in the selected window.
5940Values are interpreted as follows: 6199Values are interpreted as follows:
5941 6200
5942 t use the cursor specified for the frame 6201 t use the cursor specified for the frame
5943 nil don't display a cursor 6202 nil don't display a cursor
5944 box display a filled box cursor 6203 box display a filled box cursor
5945 hollow display a hollow box cursor 6204 hollow display a hollow box cursor
5946 bar display a vertical bar cursor with default width 6205 bar display a vertical bar cursor with default width
5947 (bar . WIDTH) display a vertical bar cursor with width WIDTH 6206 (bar . WIDTH) display a vertical bar cursor with width WIDTH
5948 hbar display a horizontal bar cursor with default height 6207 hbar display a horizontal bar cursor with default height
5949 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT 6208 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
5950 ANYTHING ELSE display a hollow box cursor 6209 ANYTHING ELSE display a hollow box cursor
5951 6210
5952When the buffer is displayed in a non-selected window, the 6211When the buffer is displayed in a non-selected window, the
5953cursor's appearance is instead controlled by the variable 6212cursor's appearance is instead controlled by the variable
@@ -5963,7 +6222,7 @@ to the default frame line height. A value of nil means add no extra space. */)
5963 6222
5964 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows", 6223 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
5965 &BVAR (current_buffer, cursor_in_non_selected_windows), Qnil, 6224 &BVAR (current_buffer, cursor_in_non_selected_windows), Qnil,
5966 doc: /* *Non-nil means show a cursor in non-selected windows. 6225 doc: /* Non-nil means show a cursor in non-selected windows.
5967If nil, only shows a cursor in the selected window. 6226If nil, only shows a cursor in the selected window.
5968If t, displays a cursor related to the usual cursor type 6227If t, displays a cursor related to the usual cursor type
5969\(a solid box becomes hollow, a bar becomes a narrower bar). 6228\(a solid box becomes hollow, a bar becomes a narrower bar).
@@ -5973,7 +6232,9 @@ Use Custom to set this variable and update the display." */);
5973 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions, 6232 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions,
5974 doc: /* List of functions called with no args to query before killing a buffer. 6233 doc: /* List of functions called with no args to query before killing a buffer.
5975The buffer being killed will be current while the functions are running. 6234The buffer being killed will be current while the functions are running.
5976If any of them returns nil, the buffer is not killed. */); 6235
6236If any of them returns nil, the buffer is not killed. Functions run by
6237this hook are supposed to not change the current buffer. */);
5977 Vkill_buffer_query_functions = Qnil; 6238 Vkill_buffer_query_functions = Qnil;
5978 6239
5979 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook, 6240 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook,
@@ -5986,7 +6247,7 @@ The function `kill-all-local-variables' runs this before doing anything else. *
5986 doc: /* Hook run when the buffer list changes. 6247 doc: /* Hook run when the buffer list changes.
5987Functions running this hook are `get-buffer-create', 6248Functions running this hook are `get-buffer-create',
5988`make-indirect-buffer', `rename-buffer', `kill-buffer', 6249`make-indirect-buffer', `rename-buffer', `kill-buffer',
5989`record-buffer' and `unrecord-buffer'. */); 6250and `bury-buffer-internal'. */);
5990 Vbuffer_list_update_hook = Qnil; 6251 Vbuffer_list_update_hook = Qnil;
5991 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook"); 6252 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook");
5992 6253
@@ -5998,7 +6259,6 @@ Functions running this hook are `get-buffer-create',
5998 defsubr (&Smake_indirect_buffer); 6259 defsubr (&Smake_indirect_buffer);
5999 defsubr (&Sgenerate_new_buffer_name); 6260 defsubr (&Sgenerate_new_buffer_name);
6000 defsubr (&Sbuffer_name); 6261 defsubr (&Sbuffer_name);
6001/*defsubr (&Sbuffer_number);*/
6002 defsubr (&Sbuffer_file_name); 6262 defsubr (&Sbuffer_file_name);
6003 defsubr (&Sbuffer_base_buffer); 6263 defsubr (&Sbuffer_base_buffer);
6004 defsubr (&Sbuffer_local_value); 6264 defsubr (&Sbuffer_local_value);
@@ -6024,6 +6284,7 @@ Functions running this hook are `get-buffer-create',
6024 defsubr (&Soverlayp); 6284 defsubr (&Soverlayp);
6025 defsubr (&Smake_overlay); 6285 defsubr (&Smake_overlay);
6026 defsubr (&Sdelete_overlay); 6286 defsubr (&Sdelete_overlay);
6287 defsubr (&Sdelete_all_overlays);
6027 defsubr (&Smove_overlay); 6288 defsubr (&Smove_overlay);
6028 defsubr (&Soverlay_start); 6289 defsubr (&Soverlay_start);
6029 defsubr (&Soverlay_end); 6290 defsubr (&Soverlay_end);