aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorJoakim Verona2012-07-27 02:22:03 +0200
committerJoakim Verona2012-07-27 02:22:03 +0200
commit5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f (patch)
tree5c55f1096a656a9759f0b53a0b5d1a2289bd366f /src/buffer.c
parent0c5c85cf2b350c965bb1ffa5b2d77c2adebc406b (diff)
parent562157c814037dcba58a20cd6908a95992c22283 (diff)
downloademacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.tar.gz
emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.zip
upstream
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c403
1 files changed, 206 insertions, 197 deletions
diff --git a/src/buffer.c b/src/buffer.c
index e501c9b73cc..06d385110c6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -107,8 +107,6 @@ static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS];
107 107
108int last_per_buffer_idx; 108int last_per_buffer_idx;
109 109
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, 110static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
113 int after, Lisp_Object arg1, 111 int after, Lisp_Object arg1,
114 Lisp_Object arg2, Lisp_Object arg3); 112 Lisp_Object arg2, Lisp_Object arg3);
@@ -155,7 +153,7 @@ static void alloc_buffer_text (struct buffer *, ptrdiff_t);
155static void free_buffer_text (struct buffer *b); 153static void free_buffer_text (struct buffer *b);
156static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); 154static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
157static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t); 155static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
158static Lisp_Object buffer_lisp_local_variables (struct buffer *); 156static Lisp_Object buffer_lisp_local_variables (struct buffer *, int);
159 157
160/* For debugging; temporary. See set_buffer_internal. */ 158/* For debugging; temporary. See set_buffer_internal. */
161/* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 159/* Lisp_Object Qlisp_mode, Vcheck_symbol; */
@@ -331,7 +329,9 @@ even if it is dead. The return value is never nil. */)
331 329
332 /* An ordinary buffer uses its own struct buffer_text. */ 330 /* An ordinary buffer uses its own struct buffer_text. */
333 b->text = &b->own_text; 331 b->text = &b->own_text;
334 b->base_buffer = 0; 332 b->base_buffer = NULL;
333 /* No one shares the text with us now. */
334 b->indirections = 0;
335 335
336 BUF_GAP_SIZE (b) = 20; 336 BUF_GAP_SIZE (b) = 20;
337 BLOCK_INPUT; 337 BLOCK_INPUT;
@@ -410,36 +410,24 @@ even if it is dead. The return value is never nil. */)
410static struct Lisp_Overlay * 410static struct Lisp_Overlay *
411copy_overlays (struct buffer *b, struct Lisp_Overlay *list) 411copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
412{ 412{
413 Lisp_Object buffer;
414 struct Lisp_Overlay *result = NULL, *tail = NULL; 413 struct Lisp_Overlay *result = NULL, *tail = NULL;
415 414
416 XSETBUFFER (buffer, b);
417
418 for (; list; list = list->next) 415 for (; list; list = list->next)
419 { 416 {
420 Lisp_Object overlay, start, end, old_overlay; 417 Lisp_Object overlay, start, end;
421 ptrdiff_t charpos; 418 struct Lisp_Marker *m;
422 419
423 XSETMISC (old_overlay, list); 420 eassert (MARKERP (list->start));
424 charpos = marker_position (OVERLAY_START (old_overlay)); 421 m = XMARKER (list->start);
425 start = Fmake_marker (); 422 start = build_marker (b, m->charpos, m->bytepos);
426 Fset_marker (start, make_number (charpos), buffer); 423 XMARKER (start)->insertion_type = m->insertion_type;
427 XMARKER (start)->insertion_type 424
428 = XMARKER (OVERLAY_START (old_overlay))->insertion_type; 425 eassert (MARKERP (list->end));
429 426 m = XMARKER (list->end);
430 charpos = marker_position (OVERLAY_END (old_overlay)); 427 end = build_marker (b, m->charpos, m->bytepos);
431 end = Fmake_marker (); 428 XMARKER (end)->insertion_type = m->insertion_type;
432 Fset_marker (end, make_number (charpos), buffer);
433 XMARKER (end)->insertion_type
434 = XMARKER (OVERLAY_END (old_overlay))->insertion_type;
435
436 overlay = allocate_misc ();
437 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
438 OVERLAY_START (overlay) = start;
439 OVERLAY_END (overlay) = end;
440 OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay));
441 XOVERLAY (overlay)->next = NULL;
442 429
430 overlay = build_overlay (start, end, Fcopy_sequence (list->plist));
443 if (tail) 431 if (tail)
444 tail = tail->next = XOVERLAY (overlay); 432 tail = tail->next = XOVERLAY (overlay);
445 else 433 else
@@ -460,16 +448,9 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
460static void 448static void
461clone_per_buffer_values (struct buffer *from, struct buffer *to) 449clone_per_buffer_values (struct buffer *from, struct buffer *to)
462{ 450{
463 Lisp_Object to_buffer;
464 int offset; 451 int offset;
465 452
466 XSETBUFFER (to_buffer, to); 453 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
467
468 /* buffer-local Lisp variables start at `undo_list',
469 tho only the ones from `name' on are GC'd normally. */
470 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
471 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
472 offset += sizeof (Lisp_Object))
473 { 454 {
474 Lisp_Object obj; 455 Lisp_Object obj;
475 456
@@ -481,9 +462,9 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
481 if (MARKERP (obj) && XMARKER (obj)->buffer == from) 462 if (MARKERP (obj) && XMARKER (obj)->buffer == from)
482 { 463 {
483 struct Lisp_Marker *m = XMARKER (obj); 464 struct Lisp_Marker *m = XMARKER (obj);
484 obj = Fmake_marker (); 465
466 obj = build_marker (to, m->charpos, m->bytepos);
485 XMARKER (obj)->insertion_type = m->insertion_type; 467 XMARKER (obj)->insertion_type = m->insertion_type;
486 set_marker_both (obj, to_buffer, m->charpos, m->bytepos);
487 } 468 }
488 469
489 PER_BUFFER_VALUE (to, offset) = obj; 470 PER_BUFFER_VALUE (to, offset) = obj;
@@ -496,7 +477,7 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
496 477
497 /* Get (a copy of) the alist of Lisp-level local variables of FROM 478 /* Get (a copy of) the alist of Lisp-level local variables of FROM
498 and install that in TO. */ 479 and install that in TO. */
499 BVAR (to, local_var_alist) = buffer_lisp_local_variables (from); 480 BVAR (to, local_var_alist) = buffer_lisp_local_variables (from, 1);
500} 481}
501 482
502 483
@@ -577,12 +558,18 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
577 558
578 b = allocate_buffer (); 559 b = allocate_buffer ();
579 560
561 /* No double indirection - if base buffer is indirect,
562 new buffer becomes an indirect to base's base. */
580 b->base_buffer = (XBUFFER (base_buffer)->base_buffer 563 b->base_buffer = (XBUFFER (base_buffer)->base_buffer
581 ? XBUFFER (base_buffer)->base_buffer 564 ? XBUFFER (base_buffer)->base_buffer
582 : XBUFFER (base_buffer)); 565 : XBUFFER (base_buffer));
583 566
584 /* Use the base buffer's text object. */ 567 /* Use the base buffer's text object. */
585 b->text = b->base_buffer->text; 568 b->text = b->base_buffer->text;
569 /* We have no own text. */
570 b->indirections = -1;
571 /* Notify base buffer that we share the text now. */
572 b->base_buffer->indirections++;
586 573
587 b->pt = b->base_buffer->pt; 574 b->pt = b->base_buffer->pt;
588 b->begv = b->base_buffer->begv; 575 b->begv = b->base_buffer->begv;
@@ -621,32 +608,24 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
621 eassert (NILP (BVAR (b->base_buffer, begv_marker))); 608 eassert (NILP (BVAR (b->base_buffer, begv_marker)));
622 eassert (NILP (BVAR (b->base_buffer, zv_marker))); 609 eassert (NILP (BVAR (b->base_buffer, zv_marker)));
623 610
624 BVAR (b->base_buffer, pt_marker) = Fmake_marker (); 611 BVAR (b->base_buffer, pt_marker)
625 set_marker_both (BVAR (b->base_buffer, pt_marker), base_buffer, 612 = build_marker (b->base_buffer, b->base_buffer->pt, b->base_buffer->pt_byte);
626 b->base_buffer->pt, 613
627 b->base_buffer->pt_byte); 614 BVAR (b->base_buffer, begv_marker)
615 = build_marker (b->base_buffer, b->base_buffer->begv, b->base_buffer->begv_byte);
628 616
629 BVAR (b->base_buffer, begv_marker) = Fmake_marker (); 617 BVAR (b->base_buffer, zv_marker)
630 set_marker_both (BVAR (b->base_buffer, begv_marker), base_buffer, 618 = build_marker (b->base_buffer, b->base_buffer->zv, b->base_buffer->zv_byte);
631 b->base_buffer->begv,
632 b->base_buffer->begv_byte);
633 619
634 BVAR (b->base_buffer, zv_marker) = Fmake_marker ();
635 set_marker_both (BVAR (b->base_buffer, zv_marker), base_buffer,
636 b->base_buffer->zv,
637 b->base_buffer->zv_byte);
638 XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1; 620 XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1;
639 } 621 }
640 622
641 if (NILP (clone)) 623 if (NILP (clone))
642 { 624 {
643 /* Give the indirect buffer markers for its narrowing. */ 625 /* Give the indirect buffer markers for its narrowing. */
644 BVAR (b, pt_marker) = Fmake_marker (); 626 BVAR (b, pt_marker) = build_marker (b, b->pt, b->pt_byte);
645 set_marker_both (BVAR (b, pt_marker), buf, b->pt, b->pt_byte); 627 BVAR (b, begv_marker) = build_marker (b, b->begv, b->begv_byte);
646 BVAR (b, begv_marker) = Fmake_marker (); 628 BVAR (b, zv_marker) = build_marker (b, b->zv, b->zv_byte);
647 set_marker_both (BVAR (b, begv_marker), buf, b->begv, b->begv_byte);
648 BVAR (b, zv_marker) = Fmake_marker ();
649 set_marker_both (BVAR (b, zv_marker), buf, b->zv, b->zv_byte);
650 XMARKER (BVAR (b, zv_marker))->insertion_type = 1; 629 XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
651 } 630 }
652 else 631 else
@@ -673,27 +652,40 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
673 return buf; 652 return buf;
674} 653}
675 654
655/* Mark OV as no longer associated with B. */
656
657static void
658drop_overlay (struct buffer *b, struct Lisp_Overlay *ov)
659{
660 eassert (b == XBUFFER (Fmarker_buffer (ov->start)));
661 modify_overlay (b, marker_position (ov->start), marker_position (ov->end));
662 Fset_marker (ov->start, Qnil, Qnil);
663 Fset_marker (ov->end, Qnil, Qnil);
664
665}
666
667/* Delete all overlays of B and reset it's overlay lists. */
668
676void 669void
677delete_all_overlays (struct buffer *b) 670delete_all_overlays (struct buffer *b)
678{ 671{
679 Lisp_Object overlay; 672 struct Lisp_Overlay *ov, *next;
680 673
681 /* `reset_buffer' blindly sets the list of overlays to NULL, so we 674 for (ov = b->overlays_before; ov; ov = next)
682 have to empty the list, otherwise we end up with overlays that
683 think they belong to this buffer while the buffer doesn't know about
684 them any more. */
685 while (b->overlays_before)
686 { 675 {
687 XSETMISC (overlay, b->overlays_before); 676 drop_overlay (b, ov);
688 Fdelete_overlay (overlay); 677 next = ov->next;
678 ov->next = NULL;
689 } 679 }
690 while (b->overlays_after) 680
681 for (ov = b->overlays_after; ov; ov = next)
691 { 682 {
692 XSETMISC (overlay, b->overlays_after); 683 drop_overlay (b, ov);
693 Fdelete_overlay (overlay); 684 next = ov->next;
685 ov->next = NULL;
694 } 686 }
695 eassert (b->overlays_before == NULL); 687
696 eassert (b->overlays_after == NULL); 688 b->overlays_before = b->overlays_after = NULL;
697} 689}
698 690
699/* Reinitialize everything about a buffer except its name and contents 691/* Reinitialize everything about a buffer except its name and contents
@@ -709,7 +701,7 @@ reset_buffer (register struct buffer *b)
709 BVAR (b, filename) = Qnil; 701 BVAR (b, filename) = Qnil;
710 BVAR (b, file_truename) = Qnil; 702 BVAR (b, file_truename) = Qnil;
711 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil; 703 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil;
712 b->modtime = 0; 704 b->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS);
713 b->modtime_size = -1; 705 b->modtime_size = -1;
714 XSETFASTINT (BVAR (b, save_length), 0); 706 XSETFASTINT (BVAR (b, save_length), 0);
715 b->last_window_start = 1; 707 b->last_window_start = 1;
@@ -820,14 +812,8 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
820 if (permanent_too || buffer_permanent_local_flags[i] == 0) 812 if (permanent_too || buffer_permanent_local_flags[i] == 0)
821 SET_PER_BUFFER_VALUE_P (b, i, 0); 813 SET_PER_BUFFER_VALUE_P (b, i, 0);
822 814
823 /* For each slot that has a default value, 815 /* For each slot that has a default value, copy that into the slot. */
824 copy that into the slot. */ 816 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
825
826 /* buffer-local Lisp variables start at `undo_list',
827 tho only the ones from `name' on are GC'd normally. */
828 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
829 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
830 offset += sizeof (Lisp_Object))
831 { 817 {
832 int idx = PER_BUFFER_IDX (offset); 818 int idx = PER_BUFFER_IDX (offset);
833 if ((idx > 0 819 if ((idx > 0
@@ -848,10 +834,14 @@ If there is no live buffer named NAME, then return NAME.
848Otherwise modify name by appending `<NUMBER>', incrementing NUMBER 834Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
849\(starting at 2) until an unused name is found, and then return that name. 835\(starting at 2) until an unused name is found, and then return that name.
850Optional second argument IGNORE specifies a name that is okay to use (if 836Optional second argument IGNORE specifies a name that is okay to use (if
851it is in the sequence to be tried) even if a buffer with that name exists. */) 837it is in the sequence to be tried) even if a buffer with that name exists.
838
839If NAME begins with a space (i.e., a buffer that is not normally
840visible to users), then if buffer NAME already exists a random number
841is first appended to NAME, to speed up finding a non-existent buffer. */)
852 (register Lisp_Object name, Lisp_Object ignore) 842 (register Lisp_Object name, Lisp_Object ignore)
853{ 843{
854 register Lisp_Object gentemp, tem; 844 register Lisp_Object gentemp, tem, tem2;
855 ptrdiff_t count; 845 ptrdiff_t count;
856 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"]; 846 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
857 847
@@ -864,11 +854,24 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
864 if (NILP (tem)) 854 if (NILP (tem))
865 return name; 855 return name;
866 856
857 if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
858 {
859 /* Note fileio.c:make_temp_name does random differently. */
860 tem2 = concat2 (name, make_formatted_string
861 (number, "-%"pI"d",
862 XFASTINT (Frandom (make_number (999999)))));
863 tem = Fget_buffer (tem2);
864 if (NILP (tem))
865 return tem2;
866 }
867 else
868 tem2 = name;
869
867 count = 1; 870 count = 1;
868 while (1) 871 while (1)
869 { 872 {
870 sprintf (number, "<%"pD"d>", ++count); 873 gentemp = concat2 (tem2, make_formatted_string
871 gentemp = concat2 (name, build_string (number)); 874 (number, "<%"pD"d>", ++count));
872 tem = Fstring_equal (gentemp, ignore); 875 tem = Fstring_equal (gentemp, ignore);
873 if (!NILP (tem)) 876 if (!NILP (tem))
874 return gentemp; 877 return gentemp;
@@ -1005,10 +1008,12 @@ buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer)
1005 1008
1006/* Return an alist of the Lisp-level buffer-local bindings of 1009/* Return an alist of the Lisp-level buffer-local bindings of
1007 buffer BUF. That is, don't include the variables maintained 1010 buffer BUF. That is, don't include the variables maintained
1008 in special slots in the buffer object. */ 1011 in special slots in the buffer object.
1012 If CLONE is zero elements of the form (VAR . unbound) are replaced
1013 by VAR. */
1009 1014
1010static Lisp_Object 1015static Lisp_Object
1011buffer_lisp_local_variables (struct buffer *buf) 1016buffer_lisp_local_variables (struct buffer *buf, int clone)
1012{ 1017{
1013 Lisp_Object result = Qnil; 1018 Lisp_Object result = Qnil;
1014 register Lisp_Object tail; 1019 register Lisp_Object tail;
@@ -1028,7 +1033,7 @@ buffer_lisp_local_variables (struct buffer *buf)
1028 if (buf != current_buffer) 1033 if (buf != current_buffer)
1029 val = XCDR (elt); 1034 val = XCDR (elt);
1030 1035
1031 result = Fcons (EQ (val, Qunbound) 1036 result = Fcons (!clone && EQ (val, Qunbound)
1032 ? XCAR (elt) 1037 ? XCAR (elt)
1033 : Fcons (XCAR (elt), val), 1038 : Fcons (XCAR (elt), val),
1034 result); 1039 result);
@@ -1057,18 +1062,13 @@ No argument or nil as argument means use current buffer as BUFFER. */)
1057 buf = XBUFFER (buffer); 1062 buf = XBUFFER (buffer);
1058 } 1063 }
1059 1064
1060 result = buffer_lisp_local_variables (buf); 1065 result = buffer_lisp_local_variables (buf, 0);
1061 1066
1062 /* Add on all the variables stored in special slots. */ 1067 /* Add on all the variables stored in special slots. */
1063 { 1068 {
1064 int offset, idx; 1069 int offset, idx;
1065 1070
1066 /* buffer-local Lisp variables start at `undo_list', 1071 FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
1067 tho only the ones from `name' on are GC'd normally. */
1068 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
1069 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
1070 /* sizeof EMACS_INT == sizeof Lisp_Object */
1071 offset += (sizeof (EMACS_INT)))
1072 { 1072 {
1073 idx = PER_BUFFER_IDX (offset); 1073 idx = PER_BUFFER_IDX (offset);
1074 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) 1074 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
@@ -1430,14 +1430,55 @@ No argument or nil as argument means do this for the current buffer. */)
1430 return Qnil; 1430 return Qnil;
1431} 1431}
1432 1432
1433/* 1433/* Truncate undo list and shrink the gap of BUFFER. */
1434 DEFVAR_LISP ("kill-buffer-hook", ..., "\ 1434
1435Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ 1435int
1436The buffer being killed will be current while the hook is running.\n\ 1436compact_buffer (struct buffer *buffer)
1437{
1438 /* Verify indirection counters. */
1439 if (buffer->base_buffer)
1440 {
1441 eassert (buffer->indirections == -1);
1442 eassert (buffer->base_buffer->indirections > 0);
1443 }
1444 else
1445 eassert (buffer->indirections >= 0);
1446
1447 /* Skip dead buffers, indirect buffers and buffers
1448 which aren't changed since last compaction. */
1449 if (!NILP (buffer->BUFFER_INTERNAL_FIELD (name))
1450 && (buffer->base_buffer == NULL)
1451 && (buffer->text->compact != buffer->text->modiff))
1452 {
1453 /* If a buffer's undo list is Qt, that means that undo is
1454 turned off in that buffer. Calling truncate_undo_list on
1455 Qt tends to return NULL, which effectively turns undo back on.
1456 So don't call truncate_undo_list if undo_list is Qt. */
1457 if (!EQ (buffer->BUFFER_INTERNAL_FIELD (undo_list), Qt))
1458 truncate_undo_list (buffer);
1459
1460 /* Shrink buffer gaps. */
1461 if (!buffer->text->inhibit_shrinking)
1462 {
1463 /* If a buffer's gap size is more than 10% of the buffer
1464 size, or larger than 2000 bytes, then shrink it
1465 accordingly. Keep a minimum size of 20 bytes. */
1466 int size = min (2000, max (20, (buffer->text->z_byte / 10)));
1467
1468 if (buffer->text->gap_size > size)
1469 {
1470 struct buffer *save_current = current_buffer;
1471 current_buffer = buffer;
1472 make_gap (-(buffer->text->gap_size - size));
1473 current_buffer = save_current;
1474 }
1475 }
1476 buffer->text->compact = buffer->text->modiff;
1477 return 1;
1478 }
1479 return 0;
1480}
1437 1481
1438Functions run by this hook are supposed to not change the current
1439buffer. See `kill-buffer'."
1440*/
1441DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ", 1482DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
1442 doc: /* Kill the buffer specified by BUFFER-OR-NAME. 1483 doc: /* Kill the buffer specified by BUFFER-OR-NAME.
1443The argument may be a buffer or the name of an existing buffer. 1484The argument may be a buffer or the name of an existing buffer.
@@ -1519,19 +1560,18 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1519 if (EQ (buffer, XWINDOW (minibuf_window)->buffer)) 1560 if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
1520 return Qnil; 1561 return Qnil;
1521 1562
1522 /* When we kill a base buffer, kill all its indirect buffers. 1563 /* When we kill an ordinary buffer which shares it's buffer text
1564 with indirect buffer(s), we must kill indirect buffer(s) too.
1523 We do it at this stage so nothing terrible happens if they 1565 We do it at this stage so nothing terrible happens if they
1524 ask questions or their hooks get errors. */ 1566 ask questions or their hooks get errors. */
1525 if (! b->base_buffer) 1567 if (!b->base_buffer && b->indirections > 0)
1526 { 1568 {
1527 struct buffer *other; 1569 struct buffer *other;
1528 1570
1529 GCPRO1 (buffer); 1571 GCPRO1 (buffer);
1530 1572
1531 for (other = all_buffers; other; other = other->header.next.buffer) 1573 FOR_EACH_BUFFER (other)
1532 /* all_buffers contains dead buffers too; 1574 if (other->base_buffer == b)
1533 don't re-kill them. */
1534 if (other->base_buffer == b && !NILP (BVAR (other, name)))
1535 { 1575 {
1536 Lisp_Object buf; 1576 Lisp_Object buf;
1537 XSETBUFFER (buf, other); 1577 XSETBUFFER (buf, other);
@@ -1660,7 +1700,15 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1660 BVAR (b, name) = Qnil; 1700 BVAR (b, name) = Qnil;
1661 1701
1662 BLOCK_INPUT; 1702 BLOCK_INPUT;
1663 if (! b->base_buffer) 1703 if (b->base_buffer)
1704 {
1705 /* Notify our base buffer that we don't share the text anymore. */
1706 eassert (b->indirections == -1);
1707 b->base_buffer->indirections--;
1708 eassert (b->base_buffer->indirections >= 0);
1709 }
1710 else
1711 /* No one shares our buffer text, can free it. */
1664 free_buffer_text (b); 1712 free_buffer_text (b);
1665 1713
1666 if (b->newline_cache) 1714 if (b->newline_cache)
@@ -2048,7 +2096,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2048 2096
2049 { /* This is probably harder to make work. */ 2097 { /* This is probably harder to make work. */
2050 struct buffer *other; 2098 struct buffer *other;
2051 for (other = all_buffers; other; other = other->header.next.buffer) 2099 FOR_EACH_BUFFER (other)
2052 if (other->base_buffer == other_buffer 2100 if (other->base_buffer == other_buffer
2053 || other->base_buffer == current_buffer) 2101 || other->base_buffer == current_buffer)
2054 error ("One of the buffers to swap has indirect buffers"); 2102 error ("One of the buffers to swap has indirect buffers");
@@ -2085,6 +2133,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2085 swapfield (zv_byte, ptrdiff_t); 2133 swapfield (zv_byte, ptrdiff_t);
2086 eassert (!current_buffer->base_buffer); 2134 eassert (!current_buffer->base_buffer);
2087 eassert (!other_buffer->base_buffer); 2135 eassert (!other_buffer->base_buffer);
2136 swapfield (indirections, ptrdiff_t);
2088 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2137 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
2089 swapfield (newline_cache, struct region_cache *); 2138 swapfield (newline_cache, struct region_cache *);
2090 swapfield (width_run_cache, struct region_cache *); 2139 swapfield (width_run_cache, struct region_cache *);
@@ -2425,7 +2474,7 @@ current buffer is cleared. */)
2425 2474
2426 /* Copy this buffer's new multibyte status 2475 /* Copy this buffer's new multibyte status
2427 into all of its indirect buffers. */ 2476 into all of its indirect buffers. */
2428 for (other = all_buffers; other; other = other->header.next.buffer) 2477 FOR_EACH_BUFFER (other)
2429 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) 2478 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name)))
2430 { 2479 {
2431 BVAR (other, enable_multibyte_characters) 2480 BVAR (other, enable_multibyte_characters)
@@ -2794,11 +2843,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2794 Lisp_Object *v, tem; 2843 Lisp_Object *v, tem;
2795 2844
2796 size = 10; 2845 size = 10;
2797 v = (Lisp_Object *) alloca (size * sizeof *v); 2846 v = alloca (size * sizeof *v);
2798 n = overlays_in (start, end, 0, &v, &size, NULL, NULL); 2847 n = overlays_in (start, end, 0, &v, &size, NULL, NULL);
2799 if (n > size) 2848 if (n > size)
2800 { 2849 {
2801 v = (Lisp_Object *) alloca (n * sizeof *v); 2850 v = alloca (n * sizeof *v);
2802 overlays_in (start, end, 0, &v, &n, NULL, NULL); 2851 overlays_in (start, end, 0, &v, &n, NULL, NULL);
2803 } 2852 }
2804 2853
@@ -2825,8 +2874,7 @@ overlay_touches_p (ptrdiff_t pos)
2825 ptrdiff_t endpos; 2874 ptrdiff_t endpos;
2826 2875
2827 XSETMISC (overlay ,tail); 2876 XSETMISC (overlay ,tail);
2828 if (!OVERLAYP (overlay)) 2877 eassert (OVERLAYP (overlay));
2829 abort ();
2830 2878
2831 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 2879 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2832 if (endpos < pos) 2880 if (endpos < pos)
@@ -2840,8 +2888,7 @@ overlay_touches_p (ptrdiff_t pos)
2840 ptrdiff_t startpos; 2888 ptrdiff_t startpos;
2841 2889
2842 XSETMISC (overlay, tail); 2890 XSETMISC (overlay, tail);
2843 if (!OVERLAYP (overlay)) 2891 eassert (OVERLAYP (overlay));
2844 abort ();
2845 2892
2846 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 2893 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2847 if (pos < startpos) 2894 if (pos < startpos)
@@ -2886,8 +2933,7 @@ ptrdiff_t
2886sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) 2933sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2887{ 2934{
2888 ptrdiff_t i, j; 2935 ptrdiff_t i, j;
2889 struct sortvec *sortvec; 2936 struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec);
2890 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2891 2937
2892 /* Put the valid and relevant overlays into sortvec. */ 2938 /* Put the valid and relevant overlays into sortvec. */
2893 2939
@@ -2897,7 +2943,7 @@ sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2897 Lisp_Object overlay; 2943 Lisp_Object overlay;
2898 2944
2899 overlay = overlay_vec[i]; 2945 overlay = overlay_vec[i];
2900 if (OVERLAY_VALID (overlay) 2946 if (OVERLAYP (overlay)
2901 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0 2947 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
2902 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0) 2948 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
2903 { 2949 {
@@ -3168,22 +3214,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3168 { 3214 {
3169 next = tail->next; 3215 next = tail->next;
3170 XSETMISC (overlay, tail); 3216 XSETMISC (overlay, tail);
3171 3217 eassert (OVERLAYP (overlay));
3172 /* If the overlay is not valid, get rid of it. */
3173 if (!OVERLAY_VALID (overlay))
3174#if 1
3175 abort ();
3176#else
3177 {
3178 /* Splice the cons cell TAIL out of overlays_before. */
3179 if (!NILP (prev))
3180 XCDR (prev) = next;
3181 else
3182 buf->overlays_before = next;
3183 tail = prev;
3184 continue;
3185 }
3186#endif
3187 3218
3188 beg = OVERLAY_START (overlay); 3219 beg = OVERLAY_START (overlay);
3189 end = OVERLAY_END (overlay); 3220 end = OVERLAY_END (overlay);
@@ -3208,7 +3239,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3208 Lisp_Object otherbeg, otheroverlay; 3239 Lisp_Object otherbeg, otheroverlay;
3209 3240
3210 XSETMISC (otheroverlay, other); 3241 XSETMISC (otheroverlay, other);
3211 eassert (OVERLAY_VALID (otheroverlay)); 3242 eassert (OVERLAYP (otheroverlay));
3212 3243
3213 otherbeg = OVERLAY_START (otheroverlay); 3244 otherbeg = OVERLAY_START (otheroverlay);
3214 if (OVERLAY_POSITION (otherbeg) >= where) 3245 if (OVERLAY_POSITION (otherbeg) >= where)
@@ -3236,22 +3267,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3236 { 3267 {
3237 next = tail->next; 3268 next = tail->next;
3238 XSETMISC (overlay, tail); 3269 XSETMISC (overlay, tail);
3239 3270 eassert (OVERLAYP (overlay));
3240 /* If the overlay is not valid, get rid of it. */
3241 if (!OVERLAY_VALID (overlay))
3242#if 1
3243 abort ();
3244#else
3245 {
3246 /* Splice the cons cell TAIL out of overlays_after. */
3247 if (!NILP (prev))
3248 XCDR (prev) = next;
3249 else
3250 buf->overlays_after = next;
3251 tail = prev;
3252 continue;
3253 }
3254#endif
3255 3271
3256 beg = OVERLAY_START (overlay); 3272 beg = OVERLAY_START (overlay);
3257 end = OVERLAY_END (overlay); 3273 end = OVERLAY_END (overlay);
@@ -3281,7 +3297,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3281 Lisp_Object otherend, otheroverlay; 3297 Lisp_Object otherend, otheroverlay;
3282 3298
3283 XSETMISC (otheroverlay, other); 3299 XSETMISC (otheroverlay, other);
3284 eassert (OVERLAY_VALID (otheroverlay)); 3300 eassert (OVERLAYP (otheroverlay));
3285 3301
3286 otherend = OVERLAY_END (otheroverlay); 3302 otherend = OVERLAY_END (otheroverlay);
3287 if (OVERLAY_POSITION (otherend) <= where) 3303 if (OVERLAY_POSITION (otherend) <= where)
@@ -3612,12 +3628,7 @@ for the rear of the overlay advance when text is inserted there
3612 if (!NILP (rear_advance)) 3628 if (!NILP (rear_advance))
3613 XMARKER (end)->insertion_type = 1; 3629 XMARKER (end)->insertion_type = 1;
3614 3630
3615 overlay = allocate_misc (); 3631 overlay = build_overlay (beg, end, Qnil);
3616 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
3617 XOVERLAY (overlay)->start = beg;
3618 XOVERLAY (overlay)->end = end;
3619 XOVERLAY (overlay)->plist = Qnil;
3620 XOVERLAY (overlay)->next = NULL;
3621 3632
3622 /* Put the new overlay on the wrong list. */ 3633 /* Put the new overlay on the wrong list. */
3623 end = OVERLAY_END (overlay); 3634 end = OVERLAY_END (overlay);
@@ -3672,18 +3683,17 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3672 ++BUF_OVERLAY_MODIFF (buf); 3683 ++BUF_OVERLAY_MODIFF (buf);
3673} 3684}
3674 3685
3675 3686/* Remove OVERLAY from LIST. */
3687
3676static struct Lisp_Overlay * 3688static struct Lisp_Overlay *
3677unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay) 3689unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay)
3678{ 3690{
3679 struct Lisp_Overlay *tmp, *prev; 3691 register struct Lisp_Overlay *tail, **prev = &list;
3680 for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next) 3692
3681 if (tmp == overlay) 3693 for (tail = list; tail; prev = &tail->next, tail = *prev)
3694 if (tail == overlay)
3682 { 3695 {
3683 if (prev) 3696 *prev = overlay->next;
3684 prev->next = tmp->next;
3685 else
3686 list = tmp->next;
3687 overlay->next = NULL; 3697 overlay->next = NULL;
3688 break; 3698 break;
3689 } 3699 }
@@ -3822,11 +3832,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3822 = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); 3832 = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3823 eassert (XOVERLAY (overlay)->next == NULL); 3833 eassert (XOVERLAY (overlay)->next == NULL);
3824 3834
3825 modify_overlay (b, 3835 drop_overlay (b, XOVERLAY (overlay));
3826 marker_position (OVERLAY_START (overlay)),
3827 marker_position (OVERLAY_END (overlay)));
3828 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
3829 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
3830 3836
3831 /* When deleting an overlay with before or after strings, turn off 3837 /* When deleting an overlay with before or after strings, turn off
3832 display optimizations for the affected buffer, on the basis that 3838 display optimizations for the affected buffer, on the basis that
@@ -3894,7 +3900,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3894 3900
3895 len = 10; 3901 len = 10;
3896 /* We can't use alloca here because overlays_at can call xrealloc. */ 3902 /* We can't use alloca here because overlays_at can call xrealloc. */
3897 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3903 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3898 3904
3899 /* Put all the overlays we want in a vector in overlay_vec. 3905 /* Put all the overlays we want in a vector in overlay_vec.
3900 Store the length in len. */ 3906 Store the length in len. */
@@ -3925,7 +3931,7 @@ end of the buffer. */)
3925 CHECK_NUMBER_COERCE_MARKER (end); 3931 CHECK_NUMBER_COERCE_MARKER (end);
3926 3932
3927 len = 10; 3933 len = 10;
3928 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3934 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3929 3935
3930 /* Put all the overlays we want in a vector in overlay_vec. 3936 /* Put all the overlays we want in a vector in overlay_vec.
3931 Store the length in len. */ 3937 Store the length in len. */
@@ -3953,7 +3959,7 @@ the value is (point-max). */)
3953 CHECK_NUMBER_COERCE_MARKER (pos); 3959 CHECK_NUMBER_COERCE_MARKER (pos);
3954 3960
3955 len = 10; 3961 len = 10;
3956 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3962 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3957 3963
3958 /* Put all the overlays we want in a vector in overlay_vec. 3964 /* Put all the overlays we want in a vector in overlay_vec.
3959 Store the length in len. 3965 Store the length in len.
@@ -3997,7 +4003,7 @@ the value is (point-min). */)
3997 return pos; 4003 return pos;
3998 4004
3999 len = 10; 4005 len = 10;
4000 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 4006 overlay_vec = xmalloc (len * sizeof *overlay_vec);
4001 4007
4002 /* Put all the overlays we want in a vector in overlay_vec. 4008 /* Put all the overlays we want in a vector in overlay_vec.
4003 Store the length in len. 4009 Store the length in len.
@@ -4252,7 +4258,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4252 First copy the vector contents, in case some of these hooks 4258 First copy the vector contents, in case some of these hooks
4253 do subsequent modification of the buffer. */ 4259 do subsequent modification of the buffer. */
4254 ptrdiff_t size = last_overlay_modification_hooks_used; 4260 ptrdiff_t size = last_overlay_modification_hooks_used;
4255 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4261 Lisp_Object *copy = alloca (size * sizeof *copy);
4256 ptrdiff_t i; 4262 ptrdiff_t i;
4257 4263
4258 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4264 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
@@ -4871,6 +4877,12 @@ void
4871init_buffer_once (void) 4877init_buffer_once (void)
4872{ 4878{
4873 int idx; 4879 int idx;
4880 /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make
4881 sure that this is still correct. Otherwise, mark_vectorlike may not
4882 trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */
4883 const int pvecsize
4884 = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header))
4885 / sizeof (Lisp_Object);
4874 4886
4875 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags); 4887 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
4876 4888
@@ -4885,27 +4897,28 @@ init_buffer_once (void)
4885 /* Prevent GC from getting confused. */ 4897 /* Prevent GC from getting confused. */
4886 buffer_defaults.text = &buffer_defaults.own_text; 4898 buffer_defaults.text = &buffer_defaults.own_text;
4887 buffer_local_symbols.text = &buffer_local_symbols.own_text; 4899 buffer_local_symbols.text = &buffer_local_symbols.own_text;
4900 /* No one will share the text with these buffers, but let's play it safe. */
4901 buffer_defaults.indirections = 0;
4902 buffer_local_symbols.indirections = 0;
4888 BUF_INTERVALS (&buffer_defaults) = 0; 4903 BUF_INTERVALS (&buffer_defaults) = 0;
4889 BUF_INTERVALS (&buffer_local_symbols) = 0; 4904 BUF_INTERVALS (&buffer_local_symbols) = 0;
4890 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, 0); 4905 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
4891 XSETBUFFER (Vbuffer_defaults, &buffer_defaults); 4906 XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
4892 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, 0); 4907 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
4893 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); 4908 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols);
4894 4909
4895 /* Set up the default values of various buffer slots. */ 4910 /* Set up the default values of various buffer slots. */
4896 /* Must do these before making the first buffer! */ 4911 /* Must do these before making the first buffer! */
4897 4912
4898 /* real setup is done in bindings.el */ 4913 /* real setup is done in bindings.el */
4899 BVAR (&buffer_defaults, mode_line_format) = make_pure_c_string ("%-"); 4914 BVAR (&buffer_defaults, mode_line_format) = build_pure_c_string ("%-");
4900 BVAR (&buffer_defaults, header_line_format) = Qnil; 4915 BVAR (&buffer_defaults, header_line_format) = Qnil;
4901 BVAR (&buffer_defaults, abbrev_mode) = Qnil; 4916 BVAR (&buffer_defaults, abbrev_mode) = Qnil;
4902 BVAR (&buffer_defaults, overwrite_mode) = Qnil; 4917 BVAR (&buffer_defaults, overwrite_mode) = Qnil;
4903 BVAR (&buffer_defaults, case_fold_search) = Qt; 4918 BVAR (&buffer_defaults, case_fold_search) = Qt;
4904 BVAR (&buffer_defaults, auto_fill_function) = Qnil; 4919 BVAR (&buffer_defaults, auto_fill_function) = Qnil;
4905 BVAR (&buffer_defaults, selective_display) = Qnil; 4920 BVAR (&buffer_defaults, selective_display) = Qnil;
4906#ifndef old
4907 BVAR (&buffer_defaults, selective_display_ellipses) = Qt; 4921 BVAR (&buffer_defaults, selective_display_ellipses) = Qt;
4908#endif
4909 BVAR (&buffer_defaults, abbrev_table) = Qnil; 4922 BVAR (&buffer_defaults, abbrev_table) = Qnil;
4910 BVAR (&buffer_defaults, display_table) = Qnil; 4923 BVAR (&buffer_defaults, display_table) = Qnil;
4911 BVAR (&buffer_defaults, undo_list) = Qnil; 4924 BVAR (&buffer_defaults, undo_list) = Qnil;
@@ -4984,9 +4997,7 @@ init_buffer_once (void)
4984 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; 4997 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx;
4985 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; 4998 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx;
4986 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; 4999 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx;
4987#ifndef old
4988 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; 5000 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx;
4989#endif
4990 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx; 5001 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx;
4991 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx; 5002 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx;
4992 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx; 5003 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx;
@@ -5030,7 +5041,7 @@ init_buffer_once (void)
5030 current_buffer = 0; 5041 current_buffer = 0;
5031 all_buffers = 0; 5042 all_buffers = 0;
5032 5043
5033 QSFundamental = make_pure_c_string ("Fundamental"); 5044 QSFundamental = build_pure_c_string ("Fundamental");
5034 5045
5035 Qfundamental_mode = intern_c_string ("fundamental-mode"); 5046 Qfundamental_mode = intern_c_string ("fundamental-mode");
5036 BVAR (&buffer_defaults, major_mode) = Qfundamental_mode; 5047 BVAR (&buffer_defaults, major_mode) = Qfundamental_mode;
@@ -5045,10 +5056,10 @@ init_buffer_once (void)
5045 Fput (Qkill_buffer_hook, Qpermanent_local, Qt); 5056 Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
5046 5057
5047 /* super-magic invisible buffer */ 5058 /* super-magic invisible buffer */
5048 Vprin1_to_string_buffer = Fget_buffer_create (make_pure_c_string (" prin1")); 5059 Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"));
5049 Vbuffer_alist = Qnil; 5060 Vbuffer_alist = Qnil;
5050 5061
5051 Fset_buffer (Fget_buffer_create (make_pure_c_string ("*scratch*"))); 5062 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
5052 5063
5053 inhibit_modification_hooks = 0; 5064 inhibit_modification_hooks = 0;
5054} 5065}
@@ -5067,7 +5078,7 @@ init_buffer (void)
5067 Map new memory. */ 5078 Map new memory. */
5068 struct buffer *b; 5079 struct buffer *b;
5069 5080
5070 for (b = all_buffers; b; b = b->header.next.buffer) 5081 FOR_EACH_BUFFER (b)
5071 if (b->text->beg == NULL) 5082 if (b->text->beg == NULL)
5072 enlarge_buffer_text (b, 0); 5083 enlarge_buffer_text (b, 0);
5073 } 5084 }
@@ -5088,14 +5099,15 @@ init_buffer (void)
5088 if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) 5099 if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
5089 { 5100 {
5090 /* Grow buffer to add directory separator and '\0'. */ 5101 /* Grow buffer to add directory separator and '\0'. */
5091 pwd = (char *) realloc (pwd, len + 2); 5102 pwd = realloc (pwd, len + 2);
5092 if (!pwd) 5103 if (!pwd)
5093 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); 5104 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
5094 pwd[len] = DIRECTORY_SEP; 5105 pwd[len] = DIRECTORY_SEP;
5095 pwd[len + 1] = '\0'; 5106 pwd[len + 1] = '\0';
5107 len++;
5096 } 5108 }
5097 5109
5098 BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd)); 5110 BVAR (current_buffer, directory) = make_unibyte_string (pwd, len);
5099 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) 5111 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
5100 /* At this moment, we still don't know how to decode the 5112 /* At this moment, we still don't know how to decode the
5101 directory name. So, we keep the bytes in multibyte form so 5113 directory name. So, we keep the bytes in multibyte form so
@@ -5202,7 +5214,7 @@ syms_of_buffer (void)
5202 Fput (Qprotected_field, Qerror_conditions, 5214 Fput (Qprotected_field, Qerror_conditions,
5203 pure_cons (Qprotected_field, pure_cons (Qerror, Qnil))); 5215 pure_cons (Qprotected_field, pure_cons (Qerror, Qnil)));
5204 Fput (Qprotected_field, Qerror_message, 5216 Fput (Qprotected_field, Qerror_message,
5205 make_pure_c_string ("Attempt to modify a protected field")); 5217 build_pure_c_string ("Attempt to modify a protected field"));
5206 5218
5207 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format", 5219 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format",
5208 mode_line_format, 5220 mode_line_format,
@@ -5594,12 +5606,10 @@ A value of t means that the character ^M makes itself and
5594all the rest of the line invisible; also, when saving the buffer 5606all the rest of the line invisible; also, when saving the buffer
5595in a file, save the ^M as a newline. */); 5607in a file, save the ^M as a newline. */);
5596 5608
5597#ifndef old
5598 DEFVAR_PER_BUFFER ("selective-display-ellipses", 5609 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5599 &BVAR (current_buffer, selective_display_ellipses), 5610 &BVAR (current_buffer, selective_display_ellipses),
5600 Qnil, 5611 Qnil,
5601 doc: /* Non-nil means display ... on previous line when a line is invisible. */); 5612 doc: /* Non-nil means display ... on previous line when a line is invisible. */);
5602#endif
5603 5613
5604 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil, 5614 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil,
5605 doc: /* Non-nil if self-insertion should replace existing text. 5615 doc: /* Non-nil if self-insertion should replace existing text.
@@ -5834,9 +5844,9 @@ An entry (TEXT . POSITION) represents the deletion of the string TEXT
5834from (abs POSITION). If POSITION is positive, point was at the front 5844from (abs POSITION). If POSITION is positive, point was at the front
5835of the text being deleted; if negative, point was at the end. 5845of the text being deleted; if negative, point was at the end.
5836 5846
5837An entry (t HIGH . LOW) indicates that the buffer previously had 5847An entry (t HIGH LOW USEC PSEC) indicates that the buffer was previously
5838\"unmodified\" status. HIGH and LOW are the high and low 16-bit portions 5848unmodified; (HIGH LOW USEC PSEC) is in the same style as (current-time)
5839of the visited file's modification time, as of that time. If the 5849and is the visited file's modification time, as of that time. If the
5840modification time of the most recent save is different, this entry is 5850modification time of the most recent save is different, this entry is
5841obsolete. 5851obsolete.
5842 5852
@@ -6027,7 +6037,6 @@ and `bury-buffer-internal'. */);
6027 defsubr (&Smake_indirect_buffer); 6037 defsubr (&Smake_indirect_buffer);
6028 defsubr (&Sgenerate_new_buffer_name); 6038 defsubr (&Sgenerate_new_buffer_name);
6029 defsubr (&Sbuffer_name); 6039 defsubr (&Sbuffer_name);
6030/*defsubr (&Sbuffer_number);*/
6031 defsubr (&Sbuffer_file_name); 6040 defsubr (&Sbuffer_file_name);
6032 defsubr (&Sbuffer_base_buffer); 6041 defsubr (&Sbuffer_base_buffer);
6033 defsubr (&Sbuffer_local_value); 6042 defsubr (&Sbuffer_local_value);