aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorTom Tromey2012-12-17 07:56:22 -0700
committerTom Tromey2012-12-17 07:56:22 -0700
commit3d6eced1ae51ffd0a782130e7c334052277e2724 (patch)
tree5d1d2ad7cd3374f922886c4a72062511a035c168 /src/buffer.c
parentbf69f522a9e135f9aa483cedd53e71e915f2bf75 (diff)
parent7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff)
downloademacs-3d6eced1ae51ffd0a782130e7c334052277e2724.tar.gz
emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.zip
merge from trunk
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c355
1 files changed, 175 insertions, 180 deletions
diff --git a/src/buffer.c b/src/buffer.c
index ef87f40e81a..c8864419076 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <sys/param.h> 26#include <sys/param.h>
27#include <errno.h> 27#include <errno.h>
28#include <stdio.h> 28#include <stdio.h>
29#include <setjmp.h>
30#include <unistd.h> 29#include <unistd.h>
31 30
32#include <verify.h> 31#include <verify.h>
@@ -58,10 +57,6 @@ struct buffer *all_buffers;
58 57
59struct buffer alignas (GCALIGNMENT) buffer_defaults; 58struct buffer alignas (GCALIGNMENT) buffer_defaults;
60 59
61/* A Lisp_Object pointer to the above, used for staticpro */
62
63static Lisp_Object Vbuffer_defaults;
64
65/* This structure marks which slots in a buffer have corresponding 60/* This structure marks which slots in a buffer have corresponding
66 default values in buffer_defaults. 61 default values in buffer_defaults.
67 Each such slot has a nonzero value in this structure. 62 Each such slot has a nonzero value in this structure.
@@ -76,18 +71,15 @@ static Lisp_Object Vbuffer_defaults;
76 and the corresponding slot in buffer_defaults is not used. 71 and the corresponding slot in buffer_defaults is not used.
77 72
78 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is 73 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
79 zero, that is a bug */ 74 zero, that is a bug. */
80 75
81struct buffer buffer_local_flags; 76struct buffer buffer_local_flags;
82 77
83/* This structure holds the names of symbols whose values may be 78/* 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. */ 79 buffer-local. It is indexed and accessed in the same way as the above. */
85 80
86struct buffer alignas (GCALIGNMENT) buffer_local_symbols; 81struct buffer alignas (GCALIGNMENT) buffer_local_symbols;
87 82
88/* A Lisp_Object pointer to the above, used for staticpro */
89static Lisp_Object Vbuffer_local_symbols;
90
91/* Return the symbol of the per-buffer variable at offset OFFSET in 83/* Return the symbol of the per-buffer variable at offset OFFSET in
92 the buffer structure. */ 84 the buffer structure. */
93 85
@@ -113,7 +105,7 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
113static void swap_out_buffer_local_variables (struct buffer *b); 105static void swap_out_buffer_local_variables (struct buffer *b);
114static void reset_buffer_local_variables (struct buffer *, bool); 106static void reset_buffer_local_variables (struct buffer *, bool);
115 107
116/* Alist of all buffer names vs the buffers. */ 108/* Alist of all buffer names vs the buffers. */
117/* This used to be a variable, but is no longer, 109/* This used to be a variable, but is no longer,
118 to prevent lossage due to user rplac'ing this alist or its elements. */ 110 to prevent lossage due to user rplac'ing this alist or its elements. */
119Lisp_Object Vbuffer_alist; 111Lisp_Object Vbuffer_alist;
@@ -132,7 +124,7 @@ static Lisp_Object Qpermanent_local_hook;
132 124
133static Lisp_Object Qprotected_field; 125static Lisp_Object Qprotected_field;
134 126
135static Lisp_Object QSFundamental; /* A string "Fundamental" */ 127static Lisp_Object QSFundamental; /* A string "Fundamental". */
136 128
137static Lisp_Object Qkill_buffer_hook; 129static Lisp_Object Qkill_buffer_hook;
138static Lisp_Object Qbuffer_list_update_hook; 130static Lisp_Object Qbuffer_list_update_hook;
@@ -156,222 +148,222 @@ static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
156static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool); 148static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool);
157 149
158/* These setters are used only in this file, so they can be private. */ 150/* These setters are used only in this file, so they can be private. */
159static inline void 151static void
160bset_abbrev_mode (struct buffer *b, Lisp_Object val) 152bset_abbrev_mode (struct buffer *b, Lisp_Object val)
161{ 153{
162 b->INTERNAL_FIELD (abbrev_mode) = val; 154 b->INTERNAL_FIELD (abbrev_mode) = val;
163} 155}
164static inline void 156static void
165bset_abbrev_table (struct buffer *b, Lisp_Object val) 157bset_abbrev_table (struct buffer *b, Lisp_Object val)
166{ 158{
167 b->INTERNAL_FIELD (abbrev_table) = val; 159 b->INTERNAL_FIELD (abbrev_table) = val;
168} 160}
169static inline void 161static void
170bset_auto_fill_function (struct buffer *b, Lisp_Object val) 162bset_auto_fill_function (struct buffer *b, Lisp_Object val)
171{ 163{
172 b->INTERNAL_FIELD (auto_fill_function) = val; 164 b->INTERNAL_FIELD (auto_fill_function) = val;
173} 165}
174static inline void 166static void
175bset_auto_save_file_format (struct buffer *b, Lisp_Object val) 167bset_auto_save_file_format (struct buffer *b, Lisp_Object val)
176{ 168{
177 b->INTERNAL_FIELD (auto_save_file_format) = val; 169 b->INTERNAL_FIELD (auto_save_file_format) = val;
178} 170}
179static inline void 171static void
180bset_auto_save_file_name (struct buffer *b, Lisp_Object val) 172bset_auto_save_file_name (struct buffer *b, Lisp_Object val)
181{ 173{
182 b->INTERNAL_FIELD (auto_save_file_name) = val; 174 b->INTERNAL_FIELD (auto_save_file_name) = val;
183} 175}
184static inline void 176static void
185bset_backed_up (struct buffer *b, Lisp_Object val) 177bset_backed_up (struct buffer *b, Lisp_Object val)
186{ 178{
187 b->INTERNAL_FIELD (backed_up) = val; 179 b->INTERNAL_FIELD (backed_up) = val;
188} 180}
189static inline void 181static void
190bset_begv_marker (struct buffer *b, Lisp_Object val) 182bset_begv_marker (struct buffer *b, Lisp_Object val)
191{ 183{
192 b->INTERNAL_FIELD (begv_marker) = val; 184 b->INTERNAL_FIELD (begv_marker) = val;
193} 185}
194static inline void 186static void
195bset_bidi_display_reordering (struct buffer *b, Lisp_Object val) 187bset_bidi_display_reordering (struct buffer *b, Lisp_Object val)
196{ 188{
197 b->INTERNAL_FIELD (bidi_display_reordering) = val; 189 b->INTERNAL_FIELD (bidi_display_reordering) = val;
198} 190}
199static inline void 191static void
200bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val) 192bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
201{ 193{
202 b->INTERNAL_FIELD (buffer_file_coding_system) = val; 194 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
203} 195}
204static inline void 196static void
205bset_cache_long_line_scans (struct buffer *b, Lisp_Object val) 197bset_cache_long_line_scans (struct buffer *b, Lisp_Object val)
206{ 198{
207 b->INTERNAL_FIELD (cache_long_line_scans) = val; 199 b->INTERNAL_FIELD (cache_long_line_scans) = val;
208} 200}
209static inline void 201static void
210bset_case_fold_search (struct buffer *b, Lisp_Object val) 202bset_case_fold_search (struct buffer *b, Lisp_Object val)
211{ 203{
212 b->INTERNAL_FIELD (case_fold_search) = val; 204 b->INTERNAL_FIELD (case_fold_search) = val;
213} 205}
214static inline void 206static void
215bset_ctl_arrow (struct buffer *b, Lisp_Object val) 207bset_ctl_arrow (struct buffer *b, Lisp_Object val)
216{ 208{
217 b->INTERNAL_FIELD (ctl_arrow) = val; 209 b->INTERNAL_FIELD (ctl_arrow) = val;
218} 210}
219static inline void 211static void
220bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val) 212bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val)
221{ 213{
222 b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val; 214 b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val;
223} 215}
224static inline void 216static void
225bset_cursor_type (struct buffer *b, Lisp_Object val) 217bset_cursor_type (struct buffer *b, Lisp_Object val)
226{ 218{
227 b->INTERNAL_FIELD (cursor_type) = val; 219 b->INTERNAL_FIELD (cursor_type) = val;
228} 220}
229static inline void 221static void
230bset_display_table (struct buffer *b, Lisp_Object val) 222bset_display_table (struct buffer *b, Lisp_Object val)
231{ 223{
232 b->INTERNAL_FIELD (display_table) = val; 224 b->INTERNAL_FIELD (display_table) = val;
233} 225}
234static inline void 226static void
235bset_extra_line_spacing (struct buffer *b, Lisp_Object val) 227bset_extra_line_spacing (struct buffer *b, Lisp_Object val)
236{ 228{
237 b->INTERNAL_FIELD (extra_line_spacing) = val; 229 b->INTERNAL_FIELD (extra_line_spacing) = val;
238} 230}
239static inline void 231static void
240bset_file_format (struct buffer *b, Lisp_Object val) 232bset_file_format (struct buffer *b, Lisp_Object val)
241{ 233{
242 b->INTERNAL_FIELD (file_format) = val; 234 b->INTERNAL_FIELD (file_format) = val;
243} 235}
244static inline void 236static void
245bset_file_truename (struct buffer *b, Lisp_Object val) 237bset_file_truename (struct buffer *b, Lisp_Object val)
246{ 238{
247 b->INTERNAL_FIELD (file_truename) = val; 239 b->INTERNAL_FIELD (file_truename) = val;
248} 240}
249static inline void 241static void
250bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val) 242bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val)
251{ 243{
252 b->INTERNAL_FIELD (fringe_cursor_alist) = val; 244 b->INTERNAL_FIELD (fringe_cursor_alist) = val;
253} 245}
254static inline void 246static void
255bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val) 247bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val)
256{ 248{
257 b->INTERNAL_FIELD (fringe_indicator_alist) = val; 249 b->INTERNAL_FIELD (fringe_indicator_alist) = val;
258} 250}
259static inline void 251static void
260bset_fringes_outside_margins (struct buffer *b, Lisp_Object val) 252bset_fringes_outside_margins (struct buffer *b, Lisp_Object val)
261{ 253{
262 b->INTERNAL_FIELD (fringes_outside_margins) = val; 254 b->INTERNAL_FIELD (fringes_outside_margins) = val;
263} 255}
264static inline void 256static void
265bset_header_line_format (struct buffer *b, Lisp_Object val) 257bset_header_line_format (struct buffer *b, Lisp_Object val)
266{ 258{
267 b->INTERNAL_FIELD (header_line_format) = val; 259 b->INTERNAL_FIELD (header_line_format) = val;
268} 260}
269static inline void 261static void
270bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val) 262bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val)
271{ 263{
272 b->INTERNAL_FIELD (indicate_buffer_boundaries) = val; 264 b->INTERNAL_FIELD (indicate_buffer_boundaries) = val;
273} 265}
274static inline void 266static void
275bset_indicate_empty_lines (struct buffer *b, Lisp_Object val) 267bset_indicate_empty_lines (struct buffer *b, Lisp_Object val)
276{ 268{
277 b->INTERNAL_FIELD (indicate_empty_lines) = val; 269 b->INTERNAL_FIELD (indicate_empty_lines) = val;
278} 270}
279static inline void 271static void
280bset_invisibility_spec (struct buffer *b, Lisp_Object val) 272bset_invisibility_spec (struct buffer *b, Lisp_Object val)
281{ 273{
282 b->INTERNAL_FIELD (invisibility_spec) = val; 274 b->INTERNAL_FIELD (invisibility_spec) = val;
283} 275}
284static inline void 276static void
285bset_left_fringe_width (struct buffer *b, Lisp_Object val) 277bset_left_fringe_width (struct buffer *b, Lisp_Object val)
286{ 278{
287 b->INTERNAL_FIELD (left_fringe_width) = val; 279 b->INTERNAL_FIELD (left_fringe_width) = val;
288} 280}
289static inline void 281static void
290bset_major_mode (struct buffer *b, Lisp_Object val) 282bset_major_mode (struct buffer *b, Lisp_Object val)
291{ 283{
292 b->INTERNAL_FIELD (major_mode) = val; 284 b->INTERNAL_FIELD (major_mode) = val;
293} 285}
294static inline void 286static void
295bset_mark (struct buffer *b, Lisp_Object val) 287bset_mark (struct buffer *b, Lisp_Object val)
296{ 288{
297 b->INTERNAL_FIELD (mark) = val; 289 b->INTERNAL_FIELD (mark) = val;
298} 290}
299static inline void 291static void
300bset_minor_modes (struct buffer *b, Lisp_Object val) 292bset_minor_modes (struct buffer *b, Lisp_Object val)
301{ 293{
302 b->INTERNAL_FIELD (minor_modes) = val; 294 b->INTERNAL_FIELD (minor_modes) = val;
303} 295}
304static inline void 296static void
305bset_mode_line_format (struct buffer *b, Lisp_Object val) 297bset_mode_line_format (struct buffer *b, Lisp_Object val)
306{ 298{
307 b->INTERNAL_FIELD (mode_line_format) = val; 299 b->INTERNAL_FIELD (mode_line_format) = val;
308} 300}
309static inline void 301static void
310bset_mode_name (struct buffer *b, Lisp_Object val) 302bset_mode_name (struct buffer *b, Lisp_Object val)
311{ 303{
312 b->INTERNAL_FIELD (mode_name) = val; 304 b->INTERNAL_FIELD (mode_name) = val;
313} 305}
314static inline void 306static void
315bset_name (struct buffer *b, Lisp_Object val) 307bset_name (struct buffer *b, Lisp_Object val)
316{ 308{
317 b->INTERNAL_FIELD (name) = val; 309 b->INTERNAL_FIELD (name) = val;
318} 310}
319static inline void 311static void
320bset_overwrite_mode (struct buffer *b, Lisp_Object val) 312bset_overwrite_mode (struct buffer *b, Lisp_Object val)
321{ 313{
322 b->INTERNAL_FIELD (overwrite_mode) = val; 314 b->INTERNAL_FIELD (overwrite_mode) = val;
323} 315}
324static inline void 316static void
325bset_pt_marker (struct buffer *b, Lisp_Object val) 317bset_pt_marker (struct buffer *b, Lisp_Object val)
326{ 318{
327 b->INTERNAL_FIELD (pt_marker) = val; 319 b->INTERNAL_FIELD (pt_marker) = val;
328} 320}
329static inline void 321static void
330bset_right_fringe_width (struct buffer *b, Lisp_Object val) 322bset_right_fringe_width (struct buffer *b, Lisp_Object val)
331{ 323{
332 b->INTERNAL_FIELD (right_fringe_width) = val; 324 b->INTERNAL_FIELD (right_fringe_width) = val;
333} 325}
334static inline void 326static void
335bset_save_length (struct buffer *b, Lisp_Object val) 327bset_save_length (struct buffer *b, Lisp_Object val)
336{ 328{
337 b->INTERNAL_FIELD (save_length) = val; 329 b->INTERNAL_FIELD (save_length) = val;
338} 330}
339static inline void 331static void
340bset_scroll_bar_width (struct buffer *b, Lisp_Object val) 332bset_scroll_bar_width (struct buffer *b, Lisp_Object val)
341{ 333{
342 b->INTERNAL_FIELD (scroll_bar_width) = val; 334 b->INTERNAL_FIELD (scroll_bar_width) = val;
343} 335}
344static inline void 336static void
345bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val) 337bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val)
346{ 338{
347 b->INTERNAL_FIELD (scroll_down_aggressively) = val; 339 b->INTERNAL_FIELD (scroll_down_aggressively) = val;
348} 340}
349static inline void 341static void
350bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val) 342bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val)
351{ 343{
352 b->INTERNAL_FIELD (scroll_up_aggressively) = val; 344 b->INTERNAL_FIELD (scroll_up_aggressively) = val;
353} 345}
354static inline void 346static void
355bset_selective_display (struct buffer *b, Lisp_Object val) 347bset_selective_display (struct buffer *b, Lisp_Object val)
356{ 348{
357 b->INTERNAL_FIELD (selective_display) = val; 349 b->INTERNAL_FIELD (selective_display) = val;
358} 350}
359static inline void 351static void
360bset_selective_display_ellipses (struct buffer *b, Lisp_Object val) 352bset_selective_display_ellipses (struct buffer *b, Lisp_Object val)
361{ 353{
362 b->INTERNAL_FIELD (selective_display_ellipses) = val; 354 b->INTERNAL_FIELD (selective_display_ellipses) = val;
363} 355}
364static inline void 356static void
365bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val) 357bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val)
366{ 358{
367 b->INTERNAL_FIELD (vertical_scroll_bar_type) = val; 359 b->INTERNAL_FIELD (vertical_scroll_bar_type) = val;
368} 360}
369static inline void 361static void
370bset_word_wrap (struct buffer *b, Lisp_Object val) 362bset_word_wrap (struct buffer *b, Lisp_Object val)
371{ 363{
372 b->INTERNAL_FIELD (word_wrap) = val; 364 b->INTERNAL_FIELD (word_wrap) = val;
373} 365}
374static inline void 366static void
375bset_zv_marker (struct buffer *b, Lisp_Object val) 367bset_zv_marker (struct buffer *b, Lisp_Object val)
376{ 368{
377 b->INTERNAL_FIELD (zv_marker) = val; 369 b->INTERNAL_FIELD (zv_marker) = val;
@@ -393,7 +385,7 @@ DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
393Value is nil if OBJECT is not a buffer or if it has been killed. */) 385Value is nil if OBJECT is not a buffer or if it has been killed. */)
394 (Lisp_Object object) 386 (Lisp_Object object)
395{ 387{
396 return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name))) 388 return ((BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
397 ? Qt : Qnil); 389 ? Qt : Qnil);
398} 390}
399 391
@@ -412,7 +404,6 @@ followed by the rest of the buffers. */)
412 Lisp_Object framelist, prevlist, tail; 404 Lisp_Object framelist, prevlist, tail;
413 Lisp_Object args[3]; 405 Lisp_Object args[3];
414 406
415 CHECK_FRAME (frame);
416 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); 407 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list);
417 prevlist = Fnreverse (Fcopy_sequence 408 prevlist = Fnreverse (Fcopy_sequence
418 (XFRAME (frame)->buried_buffer_list)); 409 (XFRAME (frame)->buried_buffer_list));
@@ -554,13 +545,15 @@ even if it is dead. The return value is never nil. */)
554 b->base_buffer = NULL; 545 b->base_buffer = NULL;
555 /* No one shares the text with us now. */ 546 /* No one shares the text with us now. */
556 b->indirections = 0; 547 b->indirections = 0;
548 /* No one shows us now. */
549 b->window_count = 0;
557 550
558 BUF_GAP_SIZE (b) = 20; 551 BUF_GAP_SIZE (b) = 20;
559 BLOCK_INPUT; 552 block_input ();
560 /* 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
561 anchoring a search. */ 554 anchoring a search. */
562 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); 555 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1);
563 UNBLOCK_INPUT; 556 unblock_input ();
564 if (! BUF_BEG_ADDR (b)) 557 if (! BUF_BEG_ADDR (b))
565 buffer_memory_full (BUF_GAP_SIZE (b) + 1); 558 buffer_memory_full (BUF_GAP_SIZE (b) + 1);
566 559
@@ -593,10 +586,6 @@ even if it is dead. The return value is never nil. */)
593 bset_width_table (b, Qnil); 586 bset_width_table (b, Qnil);
594 b->prevent_redisplay_optimizations_p = 1; 587 b->prevent_redisplay_optimizations_p = 1;
595 588
596 /* Put this on the chain of all buffers including killed ones. */
597 b->header.next.buffer = all_buffers;
598 all_buffers = b;
599
600 /* An ordinary buffer normally doesn't need markers 589 /* An ordinary buffer normally doesn't need markers
601 to handle BEGV and ZV. */ 590 to handle BEGV and ZV. */
602 bset_pt_marker (b, Qnil); 591 bset_pt_marker (b, Qnil);
@@ -661,13 +650,13 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
661 650
662/* Set an appropriate overlay of B. */ 651/* Set an appropriate overlay of B. */
663 652
664static inline void 653static void
665set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o) 654set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o)
666{ 655{
667 b->overlays_before = o; 656 b->overlays_before = o;
668} 657}
669 658
670static inline void 659static void
671set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o) 660set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o)
672{ 661{
673 b->overlays_after = o; 662 b->overlays_after = o;
@@ -785,7 +774,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
785 base_buffer = Fget_buffer (base_buffer); 774 base_buffer = Fget_buffer (base_buffer);
786 if (NILP (base_buffer)) 775 if (NILP (base_buffer))
787 error ("No such buffer: `%s'", SDATA (tem)); 776 error ("No such buffer: `%s'", SDATA (tem));
788 if (NILP (BVAR (XBUFFER (base_buffer), name))) 777 if (!BUFFER_LIVE_P (XBUFFER (base_buffer)))
789 error ("Base buffer has been killed"); 778 error ("Base buffer has been killed");
790 779
791 if (SCHARS (name) == 0) 780 if (SCHARS (name) == 0)
@@ -805,6 +794,8 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
805 b->indirections = -1; 794 b->indirections = -1;
806 /* Notify base buffer that we share the text now. */ 795 /* Notify base buffer that we share the text now. */
807 b->base_buffer->indirections++; 796 b->base_buffer->indirections++;
797 /* Always -1 for an indirect buffer. */
798 b->window_count = -1;
808 799
809 b->pt = b->base_buffer->pt; 800 b->pt = b->base_buffer->pt;
810 b->begv = b->base_buffer->begv; 801 b->begv = b->base_buffer->begv;
@@ -817,10 +808,6 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
817 b->width_run_cache = 0; 808 b->width_run_cache = 0;
818 bset_width_table (b, Qnil); 809 bset_width_table (b, Qnil);
819 810
820 /* Put this on the chain of all buffers including killed ones. */
821 b->header.next.buffer = all_buffers;
822 all_buffers = b;
823
824 name = Fcopy_sequence (name); 811 name = Fcopy_sequence (name);
825 set_string_intervals (name, NULL); 812 set_string_intervals (name, NULL);
826 bset_name (b, name); 813 bset_name (b, name);
@@ -911,6 +898,8 @@ delete_all_overlays (struct buffer *b)
911{ 898{
912 struct Lisp_Overlay *ov, *next; 899 struct Lisp_Overlay *ov, *next;
913 900
901 /* FIXME: Since each drop_overlay will scan BUF_MARKERS to unlink its
902 markers, we have an unneeded O(N^2) behavior here. */
914 for (ov = b->overlays_before; ov; ov = next) 903 for (ov = b->overlays_before; ov; ov = next)
915 { 904 {
916 drop_overlay (b, ov); 905 drop_overlay (b, ov);
@@ -1240,7 +1229,7 @@ buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer)
1240 result = Fdefault_value (variable); 1229 result = Fdefault_value (variable);
1241 break; 1230 break;
1242 } 1231 }
1243 default: abort (); 1232 default: emacs_abort ();
1244 } 1233 }
1245 1234
1246 return result; 1235 return result;
@@ -1355,9 +1344,13 @@ A non-nil FLAG means mark the buffer modified. */)
1355 /* If buffer becoming modified, lock the file. 1344 /* If buffer becoming modified, lock the file.
1356 If buffer becoming unmodified, unlock the file. */ 1345 If buffer becoming unmodified, unlock the file. */
1357 1346
1358 fn = BVAR (current_buffer, file_truename); 1347 struct buffer *b = current_buffer->base_buffer
1348 ? current_buffer->base_buffer
1349 : current_buffer;
1350
1351 fn = BVAR (b, file_truename);
1359 /* Test buffer-file-name so that binding it to nil is effective. */ 1352 /* Test buffer-file-name so that binding it to nil is effective. */
1360 if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) 1353 if (!NILP (fn) && ! NILP (BVAR (b, filename)))
1361 { 1354 {
1362 bool already = SAVE_MODIFF < MODIFF; 1355 bool already = SAVE_MODIFF < MODIFF;
1363 if (!already && !NILP (flag)) 1356 if (!already && !NILP (flag))
@@ -1538,6 +1531,16 @@ This does not change the name of the visited file (if any). */)
1538 return BVAR (current_buffer, name); 1531 return BVAR (current_buffer, name);
1539} 1532}
1540 1533
1534/* True if B can be used as 'other-than-BUFFER' buffer. */
1535
1536static bool
1537candidate_buffer (Lisp_Object b, Lisp_Object buffer)
1538{
1539 return (BUFFERP (b) && !EQ (b, buffer)
1540 && BUFFER_LIVE_P (XBUFFER (b))
1541 && !BUFFER_HIDDEN_P (XBUFFER (b)));
1542}
1543
1541DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, 1544DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0,
1542 doc: /* Return most recently selected buffer other than BUFFER. 1545 doc: /* Return most recently selected buffer other than BUFFER.
1543Buffers not visible in windows are preferred to visible buffers, unless 1546Buffers not visible in windows are preferred to visible buffers, unless
@@ -1551,23 +1554,15 @@ list first, followed by the list of all buffers. If no other buffer
1551exists, return the buffer `*scratch*' (creating it if necessary). */) 1554exists, return the buffer `*scratch*' (creating it if necessary). */)
1552 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) 1555 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
1553{ 1556{
1554 Lisp_Object tail, buf, pred; 1557 struct frame *f = decode_any_frame (frame);
1555 Lisp_Object notsogood = Qnil; 1558 Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
1556 1559 Lisp_Object buf, notsogood = Qnil;
1557 if (NILP (frame))
1558 frame = selected_frame;
1559
1560 CHECK_FRAME (frame);
1561 1560
1562 pred = frame_buffer_predicate (frame);
1563 /* Consider buffers that have been seen in the frame first. */ 1561 /* Consider buffers that have been seen in the frame first. */
1564 tail = XFRAME (frame)->buffer_list;
1565 for (; CONSP (tail); tail = XCDR (tail)) 1562 for (; CONSP (tail); tail = XCDR (tail))
1566 { 1563 {
1567 buf = XCAR (tail); 1564 buf = XCAR (tail);
1568 if (BUFFERP (buf) && !EQ (buf, buffer) 1565 if (candidate_buffer (buf, buffer)
1569 && !NILP (BVAR (XBUFFER (buf), name))
1570 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1571 /* If the frame has a buffer_predicate, disregard buffers that 1566 /* If the frame has a buffer_predicate, disregard buffers that
1572 don't fit the predicate. */ 1567 don't fit the predicate. */
1573 && (NILP (pred) || !NILP (call1 (pred, buf)))) 1568 && (NILP (pred) || !NILP (call1 (pred, buf))))
@@ -1585,9 +1580,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1585 for (; CONSP (tail); tail = XCDR (tail)) 1580 for (; CONSP (tail); tail = XCDR (tail))
1586 { 1581 {
1587 buf = Fcdr (XCAR (tail)); 1582 buf = Fcdr (XCAR (tail));
1588 if (BUFFERP (buf) && !EQ (buf, buffer) 1583 if (candidate_buffer (buf, buffer)
1589 && !NILP (BVAR (XBUFFER (buf), name))
1590 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1591 /* If the frame has a buffer_predicate, disregard buffers that 1584 /* If the frame has a buffer_predicate, disregard buffers that
1592 don't fit the predicate. */ 1585 don't fit the predicate. */
1593 && (NILP (pred) || !NILP (call1 (pred, buf)))) 1586 && (NILP (pred) || !NILP (call1 (pred, buf))))
@@ -1623,13 +1616,10 @@ other_buffer_safely (Lisp_Object buffer)
1623{ 1616{
1624 Lisp_Object tail, buf; 1617 Lisp_Object tail, buf;
1625 1618
1626 tail = Vbuffer_alist; 1619 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
1627 for (; CONSP (tail); tail = XCDR (tail))
1628 { 1620 {
1629 buf = Fcdr (XCAR (tail)); 1621 buf = Fcdr (XCAR (tail));
1630 if (BUFFERP (buf) && !EQ (buf, buffer) 1622 if (candidate_buffer (buf, buffer))
1631 && !NILP (BVAR (XBUFFER (buf), name))
1632 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' '))
1633 return buf; 1623 return buf;
1634 } 1624 }
1635 1625
@@ -1671,18 +1661,11 @@ No argument or nil as argument means do this for the current buffer. */)
1671void 1661void
1672compact_buffer (struct buffer *buffer) 1662compact_buffer (struct buffer *buffer)
1673{ 1663{
1674 /* Verify indirection counters. */ 1664 BUFFER_CHECK_INDIRECTION (buffer);
1675 if (buffer->base_buffer)
1676 {
1677 eassert (buffer->indirections == -1);
1678 eassert (buffer->base_buffer->indirections > 0);
1679 }
1680 else
1681 eassert (buffer->indirections >= 0);
1682 1665
1683 /* Skip dead buffers, indirect buffers and buffers 1666 /* Skip dead buffers, indirect buffers and buffers
1684 which aren't changed since last compaction. */ 1667 which aren't changed since last compaction. */
1685 if (!NILP (buffer->INTERNAL_FIELD (name)) 1668 if (BUFFER_LIVE_P (buffer)
1686 && (buffer->base_buffer == NULL) 1669 && (buffer->base_buffer == NULL)
1687 && (buffer->text->compact != buffer->text->modiff)) 1670 && (buffer->text->compact != buffer->text->modiff))
1688 { 1671 {
@@ -1747,7 +1730,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1747 b = XBUFFER (buffer); 1730 b = XBUFFER (buffer);
1748 1731
1749 /* Avoid trouble for buffer already dead. */ 1732 /* Avoid trouble for buffer already dead. */
1750 if (NILP (BVAR (b, name))) 1733 if (!BUFFER_LIVE_P (b))
1751 return Qnil; 1734 return Qnil;
1752 1735
1753 /* Query if the buffer is still modified. */ 1736 /* Query if the buffer is still modified. */
@@ -1783,7 +1766,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1783 } 1766 }
1784 1767
1785 /* If the hooks have killed the buffer, exit now. */ 1768 /* If the hooks have killed the buffer, exit now. */
1786 if (NILP (BVAR (b, name))) 1769 if (!BUFFER_LIVE_P (b))
1787 return Qt; 1770 return Qt;
1788 1771
1789 /* We have no more questions to ask. Verify that it is valid 1772 /* We have no more questions to ask. Verify that it is valid
@@ -1815,7 +1798,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1815 UNGCPRO; 1798 UNGCPRO;
1816 1799
1817 /* Exit if we now have killed the base buffer (Bug#11665). */ 1800 /* Exit if we now have killed the base buffer (Bug#11665). */
1818 if (NILP (BVAR (b, name))) 1801 if (!BUFFER_LIVE_P (b))
1819 return Qt; 1802 return Qt;
1820 } 1803 }
1821 1804
@@ -1826,7 +1809,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1826 replace_buffer_in_windows (buffer); 1809 replace_buffer_in_windows (buffer);
1827 1810
1828 /* Exit if replacing the buffer in windows has killed our buffer. */ 1811 /* Exit if replacing the buffer in windows has killed our buffer. */
1829 if (NILP (BVAR (b, name))) 1812 if (!BUFFER_LIVE_P (b))
1830 return Qt; 1813 return Qt;
1831 1814
1832 /* Make this buffer not be current. Exit if it is the sole visible 1815 /* Make this buffer not be current. Exit if it is the sole visible
@@ -1859,7 +1842,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1859 1842
1860 /* Killing buffer processes may run sentinels which may have killed 1843 /* Killing buffer processes may run sentinels which may have killed
1861 our buffer. */ 1844 our buffer. */
1862 if (NILP (BVAR (b, name))) 1845 if (!BUFFER_LIVE_P (b))
1863 return Qt; 1846 return Qt;
1864 1847
1865 /* These may run Lisp code and into infinite loops (if someone 1848 /* These may run Lisp code and into infinite loops (if someone
@@ -1891,7 +1874,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1891 } 1874 }
1892 1875
1893 /* Deleting an auto-save file could have killed our buffer. */ 1876 /* Deleting an auto-save file could have killed our buffer. */
1894 if (NILP (BVAR (b, name))) 1877 if (!BUFFER_LIVE_P (b))
1895 return Qt; 1878 return Qt;
1896 1879
1897 if (b->base_buffer) 1880 if (b->base_buffer)
@@ -1899,12 +1882,16 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1899 /* Unchain all markers that belong to this indirect buffer. 1882 /* Unchain all markers that belong to this indirect buffer.
1900 Don't unchain the markers that belong to the base buffer 1883 Don't unchain the markers that belong to the base buffer
1901 or its other indirect buffers. */ 1884 or its other indirect buffers. */
1902 for (m = BUF_MARKERS (b); m; ) 1885 struct Lisp_Marker **mp = &BUF_MARKERS (b);
1886 while ((m = *mp))
1903 { 1887 {
1904 struct Lisp_Marker *next = m->next;
1905 if (m->buffer == b) 1888 if (m->buffer == b)
1906 unchain_marker (m); 1889 {
1907 m = next; 1890 m->buffer = NULL;
1891 *mp = m->next;
1892 }
1893 else
1894 mp = &m->next;
1908 } 1895 }
1909 } 1896 }
1910 else 1897 else
@@ -1921,8 +1908,12 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1921 BUF_MARKERS (b) = NULL; 1908 BUF_MARKERS (b) = NULL;
1922 set_buffer_intervals (b, NULL); 1909 set_buffer_intervals (b, NULL);
1923 1910
1924 /* Perhaps we should explicitly free the interval tree here... */ 1911 /* Perhaps we should explicitly free the interval tree here... */
1925 } 1912 }
1913 /* Since we've unlinked the markers, the overlays can't be here any more
1914 either. */
1915 b->overlays_before = NULL;
1916 b->overlays_after = NULL;
1926 1917
1927 /* Reset the local variables, so that this buffer's local values 1918 /* Reset the local variables, so that this buffer's local values
1928 won't be protected from GC. They would be protected 1919 won't be protected from GC. They would be protected
@@ -1933,17 +1924,23 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1933 1924
1934 bset_name (b, Qnil); 1925 bset_name (b, Qnil);
1935 1926
1936 BLOCK_INPUT; 1927 block_input ();
1937 if (b->base_buffer) 1928 if (b->base_buffer)
1938 { 1929 {
1939 /* Notify our base buffer that we don't share the text anymore. */ 1930 /* Notify our base buffer that we don't share the text anymore. */
1940 eassert (b->indirections == -1); 1931 eassert (b->indirections == -1);
1941 b->base_buffer->indirections--; 1932 b->base_buffer->indirections--;
1942 eassert (b->base_buffer->indirections >= 0); 1933 eassert (b->base_buffer->indirections >= 0);
1934 /* Make sure that we wasn't confused. */
1935 eassert (b->window_count == -1);
1943 } 1936 }
1944 else 1937 else
1945 /* No one shares our buffer text, can free it. */ 1938 {
1946 free_buffer_text (b); 1939 /* Make sure that no one shows us. */
1940 eassert (b->window_count == 0);
1941 /* No one shares our buffer text, can free it. */
1942 free_buffer_text (b);
1943 }
1947 1944
1948 if (b->newline_cache) 1945 if (b->newline_cache)
1949 { 1946 {
@@ -1956,7 +1953,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1956 b->width_run_cache = 0; 1953 b->width_run_cache = 0;
1957 } 1954 }
1958 bset_width_table (b, Qnil); 1955 bset_width_table (b, Qnil);
1959 UNBLOCK_INPUT; 1956 unblock_input ();
1960 bset_undo_list (b, Qnil); 1957 bset_undo_list (b, Qnil);
1961 1958
1962 /* Run buffer-list-update-hook. */ 1959 /* Run buffer-list-update-hook. */
@@ -2060,7 +2057,7 @@ the current buffer's major mode. */)
2060 2057
2061 CHECK_BUFFER (buffer); 2058 CHECK_BUFFER (buffer);
2062 2059
2063 if (NILP (BVAR (XBUFFER (buffer), name))) 2060 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
2064 error ("Attempt to set major mode for a dead buffer"); 2061 error ("Attempt to set major mode for a dead buffer");
2065 2062
2066 if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0) 2063 if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0)
@@ -2115,6 +2112,8 @@ set_buffer_internal_1 (register struct buffer *b)
2115 if (current_buffer == b) 2112 if (current_buffer == b)
2116 return; 2113 return;
2117 2114
2115 BUFFER_CHECK_INDIRECTION (b);
2116
2118 old_buf = current_buffer; 2117 old_buf = current_buffer;
2119 current_buffer = b; 2118 current_buffer = b;
2120 last_known_column_point = -1; /* invalidate indentation cache */ 2119 last_known_column_point = -1; /* invalidate indentation cache */
@@ -2186,7 +2185,7 @@ set_buffer_temp (struct buffer *b)
2186DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, 2185DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
2187 doc: /* Make buffer BUFFER-OR-NAME current for editing operations. 2186 doc: /* Make buffer BUFFER-OR-NAME current for editing operations.
2188BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See 2187BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See
2189also `save-excursion' when you want to make a buffer current 2188also `with-current-buffer' when you want to make a buffer current
2190temporarily. This function does not display the buffer, so its effect 2189temporarily. This function does not display the buffer, so its effect
2191ends when the current command terminates. Use `switch-to-buffer' or 2190ends when the current command terminates. Use `switch-to-buffer' or
2192`pop-to-buffer' to switch buffers permanently. */) 2191`pop-to-buffer' to switch buffers permanently. */)
@@ -2196,7 +2195,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
2196 buffer = Fget_buffer (buffer_or_name); 2195 buffer = Fget_buffer (buffer_or_name);
2197 if (NILP (buffer)) 2196 if (NILP (buffer))
2198 nsberror (buffer_or_name); 2197 nsberror (buffer_or_name);
2199 if (NILP (BVAR (XBUFFER (buffer), name))) 2198 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
2200 error ("Selecting deleted buffer"); 2199 error ("Selecting deleted buffer");
2201 set_buffer_internal (XBUFFER (buffer)); 2200 set_buffer_internal (XBUFFER (buffer));
2202 return buffer; 2201 return buffer;
@@ -2207,7 +2206,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
2207Lisp_Object 2206Lisp_Object
2208set_buffer_if_live (Lisp_Object buffer) 2207set_buffer_if_live (Lisp_Object buffer)
2209{ 2208{
2210 if (! NILP (BVAR (XBUFFER (buffer), name))) 2209 if (BUFFER_LIVE_P (XBUFFER (buffer)))
2211 set_buffer_internal (XBUFFER (buffer)); 2210 set_buffer_internal (XBUFFER (buffer));
2212 return Qnil; 2211 return Qnil;
2213} 2212}
@@ -2302,7 +2301,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2302 CHECK_BUFFER (buffer); 2301 CHECK_BUFFER (buffer);
2303 other_buffer = XBUFFER (buffer); 2302 other_buffer = XBUFFER (buffer);
2304 2303
2305 if (NILP (BVAR (other_buffer, name))) 2304 if (!BUFFER_LIVE_P (other_buffer))
2306 error ("Cannot swap a dead buffer's text"); 2305 error ("Cannot swap a dead buffer's text");
2307 2306
2308 /* Actually, it probably works just fine. 2307 /* Actually, it probably works just fine.
@@ -2474,7 +2473,7 @@ current buffer is cleared. */)
2474 begv = BEGV, zv = ZV; 2473 begv = BEGV, zv = ZV;
2475 2474
2476 if (narrowed) 2475 if (narrowed)
2477 Fwiden (); 2476 error ("Changing multibyteness in a narrowed buffer");
2478 2477
2479 if (NILP (flag)) 2478 if (NILP (flag))
2480 { 2479 {
@@ -2669,7 +2668,7 @@ current buffer is cleared. */)
2669 /* Make sure no markers were put on the chain 2668 /* Make sure no markers were put on the chain
2670 while the chain value was incorrect. */ 2669 while the chain value was incorrect. */
2671 if (BUF_MARKERS (current_buffer)) 2670 if (BUF_MARKERS (current_buffer))
2672 abort (); 2671 emacs_abort ();
2673 2672
2674 BUF_MARKERS (current_buffer) = markers; 2673 BUF_MARKERS (current_buffer) = markers;
2675 2674
@@ -2690,15 +2689,16 @@ current buffer is cleared. */)
2690 2689
2691 UNGCPRO; 2690 UNGCPRO;
2692 2691
2693 /* Changing the multibyteness of a buffer means that all windows
2694 showing that buffer must be updated thoroughly. */
2695 current_buffer->prevent_redisplay_optimizations_p = 1; 2692 current_buffer->prevent_redisplay_optimizations_p = 1;
2696 ++windows_or_buffers_changed; 2693
2694 /* If buffer is shown in a window, let redisplay consider other windows. */
2695 if (buffer_window_count (current_buffer))
2696 ++windows_or_buffers_changed;
2697 2697
2698 /* Copy this buffer's new multibyte status 2698 /* Copy this buffer's new multibyte status
2699 into all of its indirect buffers. */ 2699 into all of its indirect buffers. */
2700 FOR_EACH_BUFFER (other) 2700 FOR_EACH_BUFFER (other)
2701 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) 2701 if (other->base_buffer == current_buffer && BUFFER_LIVE_P (other))
2702 { 2702 {
2703 BVAR (other, enable_multibyte_characters) 2703 BVAR (other, enable_multibyte_characters)
2704 = BVAR (current_buffer, enable_multibyte_characters); 2704 = BVAR (current_buffer, enable_multibyte_characters);
@@ -3144,8 +3144,8 @@ compare_overlays (const void *v1, const void *v2)
3144 between "equal" overlays. The result can still change between 3144 between "equal" overlays. The result can still change between
3145 invocations of Emacs, but it won't change in the middle of 3145 invocations of Emacs, but it won't change in the middle of
3146 `find_field' (bug#6830). */ 3146 `find_field' (bug#6830). */
3147 if (XHASH (s1->overlay) != XHASH (s2->overlay)) 3147 if (!EQ (s1->overlay, s2->overlay))
3148 return XHASH (s1->overlay) < XHASH (s2->overlay) ? -1 : 1; 3148 return XLI (s1->overlay) < XLI (s2->overlay) ? -1 : 1;
3149 return 0; 3149 return 0;
3150} 3150}
3151 3151
@@ -3411,7 +3411,7 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3411 } 3411 }
3412 } 3412 }
3413 if (p != overlay_str_buf + total) 3413 if (p != overlay_str_buf + total)
3414 abort (); 3414 emacs_abort ();
3415 if (pstr) 3415 if (pstr)
3416 *pstr = overlay_str_buf; 3416 *pstr = overlay_str_buf;
3417 return total; 3417 return total;
@@ -3699,7 +3699,6 @@ fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3699 beforep->next = current_buffer->overlays_before; 3699 beforep->next = current_buffer->overlays_before;
3700 set_buffer_overlays_before (current_buffer, before_list); 3700 set_buffer_overlays_before (current_buffer, before_list);
3701 } 3701 }
3702 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3703 3702
3704 if (afterp) 3703 if (afterp)
3705 { 3704 {
@@ -3857,17 +3856,16 @@ for the rear of the overlay advance when text is inserted there
3857 end = OVERLAY_END (overlay); 3856 end = OVERLAY_END (overlay);
3858 if (OVERLAY_POSITION (end) < b->overlay_center) 3857 if (OVERLAY_POSITION (end) < b->overlay_center)
3859 { 3858 {
3860 if (b->overlays_after) 3859 eassert (b->overlays_after || (XOVERLAY (overlay)->next == NULL));
3861 XOVERLAY (overlay)->next = b->overlays_after; 3860 XOVERLAY (overlay)->next = b->overlays_after;
3862 set_buffer_overlays_after (b, XOVERLAY (overlay)); 3861 set_buffer_overlays_after (b, XOVERLAY (overlay));
3863 } 3862 }
3864 else 3863 else
3865 { 3864 {
3866 if (b->overlays_before) 3865 eassert (b->overlays_before || (XOVERLAY (overlay)->next == NULL));
3867 XOVERLAY (overlay)->next = b->overlays_before; 3866 XOVERLAY (overlay)->next = b->overlays_before;
3868 set_buffer_overlays_before (b, XOVERLAY (overlay)); 3867 set_buffer_overlays_before (b, XOVERLAY (overlay));
3869 } 3868 }
3870
3871 /* This puts it in the right list, and in the right order. */ 3869 /* This puts it in the right list, and in the right order. */
3872 recenter_overlay_lists (b, b->overlay_center); 3870 recenter_overlay_lists (b, b->overlay_center);
3873 3871
@@ -3891,17 +3889,17 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3891 3889
3892 BUF_COMPUTE_UNCHANGED (buf, start, end); 3890 BUF_COMPUTE_UNCHANGED (buf, start, end);
3893 3891
3894 /* If this is a buffer not in the selected window, 3892 /* If BUF is visible, consider updating the display if ... */
3895 we must do other windows. */ 3893 if (buffer_window_count (buf) > 0)
3896 if (buf != XBUFFER (XWINDOW (selected_window)->buffer)) 3894 {
3897 windows_or_buffers_changed = 1; 3895 /* ... it's visible in other window than selected, */
3898 /* If multiple windows show this buffer, we must do other windows. */ 3896 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
3899 else if (buffer_shared > 1) 3897 windows_or_buffers_changed = 1;
3900 windows_or_buffers_changed = 1; 3898 /* ... or if we modify an overlay at the end of the buffer
3901 /* If we modify an overlay at the end of the buffer, we cannot 3899 and so we cannot be sure that window end is still valid. */
3902 be sure that window end is still valid. */ 3900 else if (end >= ZV && start <= ZV)
3903 else if (end >= ZV && start <= ZV) 3901 windows_or_buffers_changed = 1;
3904 windows_or_buffers_changed = 1; 3902 }
3905 3903
3906 ++BUF_OVERLAY_MODIFF (buf); 3904 ++BUF_OVERLAY_MODIFF (buf);
3907} 3905}
@@ -4151,7 +4149,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
4151 /* Put all the overlays we want in a vector in overlay_vec. 4149 /* Put all the overlays we want in a vector in overlay_vec.
4152 Store the length in len. */ 4150 Store the length in len. */
4153 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 4151 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
4154 0, 0, 0); 4152 NULL, NULL, 0);
4155 4153
4156 /* Make a list of them all. */ 4154 /* Make a list of them all. */
4157 result = Flist (noverlays, overlay_vec); 4155 result = Flist (noverlays, overlay_vec);
@@ -4594,7 +4592,7 @@ buffer_slot_type_mismatch (Lisp_Object newval, int type)
4594 case_Lisp_Int: predicate = Qintegerp; break; 4592 case_Lisp_Int: predicate = Qintegerp; break;
4595 case Lisp_String: predicate = Qstringp; break; 4593 case Lisp_String: predicate = Qstringp; break;
4596 case Lisp_Symbol: predicate = Qsymbolp; break; 4594 case Lisp_Symbol: predicate = Qsymbolp; break;
4597 default: abort (); 4595 default: emacs_abort ();
4598 } 4596 }
4599 4597
4600 wrong_type_argument (predicate, newval); 4598 wrong_type_argument (predicate, newval);
@@ -5042,7 +5040,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5042{ 5040{
5043 void *p; 5041 void *p;
5044 5042
5045 BLOCK_INPUT; 5043 block_input ();
5046#if defined USE_MMAP_FOR_BUFFERS 5044#if defined USE_MMAP_FOR_BUFFERS
5047 p = mmap_alloc ((void **) &b->text->beg, nbytes); 5045 p = mmap_alloc ((void **) &b->text->beg, nbytes);
5048#elif defined REL_ALLOC 5046#elif defined REL_ALLOC
@@ -5053,12 +5051,12 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5053 5051
5054 if (p == NULL) 5052 if (p == NULL)
5055 { 5053 {
5056 UNBLOCK_INPUT; 5054 unblock_input ();
5057 memory_full (nbytes); 5055 memory_full (nbytes);
5058 } 5056 }
5059 5057
5060 b->text->beg = (unsigned char *) p; 5058 b->text->beg = (unsigned char *) p;
5061 UNBLOCK_INPUT; 5059 unblock_input ();
5062} 5060}
5063 5061
5064/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means 5062/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
@@ -5070,7 +5068,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5070 void *p; 5068 void *p;
5071 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 5069 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
5072 + delta); 5070 + delta);
5073 BLOCK_INPUT; 5071 block_input ();
5074#if defined USE_MMAP_FOR_BUFFERS 5072#if defined USE_MMAP_FOR_BUFFERS
5075 p = mmap_realloc ((void **) &b->text->beg, nbytes); 5073 p = mmap_realloc ((void **) &b->text->beg, nbytes);
5076#elif defined REL_ALLOC 5074#elif defined REL_ALLOC
@@ -5081,12 +5079,12 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5081 5079
5082 if (p == NULL) 5080 if (p == NULL)
5083 { 5081 {
5084 UNBLOCK_INPUT; 5082 unblock_input ();
5085 memory_full (nbytes); 5083 memory_full (nbytes);
5086 } 5084 }
5087 5085
5088 BUF_BEG_ADDR (b) = (unsigned char *) p; 5086 BUF_BEG_ADDR (b) = (unsigned char *) p;
5089 UNBLOCK_INPUT; 5087 unblock_input ();
5090} 5088}
5091 5089
5092 5090
@@ -5095,7 +5093,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5095static void 5093static void
5096free_buffer_text (struct buffer *b) 5094free_buffer_text (struct buffer *b)
5097{ 5095{
5098 BLOCK_INPUT; 5096 block_input ();
5099 5097
5100#if defined USE_MMAP_FOR_BUFFERS 5098#if defined USE_MMAP_FOR_BUFFERS
5101 mmap_free ((void **) &b->text->beg); 5099 mmap_free ((void **) &b->text->beg);
@@ -5106,7 +5104,7 @@ free_buffer_text (struct buffer *b)
5106#endif 5104#endif
5107 5105
5108 BUF_BEG_ADDR (b) = NULL; 5106 BUF_BEG_ADDR (b) = NULL;
5109 UNBLOCK_INPUT; 5107 unblock_input ();
5110} 5108}
5111 5109
5112 5110
@@ -5119,11 +5117,6 @@ void
5119init_buffer_once (void) 5117init_buffer_once (void)
5120{ 5118{
5121 int idx; 5119 int idx;
5122 /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make
5123 sure that this is still correct. Otherwise, mark_vectorlike may not
5124 trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */
5125 const int pvecsize
5126 = (offsetof (struct buffer, own_text) - header_size) / word_size;
5127 5120
5128 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags); 5121 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
5129 5122
@@ -5141,12 +5134,16 @@ init_buffer_once (void)
5141 /* No one will share the text with these buffers, but let's play it safe. */ 5134 /* No one will share the text with these buffers, but let's play it safe. */
5142 buffer_defaults.indirections = 0; 5135 buffer_defaults.indirections = 0;
5143 buffer_local_symbols.indirections = 0; 5136 buffer_local_symbols.indirections = 0;
5137 /* Likewise no one will display them. */
5138 buffer_defaults.window_count = 0;
5139 buffer_local_symbols.window_count = 0;
5144 set_buffer_intervals (&buffer_defaults, NULL); 5140 set_buffer_intervals (&buffer_defaults, NULL);
5145 set_buffer_intervals (&buffer_local_symbols, NULL); 5141 set_buffer_intervals (&buffer_local_symbols, NULL);
5146 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize); 5142 /* This is not strictly necessary, but let's make them initialized. */
5147 XSETBUFFER (Vbuffer_defaults, &buffer_defaults); 5143 bset_name (&buffer_defaults, build_pure_c_string (" *buffer-defaults*"));
5148 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize); 5144 bset_name (&buffer_local_symbols, build_pure_c_string (" *buffer-local-symbols*"));
5149 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); 5145 BUFFER_PVEC_INIT (&buffer_defaults);
5146 BUFFER_PVEC_INIT (&buffer_local_symbols);
5150 5147
5151 /* Set up the default values of various buffer slots. */ 5148 /* Set up the default values of various buffer slots. */
5152 /* Must do these before making the first buffer! */ 5149 /* Must do these before making the first buffer! */
@@ -5275,7 +5272,7 @@ init_buffer_once (void)
5275 5272
5276 /* Need more room? */ 5273 /* Need more room? */
5277 if (idx >= MAX_PER_BUFFER_VARS) 5274 if (idx >= MAX_PER_BUFFER_VARS)
5278 abort (); 5275 emacs_abort ();
5279 last_per_buffer_idx = idx; 5276 last_per_buffer_idx = idx;
5280 5277
5281 Vbuffer_alist = Qnil; 5278 Vbuffer_alist = Qnil;
@@ -5416,7 +5413,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5416 if (PER_BUFFER_IDX (offset) == 0) 5413 if (PER_BUFFER_IDX (offset) == 0)
5417 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding 5414 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
5418 slot of buffer_local_flags */ 5415 slot of buffer_local_flags */
5419 abort (); 5416 emacs_abort ();
5420} 5417}
5421 5418
5422 5419
@@ -5428,8 +5425,6 @@ syms_of_buffer (void)
5428 last_overlay_modification_hooks 5425 last_overlay_modification_hooks
5429 = Fmake_vector (make_number (10), Qnil); 5426 = Fmake_vector (make_number (10), Qnil);
5430 5427
5431 staticpro (&Vbuffer_defaults);
5432 staticpro (&Vbuffer_local_symbols);
5433 staticpro (&Qfundamental_mode); 5428 staticpro (&Qfundamental_mode);
5434 staticpro (&Qmode_class); 5429 staticpro (&Qmode_class);
5435 staticpro (&QSFundamental); 5430 staticpro (&QSFundamental);
@@ -6218,15 +6213,15 @@ is a member of the list. */);
6218 doc: /* Cursor to use when this buffer is in the selected window. 6213 doc: /* Cursor to use when this buffer is in the selected window.
6219Values are interpreted as follows: 6214Values are interpreted as follows:
6220 6215
6221 t use the cursor specified for the frame 6216 t use the cursor specified for the frame
6222 nil don't display a cursor 6217 nil don't display a cursor
6223 box display a filled box cursor 6218 box display a filled box cursor
6224 hollow display a hollow box cursor 6219 hollow display a hollow box cursor
6225 bar display a vertical bar cursor with default width 6220 bar display a vertical bar cursor with default width
6226 (bar . WIDTH) display a vertical bar cursor with width WIDTH 6221 (bar . WIDTH) display a vertical bar cursor with width WIDTH
6227 hbar display a horizontal bar cursor with default height 6222 hbar display a horizontal bar cursor with default height
6228 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT 6223 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
6229 ANYTHING ELSE display a hollow box cursor 6224 ANYTHING ELSE display a hollow box cursor
6230 6225
6231When the buffer is displayed in a non-selected window, the 6226When the buffer is displayed in a non-selected window, the
6232cursor's appearance is instead controlled by the variable 6227cursor's appearance is instead controlled by the variable