comparison src/buffer.c @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 8bcbac2617a9
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 /* Buffer manipulation primitives for GNU Emacs. 1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999, 2000, 2001, 2002 2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994,
3 Free Software Foundation, Inc. 3 1995, 1997, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005 Free Software Foundation, Inc.
4 5
5 This file is part of GNU Emacs. 6 This file is part of GNU Emacs.
6 7
7 GNU Emacs is free software; you can redistribute it and/or modify 8 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 GNU General Public License for more details.
16 17
17 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to 19 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02111-1307, USA. */ 21 Boston, MA 02110-1301, USA. */
21 22
22 #include <config.h> 23 #include <config.h>
23 24
24 #include <sys/types.h> 25 #include <sys/types.h>
25 #include <sys/stat.h> 26 #include <sys/stat.h>
29 30
30 #ifndef USE_CRT_DLL 31 #ifndef USE_CRT_DLL
31 extern int errno; 32 extern int errno;
32 #endif 33 #endif
33 34
34 #ifndef MAXPATHLEN
35 /* in 4.1, param.h fails to define this. */
36 #define MAXPATHLEN 1024
37 #endif /* not MAXPATHLEN */
38 35
39 #ifdef HAVE_UNISTD_H 36 #ifdef HAVE_UNISTD_H
40 #include <unistd.h> 37 #include <unistd.h>
41 #endif 38 #endif
42 39
65 The default value occupies the same slot in this structure 62 The default value occupies the same slot in this structure
66 as an individual buffer's value occupies in that buffer. 63 as an individual buffer's value occupies in that buffer.
67 Setting the default value also goes through the alist of buffers 64 Setting the default value also goes through the alist of buffers
68 and stores into each buffer that does not say it has a local value. */ 65 and stores into each buffer that does not say it has a local value. */
69 66
70 struct buffer buffer_defaults; 67 DECL_ALIGN (struct buffer, buffer_defaults);
71 68
72 /* A Lisp_Object pointer to the above, used for staticpro */ 69 /* A Lisp_Object pointer to the above, used for staticpro */
73 70
74 static Lisp_Object Vbuffer_defaults; 71 static Lisp_Object Vbuffer_defaults;
75 72
87 and the corresponding slot in buffer_defaults is not used. 84 and the corresponding slot in buffer_defaults is not used.
88 85
89 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it, 86 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
90 but there is a default value which is copied into each buffer. 87 but there is a default value which is copied into each buffer.
91 88
92 If a slot in this structure is negative, then even though there may
93 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
94 and the corresponding slot in buffer_defaults is not used.
95
96 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is 89 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
97 zero, that is a bug */ 90 zero, that is a bug */
98 91
99 struct buffer buffer_local_flags; 92 struct buffer buffer_local_flags;
100 93
101 /* This structure holds the names of symbols whose values may be 94 /* This structure holds the names of symbols whose values may be
102 buffer-local. It is indexed and accessed in the same way as the above. */ 95 buffer-local. It is indexed and accessed in the same way as the above. */
103 96
104 struct buffer buffer_local_symbols; 97 DECL_ALIGN (struct buffer, buffer_local_symbols);
98
105 /* A Lisp_Object pointer to the above, used for staticpro */ 99 /* A Lisp_Object pointer to the above, used for staticpro */
106 static Lisp_Object Vbuffer_local_symbols; 100 static Lisp_Object Vbuffer_local_symbols;
107 101
108 /* This structure holds the required types for the values in the 102 /* This structure holds the required types for the values in the
109 buffer-local slots. If a slot contains Qnil, then the 103 buffer-local slots. If a slot contains Qnil, then the
148 Lisp_Object Vinhibit_read_only; 142 Lisp_Object Vinhibit_read_only;
149 143
150 /* List of functions to call that can query about killing a buffer. 144 /* List of functions to call that can query about killing a buffer.
151 If any of these functions returns nil, we don't kill it. */ 145 If any of these functions returns nil, we don't kill it. */
152 Lisp_Object Vkill_buffer_query_functions; 146 Lisp_Object Vkill_buffer_query_functions;
147 Lisp_Object Qkill_buffer_query_functions;
153 148
154 /* List of functions to call before changing an unmodified buffer. */ 149 /* List of functions to call before changing an unmodified buffer. */
155 Lisp_Object Vfirst_change_hook; 150 Lisp_Object Vfirst_change_hook;
156 151
157 Lisp_Object Qfirst_change_hook; 152 Lisp_Object Qfirst_change_hook;
180 Lisp_Object Qinsert_in_front_hooks; 175 Lisp_Object Qinsert_in_front_hooks;
181 Lisp_Object Qinsert_behind_hooks; 176 Lisp_Object Qinsert_behind_hooks;
182 177
183 static void alloc_buffer_text P_ ((struct buffer *, size_t)); 178 static void alloc_buffer_text P_ ((struct buffer *, size_t));
184 static void free_buffer_text P_ ((struct buffer *b)); 179 static void free_buffer_text P_ ((struct buffer *b));
185 static Lisp_Object copy_overlays P_ ((struct buffer *, Lisp_Object)); 180 static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *));
186 static void modify_overlay P_ ((struct buffer *, int, int)); 181 static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT));
182 static Lisp_Object buffer_lisp_local_variables P_ ((struct buffer *));
187 183
188 184
189 /* For debugging; temporary. See set_buffer_internal. */ 185 /* For debugging; temporary. See set_buffer_internal. */
190 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 186 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
191 187
410 406
411 reset_buffer (b); 407 reset_buffer (b);
412 reset_buffer_local_variables (b, 1); 408 reset_buffer_local_variables (b, 1);
413 409
414 b->mark = Fmake_marker (); 410 b->mark = Fmake_marker ();
415 BUF_MARKERS (b) = Qnil; 411 BUF_MARKERS (b) = NULL;
416 b->name = name; 412 b->name = name;
417 413
418 /* Put this in the alist of all live buffers. */ 414 /* Put this in the alist of all live buffers. */
419 XSETBUFFER (buf, b); 415 XSETBUFFER (buf, b);
420 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); 416 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
421 417
422 /* Fixme: Protect against errors, which would trigger infinite 418 /* An error in calling the function here (should someone redfine it)
423 regress? */ 419 can lead to infinite regress until you run out of stack. rms
420 says that's not worth protecting against. */
424 if (!NILP (Ffboundp (Qucs_set_table_for_input))) 421 if (!NILP (Ffboundp (Qucs_set_table_for_input)))
425 /* buff is on buffer-alist, so no gcpro */ 422 /* buf is on buffer-alist, so no gcpro. */
426 call1 (Qucs_set_table_for_input, buf); 423 call1 (Qucs_set_table_for_input, buf);
427 424
428 return buf; 425 return buf;
429 } 426 }
430 427
431 428
432 /* Return a list of overlays which is a copy of the overlay list 429 /* Return a list of overlays which is a copy of the overlay list
433 LIST, but for buffer B. */ 430 LIST, but for buffer B. */
434 431
435 static Lisp_Object 432 static struct Lisp_Overlay *
436 copy_overlays (b, list) 433 copy_overlays (b, list)
437 struct buffer *b; 434 struct buffer *b;
438 Lisp_Object list; 435 struct Lisp_Overlay *list;
439 { 436 {
440 Lisp_Object result, buffer; 437 Lisp_Object buffer;
438 struct Lisp_Overlay *result = NULL, *tail = NULL;
441 439
442 XSETBUFFER (buffer, b); 440 XSETBUFFER (buffer, b);
443 441
444 for (result = Qnil; CONSP (list); list = XCDR (list)) 442 for (; list; list = list->next)
445 { 443 {
446 Lisp_Object overlay, start, end, old_overlay; 444 Lisp_Object overlay, start, end, old_overlay;
447 int charpos; 445 EMACS_INT charpos;
448 446
449 old_overlay = XCAR (list); 447 XSETMISC (old_overlay, list);
450 charpos = marker_position (OVERLAY_START (old_overlay)); 448 charpos = marker_position (OVERLAY_START (old_overlay));
451 start = Fmake_marker (); 449 start = Fmake_marker ();
452 Fset_marker (start, make_number (charpos), buffer); 450 Fset_marker (start, make_number (charpos), buffer);
453 XMARKER (start)->insertion_type 451 XMARKER (start)->insertion_type
454 = XMARKER (OVERLAY_START (old_overlay))->insertion_type; 452 = XMARKER (OVERLAY_START (old_overlay))->insertion_type;
462 overlay = allocate_misc (); 460 overlay = allocate_misc ();
463 XMISCTYPE (overlay) = Lisp_Misc_Overlay; 461 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
464 OVERLAY_START (overlay) = start; 462 OVERLAY_START (overlay) = start;
465 OVERLAY_END (overlay) = end; 463 OVERLAY_END (overlay) = end;
466 OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay)); 464 OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay));
467 465 XOVERLAY (overlay)->next = NULL;
468 result = Fcons (overlay, result); 466
469 } 467 if (tail)
470 468 tail = tail->next = XOVERLAY (overlay);
471 return Fnreverse (result); 469 else
470 result = tail = XOVERLAY (overlay);
471 }
472
473 return result;
472 } 474 }
473 475
474 476
475 /* Clone per-buffer values of buffer FROM. 477 /* Clone per-buffer values of buffer FROM.
476 478
508 510
509 bcopy (from->local_flags, to->local_flags, sizeof to->local_flags); 511 bcopy (from->local_flags, to->local_flags, sizeof to->local_flags);
510 512
511 to->overlays_before = copy_overlays (to, from->overlays_before); 513 to->overlays_before = copy_overlays (to, from->overlays_before);
512 to->overlays_after = copy_overlays (to, from->overlays_after); 514 to->overlays_after = copy_overlays (to, from->overlays_after);
513 } 515
514 516 /* Get (a copy of) the alist of Lisp-level local variables of FROM
517 and install that in TO. */
518 to->local_var_alist = buffer_lisp_local_variables (from);
519 }
515 520
516 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, Smake_indirect_buffer, 521 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, Smake_indirect_buffer,
517 2, 3, 522 2, 3,
518 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", 523 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
519 doc: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME. 524 doc: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
520 BASE-BUFFER should be an existing buffer (or buffer name). 525 BASE-BUFFER should be a live buffer, or the name of an existing buffer.
521 NAME should be a string which is not the name of an existing buffer. 526 NAME should be a string which is not the name of an existing buffer.
522 Optional argument CLONE non-nil means preserve BASE-BUFFER's state, 527 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
523 such as major and minor modes, in the indirect buffer. 528 such as major and minor modes, in the indirect buffer.
524 CLONE nil means the indirect buffer's state is reset to default values. */) 529 CLONE nil means the indirect buffer's state is reset to default values. */)
525 (base_buffer, name, clone) 530 (base_buffer, name, clone)
526 Lisp_Object base_buffer, name, clone; 531 Lisp_Object base_buffer, name, clone;
527 { 532 {
528 Lisp_Object buf; 533 Lisp_Object buf, tem;
529 struct buffer *b; 534 struct buffer *b;
530 535
536 CHECK_STRING (name);
531 buf = Fget_buffer (name); 537 buf = Fget_buffer (name);
532 if (!NILP (buf)) 538 if (!NILP (buf))
533 error ("Buffer name `%s' is in use", SDATA (name)); 539 error ("Buffer name `%s' is in use", SDATA (name));
534 540
541 tem = base_buffer;
535 base_buffer = Fget_buffer (base_buffer); 542 base_buffer = Fget_buffer (base_buffer);
536 if (NILP (base_buffer)) 543 if (NILP (base_buffer))
537 error ("No such buffer: `%s'", SDATA (name)); 544 error ("No such buffer: `%s'", SDATA (tem));
545 if (NILP (XBUFFER (base_buffer)->name))
546 error ("Base buffer has been killed");
538 547
539 if (SCHARS (name) == 0) 548 if (SCHARS (name) == 0)
540 error ("Empty string for buffer name is not allowed"); 549 error ("Empty string for buffer name is not allowed");
541 550
542 b = (struct buffer *) allocate_buffer (); 551 b = (struct buffer *) allocate_buffer ();
616 b->zv_marker = Fmake_marker (); 625 b->zv_marker = Fmake_marker ();
617 set_marker_both (b->zv_marker, buf, BUF_ZV (b), BUF_ZV_BYTE (b)); 626 set_marker_both (b->zv_marker, buf, BUF_ZV (b), BUF_ZV_BYTE (b));
618 XMARKER (b->zv_marker)->insertion_type = 1; 627 XMARKER (b->zv_marker)->insertion_type = 1;
619 } 628 }
620 else 629 else
621 clone_per_buffer_values (b->base_buffer, b); 630 {
631 struct buffer *old_b = current_buffer;
632
633 clone_per_buffer_values (b->base_buffer, b);
634 b->filename = Qnil;
635 b->file_truename = Qnil;
636 b->display_count = make_number (0);
637 b->backed_up = Qnil;
638 b->auto_save_file_name = Qnil;
639 set_buffer_internal_1 (b);
640 Fset (intern ("buffer-save-without-query"), Qnil);
641 Fset (intern ("buffer-file-number"), Qnil);
642 Fset (intern ("buffer-stale-function"), Qnil);
643 set_buffer_internal_1 (old_b);
644 }
622 645
623 return buf; 646 return buf;
624 } 647 }
625 648
649 void
650 delete_all_overlays (b)
651 struct buffer *b;
652 {
653 Lisp_Object overlay;
654
655 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
656 have to empty the list, otherwise we end up with overlays that
657 think they belong to this buffer while the buffer doesn't know about
658 them any more. */
659 while (b->overlays_before)
660 {
661 XSETMISC (overlay, b->overlays_before);
662 Fdelete_overlay (overlay);
663 }
664 while (b->overlays_after)
665 {
666 XSETMISC (overlay, b->overlays_after);
667 Fdelete_overlay (overlay);
668 }
669 eassert (b->overlays_before == NULL);
670 eassert (b->overlays_after == NULL);
671 }
672
626 /* Reinitialize everything about a buffer except its name and contents 673 /* Reinitialize everything about a buffer except its name and contents
627 and local variables. */ 674 and local variables.
675 If called on an already-initialized buffer, the list of overlays
676 should be deleted before calling this function, otherwise we end up
677 with overlays that claim to belong to the buffer but the buffer
678 claims it doesn't belong to it. */
628 679
629 void 680 void
630 reset_buffer (b) 681 reset_buffer (b)
631 register struct buffer *b; 682 register struct buffer *b;
632 { 683 {
642 b->backed_up = Qnil; 693 b->backed_up = Qnil;
643 b->auto_save_modified = 0; 694 b->auto_save_modified = 0;
644 b->auto_save_failure_time = -1; 695 b->auto_save_failure_time = -1;
645 b->auto_save_file_name = Qnil; 696 b->auto_save_file_name = Qnil;
646 b->read_only = Qnil; 697 b->read_only = Qnil;
647 b->overlays_before = Qnil; 698 b->overlays_before = NULL;
648 b->overlays_after = Qnil; 699 b->overlays_after = NULL;
649 XSETFASTINT (b->overlay_center, 1); 700 b->overlay_center = BEG;
650 b->mark_active = Qnil; 701 b->mark_active = Qnil;
651 b->point_before_scroll = Qnil; 702 b->point_before_scroll = Qnil;
652 b->file_format = Qnil; 703 b->file_format = Qnil;
704 b->auto_save_file_format = Qt;
653 b->last_selected_window = Qnil; 705 b->last_selected_window = Qnil;
654 XSETINT (b->display_count, 0); 706 XSETINT (b->display_count, 0);
655 b->display_time = Qnil; 707 b->display_time = Qnil;
656 b->enable_multibyte_characters = buffer_defaults.enable_multibyte_characters; 708 b->enable_multibyte_characters = buffer_defaults.enable_multibyte_characters;
657 b->cursor_type = buffer_defaults.cursor_type; 709 b->cursor_type = buffer_defaults.cursor_type;
681 things that depend on the major mode. 733 things that depend on the major mode.
682 default-major-mode is handled at a higher level. 734 default-major-mode is handled at a higher level.
683 We ignore it here. */ 735 We ignore it here. */
684 b->major_mode = Qfundamental_mode; 736 b->major_mode = Qfundamental_mode;
685 b->keymap = Qnil; 737 b->keymap = Qnil;
686 b->abbrev_table = Vfundamental_mode_abbrev_table;
687 b->mode_name = QSFundamental; 738 b->mode_name = QSFundamental;
688 b->minor_modes = Qnil; 739 b->minor_modes = Qnil;
689 740
690 /* If the standard case table has been altered and invalidated, 741 /* If the standard case table has been altered and invalidated,
691 fix up its insides first. */ 742 fix up its insides first. */
733 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name, 784 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name,
734 1, 2, 0, 785 1, 2, 0,
735 doc: /* Return a string that is the name of no existing buffer based on NAME. 786 doc: /* Return a string that is the name of no existing buffer based on NAME.
736 If there is no live buffer named NAME, then return NAME. 787 If there is no live buffer named NAME, then return NAME.
737 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER 788 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
738 until an unused name is found, and then return that name. 789 \(starting at 2) until an unused name is found, and then return that name.
739 Optional second argument IGNORE specifies a name that is okay to use 790 Optional second argument IGNORE specifies a name that is okay to use
740 \(if it is in the sequence to be tried) 791 \(if it is in the sequence to be tried)
741 even if a buffer with that name exists. */) 792 even if a buffer with that name exists. */)
742 (name, ignore) 793 (name, ignore)
743 register Lisp_Object name, ignore; 794 register Lisp_Object name, ignore;
746 int count; 797 int count;
747 char number[10]; 798 char number[10];
748 799
749 CHECK_STRING (name); 800 CHECK_STRING (name);
750 801
802 tem = Fstring_equal (name, ignore);
803 if (!NILP (tem))
804 return name;
751 tem = Fget_buffer (name); 805 tem = Fget_buffer (name);
752 if (NILP (tem)) 806 if (NILP (tem))
753 return name; 807 return name;
754 808
755 count = 1; 809 count = 1;
792 } 846 }
793 847
794 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer, 848 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer,
795 0, 1, 0, 849 0, 1, 0,
796 doc: /* Return the base buffer of indirect buffer BUFFER. 850 doc: /* Return the base buffer of indirect buffer BUFFER.
797 If BUFFER is not indirect, return nil. */) 851 If BUFFER is not indirect, return nil.
852 BUFFER defaults to the current buffer. */)
798 (buffer) 853 (buffer)
799 register Lisp_Object buffer; 854 register Lisp_Object buffer;
800 { 855 {
801 struct buffer *base; 856 struct buffer *base;
802 Lisp_Object base_buffer; 857 Lisp_Object base_buffer;
817 872
818 DEFUN ("buffer-local-value", Fbuffer_local_value, 873 DEFUN ("buffer-local-value", Fbuffer_local_value,
819 Sbuffer_local_value, 2, 2, 0, 874 Sbuffer_local_value, 2, 2, 0,
820 doc: /* Return the value of VARIABLE in BUFFER. 875 doc: /* Return the value of VARIABLE in BUFFER.
821 If VARIABLE does not have a buffer-local binding in BUFFER, the value 876 If VARIABLE does not have a buffer-local binding in BUFFER, the value
822 is the default binding of variable. */) 877 is the default binding of the variable. */)
823 (symbol, buffer) 878 (variable, buffer)
824 register Lisp_Object symbol; 879 register Lisp_Object variable;
825 register Lisp_Object buffer; 880 register Lisp_Object buffer;
826 { 881 {
827 register struct buffer *buf; 882 register struct buffer *buf;
828 register Lisp_Object result; 883 register Lisp_Object result;
829 884
830 CHECK_SYMBOL (symbol); 885 CHECK_SYMBOL (variable);
831 CHECK_BUFFER (buffer); 886 CHECK_BUFFER (buffer);
832 buf = XBUFFER (buffer); 887 buf = XBUFFER (buffer);
833 888
889 if (SYMBOLP (variable))
890 variable = indirect_variable (variable);
891
834 /* Look in local_var_list */ 892 /* Look in local_var_list */
835 result = Fassoc (symbol, buf->local_var_alist); 893 result = Fassoc (variable, buf->local_var_alist);
836 if (NILP (result)) 894 if (NILP (result))
837 { 895 {
838 int offset, idx; 896 int offset, idx;
839 int found = 0; 897 int found = 0;
840 898
845 offset += (sizeof (EMACS_INT))) 903 offset += (sizeof (EMACS_INT)))
846 { 904 {
847 idx = PER_BUFFER_IDX (offset); 905 idx = PER_BUFFER_IDX (offset);
848 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) 906 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
849 && SYMBOLP (PER_BUFFER_SYMBOL (offset)) 907 && SYMBOLP (PER_BUFFER_SYMBOL (offset))
850 && EQ (PER_BUFFER_SYMBOL (offset), symbol)) 908 && EQ (PER_BUFFER_SYMBOL (offset), variable))
851 { 909 {
852 result = PER_BUFFER_VALUE (buf, offset); 910 result = PER_BUFFER_VALUE (buf, offset);
853 found = 1; 911 found = 1;
854 break; 912 break;
855 } 913 }
856 } 914 }
857 915
858 if (!found) 916 if (!found)
859 result = Fdefault_value (symbol); 917 result = Fdefault_value (variable);
860 } 918 }
861 else 919 else
862 { 920 {
863 Lisp_Object valcontents; 921 Lisp_Object valcontents;
864 Lisp_Object current_alist_element; 922 Lisp_Object current_alist_element;
865 923
866 /* What binding is loaded right now? */ 924 /* What binding is loaded right now? */
867 valcontents = SYMBOL_VALUE (symbol); 925 valcontents = SYMBOL_VALUE (variable);
868 current_alist_element 926 current_alist_element
869 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); 927 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
870 928
871 /* The value of the currently loaded binding is not 929 /* The value of the currently loaded binding is not
872 stored in it, but rather in the realvalue slot. 930 stored in it, but rather in the realvalue slot.
879 /* Now get the (perhaps updated) value out of the binding. */ 937 /* Now get the (perhaps updated) value out of the binding. */
880 result = XCDR (result); 938 result = XCDR (result);
881 } 939 }
882 940
883 if (EQ (result, Qunbound)) 941 if (EQ (result, Qunbound))
884 return Fsignal (Qvoid_variable, Fcons (symbol, Qnil)); 942 return Fsignal (Qvoid_variable, Fcons (variable, Qnil));
943
944 return result;
945 }
946
947 /* Return an alist of the Lisp-level buffer-local bindings of
948 buffer BUF. That is, don't include the variables maintained
949 in special slots in the buffer object. */
950
951 static Lisp_Object
952 buffer_lisp_local_variables (buf)
953 struct buffer *buf;
954 {
955 Lisp_Object result = Qnil;
956 register Lisp_Object tail;
957 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
958 {
959 Lisp_Object val, elt;
960
961 elt = XCAR (tail);
962
963 /* Reference each variable in the alist in buf.
964 If inquiring about the current buffer, this gets the current values,
965 so store them into the alist so the alist is up to date.
966 If inquiring about some other buffer, this swaps out any values
967 for that buffer, making the alist up to date automatically. */
968 val = find_symbol_value (XCAR (elt));
969 /* Use the current buffer value only if buf is the current buffer. */
970 if (buf != current_buffer)
971 val = XCDR (elt);
972
973 /* If symbol is unbound, put just the symbol in the list. */
974 if (EQ (val, Qunbound))
975 result = Fcons (XCAR (elt), result);
976 /* Otherwise, put (symbol . value) in the list. */
977 else
978 result = Fcons (Fcons (XCAR (elt), val), result);
979 }
885 980
886 return result; 981 return result;
887 } 982 }
888 983
889 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 984 DEFUN ("buffer-local-variables", Fbuffer_local_variables,
905 { 1000 {
906 CHECK_BUFFER (buffer); 1001 CHECK_BUFFER (buffer);
907 buf = XBUFFER (buffer); 1002 buf = XBUFFER (buffer);
908 } 1003 }
909 1004
910 result = Qnil; 1005 result = buffer_lisp_local_variables (buf);
911
912 {
913 register Lisp_Object tail;
914 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
915 {
916 Lisp_Object val, elt;
917
918 elt = XCAR (tail);
919
920 /* Reference each variable in the alist in buf.
921 If inquiring about the current buffer, this gets the current values,
922 so store them into the alist so the alist is up to date.
923 If inquiring about some other buffer, this swaps out any values
924 for that buffer, making the alist up to date automatically. */
925 val = find_symbol_value (XCAR (elt));
926 /* Use the current buffer value only if buf is the current buffer. */
927 if (buf != current_buffer)
928 val = XCDR (elt);
929
930 /* If symbol is unbound, put just the symbol in the list. */
931 if (EQ (val, Qunbound))
932 result = Fcons (XCAR (elt), result);
933 /* Otherwise, put (symbol . value) in the list. */
934 else
935 result = Fcons (Fcons (XCAR (elt), val), result);
936 }
937 }
938 1006
939 /* Add on all the variables stored in special slots. */ 1007 /* Add on all the variables stored in special slots. */
940 { 1008 {
941 int offset, idx; 1009 int offset, idx;
942 1010
954 } 1022 }
955 } 1023 }
956 1024
957 return result; 1025 return result;
958 } 1026 }
959
960 1027
961 DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, 1028 DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p,
962 0, 1, 0, 1029 0, 1, 0,
963 doc: /* Return t if BUFFER was modified since its file was last read or saved. 1030 doc: /* Return t if BUFFER was modified since its file was last read or saved.
964 No argument or nil as argument means use current buffer as BUFFER. */) 1031 No argument or nil as argument means use current buffer as BUFFER. */)
1028 return flag; 1095 return flag;
1029 } 1096 }
1030 1097
1031 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, 1098 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p,
1032 Srestore_buffer_modified_p, 1, 1, 0, 1099 Srestore_buffer_modified_p, 1, 1, 0,
1033 doc: /* Like `set-buffer-modified-p', with a differences concerning redisplay. 1100 doc: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
1034 It is not ensured that mode lines will be updated to show the modified 1101 It is not ensured that mode lines will be updated to show the modified
1035 state of the current buffer. Use with care. */) 1102 state of the current buffer. Use with care. */)
1036 (flag) 1103 (flag)
1037 Lisp_Object flag; 1104 Lisp_Object flag;
1038 { 1105 {
1166 for (; CONSP (tail); tail = XCDR (tail)) 1233 for (; CONSP (tail); tail = XCDR (tail))
1167 { 1234 {
1168 buf = Fcdr (XCAR (tail)); 1235 buf = Fcdr (XCAR (tail));
1169 if (EQ (buf, buffer)) 1236 if (EQ (buf, buffer))
1170 continue; 1237 continue;
1238 if (NILP (buf))
1239 continue;
1240 if (NILP (XBUFFER (buf)->name))
1241 continue;
1171 if (SREF (XBUFFER (buf)->name, 0) == ' ') 1242 if (SREF (XBUFFER (buf)->name, 0) == ' ')
1172 continue; 1243 continue;
1173 /* If the selected frame has a buffer_predicate, 1244 /* If the selected frame has a buffer_predicate,
1174 disregard buffers that don't fit the predicate. */ 1245 disregard buffers that don't fit the predicate. */
1175 if (!NILP (pred)) 1246 if (!NILP (pred))
1197 Fset_buffer_major_mode (buf); 1268 Fset_buffer_major_mode (buf);
1198 } 1269 }
1199 return buf; 1270 return buf;
1200 } 1271 }
1201 1272
1202 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo,
1203 0, 1, "",
1204 doc: /* Make BUFFER stop keeping undo information.
1205 No argument or nil as argument means do this for the current buffer. */)
1206 (buffer)
1207 register Lisp_Object buffer;
1208 {
1209 Lisp_Object real_buffer;
1210
1211 if (NILP (buffer))
1212 XSETBUFFER (real_buffer, current_buffer);
1213 else
1214 {
1215 real_buffer = Fget_buffer (buffer);
1216 if (NILP (real_buffer))
1217 nsberror (buffer);
1218 }
1219
1220 XBUFFER (real_buffer)->undo_list = Qt;
1221
1222 return Qnil;
1223 }
1224
1225 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo, 1273 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
1226 0, 1, "", 1274 0, 1, "",
1227 doc: /* Start keeping undo information for buffer BUFFER. 1275 doc: /* Start keeping undo information for buffer BUFFER.
1228 No argument or nil as argument means do this for the current buffer. */) 1276 No argument or nil as argument means do this for the current buffer. */)
1229 (buffer) 1277 (buffer)
1301 } 1349 }
1302 1350
1303 /* Run hooks with the buffer to be killed the current buffer. */ 1351 /* Run hooks with the buffer to be killed the current buffer. */
1304 { 1352 {
1305 int count = SPECPDL_INDEX (); 1353 int count = SPECPDL_INDEX ();
1306 Lisp_Object list; 1354 Lisp_Object arglist[1];
1307 1355
1308 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1356 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1309 set_buffer_internal (b); 1357 set_buffer_internal (b);
1310 1358
1311 /* First run the query functions; if any query is answered no, 1359 /* First run the query functions; if any query is answered no,
1312 don't kill the buffer. */ 1360 don't kill the buffer. */
1313 for (list = Vkill_buffer_query_functions; CONSP (list); list = XCDR (list)) 1361 arglist[0] = Qkill_buffer_query_functions;
1314 { 1362 tem = Frun_hook_with_args_until_failure (1, arglist);
1315 tem = call0 (XCAR (list)); 1363 if (NILP (tem))
1316 if (NILP (tem)) 1364 return unbind_to (count, Qnil);
1317 return unbind_to (count, Qnil);
1318 }
1319 1365
1320 /* Then run the hooks. */ 1366 /* Then run the hooks. */
1321 Frun_hooks (1, &Qkill_buffer_hook); 1367 Frun_hooks (1, &Qkill_buffer_hook);
1322 unbind_to (count, Qnil); 1368 unbind_to (count, Qnil);
1323 } 1369 }
1382 /* Unlock this buffer's file, if it is locked. */ 1428 /* Unlock this buffer's file, if it is locked. */
1383 unlock_buffer (b); 1429 unlock_buffer (b);
1384 #endif /* CLASH_DETECTION */ 1430 #endif /* CLASH_DETECTION */
1385 1431
1386 kill_buffer_processes (buf); 1432 kill_buffer_processes (buf);
1433 clear_charpos_cache (b);
1387 1434
1388 tem = Vinhibit_quit; 1435 tem = Vinhibit_quit;
1389 Vinhibit_quit = Qt; 1436 Vinhibit_quit = Qt;
1390 replace_buffer_in_all_windows (buf); 1437 replace_buffer_in_all_windows (buf);
1391 Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist); 1438 Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist);
1395 /* Delete any auto-save file, if we saved it in this session. 1442 /* Delete any auto-save file, if we saved it in this session.
1396 But not if the buffer is modified. */ 1443 But not if the buffer is modified. */
1397 if (STRINGP (b->auto_save_file_name) 1444 if (STRINGP (b->auto_save_file_name)
1398 && b->auto_save_modified != 0 1445 && b->auto_save_modified != 0
1399 && BUF_SAVE_MODIFF (b) < b->auto_save_modified 1446 && BUF_SAVE_MODIFF (b) < b->auto_save_modified
1400 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) 1447 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
1448 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1401 { 1449 {
1402 Lisp_Object tem; 1450 Lisp_Object tem;
1403 tem = Fsymbol_value (intern ("delete-auto-save-files")); 1451 tem = Fsymbol_value (intern ("delete-auto-save-files"));
1404 if (! NILP (tem)) 1452 if (! NILP (tem))
1405 internal_delete_file (b->auto_save_file_name); 1453 internal_delete_file (b->auto_save_file_name);
1408 if (b->base_buffer) 1456 if (b->base_buffer)
1409 { 1457 {
1410 /* Unchain all markers that belong to this indirect buffer. 1458 /* Unchain all markers that belong to this indirect buffer.
1411 Don't unchain the markers that belong to the base buffer 1459 Don't unchain the markers that belong to the base buffer
1412 or its other indirect buffers. */ 1460 or its other indirect buffers. */
1413 for (tem = BUF_MARKERS (b); !NILP (tem); ) 1461 for (m = BUF_MARKERS (b); m; )
1414 { 1462 {
1415 Lisp_Object next; 1463 struct Lisp_Marker *next = m->next;
1416 m = XMARKER (tem);
1417 next = m->chain;
1418 if (m->buffer == b) 1464 if (m->buffer == b)
1419 unchain_marker (tem); 1465 unchain_marker (m);
1420 tem = next; 1466 m = next;
1421 } 1467 }
1422 } 1468 }
1423 else 1469 else
1424 { 1470 {
1425 /* Unchain all markers of this buffer and its indirect buffers. 1471 /* Unchain all markers of this buffer and its indirect buffers.
1426 and leave them pointing nowhere. */ 1472 and leave them pointing nowhere. */
1427 for (tem = BUF_MARKERS (b); !NILP (tem); ) 1473 for (m = BUF_MARKERS (b); m; )
1428 { 1474 {
1429 m = XMARKER (tem); 1475 struct Lisp_Marker *next = m->next;
1430 m->buffer = 0; 1476 m->buffer = 0;
1431 tem = m->chain; 1477 m->next = NULL;
1432 m->chain = Qnil; 1478 m = next;
1433 } 1479 }
1434 BUF_MARKERS (b) = Qnil; 1480 BUF_MARKERS (b) = NULL;
1435 BUF_INTERVALS (b) = NULL_INTERVAL; 1481 BUF_INTERVALS (b) = NULL_INTERVAL;
1436 1482
1437 /* Perhaps we should explicitly free the interval tree here... */ 1483 /* Perhaps we should explicitly free the interval tree here... */
1438 } 1484 }
1439 1485
1607 record_buffer (buf); 1653 record_buffer (buf);
1608 1654
1609 Fset_window_buffer (EQ (selected_window, minibuf_window) 1655 Fset_window_buffer (EQ (selected_window, minibuf_window)
1610 ? Fnext_window (minibuf_window, Qnil, Qnil) 1656 ? Fnext_window (minibuf_window, Qnil, Qnil)
1611 : selected_window, 1657 : selected_window,
1612 buf); 1658 buf, Qnil);
1613 1659
1614 return buf; 1660 return buf;
1615 } 1661 }
1616 1662
1617 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", 1663 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
1618 doc: /* Select buffer BUFFER in the current window. 1664 doc: /* Select buffer BUFFER in the current window.
1619 BUFFER may be a buffer or a buffer name. 1665 If BUFFER does not identify an existing buffer,
1666 then this function creates a buffer with that name.
1667
1668 When called from Lisp, BUFFER may be a buffer, a string \(a buffer name),
1669 or nil. If BUFFER is nil, then this function chooses a buffer
1670 using `other-buffer'.
1620 Optional second arg NORECORD non-nil means 1671 Optional second arg NORECORD non-nil means
1621 do not put this buffer at the front of the list of recently selected ones. 1672 do not put this buffer at the front of the list of recently selected ones.
1673 This function returns the buffer it switched to.
1622 1674
1623 WARNING: This is NOT the way to work on another buffer temporarily 1675 WARNING: This is NOT the way to work on another buffer temporarily
1624 within a Lisp program! Use `set-buffer' instead. That avoids messing with 1676 within a Lisp program! Use `set-buffer' instead. That avoids messing with
1625 the window-buffer correspondences. */) 1677 the window-buffer correspondences. */)
1626 (buffer, norecord) 1678 (buffer, norecord)
1627 Lisp_Object buffer, norecord; 1679 Lisp_Object buffer, norecord;
1628 { 1680 {
1629 char *err; 1681 char *err;
1630 1682
1683 if (EQ (buffer, Fwindow_buffer (selected_window)))
1684 /* Basically a NOP. Avoid signalling an error if the selected window
1685 is dedicated, or a minibuffer, ... */
1686 return Fset_buffer (buffer);
1687
1631 err = no_switch_window (selected_window); 1688 err = no_switch_window (selected_window);
1632 if (err) error (err); 1689 if (err) error (err);
1633 1690
1634 return switch_to_buffer_1 (buffer, norecord); 1691 return switch_to_buffer_1 (buffer, norecord);
1635 } 1692 }
1636 1693
1637 DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0, 1694 DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0,
1638 doc: /* Select buffer BUFFER in some window, preferably a different one. 1695 doc: /* Select buffer BUFFER in some window, preferably a different one.
1639 If BUFFER is nil, then some other buffer is chosen. 1696 BUFFER may be a buffer, a string \(a buffer name), or nil.
1697 If BUFFER is a string which is not the name of an existing buffer,
1698 then this function creates a buffer with that name.
1699 If BUFFER is nil, then it chooses some other buffer.
1640 If `pop-up-windows' is non-nil, windows can be split to do this. 1700 If `pop-up-windows' is non-nil, windows can be split to do this.
1641 If optional second arg OTHER-WINDOW is non-nil, insist on finding another 1701 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
1642 window even if BUFFER is already visible in the selected window. 1702 window even if BUFFER is already visible in the selected window,
1703 and ignore `same-window-regexps' and `same-window-buffer-names'.
1704 This function returns the buffer it switched to.
1643 This uses the function `display-buffer' as a subroutine; see the documentation 1705 This uses the function `display-buffer' as a subroutine; see the documentation
1644 of `display-buffer' for additional customization information. 1706 of `display-buffer' for additional customization information.
1645 1707
1646 Optional third arg NORECORD non-nil means 1708 Optional third arg NORECORD non-nil means
1647 do not put this buffer at the front of the list of recently selected ones. */) 1709 do not put this buffer at the front of the list of recently selected ones. */)
1659 buf = Fget_buffer_create (buffer); 1721 buf = Fget_buffer_create (buffer);
1660 Fset_buffer_major_mode (buf); 1722 Fset_buffer_major_mode (buf);
1661 } 1723 }
1662 } 1724 }
1663 Fset_buffer (buf); 1725 Fset_buffer (buf);
1664 if (NILP (norecord)) 1726 Fselect_window (Fdisplay_buffer (buf, other_window, Qnil), norecord);
1665 /* This seems bogus since Fselect_window will call record_buffer anyway. */
1666 record_buffer (buf);
1667 Fselect_window (Fdisplay_buffer (buf, other_window, Qnil));
1668 return buf; 1727 return buf;
1669 } 1728 }
1670 1729
1671 DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0, 1730 DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
1672 doc: /* Return the current buffer as a Lisp object. */) 1731 doc: /* Return the current buffer as a Lisp object. */)
1773 } 1832 }
1774 1833
1775 /* Look down buffer's list of local Lisp variables 1834 /* Look down buffer's list of local Lisp variables
1776 to find and update any that forward into C variables. */ 1835 to find and update any that forward into C variables. */
1777 1836
1778 for (tail = b->local_var_alist; !NILP (tail); tail = XCDR (tail)) 1837 for (tail = b->local_var_alist; CONSP (tail); tail = XCDR (tail))
1779 { 1838 {
1780 valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))); 1839 valcontents = SYMBOL_VALUE (XCAR (XCAR (tail)));
1781 if ((BUFFER_LOCAL_VALUEP (valcontents) 1840 if ((BUFFER_LOCAL_VALUEP (valcontents)
1782 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1841 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1783 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue, 1842 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1788 } 1847 }
1789 1848
1790 /* Do the same with any others that were local to the previous buffer */ 1849 /* Do the same with any others that were local to the previous buffer */
1791 1850
1792 if (old_buf) 1851 if (old_buf)
1793 for (tail = old_buf->local_var_alist; !NILP (tail); tail = XCDR (tail)) 1852 for (tail = old_buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
1794 { 1853 {
1795 valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))); 1854 valcontents = SYMBOL_VALUE (XCAR (XCAR (tail)));
1796 if ((BUFFER_LOCAL_VALUEP (valcontents) 1855 if ((BUFFER_LOCAL_VALUEP (valcontents)
1797 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1856 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1798 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue, 1857 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1908 1967
1909 DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", 1968 DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
1910 doc: /* Put BUFFER at the end of the list of all buffers. 1969 doc: /* Put BUFFER at the end of the list of all buffers.
1911 There it is the least likely candidate for `other-buffer' to return; 1970 There it is the least likely candidate for `other-buffer' to return;
1912 thus, the least likely buffer for \\[switch-to-buffer] to select by default. 1971 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
1972 You can specify a buffer name as BUFFER, or an actual buffer object.
1913 If BUFFER is nil or omitted, bury the current buffer. 1973 If BUFFER is nil or omitted, bury the current buffer.
1914 Also, if BUFFER is nil or omitted, remove the current buffer from the 1974 Also, if BUFFER is nil or omitted, remove the current buffer from the
1915 selected window if it is displayed there. */) 1975 selected window if it is displayed there. */)
1916 (buffer) 1976 (buffer)
1917 register Lisp_Object buffer; 1977 register Lisp_Object buffer;
2042 1, 1, 0, 2102 1, 1, 0,
2043 doc: /* Set the multibyte flag of the current buffer to FLAG. 2103 doc: /* Set the multibyte flag of the current buffer to FLAG.
2044 If FLAG is t, this makes the buffer a multibyte buffer. 2104 If FLAG is t, this makes the buffer a multibyte buffer.
2045 If FLAG is nil, this makes the buffer a single-byte buffer. 2105 If FLAG is nil, this makes the buffer a single-byte buffer.
2046 The buffer contents remain unchanged as a sequence of bytes 2106 The buffer contents remain unchanged as a sequence of bytes
2047 but the contents viewed as characters do change. */) 2107 but the contents viewed as characters do change.
2108 If the multibyte flag was really changed, undo information of the
2109 current buffer is cleared. */)
2048 (flag) 2110 (flag)
2049 Lisp_Object flag; 2111 Lisp_Object flag;
2050 { 2112 {
2051 Lisp_Object tail, markers; 2113 struct Lisp_Marker *tail, *markers;
2052 struct buffer *other; 2114 struct buffer *other;
2053 int undo_enabled_p = !EQ (current_buffer->undo_list, Qt); 2115 int undo_enabled_p = !EQ (current_buffer->undo_list, Qt);
2054 int begv = BEGV, zv = ZV; 2116 int begv, zv;
2055 int narrowed = (BEG != begv || Z != zv); 2117 int narrowed = (BEG != BEGV || Z != ZV);
2056 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2118 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2057 2119
2058 if (current_buffer->base_buffer) 2120 if (current_buffer->base_buffer)
2059 error ("Cannot do `set-buffer-multibyte' on an indirect buffer"); 2121 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
2060 2122
2067 if (undo_enabled_p) 2129 if (undo_enabled_p)
2068 current_buffer->undo_list = Qt; 2130 current_buffer->undo_list = Qt;
2069 2131
2070 /* If the cached position is for this buffer, clear it out. */ 2132 /* If the cached position is for this buffer, clear it out. */
2071 clear_charpos_cache (current_buffer); 2133 clear_charpos_cache (current_buffer);
2134
2135 if (NILP (flag))
2136 begv = BEGV_BYTE, zv = ZV_BYTE;
2137 else
2138 begv = BEGV, zv = ZV;
2072 2139
2073 if (narrowed) 2140 if (narrowed)
2074 Fwiden (); 2141 Fwiden ();
2075 2142
2076 if (NILP (flag)) 2143 if (NILP (flag))
2088 BEGV = BEGV_BYTE; 2155 BEGV = BEGV_BYTE;
2089 ZV = ZV_BYTE; 2156 ZV = ZV_BYTE;
2090 GPT = GPT_BYTE; 2157 GPT = GPT_BYTE;
2091 TEMP_SET_PT_BOTH (PT_BYTE, PT_BYTE); 2158 TEMP_SET_PT_BOTH (PT_BYTE, PT_BYTE);
2092 2159
2093 tail = BUF_MARKERS (current_buffer); 2160
2094 while (! NILP (tail)) 2161 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
2095 { 2162 tail->charpos = tail->bytepos;
2096 XMARKER (tail)->charpos = XMARKER (tail)->bytepos;
2097 tail = XMARKER (tail)->chain;
2098 }
2099 2163
2100 /* Convert multibyte form of 8-bit characters to unibyte. */ 2164 /* Convert multibyte form of 8-bit characters to unibyte. */
2101 pos = BEG; 2165 pos = BEG;
2102 stop = GPT; 2166 stop = GPT;
2103 p = BEG_ADDR; 2167 p = BEG_ADDR;
2241 tail = markers = BUF_MARKERS (current_buffer); 2305 tail = markers = BUF_MARKERS (current_buffer);
2242 2306
2243 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from 2307 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2244 getting confused by the markers that have not yet been updated. 2308 getting confused by the markers that have not yet been updated.
2245 It is also a signal that it should never create a marker. */ 2309 It is also a signal that it should never create a marker. */
2246 BUF_MARKERS (current_buffer) = Qnil; 2310 BUF_MARKERS (current_buffer) = NULL;
2247 2311
2248 while (! NILP (tail)) 2312 for (; tail; tail = tail->next)
2249 { 2313 {
2250 XMARKER (tail)->bytepos 2314 tail->bytepos = advance_to_char_boundary (tail->bytepos);
2251 = advance_to_char_boundary (XMARKER (tail)->bytepos); 2315 tail->charpos = BYTE_TO_CHAR (tail->bytepos);
2252 XMARKER (tail)->charpos = BYTE_TO_CHAR (XMARKER (tail)->bytepos);
2253
2254 tail = XMARKER (tail)->chain;
2255 } 2316 }
2256 2317
2257 /* Make sure no markers were put on the chain 2318 /* Make sure no markers were put on the chain
2258 while the chain value was incorrect. */ 2319 while the chain value was incorrect. */
2259 if (! EQ (BUF_MARKERS (current_buffer), Qnil)) 2320 if (BUF_MARKERS (current_buffer))
2260 abort (); 2321 abort ();
2261 2322
2262 BUF_MARKERS (current_buffer) = markers; 2323 BUF_MARKERS (current_buffer) = markers;
2263 2324
2264 /* Do this last, so it can calculate the new correspondences 2325 /* Do this last, so it can calculate the new correspondences
2286 2347
2287 /* Restore the modifiedness of the buffer. */ 2348 /* Restore the modifiedness of the buffer. */
2288 if (!modified_p && !NILP (Fbuffer_modified_p (Qnil))) 2349 if (!modified_p && !NILP (Fbuffer_modified_p (Qnil)))
2289 Fset_buffer_modified_p (Qnil); 2350 Fset_buffer_modified_p (Qnil);
2290 2351
2352 #ifdef subprocesses
2291 /* Update coding systems of this buffer's process (if any). */ 2353 /* Update coding systems of this buffer's process (if any). */
2292 { 2354 {
2293 Lisp_Object process; 2355 Lisp_Object process;
2294 2356
2295 process = Fget_buffer_process (Fcurrent_buffer ()); 2357 process = Fget_buffer_process (Fcurrent_buffer ());
2296 if (PROCESSP (process)) 2358 if (PROCESSP (process))
2297 setup_process_coding_systems (process); 2359 setup_process_coding_systems (process);
2298 } 2360 }
2361 #endif /* subprocesses */
2299 2362
2300 return flag; 2363 return flag;
2301 } 2364 }
2302 2365
2303 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables, 2366 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
2420 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the 2483 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2421 default (BEGV or ZV). */ 2484 default (BEGV or ZV). */
2422 2485
2423 int 2486 int
2424 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr, change_req) 2487 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr, change_req)
2425 int pos; 2488 EMACS_INT pos;
2426 int extend; 2489 int extend;
2427 Lisp_Object **vec_ptr; 2490 Lisp_Object **vec_ptr;
2428 int *len_ptr; 2491 int *len_ptr;
2429 int *next_ptr; 2492 int *next_ptr;
2430 int *prev_ptr; 2493 int *prev_ptr;
2431 int change_req; 2494 int change_req;
2432 { 2495 {
2433 Lisp_Object tail, overlay, start, end; 2496 Lisp_Object overlay, start, end;
2497 struct Lisp_Overlay *tail;
2434 int idx = 0; 2498 int idx = 0;
2435 int len = *len_ptr; 2499 int len = *len_ptr;
2436 Lisp_Object *vec = *vec_ptr; 2500 Lisp_Object *vec = *vec_ptr;
2437 int next = ZV; 2501 int next = ZV;
2438 int prev = BEGV; 2502 int prev = BEGV;
2439 int inhibit_storing = 0; 2503 int inhibit_storing = 0;
2440 2504
2441 for (tail = current_buffer->overlays_before; 2505 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2442 GC_CONSP (tail);
2443 tail = XCDR (tail))
2444 { 2506 {
2445 int startpos, endpos; 2507 int startpos, endpos;
2446 2508
2447 overlay = XCAR (tail); 2509 XSETMISC (overlay, tail);
2448 2510
2449 start = OVERLAY_START (overlay); 2511 start = OVERLAY_START (overlay);
2450 end = OVERLAY_END (overlay); 2512 end = OVERLAY_END (overlay);
2451 endpos = OVERLAY_POSITION (end); 2513 endpos = OVERLAY_POSITION (end);
2452 if (endpos < pos) 2514 if (endpos < pos)
2489 } 2551 }
2490 else if (startpos < next) 2552 else if (startpos < next)
2491 next = startpos; 2553 next = startpos;
2492 } 2554 }
2493 2555
2494 for (tail = current_buffer->overlays_after; 2556 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2495 GC_CONSP (tail);
2496 tail = XCDR (tail))
2497 { 2557 {
2498 int startpos, endpos; 2558 int startpos, endpos;
2499 2559
2500 overlay = XCAR (tail); 2560 XSETMISC (overlay, tail);
2501 2561
2502 start = OVERLAY_START (overlay); 2562 start = OVERLAY_START (overlay);
2503 end = OVERLAY_END (overlay); 2563 end = OVERLAY_END (overlay);
2504 startpos = OVERLAY_POSITION (start); 2564 startpos = OVERLAY_POSITION (start);
2505 if (pos < startpos) 2565 if (pos < startpos)
2565 If EXTEND is non-zero, we make the vector bigger if necessary. 2625 If EXTEND is non-zero, we make the vector bigger if necessary.
2566 If EXTEND is zero, we never extend the vector, 2626 If EXTEND is zero, we never extend the vector,
2567 and we store only as many overlays as will fit. 2627 and we store only as many overlays as will fit.
2568 But we still return the total number of overlays. */ 2628 But we still return the total number of overlays. */
2569 2629
2570 int 2630 static int
2571 overlays_in (beg, end, extend, vec_ptr, len_ptr, next_ptr, prev_ptr) 2631 overlays_in (beg, end, extend, vec_ptr, len_ptr, next_ptr, prev_ptr)
2572 int beg, end; 2632 int beg, end;
2573 int extend; 2633 int extend;
2574 Lisp_Object **vec_ptr; 2634 Lisp_Object **vec_ptr;
2575 int *len_ptr; 2635 int *len_ptr;
2576 int *next_ptr; 2636 int *next_ptr;
2577 int *prev_ptr; 2637 int *prev_ptr;
2578 { 2638 {
2579 Lisp_Object tail, overlay, ostart, oend; 2639 Lisp_Object overlay, ostart, oend;
2640 struct Lisp_Overlay *tail;
2580 int idx = 0; 2641 int idx = 0;
2581 int len = *len_ptr; 2642 int len = *len_ptr;
2582 Lisp_Object *vec = *vec_ptr; 2643 Lisp_Object *vec = *vec_ptr;
2583 int next = ZV; 2644 int next = ZV;
2584 int prev = BEGV; 2645 int prev = BEGV;
2585 int inhibit_storing = 0; 2646 int inhibit_storing = 0;
2586 2647
2587 for (tail = current_buffer->overlays_before; 2648 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2588 GC_CONSP (tail);
2589 tail = XCDR (tail))
2590 { 2649 {
2591 int startpos, endpos; 2650 int startpos, endpos;
2592 2651
2593 overlay = XCAR (tail); 2652 XSETMISC (overlay, tail);
2594 2653
2595 ostart = OVERLAY_START (overlay); 2654 ostart = OVERLAY_START (overlay);
2596 oend = OVERLAY_END (overlay); 2655 oend = OVERLAY_END (overlay);
2597 endpos = OVERLAY_POSITION (oend); 2656 endpos = OVERLAY_POSITION (oend);
2598 if (endpos < beg) 2657 if (endpos < beg)
2632 } 2691 }
2633 else if (startpos < next) 2692 else if (startpos < next)
2634 next = startpos; 2693 next = startpos;
2635 } 2694 }
2636 2695
2637 for (tail = current_buffer->overlays_after; 2696 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2638 GC_CONSP (tail);
2639 tail = XCDR (tail))
2640 { 2697 {
2641 int startpos, endpos; 2698 int startpos, endpos;
2642 2699
2643 overlay = XCAR (tail); 2700 XSETMISC (overlay, tail);
2644 2701
2645 ostart = OVERLAY_START (overlay); 2702 ostart = OVERLAY_START (overlay);
2646 oend = OVERLAY_END (overlay); 2703 oend = OVERLAY_END (overlay);
2647 startpos = OVERLAY_POSITION (ostart); 2704 startpos = OVERLAY_POSITION (ostart);
2648 if (end < startpos) 2705 if (end < startpos)
2724 /* Fast function to just test if we're at an overlay boundary. */ 2781 /* Fast function to just test if we're at an overlay boundary. */
2725 int 2782 int
2726 overlay_touches_p (pos) 2783 overlay_touches_p (pos)
2727 int pos; 2784 int pos;
2728 { 2785 {
2729 Lisp_Object tail, overlay; 2786 Lisp_Object overlay;
2730 2787 struct Lisp_Overlay *tail;
2731 for (tail = current_buffer->overlays_before; GC_CONSP (tail); 2788
2732 tail = XCDR (tail)) 2789 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2733 { 2790 {
2734 int endpos; 2791 int endpos;
2735 2792
2736 overlay = XCAR (tail); 2793 XSETMISC (overlay ,tail);
2737 if (!GC_OVERLAYP (overlay)) 2794 if (!GC_OVERLAYP (overlay))
2738 abort (); 2795 abort ();
2739 2796
2740 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 2797 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2741 if (endpos < pos) 2798 if (endpos < pos)
2742 break; 2799 break;
2743 if (endpos == pos || OVERLAY_POSITION (OVERLAY_START (overlay)) == pos) 2800 if (endpos == pos || OVERLAY_POSITION (OVERLAY_START (overlay)) == pos)
2744 return 1; 2801 return 1;
2745 } 2802 }
2746 2803
2747 for (tail = current_buffer->overlays_after; GC_CONSP (tail); 2804 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2748 tail = XCDR (tail))
2749 { 2805 {
2750 int startpos; 2806 int startpos;
2751 2807
2752 overlay = XCAR (tail); 2808 XSETMISC (overlay, tail);
2753 if (!GC_OVERLAYP (overlay)) 2809 if (!GC_OVERLAYP (overlay))
2754 abort (); 2810 abort ();
2755 2811
2756 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 2812 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2757 if (pos < startpos) 2813 if (pos < startpos)
2942 PSTR, if that variable is non-null. The string may be overwritten by 2998 PSTR, if that variable is non-null. The string may be overwritten by
2943 subsequent calls. */ 2999 subsequent calls. */
2944 3000
2945 int 3001 int
2946 overlay_strings (pos, w, pstr) 3002 overlay_strings (pos, w, pstr)
2947 int pos; 3003 EMACS_INT pos;
2948 struct window *w; 3004 struct window *w;
2949 unsigned char **pstr; 3005 unsigned char **pstr;
2950 { 3006 {
2951 Lisp_Object ov, overlay, window, str; 3007 Lisp_Object overlay, window, str;
3008 struct Lisp_Overlay *ov;
2952 int startpos, endpos; 3009 int startpos, endpos;
2953 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); 3010 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
2954 3011
2955 overlay_heads.used = overlay_heads.bytes = 0; 3012 overlay_heads.used = overlay_heads.bytes = 0;
2956 overlay_tails.used = overlay_tails.bytes = 0; 3013 overlay_tails.used = overlay_tails.bytes = 0;
2957 for (ov = current_buffer->overlays_before; CONSP (ov); ov = XCDR (ov)) 3014 for (ov = current_buffer->overlays_before; ov; ov = ov->next)
2958 { 3015 {
2959 overlay = XCAR (ov); 3016 XSETMISC (overlay, ov);
2960 if (!OVERLAYP (overlay)) 3017 eassert (OVERLAYP (overlay));
2961 abort ();
2962 3018
2963 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 3019 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2964 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 3020 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2965 if (endpos < pos) 3021 if (endpos < pos)
2966 break; 3022 break;
2981 && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str))) 3037 && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
2982 record_overlay_string (&overlay_tails, str, Qnil, 3038 record_overlay_string (&overlay_tails, str, Qnil,
2983 Foverlay_get (overlay, Qpriority), 3039 Foverlay_get (overlay, Qpriority),
2984 endpos - startpos); 3040 endpos - startpos);
2985 } 3041 }
2986 for (ov = current_buffer->overlays_after; CONSP (ov); ov = XCDR (ov)) 3042 for (ov = current_buffer->overlays_after; ov; ov = ov->next)
2987 { 3043 {
2988 overlay = XCAR (ov); 3044 XSETMISC (overlay, ov);
2989 if (!OVERLAYP (overlay)) 3045 eassert (OVERLAYP (overlay));
2990 abort ();
2991 3046
2992 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 3047 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2993 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 3048 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2994 if (startpos > pos) 3049 if (startpos > pos)
2995 break; 3050 break;
3070 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3125 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3071 3126
3072 void 3127 void
3073 recenter_overlay_lists (buf, pos) 3128 recenter_overlay_lists (buf, pos)
3074 struct buffer *buf; 3129 struct buffer *buf;
3075 int pos; 3130 EMACS_INT pos;
3076 { 3131 {
3077 Lisp_Object overlay, tail, next, prev, beg, end; 3132 Lisp_Object overlay, beg, end;
3133 struct Lisp_Overlay *prev, *tail, *next;
3078 3134
3079 /* See if anything in overlays_before should move to overlays_after. */ 3135 /* See if anything in overlays_before should move to overlays_after. */
3080 3136
3081 /* We don't strictly need prev in this loop; it should always be nil. 3137 /* We don't strictly need prev in this loop; it should always be nil.
3082 But we use it for symmetry and in case that should cease to be true 3138 But we use it for symmetry and in case that should cease to be true
3083 with some future change. */ 3139 with some future change. */
3084 prev = Qnil; 3140 prev = NULL;
3085 for (tail = buf->overlays_before; 3141 for (tail = buf->overlays_before; tail; prev = tail, tail = next)
3086 CONSP (tail); 3142 {
3087 prev = tail, tail = next) 3143 next = tail->next;
3088 { 3144 XSETMISC (overlay, tail);
3089 next = XCDR (tail);
3090 overlay = XCAR (tail);
3091 3145
3092 /* If the overlay is not valid, get rid of it. */ 3146 /* If the overlay is not valid, get rid of it. */
3093 if (!OVERLAY_VALID (overlay)) 3147 if (!OVERLAY_VALID (overlay))
3094 #if 1 3148 #if 1
3095 abort (); 3149 abort ();
3110 3164
3111 if (OVERLAY_POSITION (end) > pos) 3165 if (OVERLAY_POSITION (end) > pos)
3112 { 3166 {
3113 /* OVERLAY needs to be moved. */ 3167 /* OVERLAY needs to be moved. */
3114 int where = OVERLAY_POSITION (beg); 3168 int where = OVERLAY_POSITION (beg);
3115 Lisp_Object other, other_prev; 3169 struct Lisp_Overlay *other, *other_prev;
3116 3170
3117 /* Splice the cons cell TAIL out of overlays_before. */ 3171 /* Splice the cons cell TAIL out of overlays_before. */
3118 if (!NILP (prev)) 3172 if (prev)
3119 XSETCDR (prev, next); 3173 prev->next = next;
3120 else 3174 else
3121 buf->overlays_before = next; 3175 buf->overlays_before = next;
3122 3176
3123 /* Search thru overlays_after for where to put it. */ 3177 /* Search thru overlays_after for where to put it. */
3124 other_prev = Qnil; 3178 other_prev = NULL;
3125 for (other = buf->overlays_after; 3179 for (other = buf->overlays_after; other;
3126 CONSP (other); 3180 other_prev = other, other = other->next)
3127 other_prev = other, other = XCDR (other))
3128 { 3181 {
3129 Lisp_Object otherbeg, otheroverlay; 3182 Lisp_Object otherbeg, otheroverlay;
3130 3183
3131 otheroverlay = XCAR (other); 3184 XSETMISC (otheroverlay, other);
3132 if (! OVERLAY_VALID (otheroverlay)) 3185 eassert (OVERLAY_VALID (otheroverlay));
3133 abort ();
3134 3186
3135 otherbeg = OVERLAY_START (otheroverlay); 3187 otherbeg = OVERLAY_START (otheroverlay);
3136 if (OVERLAY_POSITION (otherbeg) >= where) 3188 if (OVERLAY_POSITION (otherbeg) >= where)
3137 break; 3189 break;
3138 } 3190 }
3139 3191
3140 /* Add TAIL to overlays_after before OTHER. */ 3192 /* Add TAIL to overlays_after before OTHER. */
3141 XSETCDR (tail, other); 3193 tail->next = other;
3142 if (!NILP (other_prev)) 3194 if (other_prev)
3143 XSETCDR (other_prev, tail); 3195 other_prev->next = tail;
3144 else 3196 else
3145 buf->overlays_after = tail; 3197 buf->overlays_after = tail;
3146 tail = prev; 3198 tail = prev;
3147 } 3199 }
3148 else 3200 else
3151 so stop now. */ 3203 so stop now. */
3152 break; 3204 break;
3153 } 3205 }
3154 3206
3155 /* See if anything in overlays_after should be in overlays_before. */ 3207 /* See if anything in overlays_after should be in overlays_before. */
3156 prev = Qnil; 3208 prev = NULL;
3157 for (tail = buf->overlays_after; 3209 for (tail = buf->overlays_after; tail; prev = tail, tail = next)
3158 CONSP (tail); 3210 {
3159 prev = tail, tail = next) 3211 next = tail->next;
3160 { 3212 XSETMISC (overlay, tail);
3161 next = XCDR (tail);
3162 overlay = XCAR (tail);
3163 3213
3164 /* If the overlay is not valid, get rid of it. */ 3214 /* If the overlay is not valid, get rid of it. */
3165 if (!OVERLAY_VALID (overlay)) 3215 if (!OVERLAY_VALID (overlay))
3166 #if 1 3216 #if 1
3167 abort (); 3217 abort ();
3187 3237
3188 if (OVERLAY_POSITION (end) <= pos) 3238 if (OVERLAY_POSITION (end) <= pos)
3189 { 3239 {
3190 /* OVERLAY needs to be moved. */ 3240 /* OVERLAY needs to be moved. */
3191 int where = OVERLAY_POSITION (end); 3241 int where = OVERLAY_POSITION (end);
3192 Lisp_Object other, other_prev; 3242 struct Lisp_Overlay *other, *other_prev;
3193 3243
3194 /* Splice the cons cell TAIL out of overlays_after. */ 3244 /* Splice the cons cell TAIL out of overlays_after. */
3195 if (!NILP (prev)) 3245 if (prev)
3196 XSETCDR (prev, next); 3246 prev->next = next;
3197 else 3247 else
3198 buf->overlays_after = next; 3248 buf->overlays_after = next;
3199 3249
3200 /* Search thru overlays_before for where to put it. */ 3250 /* Search thru overlays_before for where to put it. */
3201 other_prev = Qnil; 3251 other_prev = NULL;
3202 for (other = buf->overlays_before; 3252 for (other = buf->overlays_before; other;
3203 CONSP (other); 3253 other_prev = other, other = other->next)
3204 other_prev = other, other = XCDR (other))
3205 { 3254 {
3206 Lisp_Object otherend, otheroverlay; 3255 Lisp_Object otherend, otheroverlay;
3207 3256
3208 otheroverlay = XCAR (other); 3257 XSETMISC (otheroverlay, other);
3209 if (! OVERLAY_VALID (otheroverlay)) 3258 eassert (OVERLAY_VALID (otheroverlay));
3210 abort ();
3211 3259
3212 otherend = OVERLAY_END (otheroverlay); 3260 otherend = OVERLAY_END (otheroverlay);
3213 if (OVERLAY_POSITION (otherend) <= where) 3261 if (OVERLAY_POSITION (otherend) <= where)
3214 break; 3262 break;
3215 } 3263 }
3216 3264
3217 /* Add TAIL to overlays_before before OTHER. */ 3265 /* Add TAIL to overlays_before before OTHER. */
3218 XSETCDR (tail, other); 3266 tail->next = other;
3219 if (!NILP (other_prev)) 3267 if (other_prev)
3220 XSETCDR (other_prev, tail); 3268 other_prev->next = tail;
3221 else 3269 else
3222 buf->overlays_before = tail; 3270 buf->overlays_before = tail;
3223 tail = prev; 3271 tail = prev;
3224 } 3272 }
3225 } 3273 }
3226 3274
3227 XSETFASTINT (buf->overlay_center, pos); 3275 buf->overlay_center = pos;
3228 } 3276 }
3229 3277
3230 void 3278 void
3231 adjust_overlays_for_insert (pos, length) 3279 adjust_overlays_for_insert (pos, length)
3232 int pos; 3280 EMACS_INT pos;
3233 int length; 3281 EMACS_INT length;
3234 { 3282 {
3235 /* After an insertion, the lists are still sorted properly, 3283 /* After an insertion, the lists are still sorted properly,
3236 but we may need to update the value of the overlay center. */ 3284 but we may need to update the value of the overlay center. */
3237 if (XFASTINT (current_buffer->overlay_center) >= pos) 3285 if (current_buffer->overlay_center >= pos)
3238 XSETFASTINT (current_buffer->overlay_center, 3286 current_buffer->overlay_center += length;
3239 XFASTINT (current_buffer->overlay_center) + length);
3240 } 3287 }
3241 3288
3242 void 3289 void
3243 adjust_overlays_for_delete (pos, length) 3290 adjust_overlays_for_delete (pos, length)
3244 int pos; 3291 EMACS_INT pos;
3245 int length; 3292 EMACS_INT length;
3246 { 3293 {
3247 if (XFASTINT (current_buffer->overlay_center) < pos) 3294 if (current_buffer->overlay_center < pos)
3248 /* The deletion was to our right. No change needed; the before- and 3295 /* The deletion was to our right. No change needed; the before- and
3249 after-lists are still consistent. */ 3296 after-lists are still consistent. */
3250 ; 3297 ;
3251 else if (XFASTINT (current_buffer->overlay_center) > pos + length) 3298 else if (current_buffer->overlay_center > pos + length)
3252 /* The deletion was to our left. We need to adjust the center value 3299 /* The deletion was to our left. We need to adjust the center value
3253 to account for the change in position, but the lists are consistent 3300 to account for the change in position, but the lists are consistent
3254 given the new value. */ 3301 given the new value. */
3255 XSETFASTINT (current_buffer->overlay_center, 3302 current_buffer->overlay_center -= length;
3256 XFASTINT (current_buffer->overlay_center) - length);
3257 else 3303 else
3258 /* We're right in the middle. There might be things on the after-list 3304 /* We're right in the middle. There might be things on the after-list
3259 that now belong on the before-list. Recentering will move them, 3305 that now belong on the before-list. Recentering will move them,
3260 and also update the center point. */ 3306 and also update the center point. */
3261 recenter_overlay_lists (current_buffer, pos); 3307 recenter_overlay_lists (current_buffer, pos);
3264 /* Fix up overlays that were garbled as a result of permuting markers 3310 /* Fix up overlays that were garbled as a result of permuting markers
3265 in the range START through END. Any overlay with at least one 3311 in the range START through END. Any overlay with at least one
3266 endpoint in this range will need to be unlinked from the overlay 3312 endpoint in this range will need to be unlinked from the overlay
3267 list and reinserted in its proper place. 3313 list and reinserted in its proper place.
3268 Such an overlay might even have negative size at this point. 3314 Such an overlay might even have negative size at this point.
3269 If so, we'll reverse the endpoints. Can you think of anything 3315 If so, we'll make the overlay empty. */
3270 better to do in this situation? */
3271 void 3316 void
3272 fix_overlays_in_range (start, end) 3317 fix_start_end_in_overlays (start, end)
3273 register int start, end; 3318 register int start, end;
3274 { 3319 {
3275 Lisp_Object overlay; 3320 Lisp_Object overlay;
3276 Lisp_Object before_list, after_list; 3321 struct Lisp_Overlay *before_list, *after_list;
3277 /* These are either nil, indicating that before_list or after_list 3322 /* These are either nil, indicating that before_list or after_list
3278 should be assigned, or the cons cell the cdr of which should be 3323 should be assigned, or the cons cell the cdr of which should be
3279 assigned. */ 3324 assigned. */
3280 Lisp_Object beforep = Qnil, afterp = Qnil; 3325 struct Lisp_Overlay *beforep = NULL, *afterp = NULL;
3281 /* 'Parent', likewise, indicates a cons cell or 3326 /* 'Parent', likewise, indicates a cons cell or
3282 current_buffer->overlays_before or overlays_after, depending 3327 current_buffer->overlays_before or overlays_after, depending
3283 which loop we're in. */ 3328 which loop we're in. */
3284 Lisp_Object tail, parent; 3329 struct Lisp_Overlay *tail, *parent;
3285 int startpos, endpos; 3330 int startpos, endpos;
3286 3331
3287 /* This algorithm shifts links around instead of consing and GCing. 3332 /* This algorithm shifts links around instead of consing and GCing.
3288 The loop invariant is that before_list (resp. after_list) is a 3333 The loop invariant is that before_list (resp. after_list) is a
3289 well-formed list except that its last element, the CDR of beforep 3334 well-formed list except that its last element, the CDR of beforep
3290 (resp. afterp) if beforep (afterp) isn't nil or before_list 3335 (resp. afterp) if beforep (afterp) isn't nil or before_list
3291 (after_list) if it is, is still uninitialized. So it's not a bug 3336 (after_list) if it is, is still uninitialized. So it's not a bug
3292 that before_list isn't initialized, although it may look 3337 that before_list isn't initialized, although it may look
3293 strange. */ 3338 strange. */
3294 for (parent = Qnil, tail = current_buffer->overlays_before; CONSP (tail);) 3339 for (parent = NULL, tail = current_buffer->overlays_before; tail;)
3295 { 3340 {
3296 overlay = XCAR (tail); 3341 XSETMISC (overlay, tail);
3342
3297 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 3343 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
3344 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
3345
3346 /* If the overlay is backwards, make it empty. */
3347 if (endpos < startpos)
3348 {
3349 startpos = endpos;
3350 Fset_marker (OVERLAY_START (overlay), make_number (startpos),
3351 Qnil);
3352 }
3353
3298 if (endpos < start) 3354 if (endpos < start)
3299 break; 3355 break;
3300 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 3356
3301 if (endpos < end 3357 if (endpos < end
3302 || (startpos >= start && startpos < end)) 3358 || (startpos >= start && startpos < end))
3303 { 3359 {
3304 /* If the overlay is backwards, fix that now. */
3305 if (startpos > endpos)
3306 {
3307 int tem;
3308 Fset_marker (OVERLAY_START (overlay), make_number (endpos),
3309 Qnil);
3310 Fset_marker (OVERLAY_END (overlay), make_number (startpos),
3311 Qnil);
3312 tem = startpos; startpos = endpos; endpos = tem;
3313 }
3314 /* Add it to the end of the wrong list. Later on, 3360 /* Add it to the end of the wrong list. Later on,
3315 recenter_overlay_lists will move it to the right place. */ 3361 recenter_overlay_lists will move it to the right place. */
3316 if (endpos < XINT (current_buffer->overlay_center)) 3362 if (endpos < current_buffer->overlay_center)
3317 { 3363 {
3318 if (NILP (afterp)) 3364 if (!afterp)
3319 after_list = tail; 3365 after_list = tail;
3320 else 3366 else
3321 XSETCDR (afterp, tail); 3367 afterp->next = tail;
3322 afterp = tail; 3368 afterp = tail;
3323 } 3369 }
3324 else 3370 else
3325 { 3371 {
3326 if (NILP (beforep)) 3372 if (!beforep)
3327 before_list = tail; 3373 before_list = tail;
3328 else 3374 else
3329 XSETCDR (beforep, tail); 3375 beforep->next = tail;
3330 beforep = tail; 3376 beforep = tail;
3331 } 3377 }
3332 if (NILP (parent)) 3378 if (!parent)
3333 current_buffer->overlays_before = XCDR (tail); 3379 current_buffer->overlays_before = tail->next;
3334 else 3380 else
3335 XSETCDR (parent, XCDR (tail)); 3381 parent->next = tail->next;
3336 tail = XCDR (tail); 3382 tail = tail->next;
3337 } 3383 }
3338 else 3384 else
3339 parent = tail, tail = XCDR (parent); 3385 parent = tail, tail = parent->next;
3340 } 3386 }
3341 for (parent = Qnil, tail = current_buffer->overlays_after; CONSP (tail);) 3387 for (parent = NULL, tail = current_buffer->overlays_after; tail;)
3342 { 3388 {
3343 overlay = XCAR (tail); 3389 XSETMISC (overlay, tail);
3390
3344 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 3391 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
3392 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
3393
3394 /* If the overlay is backwards, make it empty. */
3395 if (endpos < startpos)
3396 {
3397 startpos = endpos;
3398 Fset_marker (OVERLAY_START (overlay), make_number (startpos),
3399 Qnil);
3400 }
3401
3345 if (startpos >= end) 3402 if (startpos >= end)
3346 break; 3403 break;
3347 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 3404
3348 if (startpos >= start 3405 if (startpos >= start
3349 || (endpos >= start && endpos < end)) 3406 || (endpos >= start && endpos < end))
3350 { 3407 {
3351 if (startpos > endpos) 3408 if (endpos < current_buffer->overlay_center)
3352 { 3409 {
3353 int tem; 3410 if (!afterp)
3354 Fset_marker (OVERLAY_START (overlay), make_number (endpos),
3355 Qnil);
3356 Fset_marker (OVERLAY_END (overlay), make_number (startpos),
3357 Qnil);
3358 tem = startpos; startpos = endpos; endpos = tem;
3359 }
3360 if (endpos < XINT (current_buffer->overlay_center))
3361 {
3362 if (NILP (afterp))
3363 after_list = tail; 3411 after_list = tail;
3364 else 3412 else
3365 XSETCDR (afterp, tail); 3413 afterp->next = tail;
3366 afterp = tail; 3414 afterp = tail;
3367 } 3415 }
3368 else 3416 else
3369 { 3417 {
3370 if (NILP (beforep)) 3418 if (!beforep)
3371 before_list = tail; 3419 before_list = tail;
3372 else 3420 else
3373 XSETCDR (beforep, tail); 3421 beforep->next = tail;
3374 beforep = tail; 3422 beforep = tail;
3375 } 3423 }
3376 if (NILP (parent)) 3424 if (!parent)
3377 current_buffer->overlays_after = XCDR (tail); 3425 current_buffer->overlays_after = tail->next;
3378 else 3426 else
3379 XSETCDR (parent, XCDR (tail)); 3427 parent->next = tail->next;
3380 tail = XCDR (tail); 3428 tail = tail->next;
3381 } 3429 }
3382 else 3430 else
3383 parent = tail, tail = XCDR (parent); 3431 parent = tail, tail = parent->next;
3384 } 3432 }
3385 3433
3386 /* Splice the constructed (wrong) lists into the buffer's lists, 3434 /* Splice the constructed (wrong) lists into the buffer's lists,
3387 and let the recenter function make it sane again. */ 3435 and let the recenter function make it sane again. */
3388 if (!NILP (beforep)) 3436 if (beforep)
3389 { 3437 {
3390 XSETCDR (beforep, current_buffer->overlays_before); 3438 beforep->next = current_buffer->overlays_before;
3391 current_buffer->overlays_before = before_list; 3439 current_buffer->overlays_before = before_list;
3392 } 3440 }
3393 recenter_overlay_lists (current_buffer, 3441 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3394 XINT (current_buffer->overlay_center)); 3442
3395 3443 if (afterp)
3396 if (!NILP (afterp)) 3444 {
3397 { 3445 afterp->next = current_buffer->overlays_after;
3398 XSETCDR (afterp, current_buffer->overlays_after);
3399 current_buffer->overlays_after = after_list; 3446 current_buffer->overlays_after = after_list;
3400 } 3447 }
3401 recenter_overlay_lists (current_buffer, 3448 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3402 XINT (current_buffer->overlay_center));
3403 } 3449 }
3404 3450
3405 /* We have two types of overlay: the one whose ending marker is 3451 /* We have two types of overlay: the one whose ending marker is
3406 after-insertion-marker (this is the usual case) and the one whose 3452 after-insertion-marker (this is the usual case) and the one whose
3407 ending marker is before-insertion-marker. When `overlays_before' 3453 ending marker is before-insertion-marker. When `overlays_before'
3415 was at PREV, and now is at POS. */ 3461 was at PREV, and now is at POS. */
3416 3462
3417 void 3463 void
3418 fix_overlays_before (bp, prev, pos) 3464 fix_overlays_before (bp, prev, pos)
3419 struct buffer *bp; 3465 struct buffer *bp;
3420 int prev, pos; 3466 EMACS_INT prev, pos;
3421 { 3467 {
3422 /* If parent is nil, replace overlays_before; otherwise, XCDR(parent). */ 3468 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3423 Lisp_Object tail = bp->overlays_before, parent = Qnil; 3469 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3424 Lisp_Object right_pair; 3470 Lisp_Object tem;
3425 int end; 3471 EMACS_INT end;
3426 3472
3427 /* After the insertion, the several overlays may be in incorrect 3473 /* After the insertion, the several overlays may be in incorrect
3428 order. The possibility is that, in the list `overlays_before', 3474 order. The possibility is that, in the list `overlays_before',
3429 an overlay which ends at POS appears after an overlay which ends 3475 an overlay which ends at POS appears after an overlay which ends
3430 at PREV. Since POS is greater than PREV, we must fix the 3476 at PREV. Since POS is greater than PREV, we must fix the
3433 3479
3434 /* At first, find a place where disordered overlays should be linked 3480 /* At first, find a place where disordered overlays should be linked
3435 in. It is where an overlay which end before POS exists. (i.e. an 3481 in. It is where an overlay which end before POS exists. (i.e. an
3436 overlay whose ending marker is after-insertion-marker if disorder 3482 overlay whose ending marker is after-insertion-marker if disorder
3437 exists). */ 3483 exists). */
3438 while (!NILP (tail) 3484 while (tail
3439 && ((end = OVERLAY_POSITION (OVERLAY_END (XCAR (tail)))) 3485 && (XSETMISC (tem, tail),
3440 >= pos)) 3486 (end = OVERLAY_POSITION (OVERLAY_END (tem))) >= pos))
3441 { 3487 {
3442 parent = tail; 3488 parent = tail;
3443 tail = XCDR (tail); 3489 tail = tail->next;
3444 } 3490 }
3445 3491
3446 /* If we don't find such an overlay, 3492 /* If we don't find such an overlay,
3447 or the found one ends before PREV, 3493 or the found one ends before PREV,
3448 or the found one is the last one in the list, 3494 or the found one is the last one in the list,
3449 we don't have to fix anything. */ 3495 we don't have to fix anything. */
3450 if (NILP (tail) 3496 if (!tail || end < prev || !tail->next)
3451 || end < prev
3452 || NILP (XCDR (tail)))
3453 return; 3497 return;
3454 3498
3455 right_pair = parent; 3499 right_pair = parent;
3456 parent = tail; 3500 parent = tail;
3457 tail = XCDR (tail); 3501 tail = tail->next;
3458 3502
3459 /* Now, end position of overlays in the list TAIL should be before 3503 /* Now, end position of overlays in the list TAIL should be before
3460 or equal to PREV. In the loop, an overlay which ends at POS is 3504 or equal to PREV. In the loop, an overlay which ends at POS is
3461 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If 3505 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If
3462 we found an overlay which ends before PREV, the remaining 3506 we found an overlay which ends before PREV, the remaining
3463 overlays are in correct order. */ 3507 overlays are in correct order. */
3464 while (!NILP (tail)) 3508 while (tail)
3465 { 3509 {
3466 end = OVERLAY_POSITION (OVERLAY_END (XCAR (tail))); 3510 XSETMISC (tem, tail);
3511 end = OVERLAY_POSITION (OVERLAY_END (tem));
3467 3512
3468 if (end == pos) 3513 if (end == pos)
3469 { /* This overlay is disordered. */ 3514 { /* This overlay is disordered. */
3470 Lisp_Object found = tail; 3515 struct Lisp_Overlay *found = tail;
3471 3516
3472 /* Unlink the found overlay. */ 3517 /* Unlink the found overlay. */
3473 tail = XCDR (found); 3518 tail = found->next;
3474 XSETCDR (parent, tail); 3519 parent->next = tail;
3475 /* Move an overlay at RIGHT_PLACE to the next of the found one, 3520 /* Move an overlay at RIGHT_PLACE to the next of the found one,
3476 and link it into the right place. */ 3521 and link it into the right place. */
3477 if (NILP (right_pair)) 3522 if (!right_pair)
3478 { 3523 {
3479 XSETCDR (found, bp->overlays_before); 3524 found->next = bp->overlays_before;
3480 bp->overlays_before = found; 3525 bp->overlays_before = found;
3481 } 3526 }
3482 else 3527 else
3483 { 3528 {
3484 XSETCDR (found, XCDR (right_pair)); 3529 found->next = right_pair->next;
3485 XSETCDR (right_pair, found); 3530 right_pair->next = found;
3486 } 3531 }
3487 } 3532 }
3488 else if (end == prev) 3533 else if (end == prev)
3489 { 3534 {
3490 parent = tail; 3535 parent = tail;
3491 tail = XCDR (tail); 3536 tail = tail->next;
3492 } 3537 }
3493 else /* No more disordered overlay. */ 3538 else /* No more disordered overlay. */
3494 break; 3539 break;
3495 } 3540 }
3496 } 3541 }
3505 3550
3506 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 5, 0, 3551 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 5, 0,
3507 doc: /* Create a new overlay with range BEG to END in BUFFER. 3552 doc: /* Create a new overlay with range BEG to END in BUFFER.
3508 If omitted, BUFFER defaults to the current buffer. 3553 If omitted, BUFFER defaults to the current buffer.
3509 BEG and END may be integers or markers. 3554 BEG and END may be integers or markers.
3510 The fourth arg FRONT-ADVANCE, if non-nil, makes the 3555 The fourth arg FRONT-ADVANCE, if non-nil, makes the marker
3511 front delimiter advance when text is inserted there. 3556 for the front of the overlay advance when text is inserted there
3512 The fifth arg REAR-ADVANCE, if non-nil, makes the 3557 (which means the text *is not* included in the overlay).
3513 rear delimiter advance when text is inserted there. */) 3558 The fifth arg REAR-ADVANCE, if non-nil, makes the marker
3559 for the rear of the overlay advance when text is inserted there
3560 (which means the text *is* included in the overlay). */)
3514 (beg, end, buffer, front_advance, rear_advance) 3561 (beg, end, buffer, front_advance, rear_advance)
3515 Lisp_Object beg, end, buffer; 3562 Lisp_Object beg, end, buffer;
3516 Lisp_Object front_advance, rear_advance; 3563 Lisp_Object front_advance, rear_advance;
3517 { 3564 {
3518 Lisp_Object overlay; 3565 Lisp_Object overlay;
3551 overlay = allocate_misc (); 3598 overlay = allocate_misc ();
3552 XMISCTYPE (overlay) = Lisp_Misc_Overlay; 3599 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
3553 XOVERLAY (overlay)->start = beg; 3600 XOVERLAY (overlay)->start = beg;
3554 XOVERLAY (overlay)->end = end; 3601 XOVERLAY (overlay)->end = end;
3555 XOVERLAY (overlay)->plist = Qnil; 3602 XOVERLAY (overlay)->plist = Qnil;
3603 XOVERLAY (overlay)->next = NULL;
3556 3604
3557 /* Put the new overlay on the wrong list. */ 3605 /* Put the new overlay on the wrong list. */
3558 end = OVERLAY_END (overlay); 3606 end = OVERLAY_END (overlay);
3559 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) 3607 if (OVERLAY_POSITION (end) < b->overlay_center)
3560 b->overlays_after = Fcons (overlay, b->overlays_after); 3608 {
3609 if (b->overlays_after)
3610 XOVERLAY (overlay)->next = b->overlays_after;
3611 b->overlays_after = XOVERLAY (overlay);
3612 }
3561 else 3613 else
3562 b->overlays_before = Fcons (overlay, b->overlays_before); 3614 {
3615 if (b->overlays_before)
3616 XOVERLAY (overlay)->next = b->overlays_before;
3617 b->overlays_before = XOVERLAY (overlay);
3618 }
3563 3619
3564 /* This puts it in the right list, and in the right order. */ 3620 /* This puts it in the right list, and in the right order. */
3565 recenter_overlay_lists (b, XINT (b->overlay_center)); 3621 recenter_overlay_lists (b, b->overlay_center);
3566 3622
3567 /* We don't need to redisplay the region covered by the overlay, because 3623 /* We don't need to redisplay the region covered by the overlay, because
3568 the overlay has no properties at the moment. */ 3624 the overlay has no properties at the moment. */
3569 3625
3570 return overlay; 3626 return overlay;
3573 /* Mark a section of BUF as needing redisplay because of overlays changes. */ 3629 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3574 3630
3575 static void 3631 static void
3576 modify_overlay (buf, start, end) 3632 modify_overlay (buf, start, end)
3577 struct buffer *buf; 3633 struct buffer *buf;
3578 int start, end; 3634 EMACS_INT start, end;
3579 { 3635 {
3580 if (start > end) 3636 if (start > end)
3581 { 3637 {
3582 int temp = start; 3638 int temp = start;
3583 start = end; 3639 start = end;
3597 ++BUF_OVERLAY_MODIFF (buf); 3653 ++BUF_OVERLAY_MODIFF (buf);
3598 } 3654 }
3599 3655
3600 3656
3601 Lisp_Object Fdelete_overlay (); 3657 Lisp_Object Fdelete_overlay ();
3658
3659 static struct Lisp_Overlay *
3660 unchain_overlay (list, overlay)
3661 struct Lisp_Overlay *list, *overlay;
3662 {
3663 struct Lisp_Overlay *tmp, *prev;
3664 for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next)
3665 if (tmp == overlay)
3666 {
3667 if (prev)
3668 prev->next = tmp->next;
3669 else
3670 list = tmp->next;
3671 overlay->next = NULL;
3672 break;
3673 }
3674 return list;
3675 }
3602 3676
3603 DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, 3677 DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,
3604 doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER. 3678 doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3605 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now. 3679 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
3606 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current 3680 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3682 } 3756 }
3683 } 3757 }
3684 3758
3685 if (!NILP (obuffer)) 3759 if (!NILP (obuffer))
3686 { 3760 {
3687 ob->overlays_before = Fdelq (overlay, ob->overlays_before); 3761 ob->overlays_before
3688 ob->overlays_after = Fdelq (overlay, ob->overlays_after); 3762 = unchain_overlay (ob->overlays_before, XOVERLAY (overlay));
3763 ob->overlays_after
3764 = unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3765 eassert (XOVERLAY (overlay)->next == NULL);
3689 } 3766 }
3690 3767
3691 Fset_marker (OVERLAY_START (overlay), beg, buffer); 3768 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3692 Fset_marker (OVERLAY_END (overlay), end, buffer); 3769 Fset_marker (OVERLAY_END (overlay), end, buffer);
3693 3770
3694 /* Put the overlay on the wrong list. */ 3771 /* Put the overlay on the wrong list. */
3695 end = OVERLAY_END (overlay); 3772 end = OVERLAY_END (overlay);
3696 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) 3773 if (OVERLAY_POSITION (end) < b->overlay_center)
3697 b->overlays_after = Fcons (overlay, b->overlays_after); 3774 {
3775 XOVERLAY (overlay)->next = b->overlays_after;
3776 b->overlays_after = XOVERLAY (overlay);
3777 }
3698 else 3778 else
3699 b->overlays_before = Fcons (overlay, b->overlays_before); 3779 {
3780 XOVERLAY (overlay)->next = b->overlays_before;
3781 b->overlays_before = XOVERLAY (overlay);
3782 }
3700 3783
3701 /* This puts it in the right list, and in the right order. */ 3784 /* This puts it in the right list, and in the right order. */
3702 recenter_overlay_lists (b, XINT (b->overlay_center)); 3785 recenter_overlay_lists (b, b->overlay_center);
3703 3786
3704 return unbind_to (count, overlay); 3787 return unbind_to (count, overlay);
3705 } 3788 }
3706 3789
3707 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, 3790 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3720 return Qnil; 3803 return Qnil;
3721 3804
3722 b = XBUFFER (buffer); 3805 b = XBUFFER (buffer);
3723 specbind (Qinhibit_quit, Qt); 3806 specbind (Qinhibit_quit, Qt);
3724 3807
3725 b->overlays_before = Fdelq (overlay, b->overlays_before); 3808 b->overlays_before = unchain_overlay (b->overlays_before,XOVERLAY (overlay));
3726 b->overlays_after = Fdelq (overlay, b->overlays_after); 3809 b->overlays_after = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3810 eassert (XOVERLAY (overlay)->next == NULL);
3727 modify_overlay (b, 3811 modify_overlay (b,
3728 marker_position (OVERLAY_START (overlay)), 3812 marker_position (OVERLAY_START (overlay)),
3729 marker_position (OVERLAY_END (overlay))); 3813 marker_position (OVERLAY_END (overlay)));
3730 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil); 3814 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
3731 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil); 3815 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
3763 3847
3764 return (Fmarker_position (OVERLAY_END (overlay))); 3848 return (Fmarker_position (OVERLAY_END (overlay)));
3765 } 3849 }
3766 3850
3767 DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0, 3851 DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0,
3768 doc: /* Return the buffer OVERLAY belongs to. */) 3852 doc: /* Return the buffer OVERLAY belongs to.
3853 Return nil if OVERLAY has been deleted. */)
3769 (overlay) 3854 (overlay)
3770 Lisp_Object overlay; 3855 Lisp_Object overlay;
3771 { 3856 {
3772 CHECK_OVERLAY (overlay); 3857 CHECK_OVERLAY (overlay);
3773 3858
3929 Recentering overlays moves overlays between these lists. 4014 Recentering overlays moves overlays between these lists.
3930 The lists you get are copies, so that changing them has no effect. 4015 The lists you get are copies, so that changing them has no effect.
3931 However, the overlays you get are the real objects that the buffer uses. */) 4016 However, the overlays you get are the real objects that the buffer uses. */)
3932 () 4017 ()
3933 { 4018 {
3934 Lisp_Object before, after; 4019 struct Lisp_Overlay *ol;
3935 before = current_buffer->overlays_before; 4020 Lisp_Object before = Qnil, after = Qnil, tmp;
3936 if (CONSP (before)) 4021 for (ol = current_buffer->overlays_before; ol; ol = ol->next)
3937 before = Fcopy_sequence (before); 4022 {
3938 after = current_buffer->overlays_after; 4023 XSETMISC (tmp, ol);
3939 if (CONSP (after)) 4024 before = Fcons (tmp, before);
3940 after = Fcopy_sequence (after); 4025 }
3941 4026 for (ol = current_buffer->overlays_after; ol; ol = ol->next)
3942 return Fcons (before, after); 4027 {
4028 XSETMISC (tmp, ol);
4029 after = Fcons (tmp, after);
4030 }
4031 return Fcons (Fnreverse (before), Fnreverse (after));
3943 } 4032 }
3944 4033
3945 DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0, 4034 DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0,
3946 doc: /* Recenter the overlays of the current buffer around position POS. */) 4035 doc: /* Recenter the overlays of the current buffer around position POS.
4036 That makes overlay lookup faster for positions near POS (but perhaps slower
4037 for positions far away from POS). */)
3947 (pos) 4038 (pos)
3948 Lisp_Object pos; 4039 Lisp_Object pos;
3949 { 4040 {
3950 CHECK_NUMBER_COERCE_MARKER (pos); 4041 CHECK_NUMBER_COERCE_MARKER (pos);
3951 4042
4035 = Fmake_vector (make_number (oldsize * 2), Qnil); 4126 = Fmake_vector (make_number (oldsize * 2), Qnil);
4036 bcopy (XVECTOR (old)->contents, 4127 bcopy (XVECTOR (old)->contents,
4037 XVECTOR (last_overlay_modification_hooks)->contents, 4128 XVECTOR (last_overlay_modification_hooks)->contents,
4038 sizeof (Lisp_Object) * oldsize); 4129 sizeof (Lisp_Object) * oldsize);
4039 } 4130 }
4040 XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = functionlist; 4131 AREF (last_overlay_modification_hooks, last_overlay_modification_hooks_used++) = functionlist;
4041 XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = overlay; 4132 AREF (last_overlay_modification_hooks, last_overlay_modification_hooks_used++) = overlay;
4042 } 4133 }
4043 4134
4044 /* Run the modification-hooks of overlays that include 4135 /* Run the modification-hooks of overlays that include
4045 any part of the text in START to END. 4136 any part of the text in START to END.
4046 If this change is an insertion, also 4137 If this change is an insertion, also
4059 report_overlay_modification (start, end, after, arg1, arg2, arg3) 4150 report_overlay_modification (start, end, after, arg1, arg2, arg3)
4060 Lisp_Object start, end; 4151 Lisp_Object start, end;
4061 int after; 4152 int after;
4062 Lisp_Object arg1, arg2, arg3; 4153 Lisp_Object arg1, arg2, arg3;
4063 { 4154 {
4064 Lisp_Object prop, overlay, tail; 4155 Lisp_Object prop, overlay;
4156 struct Lisp_Overlay *tail;
4065 /* 1 if this change is an insertion. */ 4157 /* 1 if this change is an insertion. */
4066 int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end)); 4158 int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end));
4067 int tail_copied; 4159 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4068 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
4069 4160
4070 overlay = Qnil; 4161 overlay = Qnil;
4071 tail = Qnil; 4162 tail = NULL;
4072 GCPRO5 (overlay, tail, arg1, arg2, arg3); 4163
4073 4164 /* We used to run the functions as soon as we found them and only register
4074 if (after) 4165 them in last_overlay_modification_hooks for the purpose of the `after'
4075 { 4166 case. But running elisp code as we traverse the list of overlays is
4076 /* Call the functions recorded in last_overlay_modification_hooks 4167 painful because the list can be modified by the elisp code so we had to
4077 rather than scanning the overlays again. 4168 copy at several places. We now simply do a read-only traversal that
4078 First copy the vector contents, in case some of these hooks 4169 only collects the functions to run and we run them afterwards. It's
4079 do subsequent modification of the buffer. */ 4170 simpler, especially since all the code was already there. -stef */
4080 int size = last_overlay_modification_hooks_used; 4171
4081 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4172 if (!after)
4082 int i; 4173 {
4083 4174 /* We are being called before a change.
4084 bcopy (XVECTOR (last_overlay_modification_hooks)->contents, 4175 Scan the overlays to find the functions to call. */
4085 copy, size * sizeof (Lisp_Object)); 4176 last_overlay_modification_hooks_used = 0;
4086 gcpro1.var = copy; 4177 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4087 gcpro1.nvars = size;
4088
4089 for (i = 0; i < size;)
4090 { 4178 {
4091 Lisp_Object prop, overlay; 4179 int startpos, endpos;
4092 prop = copy[i++]; 4180 Lisp_Object ostart, oend;
4093 overlay = copy[i++]; 4181
4094 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); 4182 XSETMISC (overlay, tail);
4095 } 4183
4096 UNGCPRO; 4184 ostart = OVERLAY_START (overlay);
4097 return; 4185 oend = OVERLAY_END (overlay);
4098 } 4186 endpos = OVERLAY_POSITION (oend);
4099 4187 if (XFASTINT (start) > endpos)
4100 /* We are being called before a change. 4188 break;
4101 Scan the overlays to find the functions to call. */ 4189 startpos = OVERLAY_POSITION (ostart);
4102 last_overlay_modification_hooks_used = 0; 4190 if (insertion && (XFASTINT (start) == startpos
4103 tail_copied = 0; 4191 || XFASTINT (end) == startpos))
4104 for (tail = current_buffer->overlays_before;
4105 CONSP (tail);
4106 tail = XCDR (tail))
4107 {
4108 int startpos, endpos;
4109 Lisp_Object ostart, oend;
4110
4111 overlay = XCAR (tail);
4112
4113 ostart = OVERLAY_START (overlay);
4114 oend = OVERLAY_END (overlay);
4115 endpos = OVERLAY_POSITION (oend);
4116 if (XFASTINT (start) > endpos)
4117 break;
4118 startpos = OVERLAY_POSITION (ostart);
4119 if (insertion && (XFASTINT (start) == startpos
4120 || XFASTINT (end) == startpos))
4121 {
4122 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
4123 if (!NILP (prop))
4124 { 4192 {
4125 /* Copy TAIL in case the hook recenters the overlay lists. */ 4193 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
4126 if (!tail_copied) 4194 if (!NILP (prop))
4127 tail = Fcopy_sequence (tail); 4195 add_overlay_mod_hooklist (prop, overlay);
4128 tail_copied = 1; 4196 }
4129 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); 4197 if (insertion && (XFASTINT (start) == endpos
4198 || XFASTINT (end) == endpos))
4199 {
4200 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
4201 if (!NILP (prop))
4202 add_overlay_mod_hooklist (prop, overlay);
4203 }
4204 /* Test for intersecting intervals. This does the right thing
4205 for both insertion and deletion. */
4206 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
4207 {
4208 prop = Foverlay_get (overlay, Qmodification_hooks);
4209 if (!NILP (prop))
4210 add_overlay_mod_hooklist (prop, overlay);
4130 } 4211 }
4131 } 4212 }
4132 if (insertion && (XFASTINT (start) == endpos 4213
4133 || XFASTINT (end) == endpos)) 4214 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4134 { 4215 {
4135 prop = Foverlay_get (overlay, Qinsert_behind_hooks); 4216 int startpos, endpos;
4136 if (!NILP (prop)) 4217 Lisp_Object ostart, oend;
4218
4219 XSETMISC (overlay, tail);
4220
4221 ostart = OVERLAY_START (overlay);
4222 oend = OVERLAY_END (overlay);
4223 startpos = OVERLAY_POSITION (ostart);
4224 endpos = OVERLAY_POSITION (oend);
4225 if (XFASTINT (end) < startpos)
4226 break;
4227 if (insertion && (XFASTINT (start) == startpos
4228 || XFASTINT (end) == startpos))
4137 { 4229 {
4138 if (!tail_copied) 4230 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
4139 tail = Fcopy_sequence (tail); 4231 if (!NILP (prop))
4140 tail_copied = 1; 4232 add_overlay_mod_hooklist (prop, overlay);
4141 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); 4233 }
4234 if (insertion && (XFASTINT (start) == endpos
4235 || XFASTINT (end) == endpos))
4236 {
4237 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
4238 if (!NILP (prop))
4239 add_overlay_mod_hooklist (prop, overlay);
4240 }
4241 /* Test for intersecting intervals. This does the right thing
4242 for both insertion and deletion. */
4243 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
4244 {
4245 prop = Foverlay_get (overlay, Qmodification_hooks);
4246 if (!NILP (prop))
4247 add_overlay_mod_hooklist (prop, overlay);
4142 } 4248 }
4143 } 4249 }
4144 /* Test for intersecting intervals. This does the right thing 4250 }
4145 for both insertion and deletion. */ 4251
4146 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos) 4252 GCPRO4 (overlay, arg1, arg2, arg3);
4147 { 4253 {
4148 prop = Foverlay_get (overlay, Qmodification_hooks); 4254 /* Call the functions recorded in last_overlay_modification_hooks.
4149 if (!NILP (prop)) 4255 First copy the vector contents, in case some of these hooks
4150 { 4256 do subsequent modification of the buffer. */
4151 if (!tail_copied) 4257 int size = last_overlay_modification_hooks_used;
4152 tail = Fcopy_sequence (tail); 4258 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
4153 tail_copied = 1; 4259 int i;
4154 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); 4260
4155 } 4261 bcopy (XVECTOR (last_overlay_modification_hooks)->contents,
4156 } 4262 copy, size * sizeof (Lisp_Object));
4157 } 4263 gcpro1.var = copy;
4158 4264 gcpro1.nvars = size;
4159 tail_copied = 0; 4265
4160 for (tail = current_buffer->overlays_after; 4266 for (i = 0; i < size;)
4161 CONSP (tail); 4267 {
4162 tail = XCDR (tail)) 4268 Lisp_Object prop, overlay;
4163 { 4269 prop = copy[i++];
4164 int startpos, endpos; 4270 overlay = copy[i++];
4165 Lisp_Object ostart, oend; 4271 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
4166 4272 }
4167 overlay = XCAR (tail); 4273 }
4168
4169 ostart = OVERLAY_START (overlay);
4170 oend = OVERLAY_END (overlay);
4171 startpos = OVERLAY_POSITION (ostart);
4172 endpos = OVERLAY_POSITION (oend);
4173 if (XFASTINT (end) < startpos)
4174 break;
4175 if (insertion && (XFASTINT (start) == startpos
4176 || XFASTINT (end) == startpos))
4177 {
4178 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
4179 if (!NILP (prop))
4180 {
4181 if (!tail_copied)
4182 tail = Fcopy_sequence (tail);
4183 tail_copied = 1;
4184 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
4185 }
4186 }
4187 if (insertion && (XFASTINT (start) == endpos
4188 || XFASTINT (end) == endpos))
4189 {
4190 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
4191 if (!NILP (prop))
4192 {
4193 if (!tail_copied)
4194 tail = Fcopy_sequence (tail);
4195 tail_copied = 1;
4196 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
4197 }
4198 }
4199 /* Test for intersecting intervals. This does the right thing
4200 for both insertion and deletion. */
4201 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
4202 {
4203 prop = Foverlay_get (overlay, Qmodification_hooks);
4204 if (!NILP (prop))
4205 {
4206 if (!tail_copied)
4207 tail = Fcopy_sequence (tail);
4208 tail_copied = 1;
4209 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
4210 }
4211 }
4212 }
4213
4214 UNGCPRO; 4274 UNGCPRO;
4215 } 4275 }
4216 4276
4217 static void 4277 static void
4218 call_overlay_mod_hooks (list, overlay, after, arg1, arg2, arg3) 4278 call_overlay_mod_hooks (list, overlay, after, arg1, arg2, arg3)
4221 Lisp_Object arg1, arg2, arg3; 4281 Lisp_Object arg1, arg2, arg3;
4222 { 4282 {
4223 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4283 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4224 4284
4225 GCPRO4 (list, arg1, arg2, arg3); 4285 GCPRO4 (list, arg1, arg2, arg3);
4226 if (! after)
4227 add_overlay_mod_hooklist (list, overlay);
4228 4286
4229 while (CONSP (list)) 4287 while (CONSP (list))
4230 { 4288 {
4231 if (NILP (arg3)) 4289 if (NILP (arg3))
4232 call4 (XCAR (list), overlay, after ? Qt : Qnil, arg1, arg2); 4290 call4 (XCAR (list), overlay, after ? Qt : Qnil, arg1, arg2);
4239 4297
4240 /* Delete any zero-sized overlays at position POS, if the `evaporate' 4298 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4241 property is set. */ 4299 property is set. */
4242 void 4300 void
4243 evaporate_overlays (pos) 4301 evaporate_overlays (pos)
4244 int pos; 4302 EMACS_INT pos;
4245 { 4303 {
4246 Lisp_Object tail, overlay, hit_list; 4304 Lisp_Object overlay, hit_list;
4305 struct Lisp_Overlay *tail;
4247 4306
4248 hit_list = Qnil; 4307 hit_list = Qnil;
4249 if (pos <= XFASTINT (current_buffer->overlay_center)) 4308 if (pos <= current_buffer->overlay_center)
4250 for (tail = current_buffer->overlays_before; CONSP (tail); 4309 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4251 tail = XCDR (tail))
4252 { 4310 {
4253 int endpos; 4311 int endpos;
4254 overlay = XCAR (tail); 4312 XSETMISC (overlay, tail);
4255 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4313 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4256 if (endpos < pos) 4314 if (endpos < pos)
4257 break; 4315 break;
4258 if (endpos == pos && OVERLAY_POSITION (OVERLAY_START (overlay)) == pos 4316 if (endpos == pos && OVERLAY_POSITION (OVERLAY_START (overlay)) == pos
4259 && ! NILP (Foverlay_get (overlay, Qevaporate))) 4317 && ! NILP (Foverlay_get (overlay, Qevaporate)))
4260 hit_list = Fcons (overlay, hit_list); 4318 hit_list = Fcons (overlay, hit_list);
4261 } 4319 }
4262 else 4320 else
4263 for (tail = current_buffer->overlays_after; CONSP (tail); 4321 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4264 tail = XCDR (tail))
4265 { 4322 {
4266 int startpos; 4323 int startpos;
4267 overlay = XCAR (tail); 4324 XSETMISC (overlay, tail);
4268 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4325 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4269 if (startpos > pos) 4326 if (startpos > pos)
4270 break; 4327 break;
4271 if (startpos == pos && OVERLAY_POSITION (OVERLAY_END (overlay)) == pos 4328 if (startpos == pos && OVERLAY_POSITION (OVERLAY_END (overlay)) == pos
4272 && ! NILP (Foverlay_get (overlay, Qevaporate))) 4329 && ! NILP (Foverlay_get (overlay, Qevaporate)))
4902 buffer_defaults.abbrev_table = Qnil; 4959 buffer_defaults.abbrev_table = Qnil;
4903 buffer_defaults.display_table = Qnil; 4960 buffer_defaults.display_table = Qnil;
4904 buffer_defaults.undo_list = Qnil; 4961 buffer_defaults.undo_list = Qnil;
4905 buffer_defaults.mark_active = Qnil; 4962 buffer_defaults.mark_active = Qnil;
4906 buffer_defaults.file_format = Qnil; 4963 buffer_defaults.file_format = Qnil;
4907 buffer_defaults.overlays_before = Qnil; 4964 buffer_defaults.auto_save_file_format = Qt;
4908 buffer_defaults.overlays_after = Qnil; 4965 buffer_defaults.overlays_before = NULL;
4909 XSETFASTINT (buffer_defaults.overlay_center, BEG); 4966 buffer_defaults.overlays_after = NULL;
4967 buffer_defaults.overlay_center = BEG;
4910 4968
4911 XSETFASTINT (buffer_defaults.tab_width, 8); 4969 XSETFASTINT (buffer_defaults.tab_width, 8);
4912 buffer_defaults.truncate_lines = Qnil; 4970 buffer_defaults.truncate_lines = Qnil;
4913 buffer_defaults.ctl_arrow = Qt; 4971 buffer_defaults.ctl_arrow = Qt;
4914 buffer_defaults.direction_reversed = Qnil; 4972 buffer_defaults.direction_reversed = Qnil;
4915 buffer_defaults.cursor_type = Qt; 4973 buffer_defaults.cursor_type = Qt;
4916 buffer_defaults.extra_line_spacing = Qnil; 4974 buffer_defaults.extra_line_spacing = Qnil;
4975 buffer_defaults.cursor_in_non_selected_windows = Qt;
4917 4976
4918 #ifdef DOS_NT 4977 #ifdef DOS_NT
4919 buffer_defaults.buffer_file_type = Qnil; /* TEXT */ 4978 buffer_defaults.buffer_file_type = Qnil; /* TEXT */
4920 #endif 4979 #endif
4921 buffer_defaults.enable_multibyte_characters = Qt; 4980 buffer_defaults.enable_multibyte_characters = Qt;
4923 XSETFASTINT (buffer_defaults.fill_column, 70); 4982 XSETFASTINT (buffer_defaults.fill_column, 70);
4924 XSETFASTINT (buffer_defaults.left_margin, 0); 4983 XSETFASTINT (buffer_defaults.left_margin, 0);
4925 buffer_defaults.cache_long_line_scans = Qnil; 4984 buffer_defaults.cache_long_line_scans = Qnil;
4926 buffer_defaults.file_truename = Qnil; 4985 buffer_defaults.file_truename = Qnil;
4927 XSETFASTINT (buffer_defaults.display_count, 0); 4986 XSETFASTINT (buffer_defaults.display_count, 0);
4987 XSETFASTINT (buffer_defaults.left_margin_cols, 0);
4988 XSETFASTINT (buffer_defaults.right_margin_cols, 0);
4989 buffer_defaults.left_fringe_width = Qnil;
4990 buffer_defaults.right_fringe_width = Qnil;
4991 buffer_defaults.fringes_outside_margins = Qnil;
4992 buffer_defaults.scroll_bar_width = Qnil;
4993 buffer_defaults.vertical_scroll_bar_type = Qt;
4928 buffer_defaults.indicate_empty_lines = Qnil; 4994 buffer_defaults.indicate_empty_lines = Qnil;
4995 buffer_defaults.indicate_buffer_boundaries = Qnil;
4929 buffer_defaults.scroll_up_aggressively = Qnil; 4996 buffer_defaults.scroll_up_aggressively = Qnil;
4930 buffer_defaults.scroll_down_aggressively = Qnil; 4997 buffer_defaults.scroll_down_aggressively = Qnil;
4931 buffer_defaults.display_time = Qnil; 4998 buffer_defaults.display_time = Qnil;
4932 4999
4933 /* Assign the local-flags to the slots that have default values. 5000 /* Assign the local-flags to the slots that have default values.
4952 XSETINT (buffer_local_flags.mark_active, -1); 5019 XSETINT (buffer_local_flags.mark_active, -1);
4953 XSETINT (buffer_local_flags.point_before_scroll, -1); 5020 XSETINT (buffer_local_flags.point_before_scroll, -1);
4954 XSETINT (buffer_local_flags.file_truename, -1); 5021 XSETINT (buffer_local_flags.file_truename, -1);
4955 XSETINT (buffer_local_flags.invisibility_spec, -1); 5022 XSETINT (buffer_local_flags.invisibility_spec, -1);
4956 XSETINT (buffer_local_flags.file_format, -1); 5023 XSETINT (buffer_local_flags.file_format, -1);
5024 XSETINT (buffer_local_flags.auto_save_file_format, -1);
4957 XSETINT (buffer_local_flags.display_count, -1); 5025 XSETINT (buffer_local_flags.display_count, -1);
4958 XSETINT (buffer_local_flags.display_time, -1); 5026 XSETINT (buffer_local_flags.display_time, -1);
4959 XSETINT (buffer_local_flags.enable_multibyte_characters, -1); 5027 XSETINT (buffer_local_flags.enable_multibyte_characters, -1);
4960 5028
4961 idx = 1; 5029 idx = 1;
4985 XSETFASTINT (buffer_local_flags.category_table, idx); ++idx; 5053 XSETFASTINT (buffer_local_flags.category_table, idx); ++idx;
4986 XSETFASTINT (buffer_local_flags.direction_reversed, idx); ++idx; 5054 XSETFASTINT (buffer_local_flags.direction_reversed, idx); ++idx;
4987 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx); 5055 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx);
4988 /* Make this one a permanent local. */ 5056 /* Make this one a permanent local. */
4989 buffer_permanent_local_flags[idx++] = 1; 5057 buffer_permanent_local_flags[idx++] = 1;
4990 XSETFASTINT (buffer_local_flags.left_margin_width, idx); ++idx; 5058 XSETFASTINT (buffer_local_flags.left_margin_cols, idx); ++idx;
4991 XSETFASTINT (buffer_local_flags.right_margin_width, idx); ++idx; 5059 XSETFASTINT (buffer_local_flags.right_margin_cols, idx); ++idx;
5060 XSETFASTINT (buffer_local_flags.left_fringe_width, idx); ++idx;
5061 XSETFASTINT (buffer_local_flags.right_fringe_width, idx); ++idx;
5062 XSETFASTINT (buffer_local_flags.fringes_outside_margins, idx); ++idx;
5063 XSETFASTINT (buffer_local_flags.scroll_bar_width, idx); ++idx;
5064 XSETFASTINT (buffer_local_flags.vertical_scroll_bar_type, idx); ++idx;
4992 XSETFASTINT (buffer_local_flags.indicate_empty_lines, idx); ++idx; 5065 XSETFASTINT (buffer_local_flags.indicate_empty_lines, idx); ++idx;
5066 XSETFASTINT (buffer_local_flags.indicate_buffer_boundaries, idx); ++idx;
4993 XSETFASTINT (buffer_local_flags.scroll_up_aggressively, idx); ++idx; 5067 XSETFASTINT (buffer_local_flags.scroll_up_aggressively, idx); ++idx;
4994 XSETFASTINT (buffer_local_flags.scroll_down_aggressively, idx); ++idx; 5068 XSETFASTINT (buffer_local_flags.scroll_down_aggressively, idx); ++idx;
4995 XSETFASTINT (buffer_local_flags.header_line_format, idx); ++idx; 5069 XSETFASTINT (buffer_local_flags.header_line_format, idx); ++idx;
4996 XSETFASTINT (buffer_local_flags.cursor_type, idx); ++idx; 5070 XSETFASTINT (buffer_local_flags.cursor_type, idx); ++idx;
4997 XSETFASTINT (buffer_local_flags.extra_line_spacing, idx); ++idx; 5071 XSETFASTINT (buffer_local_flags.extra_line_spacing, idx); ++idx;
5072 XSETFASTINT (buffer_local_flags.cursor_in_non_selected_windows, idx); ++idx;
4998 5073
4999 /* Need more room? */ 5074 /* Need more room? */
5000 if (idx >= MAX_PER_BUFFER_VARS) 5075 if (idx >= MAX_PER_BUFFER_VARS)
5001 abort (); 5076 abort ();
5002 last_per_buffer_idx = idx; 5077 last_per_buffer_idx = idx;
5015 Qprotected_field = intern ("protected-field"); 5090 Qprotected_field = intern ("protected-field");
5016 5091
5017 Qpermanent_local = intern ("permanent-local"); 5092 Qpermanent_local = intern ("permanent-local");
5018 5093
5019 Qkill_buffer_hook = intern ("kill-buffer-hook"); 5094 Qkill_buffer_hook = intern ("kill-buffer-hook");
5095 Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
5020 5096
5021 Qucs_set_table_for_input = intern ("ucs-set-table-for-input"); 5097 Qucs_set_table_for_input = intern ("ucs-set-table-for-input");
5022 5098
5023 Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1")); 5099 Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
5024 5100
5031 } 5107 }
5032 5108
5033 void 5109 void
5034 init_buffer () 5110 init_buffer ()
5035 { 5111 {
5036 char buf[MAXPATHLEN + 1];
5037 char *pwd; 5112 char *pwd;
5038 struct stat dotstat, pwdstat;
5039 Lisp_Object temp; 5113 Lisp_Object temp;
5040 int rc; 5114 int len;
5041 5115
5042 #ifdef USE_MMAP_FOR_BUFFERS 5116 #ifdef USE_MMAP_FOR_BUFFERS
5043 { 5117 {
5044 /* When using the ralloc implementation based on mmap(2), buffer 5118 /* When using the ralloc implementation based on mmap(2), buffer
5045 text pointers will have been set to null in the dumped Emacs. 5119 text pointers will have been set to null in the dumped Emacs.
5054 5128
5055 Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); 5129 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5056 if (NILP (buffer_defaults.enable_multibyte_characters)) 5130 if (NILP (buffer_defaults.enable_multibyte_characters))
5057 Fset_buffer_multibyte (Qnil); 5131 Fset_buffer_multibyte (Qnil);
5058 5132
5059 /* If PWD is accurate, use it instead of calling getwd. PWD is 5133 pwd = get_current_dir_name ();
5060 sometimes a nicer name, and using it may avoid a fatal error if a 5134
5061 parent directory is searchable but not readable. */ 5135 if (!pwd)
5062 if ((pwd = getenv ("PWD")) != 0 5136 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
5063 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
5064 && stat (pwd, &pwdstat) == 0
5065 && stat (".", &dotstat) == 0
5066 && dotstat.st_ino == pwdstat.st_ino
5067 && dotstat.st_dev == pwdstat.st_dev
5068 && strlen (pwd) < MAXPATHLEN)
5069 strcpy (buf, pwd);
5070 #ifdef HAVE_GETCWD
5071 else if (getcwd (buf, MAXPATHLEN+1) == 0)
5072 fatal ("`getcwd' failed: %s\n", strerror (errno));
5073 #else
5074 else if (getwd (buf) == 0)
5075 fatal ("`getwd' failed: %s\n", buf);
5076 #endif
5077 5137
5078 #ifndef VMS 5138 #ifndef VMS
5079 /* Maybe this should really use some standard subroutine 5139 /* Maybe this should really use some standard subroutine
5080 whose definition is filename syntax dependent. */ 5140 whose definition is filename syntax dependent. */
5081 rc = strlen (buf); 5141 len = strlen (pwd);
5082 if (!(IS_DIRECTORY_SEP (buf[rc - 1]))) 5142 if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
5083 { 5143 {
5084 buf[rc] = DIRECTORY_SEP; 5144 /* Grow buffer to add directory separator and '\0'. */
5085 buf[rc + 1] = '\0'; 5145 pwd = (char *) xrealloc (pwd, len + 2);
5146 pwd[len] = DIRECTORY_SEP;
5147 pwd[len + 1] = '\0';
5086 } 5148 }
5087 #endif /* not VMS */ 5149 #endif /* not VMS */
5088 5150
5089 current_buffer->directory = build_string (buf); 5151 current_buffer->directory = make_unibyte_string (pwd, strlen (pwd));
5152 if (! NILP (buffer_defaults.enable_multibyte_characters))
5153 /* At this moment, we still don't know how to decode the
5154 directory name. So, we keep the bytes in multibyte form so
5155 that ENCODE_FILE correctly gets the original bytes. */
5156 current_buffer->directory
5157 = string_to_multibyte (current_buffer->directory);
5090 5158
5091 /* Add /: to the front of the name 5159 /* Add /: to the front of the name
5092 if it would otherwise be treated as magic. */ 5160 if it would otherwise be treated as magic. */
5093 temp = Ffind_file_name_handler (current_buffer->directory, Qt); 5161 temp = Ffind_file_name_handler (current_buffer->directory, Qt);
5094 if (! NILP (temp) 5162 if (! NILP (temp)
5100 current_buffer->directory 5168 current_buffer->directory
5101 = concat2 (build_string ("/:"), current_buffer->directory); 5169 = concat2 (build_string ("/:"), current_buffer->directory);
5102 5170
5103 temp = get_minibuffer (0); 5171 temp = get_minibuffer (0);
5104 XBUFFER (temp)->directory = current_buffer->directory; 5172 XBUFFER (temp)->directory = current_buffer->directory;
5173
5174 free (pwd);
5105 } 5175 }
5106 5176
5107 /* initialize the buffer routines */ 5177 /* initialize the buffer routines */
5108 void 5178 void
5109 syms_of_buffer () 5179 syms_of_buffer ()
5147 staticpro (&Qbefore_change_functions); 5217 staticpro (&Qbefore_change_functions);
5148 Qafter_change_functions = intern ("after-change-functions"); 5218 Qafter_change_functions = intern ("after-change-functions");
5149 staticpro (&Qafter_change_functions); 5219 staticpro (&Qafter_change_functions);
5150 staticpro (&Qucs_set_table_for_input); 5220 staticpro (&Qucs_set_table_for_input);
5151 5221
5222 Qkill_buffer_query_functions = intern ("kill-buffer-query-functions");
5223 staticpro (&Qkill_buffer_query_functions);
5224
5152 Fput (Qprotected_field, Qerror_conditions, 5225 Fput (Qprotected_field, Qerror_conditions,
5153 Fcons (Qprotected_field, Fcons (Qerror, Qnil))); 5226 Fcons (Qprotected_field, Fcons (Qerror, Qnil)));
5154 Fput (Qprotected_field, Qerror_message, 5227 Fput (Qprotected_field, Qerror_message,
5155 build_string ("Attempt to modify a protected field")); 5228 build_string ("Attempt to modify a protected field"));
5156 5229
5174 DEFVAR_LISP_NOPRO ("default-line-spacing", 5247 DEFVAR_LISP_NOPRO ("default-line-spacing",
5175 &buffer_defaults.extra_line_spacing, 5248 &buffer_defaults.extra_line_spacing,
5176 doc: /* Default value of `line-spacing' for buffers that don't override it. 5249 doc: /* Default value of `line-spacing' for buffers that don't override it.
5177 This is the same as (default-value 'line-spacing). */); 5250 This is the same as (default-value 'line-spacing). */);
5178 5251
5252 DEFVAR_LISP_NOPRO ("default-cursor-in-non-selected-windows",
5253 &buffer_defaults.cursor_in_non_selected_windows,
5254 doc: /* Default value of `cursor-in-non-selected-windows'.
5255 This is the same as (default-value 'cursor-in-non-selected-windows). */);
5256
5179 DEFVAR_LISP_NOPRO ("default-abbrev-mode", 5257 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
5180 &buffer_defaults.abbrev_mode, 5258 &buffer_defaults.abbrev_mode,
5181 doc: /* Default value of `abbrev-mode' for buffers that do not override it. 5259 doc: /* Default value of `abbrev-mode' for buffers that do not override it.
5182 This is the same as (default-value 'abbrev-mode). */); 5260 This is the same as (default-value 'abbrev-mode). */);
5183 5261
5184 DEFVAR_LISP_NOPRO ("default-ctl-arrow", 5262 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
5185 &buffer_defaults.ctl_arrow, 5263 &buffer_defaults.ctl_arrow,
5186 doc: /* Default value of `ctl-arrow' for buffers that do not override it. 5264 doc: /* Default value of `ctl-arrow' for buffers that do not override it.
5187 This is the same as (default-value 'ctl-arrow). */); 5265 This is the same as (default-value 'ctl-arrow). */);
5188 5266
5189 DEFVAR_LISP_NOPRO ("default-direction-reversed", 5267 DEFVAR_LISP_NOPRO ("default-direction-reversed",
5190 &buffer_defaults.direction_reversed, 5268 &buffer_defaults.direction_reversed,
5191 doc: /* Default value of `direction_reversed' for buffers that do not override it. 5269 doc: /* Default value of `direction-reversed' for buffers that do not override it.
5192 This is the same as (default-value 'direction-reversed). */); 5270 This is the same as (default-value 'direction-reversed). */);
5193 5271
5194 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters", 5272 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
5195 &buffer_defaults.enable_multibyte_characters, 5273 &buffer_defaults.enable_multibyte_characters,
5196 doc: /* *Default value of `enable-multibyte-characters' for buffers not overriding it. 5274 doc: /* *Default value of `enable-multibyte-characters' for buffers not overriding it.
5197 This is the same as (default-value 'enable-multibyte-characters). */); 5275 This is the same as (default-value 'enable-multibyte-characters). */);
5198 5276
5199 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system", 5277 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
5200 &buffer_defaults.buffer_file_coding_system, 5278 &buffer_defaults.buffer_file_coding_system,
5201 doc: /* Default value of `buffer-file-coding-system' for buffers not overriding it. 5279 doc: /* Default value of `buffer-file-coding-system' for buffers not overriding it.
5202 This is the same as (default-value 'buffer-file-coding-system). */); 5280 This is the same as (default-value 'buffer-file-coding-system). */);
5203 5281
5204 DEFVAR_LISP_NOPRO ("default-truncate-lines", 5282 DEFVAR_LISP_NOPRO ("default-truncate-lines",
5205 &buffer_defaults.truncate_lines, 5283 &buffer_defaults.truncate_lines,
5206 doc: /* Default value of `truncate-lines' for buffers that do not override it. 5284 doc: /* Default value of `truncate-lines' for buffers that do not override it.
5233 This is the same as (default-value 'buffer-file-type). 5311 This is the same as (default-value 'buffer-file-type).
5234 The file type is nil for text, t for binary. */); 5312 The file type is nil for text, t for binary. */);
5235 #endif 5313 #endif
5236 5314
5237 DEFVAR_LISP_NOPRO ("default-left-margin-width", 5315 DEFVAR_LISP_NOPRO ("default-left-margin-width",
5238 &buffer_defaults.left_margin_width, 5316 &buffer_defaults.left_margin_cols,
5239 doc: /* Default value of `left-margin-width' for buffers that don't override it. 5317 doc: /* Default value of `left-margin-width' for buffers that don't override it.
5240 This is the same as (default-value 'left-margin-width). */); 5318 This is the same as (default-value 'left-margin-width). */);
5241 5319
5242 DEFVAR_LISP_NOPRO ("default-right-margin-width", 5320 DEFVAR_LISP_NOPRO ("default-right-margin-width",
5243 &buffer_defaults.right_margin_width, 5321 &buffer_defaults.right_margin_cols,
5244 doc: /* Default value of `right_margin_width' for buffers that don't override it. 5322 doc: /* Default value of `right-margin-width' for buffers that don't override it.
5245 This is the same as (default-value 'right-margin-width). */); 5323 This is the same as (default-value 'right-margin-width). */);
5324
5325 DEFVAR_LISP_NOPRO ("default-left-fringe-width",
5326 &buffer_defaults.left_fringe_width,
5327 doc: /* Default value of `left-fringe-width' for buffers that don't override it.
5328 This is the same as (default-value 'left-fringe-width). */);
5329
5330 DEFVAR_LISP_NOPRO ("default-right-fringe-width",
5331 &buffer_defaults.right_fringe_width,
5332 doc: /* Default value of `right-fringe-width' for buffers that don't override it.
5333 This is the same as (default-value 'right-fringe-width). */);
5334
5335 DEFVAR_LISP_NOPRO ("default-fringes-outside-margins",
5336 &buffer_defaults.fringes_outside_margins,
5337 doc: /* Default value of `fringes-outside-margins' for buffers that don't override it.
5338 This is the same as (default-value 'fringes-outside-margins). */);
5339
5340 DEFVAR_LISP_NOPRO ("default-scroll-bar-width",
5341 &buffer_defaults.scroll_bar_width,
5342 doc: /* Default value of `scroll-bar-width' for buffers that don't override it.
5343 This is the same as (default-value 'scroll-bar-width). */);
5344
5345 DEFVAR_LISP_NOPRO ("default-vertical-scroll-bar",
5346 &buffer_defaults.vertical_scroll_bar_type,
5347 doc: /* Default value of `vertical-scroll-bar' for buffers that don't override it.
5348 This is the same as (default-value 'vertical-scroll-bar). */);
5246 5349
5247 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines", 5350 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
5248 &buffer_defaults.indicate_empty_lines, 5351 &buffer_defaults.indicate_empty_lines,
5249 doc: /* Default value of `indicate-empty-lines' for buffers that don't override it. 5352 doc: /* Default value of `indicate-empty-lines' for buffers that don't override it.
5250 This is the same as (default-value 'indicate-empty-lines). */); 5353 This is the same as (default-value 'indicate-empty-lines). */);
5354
5355 DEFVAR_LISP_NOPRO ("default-indicate-buffer-boundaries",
5356 &buffer_defaults.indicate_buffer_boundaries,
5357 doc: /* Default value of `indicate-buffer-boundaries' for buffers that don't override it.
5358 This is the same as (default-value 'indicate-buffer-boundaries). */);
5251 5359
5252 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively", 5360 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
5253 &buffer_defaults.scroll_up_aggressively, 5361 &buffer_defaults.scroll_up_aggressively,
5254 doc: /* Default value of `scroll-up-aggressively'. 5362 doc: /* Default value of `scroll-up-aggressively'.
5255 This value applies in buffers that don't have their own local values. 5363 This value applies in buffers that don't have their own local values.
5304 For a modified read-only buffer, %* gives % and %+ gives *. 5412 For a modified read-only buffer, %* gives % and %+ gives *.
5305 %s -- print process status. %l -- print the current line number. 5413 %s -- print process status. %l -- print the current line number.
5306 %c -- print the current column number (this makes editing slower). 5414 %c -- print the current column number (this makes editing slower).
5307 To make the column number update correctly in all cases, 5415 To make the column number update correctly in all cases,
5308 `column-number-mode' must be non-nil. 5416 `column-number-mode' must be non-nil.
5417 %i -- print the size of the buffer.
5418 %I -- like %i, but use k, M, G, etc., to abbreviate.
5309 %p -- print percent of buffer above top of window, or Top, Bot or All. 5419 %p -- print percent of buffer above top of window, or Top, Bot or All.
5310 %P -- print percent of buffer above bottom of window, perhaps plus Top, 5420 %P -- print percent of buffer above bottom of window, perhaps plus Top,
5311 or print Bottom or All. 5421 or print Bottom or All.
5312 %m -- print the mode name. 5422 %m -- print the mode name.
5313 %n -- print Narrow if appropriate. 5423 %n -- print Narrow if appropriate.
5317 %% -- print %. %- -- print infinitely many dashes. 5427 %% -- print %. %- -- print infinitely many dashes.
5318 Decimal digits after the % specify field width to which to pad. */); 5428 Decimal digits after the % specify field width to which to pad. */);
5319 5429
5320 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode, 5430 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode,
5321 doc: /* *Major mode for new buffers. Defaults to `fundamental-mode'. 5431 doc: /* *Major mode for new buffers. Defaults to `fundamental-mode'.
5322 nil here means use current buffer's major mode. */); 5432 nil here means use current buffer's major mode, provided it is not
5433 marked as "special".
5434
5435 When a mode is used by default, `find-file' switches to it
5436 before it reads the contents into the buffer and before
5437 it finishes setting up the buffer. Thus, the mode and
5438 its hooks should not expect certain variables such as
5439 `buffer-read-only' and `buffer-file-coding-system' to be set up. */);
5323 5440
5324 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode, 5441 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
5325 make_number (Lisp_Symbol), 5442 make_number (Lisp_Symbol),
5326 doc: /* Symbol for current buffer's major mode. */); 5443 doc: /* Symbol for current buffer's major mode. */);
5327 5444
5337 doc: /* *Non-nil if searches and matches should ignore case. */); 5454 doc: /* *Non-nil if searches and matches should ignore case. */);
5338 5455
5339 DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column, 5456 DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column,
5340 make_number (Lisp_Int), 5457 make_number (Lisp_Int),
5341 doc: /* *Column beyond which automatic line-wrapping should happen. 5458 doc: /* *Column beyond which automatic line-wrapping should happen.
5342 Interactively, you can set this using \\[set-fill-column]. */); 5459 Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5343 5460
5344 DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin, 5461 DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin,
5345 make_number (Lisp_Int), 5462 make_number (Lisp_Int),
5346 doc: /* *Column for the default indent-line-function to indent to. 5463 doc: /* *Column for the default indent-line-function to indent to.
5347 Linefeed indents to this column in Fundamental mode. */); 5464 Linefeed indents to this column in Fundamental mode. */);
5356 This variable does not apply to characters whose display is specified 5473 This variable does not apply to characters whose display is specified
5357 in the current display table (if there is one). */); 5474 in the current display table (if there is one). */);
5358 5475
5359 DEFVAR_PER_BUFFER ("enable-multibyte-characters", 5476 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
5360 &current_buffer->enable_multibyte_characters, 5477 &current_buffer->enable_multibyte_characters,
5361 make_number (-1), 5478 Qnil,
5362 doc: /* Non-nil means the buffer contents are regarded as multi-byte characters. 5479 doc: /* Non-nil means the buffer contents are regarded as multi-byte characters.
5363 Otherwise they are regarded as unibyte. This affects the display, 5480 Otherwise they are regarded as unibyte. This affects the display,
5364 file I/O and the behavior of various editing commands. 5481 file I/O and the behavior of various editing commands.
5365 5482
5366 This variable is buffer-local but you cannot set it directly; 5483 This variable is buffer-local but you cannot set it directly;
5367 use the function `set-buffer-multibyte' to change a buffer's representation. 5484 use the function `set-buffer-multibyte' to change a buffer's representation.
5368 Changing its default value with `setq-default' is supported. 5485 Changing its default value with `setq-default' is supported.
5369 See also variable `default-enable-multibyte-characters' and Info node 5486 See also variable `default-enable-multibyte-characters' and Info node
5370 `(elisp)Text Representations'. */); 5487 `(elisp)Text Representations'. */);
5488 XSYMBOL (intern ("enable-multibyte-characters"))->constant = 1;
5371 5489
5372 DEFVAR_PER_BUFFER ("buffer-file-coding-system", 5490 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
5373 &current_buffer->buffer_file_coding_system, Qnil, 5491 &current_buffer->buffer_file_coding_system, Qnil,
5374 doc: /* Coding system to be used for encoding the buffer contents on saving. 5492 doc: /* Coding system to be used for encoding the buffer contents on saving.
5375 This variable applies to saving the buffer, and also to `write-region' 5493 This variable applies to saving the buffer, and also to `write-region'
5509 the character used to draw the border between side-by-side windows 5627 the character used to draw the border between side-by-side windows
5510 (extra-slot 5, a single character). 5628 (extra-slot 5, a single character).
5511 5629
5512 See also the functions `display-table-slot' and `set-display-table-slot'. */); 5630 See also the functions `display-table-slot' and `set-display-table-slot'. */);
5513 5631
5514 DEFVAR_PER_BUFFER ("left-margin-width", &current_buffer->left_margin_width, 5632 DEFVAR_PER_BUFFER ("left-margin-width", &current_buffer->left_margin_cols,
5515 Qnil, 5633 Qnil,
5516 doc: /* *Width of left marginal area for display of a buffer. 5634 doc: /* *Width of left marginal area for display of a buffer.
5517 A value of nil means no marginal area. */); 5635 A value of nil means no marginal area. */);
5518 5636
5519 DEFVAR_PER_BUFFER ("right-margin-width", &current_buffer->right_margin_width, 5637 DEFVAR_PER_BUFFER ("right-margin-width", &current_buffer->right_margin_cols,
5520 Qnil, 5638 Qnil,
5521 doc: /* *Width of right marginal area for display of a buffer. 5639 doc: /* *Width of right marginal area for display of a buffer.
5522 A value of nil means no marginal area. */); 5640 A value of nil means no marginal area. */);
5641
5642 DEFVAR_PER_BUFFER ("left-fringe-width", &current_buffer->left_fringe_width,
5643 Qnil,
5644 doc: /* *Width of this buffer's left fringe (in pixels).
5645 A value of 0 means no left fringe is shown in this buffer's window.
5646 A value of nil means to use the left fringe width from the window's frame. */);
5647
5648 DEFVAR_PER_BUFFER ("right-fringe-width", &current_buffer->right_fringe_width,
5649 Qnil,
5650 doc: /* *Width of this buffer's right fringe (in pixels).
5651 A value of 0 means no right fringe is shown in this buffer's window.
5652 A value of nil means to use the right fringe width from the window's frame. */);
5653
5654 DEFVAR_PER_BUFFER ("fringes-outside-margins", &current_buffer->fringes_outside_margins,
5655 Qnil,
5656 doc: /* *Non-nil means to display fringes outside display margins.
5657 A value of nil means to display fringes between margins and buffer text. */);
5658
5659 DEFVAR_PER_BUFFER ("scroll-bar-width", &current_buffer->scroll_bar_width,
5660 Qnil,
5661 doc: /* *Width of this buffer's scroll bars in pixels.
5662 A value of nil means to use the scroll bar width from the window's frame. */);
5663
5664 DEFVAR_PER_BUFFER ("vertical-scroll-bar", &current_buffer->vertical_scroll_bar_type,
5665 Qnil,
5666 doc: /* *Position of this buffer's vertical scroll bar.
5667 The value takes effect whenever you tell a window to display this buffer;
5668 for instance, with `set-window-buffer' or when `display-buffer' displays it.
5669
5670 A value of `left' or `right' means put the vertical scroll bar at that side
5671 of the window; a value of nil means don't show any vertical scroll bars.
5672 A value of t (the default) means do whatever the window's frame specifies. */);
5523 5673
5524 DEFVAR_PER_BUFFER ("indicate-empty-lines", 5674 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5525 &current_buffer->indicate_empty_lines, Qnil, 5675 &current_buffer->indicate_empty_lines, Qnil,
5526 doc: /* *Visually indicate empty lines after the buffer end. 5676 doc: /* *Visually indicate empty lines after the buffer end.
5527 If non-nil, a bitmap is displayed in the left fringe of a window on 5677 If non-nil, a bitmap is displayed in the left fringe of a window on
5528 window-systems. */); 5678 window-systems. */);
5679
5680 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5681 &current_buffer->indicate_buffer_boundaries, Qnil,
5682 doc: /* *Visually indicate buffer boundaries and scrolling.
5683 If non-nil, the first and last line of the buffer are marked in the fringe
5684 of a window on window-systems with angle bitmaps, or if the window can be
5685 scrolled, the top and bottom line of the window are marked with up and down
5686 arrow bitmaps.
5687
5688 If value is a symbol `left' or `right', both angle and arrow bitmaps
5689 are displayed in the left or right fringe, resp. Any other value
5690 that doesn't look like an alist means display the angle bitmaps in
5691 the left fringe but no arrows.
5692
5693 You can exercise more precise control by using an alist as the
5694 value. Each alist element (INDICATOR . POSITION) specifies
5695 where to show one of the indicators. INDICATOR is one of `top',
5696 `bottom', `up', `down', or t, which specifies the default position,
5697 and POSITION is one of `left', `right', or nil, meaning do not show
5698 this indicator.
5699
5700 For example, ((top . left) (t . right)) places the top angle bitmap in
5701 left fringe, the bottom angle bitmap in right fringe, and both arrow
5702 bitmaps in right fringe. To show just the angle bitmaps in the left
5703 fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5529 5704
5530 DEFVAR_PER_BUFFER ("scroll-up-aggressively", 5705 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
5531 &current_buffer->scroll_up_aggressively, Qnil, 5706 &current_buffer->scroll_up_aggressively, Qnil,
5532 doc: /* How far to scroll windows upward. 5707 doc: /* How far to scroll windows upward.
5533 If you move point off the bottom, the window scrolls automatically. 5708 If you move point off the bottom, the window scrolls automatically.
5535 means scroll to center point. A fraction means scroll to put point 5710 means scroll to center point. A fraction means scroll to put point
5536 that fraction of the window's height from the bottom of the window. 5711 that fraction of the window's height from the bottom of the window.
5537 When the value is 0.0, point goes at the bottom line, which in the simple 5712 When the value is 0.0, point goes at the bottom line, which in the simple
5538 case that you moved off with C-f means scrolling just one line. 1.0 means 5713 case that you moved off with C-f means scrolling just one line. 1.0 means
5539 point goes at the top, so that in that simple case, the window 5714 point goes at the top, so that in that simple case, the window
5540 window scrolls by a full window height. Meaningful values are 5715 scrolls by a full window height. Meaningful values are
5541 between 0.0 and 1.0, inclusive. */); 5716 between 0.0 and 1.0, inclusive. */);
5542 5717
5543 DEFVAR_PER_BUFFER ("scroll-down-aggressively", 5718 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
5544 &current_buffer->scroll_down_aggressively, Qnil, 5719 &current_buffer->scroll_down_aggressively, Qnil,
5545 doc: /* How far to scroll windows downward. 5720 doc: /* How far to scroll windows downward.
5548 means scroll to center point. A fraction means scroll to put point 5723 means scroll to center point. A fraction means scroll to put point
5549 that fraction of the window's height from the top of the window. 5724 that fraction of the window's height from the top of the window.
5550 When the value is 0.0, point goes at the top line, which in the simple 5725 When the value is 0.0, point goes at the top line, which in the simple
5551 case that you moved off with C-b means scrolling just one line. 1.0 means 5726 case that you moved off with C-b means scrolling just one line. 1.0 means
5552 point goes at the bottom, so that in that simple case, the window 5727 point goes at the bottom, so that in that simple case, the window
5553 window scrolls by a full window height. Meaningful values are 5728 scrolls by a full window height. Meaningful values are
5554 between 0.0 and 1.0, inclusive. */); 5729 between 0.0 and 1.0, inclusive. */);
5555 5730
5556 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol, 5731 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
5557 "Don't ask."); 5732 "Don't ask.");
5558 */ 5733 */
5621 5796
5622 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property 5797 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
5623 was modified between BEG and END. PROPERTY is the property name, 5798 was modified between BEG and END. PROPERTY is the property name,
5624 and VALUE is the old value. 5799 and VALUE is the old value.
5625 5800
5801 An entry (apply FUN-NAME . ARGS) means undo the change with
5802 \(apply FUN-NAME ARGS).
5803
5804 An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
5805 in the active region. BEG and END is the range affected by this entry
5806 and DELTA is the number of bytes added or deleted in that range by
5807 this change.
5808
5626 An entry (MARKER . DISTANCE) indicates that the marker MARKER 5809 An entry (MARKER . DISTANCE) indicates that the marker MARKER
5627 was adjusted in position by the offset DISTANCE (an integer). 5810 was adjusted in position by the offset DISTANCE (an integer).
5628 5811
5629 An entry of the form POSITION indicates that point was at the buffer 5812 An entry of the form POSITION indicates that point was at the buffer
5630 location given by the integer. Undoing an entry of this form places 5813 location given by the integer. Undoing an entry of this form places
5640 5823
5641 DEFVAR_PER_BUFFER ("cache-long-line-scans", &current_buffer->cache_long_line_scans, Qnil, 5824 DEFVAR_PER_BUFFER ("cache-long-line-scans", &current_buffer->cache_long_line_scans, Qnil,
5642 doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly. 5825 doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
5643 5826
5644 Normally, the line-motion functions work by scanning the buffer for 5827 Normally, the line-motion functions work by scanning the buffer for
5645 newlines. Columnar operations (like move-to-column and 5828 newlines. Columnar operations (like `move-to-column' and
5646 compute-motion) also work by scanning the buffer, summing character 5829 `compute-motion') also work by scanning the buffer, summing character
5647 widths as they go. This works well for ordinary text, but if the 5830 widths as they go. This works well for ordinary text, but if the
5648 buffer's lines are very long (say, more than 500 characters), these 5831 buffer's lines are very long (say, more than 500 characters), these
5649 motion functions will take longer to execute. Emacs may also take 5832 motion functions will take longer to execute. Emacs may also take
5650 longer to update the display. 5833 longer to update the display.
5651 5834
5652 If cache-long-line-scans is non-nil, these motion functions cache the 5835 If `cache-long-line-scans' is non-nil, these motion functions cache the
5653 results of their scans, and consult the cache to avoid rescanning 5836 results of their scans, and consult the cache to avoid rescanning
5654 regions of the buffer until the text is modified. The caches are most 5837 regions of the buffer until the text is modified. The caches are most
5655 beneficial when they prevent the most searching---that is, when the 5838 beneficial when they prevent the most searching---that is, when the
5656 buffer contains long lines and large regions of characters with the 5839 buffer contains long lines and large regions of characters with the
5657 same, fixed screen width. 5840 same, fixed screen width.
5658 5841
5659 When cache-long-line-scans is non-nil, processing short lines will 5842 When `cache-long-line-scans' is non-nil, processing short lines will
5660 become slightly slower (because of the overhead of consulting the 5843 become slightly slower (because of the overhead of consulting the
5661 cache), and the caches will use memory roughly proportional to the 5844 cache), and the caches will use memory roughly proportional to the
5662 number of newlines and characters whose screen width varies. 5845 number of newlines and characters whose screen width varies.
5663 5846
5664 The caches require no explicit maintenance; their accuracy is 5847 The caches require no explicit maintenance; their accuracy is
5670 doc: /* Value of point before the last series of scroll operations, or nil. */); 5853 doc: /* Value of point before the last series of scroll operations, or nil. */);
5671 5854
5672 DEFVAR_PER_BUFFER ("buffer-file-format", &current_buffer->file_format, Qnil, 5855 DEFVAR_PER_BUFFER ("buffer-file-format", &current_buffer->file_format, Qnil,
5673 doc: /* List of formats to use when saving this buffer. 5856 doc: /* List of formats to use when saving this buffer.
5674 Formats are defined by `format-alist'. This variable is 5857 Formats are defined by `format-alist'. This variable is
5675 set when a file is visited. Automatically local in all buffers. */); 5858 set when a file is visited. */);
5859
5860 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
5861 &current_buffer->auto_save_file_format, Qnil,
5862 doc: /* *Format in which to write auto-save files.
5863 Should be a list of symbols naming formats that are defined in `format-alist'.
5864 If it is t, which is the default, auto-save files are written in the
5865 same format as a regular save would use. */);
5676 5866
5677 DEFVAR_PER_BUFFER ("buffer-invisibility-spec", 5867 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
5678 &current_buffer->invisibility_spec, Qnil, 5868 &current_buffer->invisibility_spec, Qnil,
5679 doc: /* Invisibility spec of this buffer. 5869 doc: /* Invisibility spec of this buffer.
5680 The default is t, which means that text is invisible 5870 The default is t, which means that text is invisible
5699 5889
5700 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode, 5890 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode,
5701 doc: /* *Non-nil means deactivate the mark when the buffer contents change. 5891 doc: /* *Non-nil means deactivate the mark when the buffer contents change.
5702 Non-nil also enables highlighting of the region whenever the mark is active. 5892 Non-nil also enables highlighting of the region whenever the mark is active.
5703 The variable `highlight-nonselected-windows' controls whether to highlight 5893 The variable `highlight-nonselected-windows' controls whether to highlight
5704 all windows or just the selected window. */); 5894 all windows or just the selected window.
5895
5896 If the value is `lambda', that enables Transient Mark mode temporarily
5897 until the next buffer modification. If a command sets the value to `only',
5898 that enables Transient Mark mode for the following command only.
5899 During that following command, the value of `transient-mark-mode'
5900 is `identity'. If it is still `identity' at the end of that command,
5901 it changes to nil. */);
5705 Vtransient_mark_mode = Qnil; 5902 Vtransient_mark_mode = Qnil;
5706 5903
5707 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only, 5904 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only,
5708 doc: /* *Non-nil means disregard read-only status of buffers or characters. 5905 doc: /* *Non-nil means disregard read-only status of buffers or characters.
5709 If the value is t, disregard `buffer-read-only' and all `read-only' 5906 If the value is t, disregard `buffer-read-only' and all `read-only'
5714 5911
5715 DEFVAR_PER_BUFFER ("cursor-type", &current_buffer->cursor_type, Qnil, 5912 DEFVAR_PER_BUFFER ("cursor-type", &current_buffer->cursor_type, Qnil,
5716 doc: /* Cursor to use when this buffer is in the selected window. 5913 doc: /* Cursor to use when this buffer is in the selected window.
5717 Values are interpreted as follows: 5914 Values are interpreted as follows:
5718 5915
5719 t use the cursor specified for the frame 5916 t use the cursor specified for the frame
5720 nil don't display a cursor 5917 nil don't display a cursor
5721 bar display a bar cursor with default width 5918 box display a filled box cursor
5722 (bar . WIDTH) display a bar cursor with width WIDTH 5919 hollow display a hollow box cursor
5723 ANYTHING ELSE display a box cursor. 5920 bar display a vertical bar cursor with default width
5921 (bar . WIDTH) display a vertical bar cursor with width WIDTH
5922 hbar display a horizontal bar cursor with default height
5923 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
5924 ANYTHING ELSE display a hollow box cursor
5724 5925
5725 When the buffer is displayed in a nonselected window, 5926 When the buffer is displayed in a nonselected window,
5726 this variable has no effect; the cursor appears as a hollow box. */); 5927 this variable has no effect; the cursor appears as a hollow box. */);
5727 5928
5728 DEFVAR_PER_BUFFER ("line-spacing", 5929 DEFVAR_PER_BUFFER ("line-spacing",
5729 &current_buffer->extra_line_spacing, Qnil, 5930 &current_buffer->extra_line_spacing, Qnil,
5730 doc: /* Additional space to put between lines when displaying a buffer. 5931 doc: /* Additional space to put between lines when displaying a buffer.
5731 The space is measured in pixels, and put below lines on window systems. */); 5932 The space is measured in pixels, and put below lines on window systems.
5933 If value is a floating point number, it specifies the spacing relative
5934 to the default frame line height. */);
5935
5936 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
5937 &current_buffer->cursor_in_non_selected_windows, Qnil,
5938 doc: /* *Cursor type to display in non-selected windows.
5939 t means to use hollow box cursor. See `cursor-type' for other values. */);
5732 5940
5733 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions, 5941 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
5734 doc: /* List of functions called with no args to query before killing a buffer. */); 5942 doc: /* List of functions called with no args to query before killing a buffer. */);
5735 Vkill_buffer_query_functions = Qnil; 5943 Vkill_buffer_query_functions = Qnil;
5736 5944
5750 defsubr (&Sbuffer_modified_p); 5958 defsubr (&Sbuffer_modified_p);
5751 defsubr (&Sset_buffer_modified_p); 5959 defsubr (&Sset_buffer_modified_p);
5752 defsubr (&Sbuffer_modified_tick); 5960 defsubr (&Sbuffer_modified_tick);
5753 defsubr (&Srename_buffer); 5961 defsubr (&Srename_buffer);
5754 defsubr (&Sother_buffer); 5962 defsubr (&Sother_buffer);
5755 defsubr (&Sbuffer_disable_undo);
5756 defsubr (&Sbuffer_enable_undo); 5963 defsubr (&Sbuffer_enable_undo);
5757 defsubr (&Skill_buffer); 5964 defsubr (&Skill_buffer);
5758 defsubr (&Sset_buffer_major_mode); 5965 defsubr (&Sset_buffer_major_mode);
5759 defsubr (&Sswitch_to_buffer); 5966 defsubr (&Sswitch_to_buffer);
5760 defsubr (&Spop_to_buffer); 5967 defsubr (&Spop_to_buffer);
5793 6000
5794 /* This must not be in syms_of_buffer, because Qdisabled is not 6001 /* This must not be in syms_of_buffer, because Qdisabled is not
5795 initialized when that function gets called. */ 6002 initialized when that function gets called. */
5796 Fput (intern ("erase-buffer"), Qdisabled, Qt); 6003 Fput (intern ("erase-buffer"), Qdisabled, Qt);
5797 } 6004 }
6005
6006 /* arch-tag: e48569bf-69a9-4b65-a23b-8e68769436e1
6007 (do not change this comment) */