aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorRichard M. Stallman2000-02-20 14:27:12 +0000
committerRichard M. Stallman2000-02-20 14:27:12 +0000
commit42e975f059a12ff057a204cae38750436452957d (patch)
treef5643df8acb3d986085337b56c83937f3b346180 /src/data.c
parentbe5bb1464fd84a906efc8007ba67b778de2bb20d (diff)
downloademacs-42e975f059a12ff057a204cae38750436452957d.tar.gz
emacs-42e975f059a12ff057a204cae38750436452957d.zip
(Fmake_variable_buffer_local): Doc fix.
Init found_for_buffer to 0. (Fmake_variable_frame_local): If the variable has already been buffer-local, set the check_frame field.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c148
1 files changed, 60 insertions, 88 deletions
diff --git a/src/data.c b/src/data.c
index a206c5c4994..b0a6a2ba9aa 100644
--- a/src/data.c
+++ b/src/data.c
@@ -823,39 +823,29 @@ store_symval_forwarding (symbol, valcontents, newval)
823} 823}
824 824
825/* Set up the buffer-local symbol SYMBOL for validity in the current buffer. 825/* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
826 VALCONTENTS is the contents of its value cell. 826 VALCONTENTS is the contents of its value cell,
827 Return the value forwarded one step past the buffer-local indicator. */ 827 which points to a struct Lisp_Buffer_Local_Value.
828
829 Return the value forwarded one step past the buffer-local stage.
830 This could be another forwarding pointer. */
828 831
829static Lisp_Object 832static Lisp_Object
830swap_in_symval_forwarding (symbol, valcontents) 833swap_in_symval_forwarding (symbol, valcontents)
831 Lisp_Object symbol, valcontents; 834 Lisp_Object symbol, valcontents;
832{ 835{
833 /* valcontents is a pointer to a struct resembling the cons
834 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
835
836 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
837 local_var_alist, that being the element whose car is this
838 variable. Or it can be a pointer to the
839 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
840 an element in its alist for this variable.
841
842 If the current buffer is not BUFFER, we store the current
843 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
844 appropriate alist element for the buffer now current and set up
845 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
846 element, and store into BUFFER.
847
848 Note that REALVALUE can be a forwarding pointer. */
849
850 register Lisp_Object tem1; 836 register Lisp_Object tem1;
851 tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer; 837 tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer;
852 838
853 if (NILP (tem1) || current_buffer != XBUFFER (tem1) 839 if (NILP (tem1)
854 || !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)) 840 || current_buffer != XBUFFER (tem1)
841 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
842 && ! EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)))
855 { 843 {
844 /* Unload the previously loaded binding. */
856 tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); 845 tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
857 Fsetcdr (tem1, 846 Fsetcdr (tem1,
858 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); 847 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
848 /* Choose the new binding. */
859 tem1 = assq_no_quit (symbol, current_buffer->local_var_alist); 849 tem1 = assq_no_quit (symbol, current_buffer->local_var_alist);
860 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0; 850 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
861 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; 851 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
@@ -871,6 +861,7 @@ swap_in_symval_forwarding (symbol, valcontents)
871 else 861 else
872 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1; 862 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
873 863
864 /* Load the new binding. */
874 XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = tem1; 865 XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = tem1;
875 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer); 866 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer);
876 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame; 867 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
@@ -1015,56 +1006,32 @@ set_internal (symbol, newval, buf, bindflag)
1015 else if (BUFFER_LOCAL_VALUEP (valcontents) 1006 else if (BUFFER_LOCAL_VALUEP (valcontents)
1016 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1007 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1017 { 1008 {
1018 /* valcontents is actually a pointer to a struct resembling a cons, 1009 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1019 with contents something like: 1010
1020 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE). 1011 /* What binding is loaded right now? */
1021
1022 BUFFER is the last buffer for which this symbol's value was
1023 made up to date.
1024
1025 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
1026 local_var_alist, that being the element whose car is this
1027 variable. Or it can be a pointer to the
1028 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
1029 have an element in its alist for this variable (that is, if
1030 BUFFER sees the default value of this variable).
1031
1032 If we want to examine or set the value and BUFFER is current,
1033 we just examine or set REALVALUE. If BUFFER is not current, we
1034 store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
1035 then find the appropriate alist element for the buffer now
1036 current and set up CURRENT-ALIST-ELEMENT. Then we set
1037 REALVALUE out of that element, and store into BUFFER.
1038
1039 If we are setting the variable and the current buffer does
1040 not have an alist entry for this variable, an alist entry is
1041 created.
1042
1043 Note that REALVALUE can be a forwarding pointer. Each time
1044 it is examined or set, forwarding must be done. */
1045
1046 /* What value are we caching right now? */
1047 current_alist_element 1012 current_alist_element
1048 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); 1013 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1049 1014
1050 /* If the current buffer is not the buffer whose binding is 1015 /* If the current buffer is not the buffer whose binding is
1051 currently cached, or if it's a Lisp_Buffer_Local_Value and 1016 loaded, or if there may be frame-local bindings and the frame
1052 we're looking at the default value, the cache is invalid; we 1017 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1053 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */ 1018 the default binding is loaded, the loaded binding may be the
1054 if (XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame 1019 wrong one. */
1055 ? !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame) 1020 if (buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
1056 : (buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer) 1021 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1057 || (BUFFER_LOCAL_VALUEP (valcontents) 1022 && !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame))
1058 && EQ (XCAR (current_alist_element), 1023 || (BUFFER_LOCAL_VALUEP (valcontents)
1059 current_alist_element)))) 1024 && EQ (XCAR (current_alist_element),
1025 current_alist_element)))
1060 { 1026 {
1061 /* Write out the cached value for the old buffer; copy it 1027 /* The currently loaded binding is not necessarily valid.
1062 back to its alist element. This works if the current 1028 We need to unload it, and choose a new binding. */
1063 buffer only sees the default value, too. */ 1029
1030 /* Write out `realvalue' to the old loaded binding. */
1064 Fsetcdr (current_alist_element, 1031 Fsetcdr (current_alist_element,
1065 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); 1032 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1066 1033
1067 /* Find the new value for CURRENT-ALIST-ELEMENT. */ 1034 /* Find the new binding. */
1068 tem1 = Fassq (symbol, buf->local_var_alist); 1035 tem1 = Fassq (symbol, buf->local_var_alist);
1069 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1; 1036 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
1070 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0; 1037 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
@@ -1097,7 +1064,7 @@ set_internal (symbol, newval, buf, bindflag)
1097 and we're not within a let that was made for this buffer, 1064 and we're not within a let that was made for this buffer,
1098 create a new buffer-local binding for the variable. 1065 create a new buffer-local binding for the variable.
1099 That means, give this buffer a new assoc for a local value 1066 That means, give this buffer a new assoc for a local value
1100 and set CURRENT-ALIST-ELEMENT to point to that. */ 1067 and load that binding. */
1101 else 1068 else
1102 { 1069 {
1103 tem1 = Fcons (symbol, Fcdr (current_alist_element)); 1070 tem1 = Fcons (symbol, Fcdr (current_alist_element));
@@ -1106,11 +1073,11 @@ set_internal (symbol, newval, buf, bindflag)
1106 } 1073 }
1107 } 1074 }
1108 1075
1109 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */ 1076 /* Record which binding is now loaded. */
1110 XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) 1077 XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr)
1111 = tem1; 1078 = tem1;
1112 1079
1113 /* Set BUFFER and FRAME for binding now loaded. */ 1080 /* Set `buffer' and `frame' slots for thebinding now loaded. */
1114 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, buf); 1081 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, buf);
1115 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame; 1082 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
1116 } 1083 }
@@ -1157,7 +1124,7 @@ default_value (symbol)
1157 { 1124 {
1158 /* If var is set up for a buffer that lacks a local value for it, 1125 /* If var is set up for a buffer that lacks a local value for it,
1159 the current value is nominally the default value. 1126 the current value is nominally the default value.
1160 But the current value slot may be more up to date, since 1127 But the `realvalue' slot may be more up to date, since
1161 ordinary setq stores just that slot. So use that. */ 1128 ordinary setq stores just that slot. So use that. */
1162 Lisp_Object current_alist_element, alist_element_car; 1129 Lisp_Object current_alist_element, alist_element_car;
1163 current_alist_element 1130 current_alist_element
@@ -1240,10 +1207,10 @@ for this variable.")
1240 && !SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1207 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
1241 return Fset (symbol, value); 1208 return Fset (symbol, value);
1242 1209
1243 /* Store new value into the DEFAULT-VALUE slot */ 1210 /* Store new value into the DEFAULT-VALUE slot. */
1244 XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = value; 1211 XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = value;
1245 1212
1246 /* If that slot is current, we must set the REALVALUE slot too */ 1213 /* If the default binding is now loaded, set the REALVALUE slot too. */
1247 current_alist_element 1214 current_alist_element
1248 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); 1215 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1249 alist_element_buffer = Fcar (current_alist_element); 1216 alist_element_buffer = Fcar (current_alist_element);
@@ -1296,12 +1263,14 @@ of previous SYMs.")
1296 1263
1297DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local, 1264DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1298 1, 1, "vMake Variable Buffer Local: ", 1265 1, 1, "vMake Variable Buffer Local: ",
1299 "Make VARIABLE have a separate value for each buffer.\n\ 1266 "Make VARIABLE become buffer-local whenever it is set.\n\
1300At any time, the value for the current buffer is in effect.\n\ 1267At any time, the value for the current buffer is in effect,\n\
1301There is also a default value which is seen in any buffer which has not yet\n\ 1268unless the variable has never been set in this buffer,\n\
1302set its own value.\n\ 1269in which case the default value is in effect.\n\
1303Using `set' or `setq' to set the variable causes it to have a separate value\n\ 1270Note that binding the variable with `let', or setting it while\n\
1304for the current buffer if it was previously using the default value.\n\ 1271a `let'-style binding made in this buffer is in effect,\n\
1272does not make the variable buffer-local.\n\
1273\n\
1305The function `default-value' gets the default value and `set-default' sets it.") 1274The function `default-value' gets the default value and `set-default' sets it.")
1306 (variable) 1275 (variable)
1307 register Lisp_Object variable; 1276 register Lisp_Object variable;
@@ -1330,7 +1299,7 @@ The function `default-value' gets the default value and `set-default' sets it.")
1330 XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value; 1299 XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
1331 XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer (); 1300 XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer ();
1332 XBUFFER_LOCAL_VALUE (newval)->frame = Qnil; 1301 XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
1333 XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 1; 1302 XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
1334 XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0; 1303 XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
1335 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0; 1304 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1336 XBUFFER_LOCAL_VALUE (newval)->cdr = tem; 1305 XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
@@ -1376,7 +1345,7 @@ Use `make-local-hook' instead.")
1376 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound)); 1345 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1377 return variable; 1346 return variable;
1378 } 1347 }
1379 /* Make sure symbol is set up to hold per-buffer values */ 1348 /* Make sure symbol is set up to hold per-buffer values. */
1380 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1349 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents))
1381 { 1350 {
1382 Lisp_Object newval; 1351 Lisp_Object newval;
@@ -1393,7 +1362,7 @@ Use `make-local-hook' instead.")
1393 XBUFFER_LOCAL_VALUE (newval)->cdr = tem; 1362 XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
1394 XSYMBOL (variable)->value = newval; 1363 XSYMBOL (variable)->value = newval;
1395 } 1364 }
1396 /* Make sure this buffer has its own value of symbol */ 1365 /* Make sure this buffer has its own value of symbol. */
1397 tem = Fassq (variable, current_buffer->local_var_alist); 1366 tem = Fassq (variable, current_buffer->local_var_alist);
1398 if (NILP (tem)) 1367 if (NILP (tem))
1399 { 1368 {
@@ -1407,7 +1376,7 @@ Use `make-local-hook' instead.")
1407 current_buffer->local_var_alist); 1376 current_buffer->local_var_alist);
1408 1377
1409 /* Make sure symbol does not think it is set up for this buffer; 1378 /* Make sure symbol does not think it is set up for this buffer;
1410 force it to look once again for this buffer's value */ 1379 force it to look once again for this buffer's value. */
1411 { 1380 {
1412 Lisp_Object *pvalbuf; 1381 Lisp_Object *pvalbuf;
1413 1382
@@ -1420,10 +1389,10 @@ Use `make-local-hook' instead.")
1420 } 1389 }
1421 } 1390 }
1422 1391
1423 /* If the symbol forwards into a C variable, then swap in the 1392 /* If the symbol forwards into a C variable, then load the binding
1424 variable for this buffer immediately. If C code modifies the 1393 for this buffer now. If C code modifies the variable before we
1425 variable before we swap in, then that new value will clobber the 1394 load the binding in, then that new value will clobber the default
1426 default value the next time we swap. */ 1395 binding the next time we unload it. */
1427 valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->realvalue; 1396 valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->realvalue;
1428 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents)) 1397 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
1429 swap_in_symval_forwarding (variable, XSYMBOL (variable)->value); 1398 swap_in_symval_forwarding (variable, XSYMBOL (variable)->value);
@@ -1463,16 +1432,16 @@ From now on the default value will apply in this buffer.")
1463 && !SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1432 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
1464 return variable; 1433 return variable;
1465 1434
1466 /* Get rid of this buffer's alist element, if any */ 1435 /* Get rid of this buffer's alist element, if any. */
1467 1436
1468 tem = Fassq (variable, current_buffer->local_var_alist); 1437 tem = Fassq (variable, current_buffer->local_var_alist);
1469 if (!NILP (tem)) 1438 if (!NILP (tem))
1470 current_buffer->local_var_alist 1439 current_buffer->local_var_alist
1471 = Fdelq (tem, current_buffer->local_var_alist); 1440 = Fdelq (tem, current_buffer->local_var_alist);
1472 1441
1473 /* If the symbol is set up for the current buffer, recompute its 1442 /* If the symbol is set up with the current buffer's binding
1474 value. We have to do it now, or else forwarded objects won't 1443 loaded, recompute its value. We have to do it now, or else
1475 work right. */ 1444 forwarded objects won't work right. */
1476 { 1445 {
1477 Lisp_Object *pvalbuf; 1446 Lisp_Object *pvalbuf;
1478 valcontents = XSYMBOL (variable)->value; 1447 valcontents = XSYMBOL (variable)->value;
@@ -1513,7 +1482,10 @@ See `modify-frame-parameters'.")
1513 1482
1514 if (BUFFER_LOCAL_VALUEP (valcontents) 1483 if (BUFFER_LOCAL_VALUEP (valcontents)
1515 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1484 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1516 return variable; 1485 {
1486 XBUFFER_LOCAL_VALUE (valcontents)->check_frame = 1;
1487 return variable;
1488 }
1517 1489
1518 if (EQ (valcontents, Qunbound)) 1490 if (EQ (valcontents, Qunbound))
1519 XSYMBOL (variable)->value = Qnil; 1491 XSYMBOL (variable)->value = Qnil;