aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorGerd Moellmann2000-03-26 14:07:30 +0000
committerGerd Moellmann2000-03-26 14:07:30 +0000
commit7c02e886dd1b89854a17c56edfc336eb67c792c9 (patch)
tree5a36e034d1123f3e2a9b29cdbc669e5851a6b2ec /src/buffer.c
parent4e4dfa78179f9e6d3375c7c0db235111d6137493 (diff)
downloademacs-7c02e886dd1b89854a17c56edfc336eb67c792c9.tar.gz
emacs-7c02e886dd1b89854a17c56edfc336eb67c792c9.zip
(buffer_permanent_local_flags): Make a char array.
(max_buffer_local_idx): New variable. (reset_buffer_local_variables, Fbuffer_local_variables): Rewritten for new handling of per-buffer variables. (buffer_slot_type_mismatch): Use new macros for per-buffer vars. (init_buffer_once): Initialize per-buffer vars differently. Set max_buffer_local_idx.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c151
1 files changed, 84 insertions, 67 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 878a81c47c7..268d8bb5519 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -73,8 +73,8 @@ static Lisp_Object Vbuffer_defaults;
73 The value has only one nonzero bit. 73 The value has only one nonzero bit.
74 74
75 When a buffer has its own local value for a slot, 75 When a buffer has its own local value for a slot,
76 the bit for that slot (found in the same slot in this structure) 76 the entry for that slot (found in the same slot in this structure)
77 is turned on in the buffer's local_var_flags slot. 77 is turned on in the buffer's local_flags array.
78 78
79 If a slot in this structure is -1, then even though there may 79 If a slot in this structure is -1, then even though there may
80 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it; 80 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
@@ -112,7 +112,11 @@ struct buffer buffer_local_types;
112 112
113/* Flags indicating which built-in buffer-local variables 113/* Flags indicating which built-in buffer-local variables
114 are permanent locals. */ 114 are permanent locals. */
115static int buffer_permanent_local_flags; 115static char buffer_permanent_local_flags[MAX_BUFFER_LOCAL_VARS];
116
117/* Number of per-buffer variables used. */
118
119int max_buffer_local_idx;
116 120
117Lisp_Object Fset_buffer (); 121Lisp_Object Fset_buffer ();
118void set_buffer_internal (); 122void set_buffer_internal ();
@@ -556,13 +560,7 @@ reset_buffer_local_variables (b, permanent_too)
556 int permanent_too; 560 int permanent_too;
557{ 561{
558 register int offset; 562 register int offset;
559 int dont_reset; 563 int i;
560
561 /* Decide which built-in local variables to reset. */
562 if (permanent_too)
563 dont_reset = 0;
564 else
565 dont_reset = buffer_permanent_local_flags;
566 564
567 /* Reset the major mode to Fundamental, together with all the 565 /* Reset the major mode to Fundamental, together with all the
568 things that depend on the major mode. 566 things that depend on the major mode.
@@ -597,22 +595,24 @@ reset_buffer_local_variables (b, permanent_too)
597 595
598 /* Reset all (or most) per-buffer variables to their defaults. */ 596 /* Reset all (or most) per-buffer variables to their defaults. */
599 b->local_var_alist = Qnil; 597 b->local_var_alist = Qnil;
600 b->local_var_flags &= dont_reset; 598 for (i = 0; i < max_buffer_local_idx; ++i)
599 if (permanent_too || buffer_permanent_local_flags[i] == 0)
600 SET_BUFFER_HAS_LOCAL_VALUE_P (b, i, 0);
601 601
602 /* For each slot that has a default value, 602 /* For each slot that has a default value,
603 copy that into the slot. */ 603 copy that into the slot. */
604 604
605 for (offset = (char *)&buffer_local_flags.name - (char *)&buffer_local_flags; 605 for (offset = BUFFER_LOCAL_VAR_OFFSET (name);
606 offset < sizeof (struct buffer); 606 offset < sizeof *b;
607 offset += sizeof (Lisp_Object)) /* sizeof EMACS_INT == sizeof Lisp_Object */ 607 offset += sizeof (Lisp_Object))
608 { 608 {
609 int flag = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)); 609 int idx = BUFFER_LOCAL_IDX (offset);
610 if ((flag > 0 610 if ((idx > 0
611 /* Don't reset a permanent local. */ 611 && (permanent_too
612 && ! (dont_reset & flag)) 612 || buffer_permanent_local_flags[idx] == 0))
613 || flag == -2) 613 /* Is -2 used anywhere? */
614 *(Lisp_Object *)(offset + (char *)b) 614 || idx == -2)
615 = *(Lisp_Object *)(offset + (char *)&buffer_defaults); 615 BUFFER_LOCAL_VALUE (b, offset) = BUFFER_LOCAL_DEFAULT_VALUE (offset);
616 } 616 }
617} 617}
618 618
@@ -757,20 +757,19 @@ No argument or nil as argument means use current buffer as BUFFER.")
757 757
758 /* Add on all the variables stored in special slots. */ 758 /* Add on all the variables stored in special slots. */
759 { 759 {
760 register int offset, mask; 760 int offset, idx;
761 761
762 for (offset = (char *)&buffer_local_symbols.name - (char *)&buffer_local_symbols; 762 for (offset = BUFFER_LOCAL_VAR_OFFSET (name);
763 offset < sizeof (struct buffer); 763 offset < sizeof (struct buffer);
764 offset += (sizeof (EMACS_INT))) /* sizeof EMACS_INT == sizeof Lisp_Object */ 764 /* sizeof EMACS_INT == sizeof Lisp_Object */
765 offset += (sizeof (EMACS_INT)))
765 { 766 {
766 mask = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)); 767 idx = BUFFER_LOCAL_IDX (offset);
767 if (mask == -1 || (buf->local_var_flags & mask)) 768 if ((idx == -1 || BUFFER_HAS_LOCAL_VALUE_P (buf, idx))
768 if (SYMBOLP (*(Lisp_Object *)(offset 769 && SYMBOLP (BUFFER_LOCAL_SYMBOL (offset)))
769 + (char *)&buffer_local_symbols))) 770 result = Fcons (Fcons (BUFFER_LOCAL_SYMBOL (offset),
770 result = Fcons (Fcons (*((Lisp_Object *) 771 BUFFER_LOCAL_VALUE (buf, offset)),
771 (offset + (char *)&buffer_local_symbols)), 772 result);
772 *(Lisp_Object *)(offset + (char *)buf)),
773 result);
774 } 773 }
775 } 774 }
776 775
@@ -3822,25 +3821,37 @@ buffer_slot_type_mismatch (offset)
3822{ 3821{
3823 Lisp_Object sym; 3822 Lisp_Object sym;
3824 char *type_name; 3823 char *type_name;
3825 sym = *(Lisp_Object *)(offset + (char *)&buffer_local_symbols); 3824
3826 switch (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_types))) 3825 switch (XINT (BUFFER_LOCAL_TYPE (offset)))
3827 { 3826 {
3828 case Lisp_Int: type_name = "integers"; break; 3827 case Lisp_Int:
3829 case Lisp_String: type_name = "strings"; break; 3828 type_name = "integers";
3830 case Lisp_Symbol: type_name = "symbols"; break; 3829 break;
3831 3830
3831 case Lisp_String:
3832 type_name = "strings";
3833 break;
3834
3835 case Lisp_Symbol:
3836 type_name = "symbols";
3837 break;
3838
3832 default: 3839 default:
3833 abort (); 3840 abort ();
3834 } 3841 }
3835 3842
3843 sym = BUFFER_LOCAL_SYMBOL (offset);
3836 error ("Only %s should be stored in the buffer-local variable %s", 3844 error ("Only %s should be stored in the buffer-local variable %s",
3837 type_name, XSYMBOL (sym)->name->data); 3845 type_name, XSYMBOL (sym)->name->data);
3838} 3846}
3847
3839 3848
3840void 3849void
3841init_buffer_once () 3850init_buffer_once ()
3842{ 3851{
3843 buffer_permanent_local_flags = 0; 3852 int idx;
3853
3854 bzero (buffer_permanent_local_flags, sizeof buffer_permanent_local_flags);
3844 3855
3845 /* Make sure all markable slots in buffer_defaults 3856 /* Make sure all markable slots in buffer_defaults
3846 are initialized reasonably, so mark_buffer won't choke. */ 3857 are initialized reasonably, so mark_buffer won't choke. */
@@ -3927,40 +3938,46 @@ init_buffer_once ()
3927 XSETINT (buffer_local_flags.display_time, -1); 3938 XSETINT (buffer_local_flags.display_time, -1);
3928 XSETINT (buffer_local_flags.enable_multibyte_characters, -1); 3939 XSETINT (buffer_local_flags.enable_multibyte_characters, -1);
3929 3940
3930 XSETFASTINT (buffer_local_flags.mode_line_format, 1); 3941 idx = 1;
3931 XSETFASTINT (buffer_local_flags.abbrev_mode, 2); 3942 XSETFASTINT (buffer_local_flags.mode_line_format, idx); ++idx;
3932 XSETFASTINT (buffer_local_flags.overwrite_mode, 4); 3943 XSETFASTINT (buffer_local_flags.abbrev_mode, idx); ++idx;
3933 XSETFASTINT (buffer_local_flags.case_fold_search, 8); 3944 XSETFASTINT (buffer_local_flags.overwrite_mode, idx); ++idx;
3934 XSETFASTINT (buffer_local_flags.auto_fill_function, 0x10); 3945 XSETFASTINT (buffer_local_flags.case_fold_search, idx); ++idx;
3935 XSETFASTINT (buffer_local_flags.selective_display, 0x20); 3946 XSETFASTINT (buffer_local_flags.auto_fill_function, idx); ++idx;
3947 XSETFASTINT (buffer_local_flags.selective_display, idx); ++idx;
3936#ifndef old 3948#ifndef old
3937 XSETFASTINT (buffer_local_flags.selective_display_ellipses, 0x40); 3949 XSETFASTINT (buffer_local_flags.selective_display_ellipses, idx); ++idx;
3938#endif 3950#endif
3939 XSETFASTINT (buffer_local_flags.tab_width, 0x80); 3951 XSETFASTINT (buffer_local_flags.tab_width, idx); ++idx;
3940 XSETFASTINT (buffer_local_flags.truncate_lines, 0x100); 3952 XSETFASTINT (buffer_local_flags.truncate_lines, idx); ++idx;
3941 XSETFASTINT (buffer_local_flags.ctl_arrow, 0x200); 3953 XSETFASTINT (buffer_local_flags.ctl_arrow, idx); ++idx;
3942 XSETFASTINT (buffer_local_flags.fill_column, 0x400); 3954 XSETFASTINT (buffer_local_flags.fill_column, idx); ++idx;
3943 XSETFASTINT (buffer_local_flags.left_margin, 0x800); 3955 XSETFASTINT (buffer_local_flags.left_margin, idx); ++idx;
3944 XSETFASTINT (buffer_local_flags.abbrev_table, 0x1000); 3956 XSETFASTINT (buffer_local_flags.abbrev_table, idx); ++idx;
3945 XSETFASTINT (buffer_local_flags.display_table, 0x2000); 3957 XSETFASTINT (buffer_local_flags.display_table, idx); ++idx;
3946#ifdef DOS_NT 3958#ifdef DOS_NT
3947 XSETFASTINT (buffer_local_flags.buffer_file_type, 0x4000); 3959 XSETFASTINT (buffer_local_flags.buffer_file_type, idx);
3948 /* Make this one a permanent local. */ 3960 /* Make this one a permanent local. */
3949 buffer_permanent_local_flags |= 0x4000; 3961 buffer_permanent_local_flags[idx++] = 1;
3950#endif 3962#endif
3951 XSETFASTINT (buffer_local_flags.syntax_table, 0x8000); 3963 XSETFASTINT (buffer_local_flags.syntax_table, idx); ++idx;
3952 XSETFASTINT (buffer_local_flags.cache_long_line_scans, 0x10000); 3964 XSETFASTINT (buffer_local_flags.cache_long_line_scans, idx); ++idx;
3953 XSETFASTINT (buffer_local_flags.category_table, 0x20000); 3965 XSETFASTINT (buffer_local_flags.category_table, idx); ++idx;
3954 XSETFASTINT (buffer_local_flags.direction_reversed, 0x40000); 3966 XSETFASTINT (buffer_local_flags.direction_reversed, idx); ++idx;
3955 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, 0x80000); 3967 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx);
3956 /* Make this one a permanent local. */ 3968 /* Make this one a permanent local. */
3957 buffer_permanent_local_flags |= 0x80000; 3969 buffer_permanent_local_flags[idx++] = 1;
3958 XSETFASTINT (buffer_local_flags.left_margin_width, 0x100000); 3970 XSETFASTINT (buffer_local_flags.left_margin_width, idx); ++idx;
3959 XSETFASTINT (buffer_local_flags.right_margin_width, 0x200000); 3971 XSETFASTINT (buffer_local_flags.right_margin_width, idx); ++idx;
3960 XSETFASTINT (buffer_local_flags.indicate_empty_lines, 0x400000); 3972 XSETFASTINT (buffer_local_flags.indicate_empty_lines, idx); ++idx;
3961 XSETFASTINT (buffer_local_flags.scroll_up_aggressively, 0x800000); 3973 XSETFASTINT (buffer_local_flags.scroll_up_aggressively, idx); ++idx;
3962 XSETFASTINT (buffer_local_flags.scroll_down_aggressively, 0x1000000); 3974 XSETFASTINT (buffer_local_flags.scroll_down_aggressively, idx); ++idx;
3963 XSETFASTINT (buffer_local_flags.header_line_format, 0x2000000); 3975 XSETFASTINT (buffer_local_flags.header_line_format, idx); ++idx;
3976
3977 /* Need more room? */
3978 if (idx >= MAX_BUFFER_LOCAL_VARS)
3979 abort ();
3980 max_buffer_local_idx = idx;
3964 3981
3965 Vbuffer_alist = Qnil; 3982 Vbuffer_alist = Qnil;
3966 current_buffer = 0; 3983 current_buffer = 0;