aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c221
1 files changed, 96 insertions, 125 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 0759ce1c43c..339bc99dcb1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -78,9 +78,6 @@ static Lisp_Object Vbuffer_defaults;
78 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it; 78 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
79 and the corresponding slot in buffer_defaults is not used. 79 and the corresponding slot in buffer_defaults is not used.
80 80
81 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
82 but there is a default value which is copied into each buffer.
83
84 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is 81 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
85 zero, that is a bug */ 82 zero, that is a bug */
86 83
@@ -94,6 +91,12 @@ DECL_ALIGN (struct buffer, buffer_local_symbols);
94/* A Lisp_Object pointer to the above, used for staticpro */ 91/* A Lisp_Object pointer to the above, used for staticpro */
95static Lisp_Object Vbuffer_local_symbols; 92static Lisp_Object Vbuffer_local_symbols;
96 93
94/* Return the symbol of the per-buffer variable at offset OFFSET in
95 the buffer structure. */
96
97#define PER_BUFFER_SYMBOL(OFFSET) \
98 (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_symbols))
99
97/* Flags indicating which built-in buffer-local variables 100/* Flags indicating which built-in buffer-local variables
98 are permanent locals. */ 101 are permanent locals. */
99static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS]; 102static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS];
@@ -507,7 +510,7 @@ clone_per_buffer_values (from, to)
507 continue; 510 continue;
508 511
509 obj = PER_BUFFER_VALUE (from, offset); 512 obj = PER_BUFFER_VALUE (from, offset);
510 if (MARKERP (obj)) 513 if (MARKERP (obj) && XMARKER (obj)->buffer == from)
511 { 514 {
512 struct Lisp_Marker *m = XMARKER (obj); 515 struct Lisp_Marker *m = XMARKER (obj);
513 obj = Fmake_marker (); 516 obj = Fmake_marker ();
@@ -770,9 +773,7 @@ reset_buffer_local_variables (b, permanent_too)
770 { 773 {
771 Lisp_Object tmp, prop, last = Qnil; 774 Lisp_Object tmp, prop, last = Qnil;
772 for (tmp = b->local_var_alist; CONSP (tmp); tmp = XCDR (tmp)) 775 for (tmp = b->local_var_alist; CONSP (tmp); tmp = XCDR (tmp))
773 if (CONSP (XCAR (tmp)) 776 if (!NILP (prop = Fget (XCAR (XCAR (tmp)), Qpermanent_local)))
774 && SYMBOLP (XCAR (XCAR (tmp)))
775 && !NILP (prop = Fget (XCAR (XCAR (tmp)), Qpermanent_local)))
776 { 777 {
777 /* If permanent-local, keep it. */ 778 /* If permanent-local, keep it. */
778 last = tmp; 779 last = tmp;
@@ -822,9 +823,7 @@ reset_buffer_local_variables (b, permanent_too)
822 int idx = PER_BUFFER_IDX (offset); 823 int idx = PER_BUFFER_IDX (offset);
823 if ((idx > 0 824 if ((idx > 0
824 && (permanent_too 825 && (permanent_too
825 || buffer_permanent_local_flags[idx] == 0)) 826 || buffer_permanent_local_flags[idx] == 0)))
826 /* Is -2 used anywhere? */
827 || idx == -2)
828 PER_BUFFER_VALUE (b, offset) = PER_BUFFER_DEFAULT (offset); 827 PER_BUFFER_VALUE (b, offset) = PER_BUFFER_DEFAULT (offset);
829 } 828 }
830} 829}
@@ -938,59 +937,49 @@ is the default binding of the variable. */)
938 CHECK_SYMBOL (variable); 937 CHECK_SYMBOL (variable);
939 CHECK_BUFFER (buffer); 938 CHECK_BUFFER (buffer);
940 buf = XBUFFER (buffer); 939 buf = XBUFFER (buffer);
940 sym = XSYMBOL (variable);
941 941
942 sym = indirect_variable (XSYMBOL (variable)); 942 start:
943 XSETSYMBOL (variable, sym); 943 switch (sym->redirect)
944
945 /* Look in local_var_list */
946 result = Fassoc (variable, buf->local_var_alist);
947 if (NILP (result))
948 { 944 {
949 int offset, idx; 945 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
950 int found = 0; 946 case SYMBOL_PLAINVAL: result = SYMBOL_VAL (sym); break;
951 947 case SYMBOL_LOCALIZED:
952 /* Look in special slots */ 948 { /* Look in local_var_alist. */
953 /* buffer-local Lisp variables start at `undo_list', 949 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
954 tho only the ones from `name' on are GC'd normally. */ 950 XSETSYMBOL (variable, sym); /* Update In case of aliasing. */
955 for (offset = PER_BUFFER_VAR_OFFSET (undo_list); 951 result = Fassoc (variable, buf->local_var_alist);
956 offset < sizeof (struct buffer); 952 if (!NILP (result))
957 /* sizeof EMACS_INT == sizeof Lisp_Object */ 953 {
958 offset += (sizeof (EMACS_INT))) 954 if (blv->fwd)
959 { 955 { /* What binding is loaded right now? */
960 idx = PER_BUFFER_IDX (offset); 956 Lisp_Object current_alist_element = blv->valcell;
961 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
962 && SYMBOLP (PER_BUFFER_SYMBOL (offset))
963 && EQ (PER_BUFFER_SYMBOL (offset), variable))
964 {
965 result = PER_BUFFER_VALUE (buf, offset);
966 found = 1;
967 break;
968 }
969 }
970
971 if (!found)
972 result = Fdefault_value (variable);
973 }
974 else
975 {
976 Lisp_Object valcontents;
977 Lisp_Object current_alist_element;
978
979 /* What binding is loaded right now? */
980 valcontents = sym->value;
981 current_alist_element
982 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
983
984 /* The value of the currently loaded binding is not
985 stored in it, but rather in the realvalue slot.
986 Store that value into the binding it belongs to
987 in case that is the one we are about to use. */
988 957
989 Fsetcdr (current_alist_element, 958 /* The value of the currently loaded binding is not
990 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); 959 stored in it, but rather in the realvalue slot.
960 Store that value into the binding it belongs to
961 in case that is the one we are about to use. */
991 962
992 /* Now get the (perhaps updated) value out of the binding. */ 963 XSETCDR (current_alist_element,
993 result = XCDR (result); 964 do_symval_forwarding (blv->fwd));
965 }
966 /* Now get the (perhaps updated) value out of the binding. */
967 result = XCDR (result);
968 }
969 else
970 result = Fdefault_value (variable);
971 break;
972 }
973 case SYMBOL_FORWARDED:
974 {
975 union Lisp_Fwd *fwd = SYMBOL_FWD (sym);
976 if (BUFFER_OBJFWDP (fwd))
977 result = PER_BUFFER_VALUE (buf, XBUFFER_OBJFWD (fwd)->offset);
978 else
979 result = Fdefault_value (variable);
980 break;
981 }
982 default: abort ();
994 } 983 }
995 984
996 if (!EQ (result, Qunbound)) 985 if (!EQ (result, Qunbound))
@@ -1025,12 +1014,7 @@ buffer_lisp_local_variables (buf)
1025 if (buf != current_buffer) 1014 if (buf != current_buffer)
1026 val = XCDR (elt); 1015 val = XCDR (elt);
1027 1016
1028 /* If symbol is unbound, put just the symbol in the list. */ 1017 result = Fcons (Fcons (XCAR (elt), val), result);
1029 if (EQ (val, Qunbound))
1030 result = Fcons (XCAR (elt), result);
1031 /* Otherwise, put (symbol . value) in the list. */
1032 else
1033 result = Fcons (Fcons (XCAR (elt), val), result);
1034 } 1018 }
1035 1019
1036 return result; 1020 return result;
@@ -1563,7 +1547,7 @@ with SIGHUP. */)
1563 Lisp_Object tem; 1547 Lisp_Object tem;
1564 tem = Fsymbol_value (intern ("delete-auto-save-files")); 1548 tem = Fsymbol_value (intern ("delete-auto-save-files"));
1565 if (! NILP (tem)) 1549 if (! NILP (tem))
1566 internal_delete_file (b->auto_save_file_name); 1550 internal_delete_file (b->auto_save_file_name, Qt);
1567 } 1551 }
1568 1552
1569 if (b->base_buffer) 1553 if (b->base_buffer)
@@ -1862,8 +1846,7 @@ set_buffer_internal_1 (b)
1862 register struct buffer *b; 1846 register struct buffer *b;
1863{ 1847{
1864 register struct buffer *old_buf; 1848 register struct buffer *old_buf;
1865 register Lisp_Object tail, valcontents; 1849 register Lisp_Object tail;
1866 Lisp_Object tem;
1867 1850
1868#ifdef USE_MMAP_FOR_BUFFERS 1851#ifdef USE_MMAP_FOR_BUFFERS
1869 if (b->text->beg == NULL) 1852 if (b->text->beg == NULL)
@@ -1935,34 +1918,21 @@ set_buffer_internal_1 (b)
1935 /* Look down buffer's list of local Lisp variables 1918 /* Look down buffer's list of local Lisp variables
1936 to find and update any that forward into C variables. */ 1919 to find and update any that forward into C variables. */
1937 1920
1938 for (tail = b->local_var_alist; CONSP (tail); tail = XCDR (tail)) 1921 do
1939 { 1922 {
1940 if (CONSP (XCAR (tail)) 1923 for (tail = b->local_var_alist; CONSP (tail); tail = XCDR (tail))
1941 && SYMBOLP (XCAR (XCAR (tail))) 1924 {
1942 && (valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))), 1925 Lisp_Object var = XCAR (XCAR (tail));
1943 (BUFFER_LOCAL_VALUEP (valcontents))) 1926 struct Lisp_Symbol *sym = XSYMBOL (var);
1944 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue, 1927 if (sym->redirect == SYMBOL_LOCALIZED /* Just to be sure. */
1945 (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem)))) 1928 && SYMBOL_BLV (sym)->fwd)
1946 /* Just reference the variable to cause it to become set for 1929 /* Just reference the variable
1947 this buffer. */ 1930 to cause it to become set for this buffer. */
1948 Fsymbol_value (XCAR (XCAR (tail))); 1931 Fsymbol_value (var);
1932 }
1949 } 1933 }
1950
1951 /* Do the same with any others that were local to the previous buffer */ 1934 /* Do the same with any others that were local to the previous buffer */
1952 1935 while (b != old_buf && (b = old_buf, b));
1953 if (old_buf)
1954 for (tail = old_buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
1955 {
1956 if (CONSP (tail)
1957 && SYMBOLP (XCAR (XCAR (tail)))
1958 && (valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))),
1959 (BUFFER_LOCAL_VALUEP (valcontents)))
1960 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1961 (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem))))
1962 /* Just reference the variable to cause it to become set for
1963 this buffer. */
1964 Fsymbol_value (XCAR (XCAR (tail)));
1965 }
1966} 1936}
1967 1937
1968/* Switch to buffer B temporarily for redisplay purposes. 1938/* Switch to buffer B temporarily for redisplay purposes.
@@ -2677,23 +2647,22 @@ static void
2677swap_out_buffer_local_variables (b) 2647swap_out_buffer_local_variables (b)
2678 struct buffer *b; 2648 struct buffer *b;
2679{ 2649{
2680 Lisp_Object oalist, alist, sym, buffer; 2650 Lisp_Object oalist, alist, buffer;
2681 2651
2682 XSETBUFFER (buffer, b); 2652 XSETBUFFER (buffer, b);
2683 oalist = b->local_var_alist; 2653 oalist = b->local_var_alist;
2684 2654
2685 for (alist = oalist; CONSP (alist); alist = XCDR (alist)) 2655 for (alist = oalist; CONSP (alist); alist = XCDR (alist))
2686 { 2656 {
2687 if (CONSP (XCAR (alist)) 2657 Lisp_Object sym = XCAR (XCAR (alist));
2688 && (sym = XCAR (XCAR (alist)), SYMBOLP (sym)) 2658 eassert (XSYMBOL (sym)->redirect == SYMBOL_LOCALIZED);
2689 /* Need not do anything if some other buffer's binding is 2659 /* Need not do anything if some other buffer's binding is
2690 now encached. */ 2660 now encached. */
2691 && EQ (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym))->buffer, 2661 if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer))
2692 buffer))
2693 { 2662 {
2694 /* Symbol is set up for this buffer's old local value: 2663 /* Symbol is set up for this buffer's old local value:
2695 swap it out! */ 2664 swap it out! */
2696 swap_in_global_binding (sym); 2665 swap_in_global_binding (XSYMBOL (sym));
2697 } 2666 }
2698 } 2667 }
2699} 2668}
@@ -5162,7 +5131,9 @@ init_buffer_once ()
5162 /* Make sure all markable slots in buffer_defaults 5131 /* Make sure all markable slots in buffer_defaults
5163 are initialized reasonably, so mark_buffer won't choke. */ 5132 are initialized reasonably, so mark_buffer won't choke. */
5164 reset_buffer (&buffer_defaults); 5133 reset_buffer (&buffer_defaults);
5134 eassert (EQ (buffer_defaults.name, make_number (0)));
5165 reset_buffer_local_variables (&buffer_defaults, 1); 5135 reset_buffer_local_variables (&buffer_defaults, 1);
5136 eassert (EQ (buffer_local_symbols.name, make_number (0)));
5166 reset_buffer (&buffer_local_symbols); 5137 reset_buffer (&buffer_local_symbols);
5167 reset_buffer_local_variables (&buffer_local_symbols, 1); 5138 reset_buffer_local_variables (&buffer_local_symbols, 1);
5168 /* Prevent GC from getting confused. */ 5139 /* Prevent GC from getting confused. */
@@ -5204,7 +5175,6 @@ init_buffer_once ()
5204 buffer_defaults.word_wrap = Qnil; 5175 buffer_defaults.word_wrap = Qnil;
5205 buffer_defaults.ctl_arrow = Qt; 5176 buffer_defaults.ctl_arrow = Qt;
5206 buffer_defaults.bidi_display_reordering = Qnil; 5177 buffer_defaults.bidi_display_reordering = Qnil;
5207 buffer_defaults.direction_reversed = Qnil;
5208 buffer_defaults.bidi_paragraph_direction = Qnil; 5178 buffer_defaults.bidi_paragraph_direction = Qnil;
5209 buffer_defaults.cursor_type = Qt; 5179 buffer_defaults.cursor_type = Qt;
5210 buffer_defaults.extra_line_spacing = Qnil; 5180 buffer_defaults.extra_line_spacing = Qnil;
@@ -5291,7 +5261,6 @@ init_buffer_once ()
5291 XSETFASTINT (buffer_local_flags.cache_long_line_scans, idx); ++idx; 5261 XSETFASTINT (buffer_local_flags.cache_long_line_scans, idx); ++idx;
5292 XSETFASTINT (buffer_local_flags.category_table, idx); ++idx; 5262 XSETFASTINT (buffer_local_flags.category_table, idx); ++idx;
5293 XSETFASTINT (buffer_local_flags.bidi_display_reordering, idx); ++idx; 5263 XSETFASTINT (buffer_local_flags.bidi_display_reordering, idx); ++idx;
5294 XSETFASTINT (buffer_local_flags.direction_reversed, idx); ++idx;
5295 XSETFASTINT (buffer_local_flags.bidi_paragraph_direction, idx); ++idx; 5264 XSETFASTINT (buffer_local_flags.bidi_paragraph_direction, idx); ++idx;
5296 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx); 5265 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx);
5297 /* Make this one a permanent local. */ 5266 /* Make this one a permanent local. */
@@ -5421,33 +5390,41 @@ init_buffer ()
5421 in the buffer that is current now. */ 5390 in the buffer that is current now. */
5422 5391
5423/* TYPE is nil for a general Lisp variable. 5392/* TYPE is nil for a general Lisp variable.
5424 An integer specifies a type; then only LIsp values 5393 An integer specifies a type; then only Lisp values
5425 with that type code are allowed (except that nil is allowed too). 5394 with that type code are allowed (except that nil is allowed too).
5426 LNAME is the LIsp-level variable name. 5395 LNAME is the Lisp-level variable name.
5427 VNAME is the name of the buffer slot. 5396 VNAME is the name of the buffer slot.
5428 DOC is a dummy where you write the doc string as a comment. */ 5397 DOC is a dummy where you write the doc string as a comment. */
5429#define DEFVAR_PER_BUFFER(lname, vname, type, doc) \ 5398#define DEFVAR_PER_BUFFER(lname, vname, type, doc) \
5430 defvar_per_buffer (lname, vname, type, 0) 5399 do { \
5400 static struct Lisp_Buffer_Objfwd bo_fwd; \
5401 defvar_per_buffer (&bo_fwd, lname, vname, type, 0); \
5402 } while (0)
5431 5403
5432static void 5404static void
5433defvar_per_buffer (namestring, address, type, doc) 5405defvar_per_buffer (bo_fwd, namestring, address, type, doc)
5406 struct Lisp_Buffer_Objfwd *bo_fwd;
5434 char *namestring; 5407 char *namestring;
5435 Lisp_Object *address; 5408 Lisp_Object *address;
5436 Lisp_Object type; 5409 Lisp_Object type;
5437 char *doc; 5410 char *doc;
5438{ 5411{
5439 Lisp_Object sym, val; 5412 struct Lisp_Symbol *sym;
5440 int offset; 5413 int offset;
5441 5414
5442 sym = intern (namestring); 5415 sym = XSYMBOL (intern (namestring));
5443 val = allocate_misc ();
5444 offset = (char *)address - (char *)current_buffer; 5416 offset = (char *)address - (char *)current_buffer;
5445 5417
5446 XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd; 5418 bo_fwd->type = Lisp_Fwd_Buffer_Obj;
5447 XBUFFER_OBJFWD (val)->offset = offset; 5419 bo_fwd->offset = offset;
5448 XBUFFER_OBJFWD (val)->slottype = type; 5420 bo_fwd->slottype = type;
5449 SET_SYMBOL_VALUE (sym, val); 5421 sym->redirect = SYMBOL_FORWARDED;
5450 PER_BUFFER_SYMBOL (offset) = sym; 5422 {
5423 /* I tried to do the job without a cast, but it seems impossible.
5424 union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */
5425 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *)bo_fwd);
5426 }
5427 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym);
5451 5428
5452 if (PER_BUFFER_IDX (offset) == 0) 5429 if (PER_BUFFER_IDX (offset) == 0)
5453 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding 5430 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
@@ -5805,25 +5782,19 @@ The variable `coding-system-for-write', if non-nil, overrides this variable.
5805 5782
5806This variable is never applied to a way of decoding a file while reading it. */); 5783This variable is never applied to a way of decoding a file while reading it. */);
5807 5784
5808 DEFVAR_PER_BUFFER ("direction-reversed",
5809 &current_buffer->direction_reversed, Qnil,
5810 doc: /* Non-nil means set beginning of lines at the right edge of the window.
5811See also the variable `bidi-display-reordering'. */);
5812
5813 DEFVAR_PER_BUFFER ("bidi-display-reordering", 5785 DEFVAR_PER_BUFFER ("bidi-display-reordering",
5814 &current_buffer->bidi_display_reordering, Qnil, 5786 &current_buffer->bidi_display_reordering, Qnil,
5815 doc: /* Non-nil means reorder bidirectional text for display in the visual order. 5787 doc: /* Non-nil means reorder bidirectional text for display in the visual order. */);
5816See also the variable `direction-reversed'. */);
5817 5788
5818 DEFVAR_PER_BUFFER ("bidi-paragraph-direction", 5789 DEFVAR_PER_BUFFER ("bidi-paragraph-direction",
5819 &current_buffer->bidi_paragraph_direction, Qnil, 5790 &current_buffer->bidi_paragraph_direction, Qnil,
5820 doc: /* *If non-nil, forces directionality of text paragraphs in the buffer. 5791 doc: /* *If non-nil, forces directionality of text paragraphs in the buffer.
5821 5792
5822If this is nil (the default), the direction of each paragraph is 5793If this is nil (the default), the direction of each paragraph is
5823determined by the first strong directional character of its text. 5794determined by the first strong directional character of its text.
5824The values of `right-to-left' and `left-to-right' override that. 5795The values of `right-to-left' and `left-to-right' override that.
5825Any other value is treated as nil. 5796Any other value is treated as nil.
5826 5797
5827This variable has no effect unless the buffer's value of 5798This variable has no effect unless the buffer's value of
5828\`bidi-display-reordering' is non-nil. */); 5799\`bidi-display-reordering' is non-nil. */);
5829 5800