Mercurial > hg > xemacs-beta
annotate src/symbols.c @ 5117:3742ea8250b5 ben-lisp-object ben-lisp-object-final-ws-year-2005
Checking in final CVS version of workspace 'ben-lisp-object'
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 26 Dec 2009 00:20:27 -0600 |
parents | b7f26b2f78bd |
children | e0db3c197671 |
rev | line source |
---|---|
428 | 1 /* "intern" and friends -- moved here from lread.c and data.c |
2 Copyright (C) 1985-1989, 1992-1994 Free Software Foundation, Inc. | |
793 | 3 Copyright (C) 1995, 2000, 2001, 2002 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: FSF 19.30. */ | |
23 | |
24 /* This file has been Mule-ized. */ | |
25 | |
26 /* NOTE: | |
27 | |
28 The value cell of a symbol can contain a simple value or one of | |
29 various symbol-value-magic objects. Some of these objects can | |
30 chain into other kinds of objects. Here is a table of possibilities: | |
31 | |
32 1a) simple value | |
33 1b) Qunbound | |
34 1c) symbol-value-forward, excluding Qunbound | |
35 2) symbol-value-buffer-local -> 1a or 1b or 1c | |
36 3) symbol-value-lisp-magic -> 1a or 1b or 1c | |
37 4) symbol-value-lisp-magic -> symbol-value-buffer-local -> 1a or 1b or 1c | |
38 5) symbol-value-varalias | |
39 6) symbol-value-lisp-magic -> symbol-value-varalias | |
40 | |
41 The "chain" of a symbol-value-buffer-local is its current_value slot. | |
42 | |
43 The "chain" of a symbol-value-lisp-magic is its shadowed slot, which | |
44 applies for handler types without associated handlers. | |
45 | |
46 All other fields in all the structures (including the "shadowed" slot | |
47 in a symbol-value-varalias) can *only* contain a simple value or Qunbound. | |
48 | |
49 */ | |
50 | |
51 /* #### Ugh, though, this file does awful things with symbol-value-magic | |
52 objects. This ought to be cleaned up. */ | |
53 | |
54 #include <config.h> | |
55 #include "lisp.h" | |
56 | |
57 #include "buffer.h" /* for Vbuffer_defaults */ | |
872 | 58 #include "console-impl.h" |
428 | 59 #include "elhash.h" |
60 | |
61 Lisp_Object Qad_advice_info, Qad_activate; | |
62 | |
63 Lisp_Object Qget_value, Qset_value, Qbound_predicate, Qmake_unbound; | |
64 Lisp_Object Qlocal_predicate, Qmake_local; | |
65 | |
66 Lisp_Object Qboundp, Qglobally_boundp, Qmakunbound; | |
67 Lisp_Object Qsymbol_value, Qset, Qdefault_boundp, Qdefault_value; | |
68 Lisp_Object Qset_default, Qsetq_default; | |
69 Lisp_Object Qmake_variable_buffer_local, Qmake_local_variable; | |
70 Lisp_Object Qkill_local_variable, Qkill_console_local_variable; | |
71 Lisp_Object Qsymbol_value_in_buffer, Qsymbol_value_in_console; | |
72 Lisp_Object Qlocal_variable_p; | |
73 | |
74 Lisp_Object Qconst_integer, Qconst_boolean, Qconst_object; | |
75 Lisp_Object Qconst_specifier; | |
76 Lisp_Object Qdefault_buffer, Qcurrent_buffer, Qconst_current_buffer; | |
77 Lisp_Object Qdefault_console, Qselected_console, Qconst_selected_console; | |
78 | |
79 static Lisp_Object maybe_call_magic_handler (Lisp_Object sym, | |
80 Lisp_Object funsym, | |
81 int nargs, ...); | |
82 static Lisp_Object fetch_value_maybe_past_magic (Lisp_Object sym, | |
83 Lisp_Object follow_past_lisp_magic); | |
84 static Lisp_Object *value_slot_past_magic (Lisp_Object sym); | |
85 static Lisp_Object follow_varalias_pointers (Lisp_Object symbol, | |
86 Lisp_Object follow_past_lisp_magic); | |
87 | |
88 | |
89 static Lisp_Object | |
90 mark_symbol (Lisp_Object obj) | |
91 { | |
440 | 92 Lisp_Symbol *sym = XSYMBOL (obj); |
428 | 93 |
94 mark_object (sym->value); | |
95 mark_object (sym->function); | |
793 | 96 mark_object (sym->name); |
428 | 97 if (!symbol_next (sym)) |
98 return sym->plist; | |
99 else | |
100 { | |
101 mark_object (sym->plist); | |
102 /* Mark the rest of the symbols in the obarray hash-chain */ | |
103 sym = symbol_next (sym); | |
793 | 104 return wrap_symbol (sym); |
428 | 105 } |
106 } | |
107 | |
1204 | 108 static const struct memory_description symbol_description[] = { |
440 | 109 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, next) }, |
110 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, name) }, | |
111 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, value) }, | |
112 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, function) }, | |
113 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, plist) }, | |
428 | 114 { XD_END } |
115 }; | |
116 | |
442 | 117 /* Symbol plists are directly accessible, so we need to protect against |
118 invalid property list structure */ | |
119 | |
120 static Lisp_Object | |
121 symbol_getprop (Lisp_Object symbol, Lisp_Object property) | |
122 { | |
123 return external_plist_get (&XSYMBOL (symbol)->plist, property, 0, ERROR_ME); | |
124 } | |
125 | |
126 static int | |
127 symbol_putprop (Lisp_Object symbol, Lisp_Object property, Lisp_Object value) | |
128 { | |
129 external_plist_put (&XSYMBOL (symbol)->plist, property, value, 0, ERROR_ME); | |
130 return 1; | |
131 } | |
132 | |
133 static int | |
134 symbol_remprop (Lisp_Object symbol, Lisp_Object property) | |
135 { | |
136 return external_remprop (&XSYMBOL (symbol)->plist, property, 0, ERROR_ME); | |
137 } | |
138 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
139 DEFINE_BASIC_LISP_OBJECT_WITH_PROPS ("symbol", symbol, |
934 | 140 mark_symbol, print_symbol, |
141 0, 0, 0, symbol_description, | |
142 symbol_getprop, | |
143 symbol_putprop, | |
144 symbol_remprop, | |
145 Fsymbol_plist, | |
146 Lisp_Symbol); | |
428 | 147 |
148 /**********************************************************************/ | |
149 /* Intern */ | |
150 /**********************************************************************/ | |
151 | |
152 /* #### using a vector here is way bogus. Use a hash table instead. */ | |
153 | |
154 Lisp_Object Vobarray; | |
155 | |
156 static Lisp_Object initial_obarray; | |
157 | |
158 /* oblookup stores the bucket number here, for the sake of Funintern. */ | |
159 | |
160 static int oblookup_last_bucket_number; | |
161 | |
162 static Lisp_Object | |
163 check_obarray (Lisp_Object obarray) | |
164 { | |
165 while (!VECTORP (obarray) || XVECTOR_LENGTH (obarray) == 0) | |
166 { | |
167 /* If Vobarray is now invalid, force it to be valid. */ | |
168 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; | |
169 | |
170 obarray = wrong_type_argument (Qvectorp, obarray); | |
171 } | |
172 return obarray; | |
173 } | |
174 | |
175 Lisp_Object | |
867 | 176 intern_int (const Ibyte *str) |
428 | 177 { |
771 | 178 Bytecount len = qxestrlen (str); |
428 | 179 Lisp_Object obarray = Vobarray; |
180 | |
181 if (!VECTORP (obarray) || XVECTOR_LENGTH (obarray) == 0) | |
182 obarray = check_obarray (obarray); | |
183 | |
184 { | |
771 | 185 Lisp_Object tem = oblookup (obarray, str, len); |
428 | 186 if (SYMBOLP (tem)) |
187 return tem; | |
188 } | |
189 | |
771 | 190 return Fintern (make_string (str, len), obarray); |
191 } | |
192 | |
193 Lisp_Object | |
867 | 194 intern (const CIbyte *str) |
771 | 195 { |
867 | 196 return intern_int ((Ibyte *) str); |
428 | 197 } |
198 | |
814 | 199 Lisp_Object |
867 | 200 intern_converting_underscores_to_dashes (const CIbyte *str) |
814 | 201 { |
202 Bytecount len = strlen (str); | |
867 | 203 CIbyte *tmp = alloca_extbytes (len + 1); |
814 | 204 Bytecount i; |
205 strcpy (tmp, str); | |
206 for (i = 0; i < len; i++) | |
207 if (tmp[i] == '_') | |
208 tmp[i] = '-'; | |
867 | 209 return intern_int ((Ibyte *) tmp); |
814 | 210 } |
211 | |
428 | 212 DEFUN ("intern", Fintern, 1, 2, 0, /* |
213 Return the canonical symbol whose name is STRING. | |
214 If there is none, one is created by this function and returned. | |
444 | 215 Optional second argument OBARRAY specifies the obarray to use; |
216 it defaults to the value of the variable `obarray'. | |
428 | 217 */ |
218 (string, obarray)) | |
219 { | |
220 Lisp_Object object, *ptr; | |
793 | 221 Lisp_Object symbol; |
428 | 222 Bytecount len; |
223 | |
224 if (NILP (obarray)) obarray = Vobarray; | |
225 obarray = check_obarray (obarray); | |
226 | |
227 CHECK_STRING (string); | |
228 | |
229 len = XSTRING_LENGTH (string); | |
230 object = oblookup (obarray, XSTRING_DATA (string), len); | |
231 if (!INTP (object)) | |
232 /* Found it */ | |
233 return object; | |
234 | |
235 ptr = &XVECTOR_DATA (obarray)[XINT (object)]; | |
236 | |
237 object = Fmake_symbol (string); | |
793 | 238 symbol = object; |
428 | 239 |
240 if (SYMBOLP (*ptr)) | |
793 | 241 XSYMBOL_NEXT (symbol) = XSYMBOL (*ptr); |
428 | 242 else |
793 | 243 XSYMBOL_NEXT (symbol) = 0; |
428 | 244 *ptr = object; |
245 | |
826 | 246 if (string_byte (XSYMBOL_NAME (symbol), 0) == ':' && EQ (obarray, Vobarray)) |
428 | 247 { |
248 /* The LISP way is to put keywords in their own package, but we | |
249 don't have packages, so we do something simpler. Someday, | |
250 maybe we'll have packages and then this will be reworked. | |
251 --Stig. */ | |
793 | 252 XSYMBOL_VALUE (symbol) = object; |
428 | 253 } |
254 | |
255 return object; | |
256 } | |
257 | |
258 DEFUN ("intern-soft", Fintern_soft, 1, 2, 0, /* | |
259 Return the canonical symbol named NAME, or nil if none exists. | |
260 NAME may be a string or a symbol. If it is a symbol, that exact | |
261 symbol is searched for. | |
444 | 262 Optional second argument OBARRAY specifies the obarray to use; |
263 it defaults to the value of the variable `obarray'. | |
428 | 264 */ |
265 (name, obarray)) | |
266 { | |
267 /* #### Bug! (intern-soft "nil") returns nil. Perhaps we should | |
268 add a DEFAULT-IF-NOT-FOUND arg, like in get. */ | |
269 Lisp_Object tem; | |
793 | 270 Lisp_Object string; |
428 | 271 |
272 if (NILP (obarray)) obarray = Vobarray; | |
273 obarray = check_obarray (obarray); | |
274 | |
275 if (!SYMBOLP (name)) | |
276 { | |
277 CHECK_STRING (name); | |
793 | 278 string = name; |
428 | 279 } |
280 else | |
281 string = symbol_name (XSYMBOL (name)); | |
282 | |
793 | 283 tem = oblookup (obarray, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
428 | 284 if (INTP (tem) || (SYMBOLP (name) && !EQ (name, tem))) |
285 return Qnil; | |
286 else | |
287 return tem; | |
288 } | |
289 | |
290 DEFUN ("unintern", Funintern, 1, 2, 0, /* | |
291 Delete the symbol named NAME, if any, from OBARRAY. | |
292 The value is t if a symbol was found and deleted, nil otherwise. | |
293 NAME may be a string or a symbol. If it is a symbol, that symbol | |
294 is deleted, if it belongs to OBARRAY--no other symbol is deleted. | |
444 | 295 OBARRAY defaults to the value of the variable `obarray'. |
428 | 296 */ |
297 (name, obarray)) | |
298 { | |
299 Lisp_Object tem; | |
793 | 300 Lisp_Object string; |
428 | 301 int hash; |
302 | |
303 if (NILP (obarray)) obarray = Vobarray; | |
304 obarray = check_obarray (obarray); | |
305 | |
306 if (SYMBOLP (name)) | |
307 string = symbol_name (XSYMBOL (name)); | |
308 else | |
309 { | |
310 CHECK_STRING (name); | |
793 | 311 string = name; |
428 | 312 } |
313 | |
793 | 314 tem = oblookup (obarray, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
428 | 315 if (INTP (tem)) |
316 return Qnil; | |
317 /* If arg was a symbol, don't delete anything but that symbol itself. */ | |
318 if (SYMBOLP (name) && !EQ (name, tem)) | |
319 return Qnil; | |
320 | |
321 hash = oblookup_last_bucket_number; | |
322 | |
323 if (EQ (XVECTOR_DATA (obarray)[hash], tem)) | |
324 { | |
325 if (XSYMBOL (tem)->next) | |
793 | 326 XVECTOR_DATA (obarray)[hash] = wrap_symbol (XSYMBOL (tem)->next); |
428 | 327 else |
328 XVECTOR_DATA (obarray)[hash] = Qzero; | |
329 } | |
330 else | |
331 { | |
332 Lisp_Object tail, following; | |
333 | |
334 for (tail = XVECTOR_DATA (obarray)[hash]; | |
335 XSYMBOL (tail)->next; | |
336 tail = following) | |
337 { | |
793 | 338 following = wrap_symbol (XSYMBOL (tail)->next); |
428 | 339 if (EQ (following, tem)) |
340 { | |
341 XSYMBOL (tail)->next = XSYMBOL (following)->next; | |
342 break; | |
343 } | |
344 } | |
345 } | |
346 return Qt; | |
347 } | |
348 | |
349 /* Return the symbol in OBARRAY whose names matches the string | |
350 of SIZE characters at PTR. If there is no such symbol in OBARRAY, | |
351 return the index into OBARRAY that the string hashes to. | |
352 | |
353 Also store the bucket number in oblookup_last_bucket_number. */ | |
354 | |
355 Lisp_Object | |
867 | 356 oblookup (Lisp_Object obarray, const Ibyte *ptr, Bytecount size) |
428 | 357 { |
490 | 358 unsigned int hash, obsize; |
440 | 359 Lisp_Symbol *tail; |
428 | 360 Lisp_Object bucket; |
361 | |
362 if (!VECTORP (obarray) || | |
363 (obsize = XVECTOR_LENGTH (obarray)) == 0) | |
364 { | |
365 obarray = check_obarray (obarray); | |
366 obsize = XVECTOR_LENGTH (obarray); | |
367 } | |
368 hash = hash_string (ptr, size) % obsize; | |
369 oblookup_last_bucket_number = hash; | |
370 bucket = XVECTOR_DATA (obarray)[hash]; | |
371 if (ZEROP (bucket)) | |
372 ; | |
373 else if (!SYMBOLP (bucket)) | |
563 | 374 signal_error (Qinvalid_state, "Bad data in guts of obarray", Qunbound); /* Like CADR error message */ |
428 | 375 else |
376 for (tail = XSYMBOL (bucket); ;) | |
377 { | |
793 | 378 if (XSTRING_LENGTH (tail->name) == size && |
379 !memcmp (XSTRING_DATA (tail->name), ptr, size)) | |
428 | 380 { |
793 | 381 return wrap_symbol (tail); |
428 | 382 } |
383 tail = symbol_next (tail); | |
384 if (!tail) | |
385 break; | |
386 } | |
387 return make_int (hash); | |
388 } | |
389 | |
490 | 390 /* An excellent string hashing function. |
391 Adapted from glib's g_str_hash(). | |
392 Investigation by Karl Nelson <kenelson@ece.ucdavis.edu>. | |
393 Do a web search for "g_str_hash X31_HASH" if you want to know more. */ | |
394 unsigned int | |
867 | 395 hash_string (const Ibyte *ptr, Bytecount len) |
428 | 396 { |
490 | 397 unsigned int hash; |
398 | |
399 for (hash = 0; len; len--, ptr++) | |
400 /* (31 * hash) will probably be optimized to ((hash << 5) - hash). */ | |
401 hash = 31 * hash + *ptr; | |
402 | |
403 return hash; | |
428 | 404 } |
405 | |
406 /* Map FN over OBARRAY. The mapping is stopped when FN returns a | |
407 non-zero value. */ | |
408 void | |
409 map_obarray (Lisp_Object obarray, | |
410 int (*fn) (Lisp_Object, void *), void *arg) | |
411 { | |
412 REGISTER int i; | |
413 | |
414 CHECK_VECTOR (obarray); | |
415 for (i = XVECTOR_LENGTH (obarray) - 1; i >= 0; i--) | |
416 { | |
417 Lisp_Object tail = XVECTOR_DATA (obarray)[i]; | |
418 if (SYMBOLP (tail)) | |
419 while (1) | |
420 { | |
440 | 421 Lisp_Symbol *next; |
428 | 422 if ((*fn) (tail, arg)) |
423 return; | |
424 next = symbol_next (XSYMBOL (tail)); | |
425 if (!next) | |
426 break; | |
793 | 427 tail = wrap_symbol (next); |
428 | 428 } |
429 } | |
430 } | |
431 | |
432 static int | |
433 mapatoms_1 (Lisp_Object sym, void *arg) | |
434 { | |
435 call1 (*(Lisp_Object *)arg, sym); | |
436 return 0; | |
437 } | |
438 | |
439 DEFUN ("mapatoms", Fmapatoms, 1, 2, 0, /* | |
440 Call FUNCTION on every symbol in OBARRAY. | |
441 OBARRAY defaults to the value of `obarray'. | |
442 */ | |
443 (function, obarray)) | |
444 { | |
442 | 445 struct gcpro gcpro1; |
446 | |
428 | 447 if (NILP (obarray)) |
448 obarray = Vobarray; | |
449 obarray = check_obarray (obarray); | |
450 | |
442 | 451 GCPRO1 (obarray); |
428 | 452 map_obarray (obarray, mapatoms_1, &function); |
442 | 453 UNGCPRO; |
428 | 454 return Qnil; |
455 } | |
456 | |
457 | |
458 /**********************************************************************/ | |
459 /* Apropos */ | |
460 /**********************************************************************/ | |
461 | |
462 struct appropos_mapper_closure | |
463 { | |
464 Lisp_Object regexp; | |
465 Lisp_Object predicate; | |
466 Lisp_Object accumulation; | |
467 }; | |
468 | |
469 static int | |
470 apropos_mapper (Lisp_Object symbol, void *arg) | |
471 { | |
472 struct appropos_mapper_closure *closure = | |
473 (struct appropos_mapper_closure *) arg; | |
474 Bytecount match = fast_lisp_string_match (closure->regexp, | |
475 Fsymbol_name (symbol)); | |
476 | |
477 if (match >= 0 && | |
478 (NILP (closure->predicate) || | |
479 !NILP (call1 (closure->predicate, symbol)))) | |
480 closure->accumulation = Fcons (symbol, closure->accumulation); | |
481 | |
482 return 0; | |
483 } | |
484 | |
485 DEFUN ("apropos-internal", Fapropos_internal, 1, 2, 0, /* | |
444 | 486 Return a list of all symbols whose names contain match for REGEXP. |
487 If optional 2nd arg PREDICATE is non-nil, only symbols for which | |
488 \(funcall PREDICATE SYMBOL) returns non-nil are returned. | |
428 | 489 */ |
490 (regexp, predicate)) | |
491 { | |
492 struct appropos_mapper_closure closure; | |
442 | 493 struct gcpro gcpro1; |
428 | 494 |
495 CHECK_STRING (regexp); | |
496 | |
497 closure.regexp = regexp; | |
498 closure.predicate = predicate; | |
499 closure.accumulation = Qnil; | |
442 | 500 GCPRO1 (closure.accumulation); |
428 | 501 map_obarray (Vobarray, apropos_mapper, &closure); |
502 closure.accumulation = Fsort (closure.accumulation, Qstring_lessp); | |
442 | 503 UNGCPRO; |
428 | 504 return closure.accumulation; |
505 } | |
506 | |
507 | |
508 /* Extract and set components of symbols */ | |
509 | |
510 static void set_up_buffer_local_cache (Lisp_Object sym, | |
511 struct symbol_value_buffer_local *bfwd, | |
512 struct buffer *buf, | |
513 Lisp_Object new_alist_el, | |
514 int set_it_p); | |
515 | |
516 DEFUN ("boundp", Fboundp, 1, 1, 0, /* | |
517 Return t if SYMBOL's value is not void. | |
518 */ | |
519 (symbol)) | |
520 { | |
521 CHECK_SYMBOL (symbol); | |
522 return UNBOUNDP (find_symbol_value (symbol)) ? Qnil : Qt; | |
523 } | |
524 | |
525 DEFUN ("globally-boundp", Fglobally_boundp, 1, 1, 0, /* | |
526 Return t if SYMBOL has a global (non-bound) value. | |
527 This is for the byte-compiler; you really shouldn't be using this. | |
528 */ | |
529 (symbol)) | |
530 { | |
531 CHECK_SYMBOL (symbol); | |
532 return UNBOUNDP (top_level_value (symbol)) ? Qnil : Qt; | |
533 } | |
534 | |
535 DEFUN ("fboundp", Ffboundp, 1, 1, 0, /* | |
536 Return t if SYMBOL's function definition is not void. | |
537 */ | |
538 (symbol)) | |
539 { | |
540 CHECK_SYMBOL (symbol); | |
541 return UNBOUNDP (XSYMBOL (symbol)->function) ? Qnil : Qt; | |
542 } | |
543 | |
544 /* Return non-zero if SYM's value or function (the current contents of | |
545 which should be passed in as VAL) is constant, i.e. unsettable. */ | |
546 | |
547 static int | |
548 symbol_is_constant (Lisp_Object sym, Lisp_Object val) | |
549 { | |
550 /* #### - I wonder if it would be better to just have a new magic value | |
551 type and make nil, t, and all keywords have that same magic | |
552 constant_symbol value. This test is awfully specific about what is | |
553 constant and what isn't. --Stig */ | |
554 if (EQ (sym, Qnil) || | |
555 EQ (sym, Qt)) | |
556 return 1; | |
557 | |
558 if (SYMBOL_VALUE_MAGIC_P (val)) | |
559 switch (XSYMBOL_VALUE_MAGIC_TYPE (val)) | |
560 { | |
561 case SYMVAL_CONST_OBJECT_FORWARD: | |
562 case SYMVAL_CONST_SPECIFIER_FORWARD: | |
563 case SYMVAL_CONST_FIXNUM_FORWARD: | |
564 case SYMVAL_CONST_BOOLEAN_FORWARD: | |
565 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
566 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
567 return 1; | |
568 default: break; /* Warning suppression */ | |
569 } | |
570 | |
571 /* We don't return true for keywords here because they are handled | |
572 specially by reject_constant_symbols(). */ | |
573 return 0; | |
574 } | |
575 | |
576 /* We are setting SYM's value slot (or function slot, if FUNCTION_P is | |
577 non-zero) to NEWVAL. Make sure this is allowed. | |
578 FOLLOW_PAST_LISP_MAGIC specifies whether we delve past | |
579 symbol-value-lisp-magic objects. */ | |
580 | |
581 void | |
582 reject_constant_symbols (Lisp_Object sym, Lisp_Object newval, int function_p, | |
583 Lisp_Object follow_past_lisp_magic) | |
584 { | |
585 Lisp_Object val = | |
586 (function_p ? XSYMBOL (sym)->function | |
587 : fetch_value_maybe_past_magic (sym, follow_past_lisp_magic)); | |
588 | |
589 if (SYMBOL_VALUE_MAGIC_P (val) && | |
590 XSYMBOL_VALUE_MAGIC_TYPE (val) == SYMVAL_CONST_SPECIFIER_FORWARD) | |
563 | 591 invalid_change ("Use `set-specifier' to change a specifier's value", |
592 sym); | |
428 | 593 |
996 | 594 if ( |
595 #ifdef HAVE_SHLIB | |
596 !(unloading_module && UNBOUNDP(newval)) && | |
597 #endif | |
598 (symbol_is_constant (sym, val) | |
599 || (SYMBOL_IS_KEYWORD (sym) && !EQ (newval, sym)))) | |
563 | 600 signal_error_1 (Qsetting_constant, |
601 UNBOUNDP (newval) ? list1 (sym) : list2 (sym, newval)); | |
428 | 602 } |
603 | |
604 /* Verify that it's ok to make SYM buffer-local. This rejects | |
605 constants and default-buffer-local variables. FOLLOW_PAST_LISP_MAGIC | |
606 specifies whether we delve into symbol-value-lisp-magic objects. | |
607 (Should be a symbol indicating what action is being taken; that way, | |
608 we don't delve if there's a handler for that action, but do otherwise.) */ | |
609 | |
610 static void | |
611 verify_ok_for_buffer_local (Lisp_Object sym, | |
612 Lisp_Object follow_past_lisp_magic) | |
613 { | |
614 Lisp_Object val = fetch_value_maybe_past_magic (sym, follow_past_lisp_magic); | |
615 | |
616 if (symbol_is_constant (sym, val)) | |
617 goto not_ok; | |
618 if (SYMBOL_VALUE_MAGIC_P (val)) | |
619 switch (XSYMBOL_VALUE_MAGIC_TYPE (val)) | |
620 { | |
621 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
622 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
623 /* #### It's theoretically possible for it to be reasonable | |
624 to have both console-local and buffer-local variables, | |
625 but I don't want to consider that right now. */ | |
626 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
627 goto not_ok; | |
628 default: break; /* Warning suppression */ | |
629 } | |
630 | |
631 return; | |
632 | |
633 not_ok: | |
563 | 634 invalid_change ("Symbol may not be buffer-local", sym); |
428 | 635 } |
636 | |
637 DEFUN ("makunbound", Fmakunbound, 1, 1, 0, /* | |
638 Make SYMBOL's value be void. | |
639 */ | |
640 (symbol)) | |
641 { | |
642 Fset (symbol, Qunbound); | |
643 return symbol; | |
644 } | |
645 | |
646 DEFUN ("fmakunbound", Ffmakunbound, 1, 1, 0, /* | |
647 Make SYMBOL's function definition be void. | |
648 */ | |
649 (symbol)) | |
650 { | |
651 CHECK_SYMBOL (symbol); | |
652 reject_constant_symbols (symbol, Qunbound, 1, Qt); | |
653 XSYMBOL (symbol)->function = Qunbound; | |
654 return symbol; | |
655 } | |
656 | |
657 DEFUN ("symbol-function", Fsymbol_function, 1, 1, 0, /* | |
658 Return SYMBOL's function definition. Error if that is void. | |
659 */ | |
660 (symbol)) | |
661 { | |
662 CHECK_SYMBOL (symbol); | |
663 if (UNBOUNDP (XSYMBOL (symbol)->function)) | |
664 signal_void_function_error (symbol); | |
665 return XSYMBOL (symbol)->function; | |
666 } | |
667 | |
668 DEFUN ("symbol-plist", Fsymbol_plist, 1, 1, 0, /* | |
669 Return SYMBOL's property list. | |
670 */ | |
671 (symbol)) | |
672 { | |
673 CHECK_SYMBOL (symbol); | |
674 return XSYMBOL (symbol)->plist; | |
675 } | |
676 | |
677 DEFUN ("symbol-name", Fsymbol_name, 1, 1, 0, /* | |
678 Return SYMBOL's name, a string. | |
679 */ | |
680 (symbol)) | |
681 { | |
682 CHECK_SYMBOL (symbol); | |
793 | 683 return XSYMBOL (symbol)->name; |
428 | 684 } |
685 | |
686 DEFUN ("fset", Ffset, 2, 2, 0, /* | |
687 Set SYMBOL's function definition to NEWDEF, and return NEWDEF. | |
688 */ | |
689 (symbol, newdef)) | |
690 { | |
691 /* This function can GC */ | |
692 CHECK_SYMBOL (symbol); | |
693 reject_constant_symbols (symbol, newdef, 1, Qt); | |
694 if (!NILP (Vautoload_queue) && !UNBOUNDP (XSYMBOL (symbol)->function)) | |
695 Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function), | |
696 Vautoload_queue); | |
697 XSYMBOL (symbol)->function = newdef; | |
698 /* Handle automatic advice activation */ | |
699 if (CONSP (XSYMBOL (symbol)->plist) && | |
700 !NILP (Fget (symbol, Qad_advice_info, Qnil))) | |
701 { | |
702 call2 (Qad_activate, symbol, Qnil); | |
703 newdef = XSYMBOL (symbol)->function; | |
704 } | |
705 return newdef; | |
706 } | |
707 | |
708 /* FSFmacs */ | |
709 DEFUN ("define-function", Fdefine_function, 2, 2, 0, /* | |
710 Set SYMBOL's function definition to NEWDEF, and return NEWDEF. | |
711 Associates the function with the current load file, if any. | |
712 */ | |
713 (symbol, newdef)) | |
714 { | |
715 /* This function can GC */ | |
716 Ffset (symbol, newdef); | |
717 LOADHIST_ATTACH (symbol); | |
718 return newdef; | |
719 } | |
720 | |
721 | |
722 DEFUN ("setplist", Fsetplist, 2, 2, 0, /* | |
723 Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. | |
724 */ | |
725 (symbol, newplist)) | |
726 { | |
727 CHECK_SYMBOL (symbol); | |
728 | |
729 XSYMBOL (symbol)->plist = newplist; | |
730 return newplist; | |
731 } | |
732 | |
733 | |
734 /**********************************************************************/ | |
735 /* symbol-value */ | |
736 /**********************************************************************/ | |
737 | |
738 /* If the contents of the value cell of a symbol is one of the following | |
739 three types of objects, then the symbol is "magic" in that setting | |
740 and retrieving its value doesn't just set or retrieve the raw | |
741 contents of the value cell. None of these objects can escape to | |
742 the user level, so there is no loss of generality. | |
743 | |
744 If a symbol is "unbound", then the contents of its value cell is | |
745 Qunbound. Despite appearances, this is *not* a symbol, but is a | |
746 symbol-value-forward object. This is so that printing it results | |
747 in "INTERNAL OBJECT (XEmacs bug?)", in case it leaks to Lisp, somehow. | |
748 | |
749 Logically all of the following objects are "symbol-value-magic" | |
750 objects, and there are some games played w.r.t. this (#### this | |
751 should be cleaned up). SYMBOL_VALUE_MAGIC_P is true for all of | |
752 the object types. XSYMBOL_VALUE_MAGIC_TYPE returns the type of | |
753 symbol-value-magic object. There are more than three types | |
754 returned by this macro: in particular, symbol-value-forward | |
755 has eight subtypes, and symbol-value-buffer-local has two. See | |
756 symeval.h. | |
757 | |
758 1. symbol-value-forward | |
759 | |
760 symbol-value-forward is used for variables whose actual contents | |
761 are stored in a C variable of some sort, and for Qunbound. The | |
762 lcheader.next field (which is only used to chain together free | |
763 lcrecords) holds a pointer to the actual C variable. Included | |
764 in this type are "buffer-local" variables that are actually | |
765 stored in the buffer object itself; in this case, the "pointer" | |
766 is an offset into the struct buffer structure. | |
767 | |
768 The subtypes are as follows: | |
769 | |
770 SYMVAL_OBJECT_FORWARD: | |
771 (declare with DEFVAR_LISP) | |
772 The value of this variable is stored in a C variable of type | |
773 "Lisp_Object". Setting this variable sets the C variable. | |
774 Accessing this variable retrieves a value from the C variable. | |
775 These variables can be buffer-local -- in this case, the | |
776 raw symbol-value field gets converted into a | |
777 symbol-value-buffer-local, whose "current_value" slot contains | |
778 the symbol-value-forward. (See below.) | |
779 | |
780 SYMVAL_FIXNUM_FORWARD: | |
458 | 781 (declare with DEFVAR_INT) |
782 Similar to SYMVAL_OBJECT_FORWARD except that the C variable | |
783 is of type "Fixnum", a typedef for "EMACS_INT", and the corresponding | |
784 lisp variable is always the corresponding integer. | |
785 | |
428 | 786 SYMVAL_BOOLEAN_FORWARD: |
458 | 787 (declare with DEFVAR_BOOL) |
428 | 788 Similar to SYMVAL_OBJECT_FORWARD except that the C variable |
458 | 789 is of type "int" and is a boolean. |
428 | 790 |
791 SYMVAL_CONST_OBJECT_FORWARD: | |
792 SYMVAL_CONST_FIXNUM_FORWARD: | |
793 SYMVAL_CONST_BOOLEAN_FORWARD: | |
794 (declare with DEFVAR_CONST_LISP, DEFVAR_CONST_INT, or | |
795 DEFVAR_CONST_BOOL) | |
796 Similar to SYMVAL_OBJECT_FORWARD, SYMVAL_FIXNUM_FORWARD, or | |
797 SYMVAL_BOOLEAN_FORWARD, respectively, except that the value cannot | |
798 be changed. | |
799 | |
800 SYMVAL_CONST_SPECIFIER_FORWARD: | |
801 (declare with DEFVAR_SPECIFIER) | |
440 | 802 Exactly like SYMVAL_CONST_OBJECT_FORWARD except that the error |
803 message you get when attempting to set the value says to use | |
428 | 804 `set-specifier' instead. |
805 | |
806 SYMVAL_CURRENT_BUFFER_FORWARD: | |
807 (declare with DEFVAR_BUFFER_LOCAL) | |
808 This is used for built-in buffer-local variables -- i.e. | |
809 Lisp variables whose value is stored in the "struct buffer". | |
810 Variables of this sort always forward into C "Lisp_Object" | |
811 fields (although there's no reason in principle that other | |
812 types for ints and booleans couldn't be added). Note that | |
813 some of these variables are automatically local in each | |
814 buffer, while some are only local when they become set | |
815 (similar to `make-variable-buffer-local'). In these latter | |
816 cases, of course, the default value shows through in all | |
817 buffers in which the variable doesn't have a local value. | |
818 This is implemented by making sure the "struct buffer" field | |
819 always contains the correct value (whether it's local or | |
820 a default) and maintaining a mask in the "struct buffer" | |
821 indicating which fields are local. When `set-default' is | |
822 called on a variable that's not always local to all buffers, | |
823 it loops through each buffer and sets the corresponding | |
824 field in each buffer without a local value for the field, | |
825 according to the mask. | |
826 | |
827 Calling `make-local-variable' on a variable of this sort | |
828 only has the effect of maybe changing the current buffer's mask. | |
829 Calling `make-variable-buffer-local' on a variable of this | |
830 sort has no effect at all. | |
831 | |
832 SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
833 (declare with DEFVAR_CONST_BUFFER_LOCAL) | |
834 Same as SYMVAL_CURRENT_BUFFER_FORWARD except that the | |
835 value cannot be set. | |
836 | |
837 SYMVAL_DEFAULT_BUFFER_FORWARD: | |
838 (declare with DEFVAR_BUFFER_DEFAULTS) | |
839 This is used for the Lisp variables that contain the | |
840 default values of built-in buffer-local variables. Setting | |
841 or referencing one of these variables forwards into a slot | |
842 in the special struct buffer Vbuffer_defaults. | |
843 | |
844 SYMVAL_UNBOUND_MARKER: | |
845 This is used for only one object, Qunbound. | |
846 | |
847 SYMVAL_SELECTED_CONSOLE_FORWARD: | |
848 (declare with DEFVAR_CONSOLE_LOCAL) | |
849 This is used for built-in console-local variables -- i.e. | |
850 Lisp variables whose value is stored in the "struct console". | |
851 These work just like built-in buffer-local variables. | |
852 However, calling `make-local-variable' or | |
853 `make-variable-buffer-local' on one of these variables | |
854 is currently disallowed because that would entail having | |
855 both console-local and buffer-local variables, which is | |
856 trickier to implement. | |
857 | |
858 SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
859 (declare with DEFVAR_CONST_CONSOLE_LOCAL) | |
860 Same as SYMVAL_SELECTED_CONSOLE_FORWARD except that the | |
861 value cannot be set. | |
862 | |
863 SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
864 (declare with DEFVAR_CONSOLE_DEFAULTS) | |
865 This is used for the Lisp variables that contain the | |
866 default values of built-in console-local variables. Setting | |
867 or referencing one of these variables forwards into a slot | |
868 in the special struct console Vconsole_defaults. | |
869 | |
870 | |
871 2. symbol-value-buffer-local | |
872 | |
873 symbol-value-buffer-local is used for variables that have had | |
874 `make-local-variable' or `make-variable-buffer-local' applied | |
875 to them. This object contains an alist mapping buffers to | |
876 values. In addition, the object contains a "current value", | |
877 which is the value in some buffer. Whenever you access the | |
878 variable with `symbol-value' or set it with `set' or `setq', | |
879 things are switched around so that the "current value" | |
880 refers to the current buffer, if it wasn't already. This | |
881 way, repeated references to a variable in the same buffer | |
882 are almost as efficient as if the variable weren't buffer | |
883 local. Note that the alist may not be up-to-date w.r.t. | |
884 the buffer whose value is current, as the "current value" | |
885 cache is normally only flushed into the alist when the | |
886 buffer it refers to changes. | |
887 | |
888 Note also that it is possible for `make-local-variable' | |
889 or `make-variable-buffer-local' to be called on a variable | |
890 that forwards into a C variable (i.e. a variable whose | |
891 value cell is a symbol-value-forward). In this case, | |
892 the value cell becomes a symbol-value-buffer-local (as | |
893 always), and the symbol-value-forward moves into | |
894 the "current value" cell in this object. Also, in | |
895 this case the "current value" *always* refers to the | |
896 current buffer, so that the values of the C variable | |
897 always is the correct value for the current buffer. | |
898 set_buffer_internal() automatically updates the current-value | |
899 cells of all buffer-local variables that forward into C | |
900 variables. (There is a list of all buffer-local variables | |
901 that is maintained for this and other purposes.) | |
902 | |
903 Note that only certain types of `symbol-value-forward' objects | |
904 can find their way into the "current value" cell of a | |
905 `symbol-value-buffer-local' object: SYMVAL_OBJECT_FORWARD, | |
906 SYMVAL_FIXNUM_FORWARD, SYMVAL_BOOLEAN_FORWARD, and | |
907 SYMVAL_UNBOUND_MARKER. The SYMVAL_CONST_*_FORWARD cannot | |
908 be buffer-local because they are unsettable; | |
909 SYMVAL_DEFAULT_*_FORWARD cannot be buffer-local because that | |
910 makes no sense; making SYMVAL_CURRENT_BUFFER_FORWARD buffer-local | |
911 does not have much of an effect (it's already buffer-local); and | |
912 SYMVAL_SELECTED_CONSOLE_FORWARD cannot be buffer-local because | |
913 that's not currently implemented. | |
914 | |
915 | |
916 3. symbol-value-varalias | |
917 | |
918 A symbol-value-varalias object is used for variables that | |
919 are aliases for other variables. This object contains | |
920 the symbol that this variable is aliased to. | |
921 symbol-value-varalias objects cannot occur anywhere within | |
922 a symbol-value-buffer-local object, and most of the | |
923 low-level functions below do not accept them; you need | |
924 to call follow_varalias_pointers to get the actual | |
925 symbol to operate on. */ | |
926 | |
1204 | 927 static const struct memory_description symbol_value_buffer_local_description[] = { |
928 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, default_value) }, | |
929 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_value) }, | |
930 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_buffer) }, | |
931 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_alist_element) }, | |
932 { XD_END } | |
933 }; | |
934 | |
428 | 935 static Lisp_Object |
936 mark_symbol_value_buffer_local (Lisp_Object obj) | |
937 { | |
938 struct symbol_value_buffer_local *bfwd; | |
939 | |
800 | 940 #ifdef ERROR_CHECK_TYPES |
428 | 941 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_BUFFER_LOCAL || |
942 XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_SOME_BUFFER_LOCAL); | |
943 #endif | |
944 | |
945 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (obj); | |
946 mark_object (bfwd->default_value); | |
947 mark_object (bfwd->current_value); | |
948 mark_object (bfwd->current_buffer); | |
949 return bfwd->current_alist_element; | |
950 } | |
951 | |
1204 | 952 |
953 static const struct memory_description symbol_value_lisp_magic_description[] = { | |
954 { XD_LISP_OBJECT_ARRAY, offsetof (struct symbol_value_lisp_magic, handler), MAGIC_HANDLER_MAX }, | |
955 { XD_LISP_OBJECT_ARRAY, offsetof (struct symbol_value_lisp_magic, harg), MAGIC_HANDLER_MAX }, | |
956 { XD_LISP_OBJECT, offsetof (struct symbol_value_lisp_magic, shadowed) }, | |
957 { XD_END } | |
958 }; | |
959 | |
428 | 960 static Lisp_Object |
961 mark_symbol_value_lisp_magic (Lisp_Object obj) | |
962 { | |
963 struct symbol_value_lisp_magic *bfwd; | |
964 int i; | |
965 | |
966 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_LISP_MAGIC); | |
967 | |
968 bfwd = XSYMBOL_VALUE_LISP_MAGIC (obj); | |
969 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
970 { | |
971 mark_object (bfwd->handler[i]); | |
972 mark_object (bfwd->harg[i]); | |
973 } | |
974 return bfwd->shadowed; | |
975 } | |
976 | |
1204 | 977 static const struct memory_description symbol_value_varalias_description[] = { |
978 { XD_LISP_OBJECT, offsetof (struct symbol_value_varalias, aliasee) }, | |
979 { XD_LISP_OBJECT, offsetof (struct symbol_value_varalias, shadowed) }, | |
980 { XD_END } | |
981 }; | |
982 | |
428 | 983 static Lisp_Object |
984 mark_symbol_value_varalias (Lisp_Object obj) | |
985 { | |
986 struct symbol_value_varalias *bfwd; | |
987 | |
988 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_VARALIAS); | |
989 | |
990 bfwd = XSYMBOL_VALUE_VARALIAS (obj); | |
991 mark_object (bfwd->shadowed); | |
992 return bfwd->aliasee; | |
993 } | |
994 | |
995 /* Should never, ever be called. (except by an external debugger) */ | |
996 void | |
2286 | 997 print_symbol_value_magic (Lisp_Object obj, Lisp_Object printcharfun, |
998 int UNUSED (escapeflag)) | |
428 | 999 { |
800 | 1000 write_fmt_string (printcharfun, |
1001 "#<INTERNAL OBJECT (XEmacs bug?) (%s type %d) 0x%lx>", | |
1002 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, | |
1003 XSYMBOL_VALUE_MAGIC_TYPE (obj), | |
1004 (long) XPNTR (obj)); | |
428 | 1005 } |
1006 | |
1204 | 1007 static const struct memory_description symbol_value_forward_description[] = { |
428 | 1008 { XD_END } |
1009 }; | |
1010 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1011 DEFINE_LISP_OBJECT ("symbol-value-forward", |
934 | 1012 symbol_value_forward, |
1013 0, | |
1014 print_symbol_value_magic, 0, 0, 0, | |
1015 symbol_value_forward_description, | |
1016 struct symbol_value_forward); | |
1017 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1018 DEFINE_LISP_OBJECT ("symbol-value-buffer-local", |
934 | 1019 symbol_value_buffer_local, |
1020 mark_symbol_value_buffer_local, | |
1021 print_symbol_value_magic, 0, 0, 0, | |
1022 symbol_value_buffer_local_description, | |
1023 struct symbol_value_buffer_local); | |
1024 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1025 DEFINE_LISP_OBJECT ("symbol-value-lisp-magic", |
934 | 1026 symbol_value_lisp_magic, |
1027 mark_symbol_value_lisp_magic, | |
1028 print_symbol_value_magic, 0, 0, 0, | |
1029 symbol_value_lisp_magic_description, | |
1030 struct symbol_value_lisp_magic); | |
1031 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1032 DEFINE_LISP_OBJECT ("symbol-value-varalias", |
934 | 1033 symbol_value_varalias, |
1034 mark_symbol_value_varalias, | |
1035 print_symbol_value_magic, 0, 0, 0, | |
1036 symbol_value_varalias_description, | |
1037 struct symbol_value_varalias); | |
1038 | |
428 | 1039 |
1040 /* Getting and setting values of symbols */ | |
1041 | |
1042 /* Given the raw contents of a symbol value cell, return the Lisp value of | |
1043 the symbol. However, VALCONTENTS cannot be a symbol-value-buffer-local, | |
1044 symbol-value-lisp-magic, or symbol-value-varalias. | |
1045 | |
1046 BUFFER specifies a buffer, and is used for built-in buffer-local | |
1047 variables, which are of type SYMVAL_CURRENT_BUFFER_FORWARD. | |
1048 Note that such variables are never encapsulated in a | |
1049 symbol-value-buffer-local structure. | |
1050 | |
1051 CONSOLE specifies a console, and is used for built-in console-local | |
1052 variables, which are of type SYMVAL_SELECTED_CONSOLE_FORWARD. | |
1053 Note that such variables are (currently) never encapsulated in a | |
1054 symbol-value-buffer-local structure. | |
1055 */ | |
1056 | |
1057 static Lisp_Object | |
1058 do_symval_forwarding (Lisp_Object valcontents, struct buffer *buffer, | |
1059 struct console *console) | |
1060 { | |
442 | 1061 const struct symbol_value_forward *fwd; |
428 | 1062 |
1063 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1064 return valcontents; | |
1065 | |
1066 fwd = XSYMBOL_VALUE_FORWARD (valcontents); | |
1067 switch (fwd->magic.type) | |
1068 { | |
1069 case SYMVAL_FIXNUM_FORWARD: | |
1070 case SYMVAL_CONST_FIXNUM_FORWARD: | |
458 | 1071 return make_int (*((Fixnum *)symbol_value_forward_forward (fwd))); |
428 | 1072 |
1073 case SYMVAL_BOOLEAN_FORWARD: | |
1074 case SYMVAL_CONST_BOOLEAN_FORWARD: | |
1075 return *((int *)symbol_value_forward_forward (fwd)) ? Qt : Qnil; | |
1076 | |
1077 case SYMVAL_OBJECT_FORWARD: | |
1078 case SYMVAL_CONST_OBJECT_FORWARD: | |
1079 case SYMVAL_CONST_SPECIFIER_FORWARD: | |
1080 return *((Lisp_Object *)symbol_value_forward_forward (fwd)); | |
1081 | |
1082 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
1083 return (*((Lisp_Object *)((char *) XBUFFER (Vbuffer_defaults) | |
1084 + ((char *)symbol_value_forward_forward (fwd) | |
1085 - (char *)&buffer_local_flags)))); | |
1086 | |
1087 | |
1088 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1089 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
1090 assert (buffer); | |
1091 return (*((Lisp_Object *)((char *)buffer | |
1092 + ((char *)symbol_value_forward_forward (fwd) | |
1093 - (char *)&buffer_local_flags)))); | |
1094 | |
1095 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1096 return (*((Lisp_Object *)((char *) XCONSOLE (Vconsole_defaults) | |
1097 + ((char *)symbol_value_forward_forward (fwd) | |
1098 - (char *)&console_local_flags)))); | |
1099 | |
1100 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1101 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
1102 assert (console); | |
1103 return (*((Lisp_Object *)((char *)console | |
1104 + ((char *)symbol_value_forward_forward (fwd) | |
1105 - (char *)&console_local_flags)))); | |
1106 | |
1107 case SYMVAL_UNBOUND_MARKER: | |
1108 return valcontents; | |
1109 | |
1110 default: | |
2500 | 1111 ABORT (); |
428 | 1112 } |
1113 return Qnil; /* suppress compiler warning */ | |
1114 } | |
1115 | |
1116 /* Set the value of default-buffer-local variable SYM to VALUE. */ | |
1117 | |
1118 static void | |
1119 set_default_buffer_slot_variable (Lisp_Object sym, | |
1120 Lisp_Object value) | |
1121 { | |
1122 /* Handle variables like case-fold-search that have special slots in | |
1123 the buffer. Make them work apparently like buffer_local variables. | |
1124 */ | |
1125 /* At this point, the value cell may not contain a symbol-value-varalias | |
1126 or symbol-value-buffer-local, and if there's a handler, we should | |
1127 have already called it. */ | |
1128 Lisp_Object valcontents = fetch_value_maybe_past_magic (sym, Qt); | |
442 | 1129 const struct symbol_value_forward *fwd |
428 | 1130 = XSYMBOL_VALUE_FORWARD (valcontents); |
1131 int offset = ((char *) symbol_value_forward_forward (fwd) | |
1132 - (char *) &buffer_local_flags); | |
1133 int mask = XINT (*((Lisp_Object *) symbol_value_forward_forward (fwd))); | |
1134 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, Lisp_Object in_object, | |
1135 int flags) = symbol_value_forward_magicfun (fwd); | |
1136 | |
1137 *((Lisp_Object *) (offset + (char *) XBUFFER (Vbuffer_defaults))) | |
1138 = value; | |
1139 | |
1140 if (mask > 0) /* Not always per-buffer */ | |
1141 { | |
1142 /* Set value in each buffer which hasn't shadowed the default */ | |
1143 LIST_LOOP_2 (elt, Vbuffer_alist) | |
1144 { | |
1145 struct buffer *b = XBUFFER (XCDR (elt)); | |
1146 if (!(b->local_var_flags & mask)) | |
1147 { | |
1148 if (magicfun) | |
771 | 1149 magicfun (sym, &value, wrap_buffer (b), 0); |
428 | 1150 *((Lisp_Object *) (offset + (char *) b)) = value; |
1151 } | |
1152 } | |
1153 } | |
1154 } | |
1155 | |
1156 /* Set the value of default-console-local variable SYM to VALUE. */ | |
1157 | |
1158 static void | |
1159 set_default_console_slot_variable (Lisp_Object sym, | |
1160 Lisp_Object value) | |
1161 { | |
1162 /* Handle variables like case-fold-search that have special slots in | |
1163 the console. Make them work apparently like console_local variables. | |
1164 */ | |
1165 /* At this point, the value cell may not contain a symbol-value-varalias | |
1166 or symbol-value-buffer-local, and if there's a handler, we should | |
1167 have already called it. */ | |
1168 Lisp_Object valcontents = fetch_value_maybe_past_magic (sym, Qt); | |
442 | 1169 const struct symbol_value_forward *fwd |
428 | 1170 = XSYMBOL_VALUE_FORWARD (valcontents); |
1171 int offset = ((char *) symbol_value_forward_forward (fwd) | |
1172 - (char *) &console_local_flags); | |
1173 int mask = XINT (*((Lisp_Object *) symbol_value_forward_forward (fwd))); | |
1174 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, Lisp_Object in_object, | |
1175 int flags) = symbol_value_forward_magicfun (fwd); | |
1176 | |
1177 *((Lisp_Object *) (offset + (char *) XCONSOLE (Vconsole_defaults))) | |
1178 = value; | |
1179 | |
1180 if (mask > 0) /* Not always per-console */ | |
1181 { | |
1182 /* Set value in each console which hasn't shadowed the default */ | |
1183 LIST_LOOP_2 (console, Vconsole_list) | |
1184 { | |
1185 struct console *d = XCONSOLE (console); | |
1186 if (!(d->local_var_flags & mask)) | |
1187 { | |
1188 if (magicfun) | |
1189 magicfun (sym, &value, console, 0); | |
1190 *((Lisp_Object *) (offset + (char *) d)) = value; | |
1191 } | |
1192 } | |
1193 } | |
1194 } | |
1195 | |
1196 /* Store NEWVAL into SYM. | |
1197 | |
1198 SYM's value slot may *not* be types (5) or (6) above, | |
1199 i.e. no symbol-value-varalias objects. (You should have | |
1200 forwarded past all of these.) | |
1201 | |
1202 SYM should not be an unsettable symbol or a symbol with | |
1203 a magic `set-value' handler (unless you want to explicitly | |
1204 ignore this handler). | |
1205 | |
1206 OVALUE is the current value of SYM, but forwarded past any | |
1207 symbol-value-buffer-local and symbol-value-lisp-magic objects. | |
1208 (i.e. if SYM is a symbol-value-buffer-local, OVALUE should be | |
1209 the contents of its current-value cell.) NEWVAL may only be | |
1210 a simple value or Qunbound. If SYM is a symbol-value-buffer-local, | |
1211 this function will only modify its current-value cell, which should | |
1212 already be set up to point to the current buffer. | |
1213 */ | |
1214 | |
1215 static void | |
1216 store_symval_forwarding (Lisp_Object sym, Lisp_Object ovalue, | |
1217 Lisp_Object newval) | |
1218 { | |
1219 if (!SYMBOL_VALUE_MAGIC_P (ovalue) || UNBOUNDP (ovalue)) | |
1220 { | |
1221 Lisp_Object *store_pointer = value_slot_past_magic (sym); | |
1222 | |
1223 if (SYMBOL_VALUE_BUFFER_LOCAL_P (*store_pointer)) | |
1224 store_pointer = | |
1225 &XSYMBOL_VALUE_BUFFER_LOCAL (*store_pointer)->current_value; | |
1226 | |
1227 assert (UNBOUNDP (*store_pointer) | |
1228 || !SYMBOL_VALUE_MAGIC_P (*store_pointer)); | |
1229 *store_pointer = newval; | |
1230 } | |
1231 else | |
1232 { | |
442 | 1233 const struct symbol_value_forward *fwd = XSYMBOL_VALUE_FORWARD (ovalue); |
428 | 1234 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, |
1235 Lisp_Object in_object, int flags) | |
1236 = symbol_value_forward_magicfun (fwd); | |
1237 | |
1238 switch (XSYMBOL_VALUE_MAGIC_TYPE (ovalue)) | |
1239 { | |
1240 case SYMVAL_FIXNUM_FORWARD: | |
1241 CHECK_INT (newval); | |
1242 if (magicfun) | |
1243 magicfun (sym, &newval, Qnil, 0); | |
458 | 1244 *((Fixnum *) symbol_value_forward_forward (fwd)) = XINT (newval); |
428 | 1245 return; |
1246 | |
1247 case SYMVAL_BOOLEAN_FORWARD: | |
1248 if (magicfun) | |
1249 magicfun (sym, &newval, Qnil, 0); | |
1250 *((int *) symbol_value_forward_forward (fwd)) | |
1251 = !NILP (newval); | |
1252 return; | |
1253 | |
1254 case SYMVAL_OBJECT_FORWARD: | |
1255 if (magicfun) | |
1256 magicfun (sym, &newval, Qnil, 0); | |
1257 *((Lisp_Object *) symbol_value_forward_forward (fwd)) = newval; | |
1258 return; | |
1259 | |
1260 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
1261 set_default_buffer_slot_variable (sym, newval); | |
1262 return; | |
1263 | |
1264 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1265 if (magicfun) | |
771 | 1266 magicfun (sym, &newval, wrap_buffer (current_buffer), 0); |
428 | 1267 *((Lisp_Object *) ((char *) current_buffer |
1268 + ((char *) symbol_value_forward_forward (fwd) | |
1269 - (char *) &buffer_local_flags))) | |
1270 = newval; | |
1271 return; | |
1272 | |
1273 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1274 set_default_console_slot_variable (sym, newval); | |
1275 return; | |
1276 | |
1277 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1278 if (magicfun) | |
1279 magicfun (sym, &newval, Vselected_console, 0); | |
1280 *((Lisp_Object *) ((char *) XCONSOLE (Vselected_console) | |
1281 + ((char *) symbol_value_forward_forward (fwd) | |
1282 - (char *) &console_local_flags))) | |
1283 = newval; | |
1284 return; | |
1285 | |
1286 default: | |
2500 | 1287 ABORT (); |
428 | 1288 } |
1289 } | |
1290 } | |
1291 | |
1292 /* Given a per-buffer variable SYMBOL and its raw value-cell contents | |
1293 BFWD, locate and return a pointer to the element in BUFFER's | |
1294 local_var_alist for SYMBOL. The return value will be Qnil if | |
1295 BUFFER does not have its own value for SYMBOL (i.e. the default | |
1296 value is seen in that buffer). | |
1297 */ | |
1298 | |
1299 static Lisp_Object | |
1300 buffer_local_alist_element (struct buffer *buffer, Lisp_Object symbol, | |
1301 struct symbol_value_buffer_local *bfwd) | |
1302 { | |
1303 if (!NILP (bfwd->current_buffer) && | |
1304 XBUFFER (bfwd->current_buffer) == buffer) | |
1305 /* This is just an optimization of the below. */ | |
1306 return bfwd->current_alist_element; | |
1307 else | |
1308 return assq_no_quit (symbol, buffer->local_var_alist); | |
1309 } | |
1310 | |
1311 /* [Remember that the slot that mirrors CURRENT-VALUE in the | |
1312 symbol-value-buffer-local of a per-buffer variable -- i.e. the | |
1313 slot in CURRENT-BUFFER's local_var_alist, or the DEFAULT-VALUE | |
1314 slot -- may be out of date.] | |
1315 | |
1316 Write out any cached value in buffer-local variable SYMBOL's | |
1317 buffer-local structure, which is passed in as BFWD. | |
1318 */ | |
1319 | |
1320 static void | |
2286 | 1321 write_out_buffer_local_cache (Lisp_Object UNUSED (symbol), |
428 | 1322 struct symbol_value_buffer_local *bfwd) |
1323 { | |
1324 if (!NILP (bfwd->current_buffer)) | |
1325 { | |
1326 /* We pass 0 for BUFFER because only SYMVAL_CURRENT_BUFFER_FORWARD | |
1327 uses it, and that type cannot be inside a symbol-value-buffer-local */ | |
1328 Lisp_Object cval = do_symval_forwarding (bfwd->current_value, 0, 0); | |
1329 if (NILP (bfwd->current_alist_element)) | |
1330 /* current_value may be updated more recently than default_value */ | |
1331 bfwd->default_value = cval; | |
1332 else | |
1333 Fsetcdr (bfwd->current_alist_element, cval); | |
1334 } | |
1335 } | |
1336 | |
1337 /* SYM is a buffer-local variable, and BFWD is its buffer-local structure. | |
1338 Set up BFWD's cache for validity in buffer BUF. This assumes that | |
1339 the cache is currently in a consistent state (this can include | |
1340 not having any value cached, if BFWD->CURRENT_BUFFER is nil). | |
1341 | |
1342 If the cache is already set up for BUF, this function does nothing | |
1343 at all. | |
1344 | |
1345 Otherwise, if SYM forwards out to a C variable, this also forwards | |
1346 SYM's value in BUF out to the variable. Therefore, you generally | |
1347 only want to call this when BUF is, or is about to become, the | |
1348 current buffer. | |
1349 | |
1350 (Otherwise, you can just retrieve the value without changing the | |
1351 cache, at the expense of slower retrieval.) | |
1352 */ | |
1353 | |
1354 static void | |
1355 set_up_buffer_local_cache (Lisp_Object sym, | |
1356 struct symbol_value_buffer_local *bfwd, | |
1357 struct buffer *buf, | |
1358 Lisp_Object new_alist_el, | |
1359 int set_it_p) | |
1360 { | |
1361 Lisp_Object new_val; | |
1362 | |
1363 if (!NILP (bfwd->current_buffer) | |
1364 && buf == XBUFFER (bfwd->current_buffer)) | |
1365 /* Cache is already set up. */ | |
1366 return; | |
1367 | |
1368 /* Flush out the old cache. */ | |
1369 write_out_buffer_local_cache (sym, bfwd); | |
1370 | |
1371 /* Retrieve the new alist element and new value. */ | |
1372 if (NILP (new_alist_el) | |
1373 && set_it_p) | |
1374 new_alist_el = buffer_local_alist_element (buf, sym, bfwd); | |
1375 | |
1376 if (NILP (new_alist_el)) | |
1377 new_val = bfwd->default_value; | |
1378 else | |
1379 new_val = Fcdr (new_alist_el); | |
1380 | |
1381 bfwd->current_alist_element = new_alist_el; | |
793 | 1382 bfwd->current_buffer = wrap_buffer (buf); |
428 | 1383 |
1384 /* Now store the value into the current-value slot. | |
1385 We don't simply write it there, because the current-value | |
1386 slot might be a forwarding pointer, in which case we need | |
1387 to instead write the value into the C variable. | |
1388 | |
1389 We might also want to call a magic function. | |
1390 | |
1391 So instead, we call this function. */ | |
1392 store_symval_forwarding (sym, bfwd->current_value, new_val); | |
1393 } | |
1394 | |
446 | 1395 |
1396 /* SYM is a buffer-local variable, and BFWD is its buffer-local structure. | |
1397 Flush the cache. BFWD->CURRENT_BUFFER will be nil after this operation. | |
1398 */ | |
1399 | |
1400 static void | |
1401 flush_buffer_local_cache (Lisp_Object sym, | |
1402 struct symbol_value_buffer_local *bfwd) | |
1403 { | |
1404 if (NILP (bfwd->current_buffer)) | |
1405 /* Cache is already flushed. */ | |
1406 return; | |
1407 | |
1408 /* Flush out the old cache. */ | |
1409 write_out_buffer_local_cache (sym, bfwd); | |
1410 | |
1411 bfwd->current_alist_element = Qnil; | |
1412 bfwd->current_buffer = Qnil; | |
1413 | |
1414 /* Now store default the value into the current-value slot. | |
1415 We don't simply write it there, because the current-value | |
1416 slot might be a forwarding pointer, in which case we need | |
1417 to instead write the value into the C variable. | |
1418 | |
1419 We might also want to call a magic function. | |
1420 | |
1421 So instead, we call this function. */ | |
1422 store_symval_forwarding (sym, bfwd->current_value, bfwd->default_value); | |
1423 } | |
1424 | |
1425 /* Flush all the buffer-local variable caches. Whoever has a | |
1426 non-interned buffer-local variable will be spanked. Whoever has a | |
1427 magic variable that interns or uninterns symbols... I don't even | |
1428 want to think about it. | |
1429 */ | |
1430 | |
1431 void | |
1432 flush_all_buffer_local_cache (void) | |
1433 { | |
1434 Lisp_Object *syms = XVECTOR_DATA (Vobarray); | |
1435 long count = XVECTOR_LENGTH (Vobarray); | |
1436 long i; | |
1437 | |
1438 for (i=0; i<count; i++) | |
1439 { | |
1440 Lisp_Object sym = syms[i]; | |
1441 Lisp_Object value; | |
1442 | |
1443 if (!ZEROP (sym)) | |
1444 for(;;) | |
1445 { | |
1446 Lisp_Symbol *next; | |
1447 assert (SYMBOLP (sym)); | |
1448 value = fetch_value_maybe_past_magic (sym, Qt); | |
1449 if (SYMBOL_VALUE_BUFFER_LOCAL_P (value)) | |
1450 flush_buffer_local_cache (sym, XSYMBOL_VALUE_BUFFER_LOCAL (value)); | |
1451 | |
1452 next = symbol_next (XSYMBOL (sym)); | |
1453 if (!next) | |
1454 break; | |
793 | 1455 sym = wrap_symbol (next); |
446 | 1456 } |
1457 } | |
1458 } | |
1459 | |
428 | 1460 |
1461 void | |
1462 kill_buffer_local_variables (struct buffer *buf) | |
1463 { | |
1464 Lisp_Object prev = Qnil; | |
1465 Lisp_Object alist; | |
1466 | |
1467 /* Any which are supposed to be permanent, | |
1468 make local again, with the same values they had. */ | |
1469 | |
1470 for (alist = buf->local_var_alist; !NILP (alist); alist = XCDR (alist)) | |
1471 { | |
1472 Lisp_Object sym = XCAR (XCAR (alist)); | |
1473 struct symbol_value_buffer_local *bfwd; | |
1474 /* Variables with a symbol-value-varalias should not be here | |
1475 (we should have forwarded past them) and there must be a | |
1476 symbol-value-buffer-local. If there's a symbol-value-lisp-magic, | |
1477 just forward past it; if the variable has a handler, it was | |
1478 already called. */ | |
1479 Lisp_Object value = fetch_value_maybe_past_magic (sym, Qt); | |
1480 | |
1481 assert (SYMBOL_VALUE_BUFFER_LOCAL_P (value)); | |
1482 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (value); | |
1483 | |
1484 if (!NILP (Fget (sym, Qpermanent_local, Qnil))) | |
1485 /* prev points to the last alist element that is still | |
1486 staying around, so *only* update it now. This didn't | |
1487 used to be the case; this bug has been around since | |
1488 mly's rewrite two years ago! */ | |
1489 prev = alist; | |
1490 else | |
1491 { | |
1492 /* Really truly kill it. */ | |
1493 if (!NILP (prev)) | |
1494 XCDR (prev) = XCDR (alist); | |
1495 else | |
1496 buf->local_var_alist = XCDR (alist); | |
1497 | |
1498 /* We just effectively changed the value for this variable | |
1499 in BUF. So: */ | |
1500 | |
1501 /* (1) If the cache is caching BUF, invalidate the cache. */ | |
1502 if (!NILP (bfwd->current_buffer) && | |
1503 buf == XBUFFER (bfwd->current_buffer)) | |
1504 bfwd->current_buffer = Qnil; | |
1505 | |
1506 /* (2) If we changed the value in current_buffer and this | |
1507 variable forwards to a C variable, we need to change the | |
1508 value of the C variable. set_up_buffer_local_cache() | |
1509 will do this. It doesn't hurt to do it whenever | |
1510 BUF == current_buffer, so just go ahead and do that. */ | |
1511 if (buf == current_buffer) | |
1512 set_up_buffer_local_cache (sym, bfwd, buf, Qnil, 0); | |
1513 } | |
1514 } | |
1515 } | |
1516 | |
1517 static Lisp_Object | |
1518 find_symbol_value_1 (Lisp_Object sym, struct buffer *buf, | |
1519 struct console *con, int swap_it_in, | |
1520 Lisp_Object symcons, int set_it_p) | |
1521 { | |
1522 Lisp_Object valcontents; | |
1523 | |
1524 retry: | |
1525 valcontents = XSYMBOL (sym)->value; | |
1526 | |
1527 retry_2: | |
1528 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1529 return valcontents; | |
1530 | |
1531 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
1532 { | |
1533 case SYMVAL_LISP_MAGIC: | |
1534 /* #### kludge */ | |
1535 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
1536 /* semi-change-o */ | |
1537 goto retry_2; | |
1538 | |
1539 case SYMVAL_VARALIAS: | |
1540 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); | |
1541 symcons = Qnil; | |
1542 /* presto change-o! */ | |
1543 goto retry; | |
1544 | |
1545 case SYMVAL_BUFFER_LOCAL: | |
1546 case SYMVAL_SOME_BUFFER_LOCAL: | |
1547 { | |
1548 struct symbol_value_buffer_local *bfwd | |
1549 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
1550 | |
1551 if (swap_it_in) | |
1552 { | |
1553 set_up_buffer_local_cache (sym, bfwd, buf, symcons, set_it_p); | |
1554 valcontents = bfwd->current_value; | |
1555 } | |
1556 else | |
1557 { | |
1558 if (!NILP (bfwd->current_buffer) && | |
1559 buf == XBUFFER (bfwd->current_buffer)) | |
1560 valcontents = bfwd->current_value; | |
1561 else if (NILP (symcons)) | |
1562 { | |
1563 if (set_it_p) | |
1564 valcontents = assq_no_quit (sym, buf->local_var_alist); | |
1565 if (NILP (valcontents)) | |
1566 valcontents = bfwd->default_value; | |
1567 else | |
1568 valcontents = XCDR (valcontents); | |
1569 } | |
1570 else | |
1571 valcontents = XCDR (symcons); | |
1572 } | |
1573 break; | |
1574 } | |
1575 | |
1576 default: | |
1577 break; | |
1578 } | |
1579 return do_symval_forwarding (valcontents, buf, con); | |
1580 } | |
1581 | |
1582 | |
1583 /* Find the value of a symbol in BUFFER, returning Qunbound if it's not | |
1584 bound. Note that it must not be possible to QUIT within this | |
1585 function. */ | |
1586 | |
1587 Lisp_Object | |
1588 symbol_value_in_buffer (Lisp_Object sym, Lisp_Object buffer) | |
1589 { | |
1590 struct buffer *buf; | |
1591 | |
1592 CHECK_SYMBOL (sym); | |
1593 | |
1594 if (NILP (buffer)) | |
1595 buf = current_buffer; | |
1596 else | |
1597 { | |
1598 CHECK_BUFFER (buffer); | |
1599 buf = XBUFFER (buffer); | |
1600 } | |
1601 | |
1602 return find_symbol_value_1 (sym, buf, | |
1603 /* If it bombs out at startup due to a | |
1604 Lisp error, this may be nil. */ | |
1605 CONSOLEP (Vselected_console) | |
1606 ? XCONSOLE (Vselected_console) : 0, 0, Qnil, 1); | |
1607 } | |
1608 | |
1609 static Lisp_Object | |
1610 symbol_value_in_console (Lisp_Object sym, Lisp_Object console) | |
1611 { | |
1612 CHECK_SYMBOL (sym); | |
1613 | |
1614 if (NILP (console)) | |
1615 console = Vselected_console; | |
1616 else | |
1617 CHECK_CONSOLE (console); | |
1618 | |
1619 return find_symbol_value_1 (sym, current_buffer, XCONSOLE (console), 0, | |
1620 Qnil, 1); | |
1621 } | |
1622 | |
1623 /* Return the current value of SYM. The difference between this function | |
1624 and calling symbol_value_in_buffer with a BUFFER of Qnil is that | |
1625 this updates the CURRENT_VALUE slot of buffer-local variables to | |
1626 point to the current buffer, while symbol_value_in_buffer doesn't. */ | |
1627 | |
1628 Lisp_Object | |
1629 find_symbol_value (Lisp_Object sym) | |
1630 { | |
1631 /* WARNING: This function can be called when current_buffer is 0 | |
1632 and Vselected_console is Qnil, early in initialization. */ | |
1633 struct console *con; | |
1634 Lisp_Object valcontents; | |
1635 | |
1636 CHECK_SYMBOL (sym); | |
1637 | |
1638 valcontents = XSYMBOL (sym)->value; | |
1639 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1640 return valcontents; | |
1641 | |
1642 if (CONSOLEP (Vselected_console)) | |
1643 con = XCONSOLE (Vselected_console); | |
1644 else | |
1645 { | |
1646 /* This can also get called while we're preparing to shutdown. | |
1647 #### What should really happen in that case? Should we | |
1648 actually fix things so we can't get here in that case? */ | |
1649 #ifndef PDUMP | |
1650 assert (!initialized || preparing_for_armageddon); | |
1651 #endif | |
1652 con = 0; | |
1653 } | |
1654 | |
1655 return find_symbol_value_1 (sym, current_buffer, con, 1, Qnil, 1); | |
1656 } | |
1657 | |
1658 /* This is an optimized function for quick lookup of buffer local symbols | |
1659 by avoiding O(n) search. This will work when either: | |
1660 a) We have already found the symbol e.g. by traversing local_var_alist. | |
1661 or | |
1662 b) We know that the symbol will not be found in the current buffer's | |
1663 list of local variables. | |
1664 In the former case, find_it_p is 1 and symbol_cons is the element from | |
1665 local_var_alist. In the latter case, find_it_p is 0 and symbol_cons | |
1666 is the symbol. | |
1667 | |
1668 This function is called from set_buffer_internal which does both of these | |
1669 things. */ | |
1670 | |
1671 Lisp_Object | |
1672 find_symbol_value_quickly (Lisp_Object symbol_cons, int find_it_p) | |
1673 { | |
1674 /* WARNING: This function can be called when current_buffer is 0 | |
1675 and Vselected_console is Qnil, early in initialization. */ | |
1676 struct console *con; | |
1677 Lisp_Object sym = find_it_p ? XCAR (symbol_cons) : symbol_cons; | |
1678 | |
1679 CHECK_SYMBOL (sym); | |
1680 if (CONSOLEP (Vselected_console)) | |
1681 con = XCONSOLE (Vselected_console); | |
1682 else | |
1683 { | |
1684 /* This can also get called while we're preparing to shutdown. | |
1685 #### What should really happen in that case? Should we | |
1686 actually fix things so we can't get here in that case? */ | |
1687 #ifndef PDUMP | |
1688 assert (!initialized || preparing_for_armageddon); | |
1689 #endif | |
1690 con = 0; | |
1691 } | |
1692 | |
1693 return find_symbol_value_1 (sym, current_buffer, con, 1, | |
1694 find_it_p ? symbol_cons : Qnil, | |
1695 find_it_p); | |
1696 } | |
1697 | |
1698 DEFUN ("symbol-value", Fsymbol_value, 1, 1, 0, /* | |
1699 Return SYMBOL's value. Error if that is void. | |
1700 */ | |
1701 (symbol)) | |
1702 { | |
1703 Lisp_Object val = find_symbol_value (symbol); | |
1704 | |
1705 if (UNBOUNDP (val)) | |
1706 return Fsignal (Qvoid_variable, list1 (symbol)); | |
1707 else | |
1708 return val; | |
1709 } | |
1710 | |
1711 DEFUN ("set", Fset, 2, 2, 0, /* | |
1712 Set SYMBOL's value to NEWVAL, and return NEWVAL. | |
1713 */ | |
1714 (symbol, newval)) | |
1715 { | |
1716 REGISTER Lisp_Object valcontents; | |
440 | 1717 Lisp_Symbol *sym; |
428 | 1718 /* remember, we're called by Fmakunbound() as well */ |
1719 | |
1720 CHECK_SYMBOL (symbol); | |
1721 | |
1722 retry: | |
1723 sym = XSYMBOL (symbol); | |
1724 valcontents = sym->value; | |
1725 | |
1726 if (EQ (symbol, Qnil) || | |
1727 EQ (symbol, Qt) || | |
1728 SYMBOL_IS_KEYWORD (symbol)) | |
1729 reject_constant_symbols (symbol, newval, 0, | |
1730 UNBOUNDP (newval) ? Qmakunbound : Qset); | |
1731 | |
1732 if (!SYMBOL_VALUE_MAGIC_P (valcontents) || UNBOUNDP (valcontents)) | |
1733 { | |
1734 sym->value = newval; | |
1735 return newval; | |
1736 } | |
1737 | |
1738 reject_constant_symbols (symbol, newval, 0, | |
1739 UNBOUNDP (newval) ? Qmakunbound : Qset); | |
1740 | |
1741 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
1742 { | |
1743 case SYMVAL_LISP_MAGIC: | |
1744 { | |
1745 if (UNBOUNDP (newval)) | |
440 | 1746 { |
1747 maybe_call_magic_handler (symbol, Qmakunbound, 0); | |
1748 return XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed = Qunbound; | |
1749 } | |
428 | 1750 else |
440 | 1751 { |
1752 maybe_call_magic_handler (symbol, Qset, 1, newval); | |
1753 return XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed = newval; | |
1754 } | |
428 | 1755 } |
1756 | |
1757 case SYMVAL_VARALIAS: | |
1758 symbol = follow_varalias_pointers (symbol, | |
1759 UNBOUNDP (newval) | |
1760 ? Qmakunbound : Qset); | |
1761 /* presto change-o! */ | |
1762 goto retry; | |
1763 | |
1764 case SYMVAL_FIXNUM_FORWARD: | |
996 | 1765 case SYMVAL_CONST_FIXNUM_FORWARD: |
428 | 1766 case SYMVAL_BOOLEAN_FORWARD: |
996 | 1767 case SYMVAL_CONST_BOOLEAN_FORWARD: |
428 | 1768 case SYMVAL_DEFAULT_BUFFER_FORWARD: |
1769 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1770 if (UNBOUNDP (newval)) | |
996 | 1771 { |
1772 #ifdef HAVE_SHLIB | |
1773 if (unloading_module) | |
1774 { | |
1775 sym->value = newval; | |
1776 return newval; | |
1777 } | |
1778 else | |
1779 #endif | |
1780 invalid_change ("Cannot makunbound", symbol); | |
1781 } | |
1782 break; | |
1783 | |
1784 case SYMVAL_OBJECT_FORWARD: | |
1785 case SYMVAL_CONST_OBJECT_FORWARD: | |
1786 if (UNBOUNDP (newval)) | |
1787 { | |
1788 #ifdef HAVE_SHLIB | |
1789 if (unloading_module) | |
1790 { | |
1111 | 1791 unstaticpro_nodump ((Lisp_Object *) |
1792 symbol_value_forward_forward | |
996 | 1793 (XSYMBOL_VALUE_FORWARD (valcontents))); |
1794 sym->value = newval; | |
1795 return newval; | |
1796 } | |
1797 else | |
1798 #endif | |
1799 invalid_change ("Cannot makunbound", symbol); | |
1800 } | |
428 | 1801 break; |
1802 | |
1803 /* case SYMVAL_UNBOUND_MARKER: break; */ | |
1804 | |
1805 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1806 { | |
442 | 1807 const struct symbol_value_forward *fwd |
428 | 1808 = XSYMBOL_VALUE_FORWARD (valcontents); |
1809 int mask = XINT (*((Lisp_Object *) | |
1810 symbol_value_forward_forward (fwd))); | |
1811 if (mask > 0) | |
1812 /* Setting this variable makes it buffer-local */ | |
1813 current_buffer->local_var_flags |= mask; | |
1814 break; | |
1815 } | |
1816 | |
1817 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1818 { | |
442 | 1819 const struct symbol_value_forward *fwd |
428 | 1820 = XSYMBOL_VALUE_FORWARD (valcontents); |
1821 int mask = XINT (*((Lisp_Object *) | |
1822 symbol_value_forward_forward (fwd))); | |
1823 if (mask > 0) | |
1824 /* Setting this variable makes it console-local */ | |
1825 XCONSOLE (Vselected_console)->local_var_flags |= mask; | |
1826 break; | |
1827 } | |
1828 | |
1829 case SYMVAL_BUFFER_LOCAL: | |
1830 case SYMVAL_SOME_BUFFER_LOCAL: | |
1831 { | |
1832 /* If we want to examine or set the value and | |
1833 CURRENT-BUFFER is current, we just examine or set | |
1834 CURRENT-VALUE. If CURRENT-BUFFER is not current, we | |
1835 store the current CURRENT-VALUE value into | |
1836 CURRENT-ALIST- ELEMENT, then find the appropriate alist | |
1837 element for the buffer now current and set up | |
1838 CURRENT-ALIST-ELEMENT. Then we set CURRENT-VALUE out | |
1839 of that element, and store into CURRENT-BUFFER. | |
1840 | |
1841 If we are setting the variable and the current buffer does | |
1842 not have an alist entry for this variable, an alist entry is | |
1843 created. | |
1844 | |
1845 Note that CURRENT-VALUE can be a forwarding pointer. | |
1846 Each time it is examined or set, forwarding must be | |
1847 done. */ | |
1848 struct symbol_value_buffer_local *bfwd | |
1849 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
1850 int some_buffer_local_p = | |
1851 (bfwd->magic.type == SYMVAL_SOME_BUFFER_LOCAL); | |
1852 /* What value are we caching right now? */ | |
1853 Lisp_Object aelt = bfwd->current_alist_element; | |
1854 | |
1855 if (!NILP (bfwd->current_buffer) && | |
1856 current_buffer == XBUFFER (bfwd->current_buffer) | |
1857 && ((some_buffer_local_p) | |
1858 ? 1 /* doesn't automatically become local */ | |
1859 : !NILP (aelt) /* already local */ | |
1860 )) | |
1861 { | |
1862 /* Cache is valid */ | |
1863 valcontents = bfwd->current_value; | |
1864 } | |
1865 else | |
1866 { | |
1867 /* If the current buffer is not the buffer whose binding is | |
1868 currently cached, or if it's a SYMVAL_BUFFER_LOCAL and | |
1869 we're looking at the default value, the cache is invalid; we | |
1870 need to write it out, and find the new CURRENT-ALIST-ELEMENT | |
1871 */ | |
1872 | |
1873 /* Write out the cached value for the old buffer; copy it | |
1874 back to its alist element. This works if the current | |
1875 buffer only sees the default value, too. */ | |
1876 write_out_buffer_local_cache (symbol, bfwd); | |
1877 | |
1878 /* Find the new value for CURRENT-ALIST-ELEMENT. */ | |
1879 aelt = buffer_local_alist_element (current_buffer, symbol, bfwd); | |
1880 if (NILP (aelt)) | |
1881 { | |
1882 /* This buffer is still seeing the default value. */ | |
1883 if (!some_buffer_local_p) | |
1884 { | |
1885 /* If it's a SYMVAL_BUFFER_LOCAL, give this buffer a | |
1886 new assoc for a local value and set | |
1887 CURRENT-ALIST-ELEMENT to point to that. */ | |
1888 aelt = | |
1889 do_symval_forwarding (bfwd->current_value, | |
1890 current_buffer, | |
1891 XCONSOLE (Vselected_console)); | |
1892 aelt = Fcons (symbol, aelt); | |
1893 current_buffer->local_var_alist | |
1894 = Fcons (aelt, current_buffer->local_var_alist); | |
1895 } | |
1896 else | |
1897 { | |
1898 /* If the variable is a SYMVAL_SOME_BUFFER_LOCAL, | |
1899 we're currently seeing the default value. */ | |
1900 ; | |
1901 } | |
1902 } | |
1903 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */ | |
1904 bfwd->current_alist_element = aelt; | |
1905 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */ | |
793 | 1906 bfwd->current_buffer = wrap_buffer (current_buffer); |
428 | 1907 valcontents = bfwd->current_value; |
1908 } | |
1909 break; | |
1910 } | |
1911 default: | |
2500 | 1912 ABORT (); |
428 | 1913 } |
1914 store_symval_forwarding (symbol, valcontents, newval); | |
1915 | |
1916 return newval; | |
1917 } | |
1918 | |
1919 | |
1920 /* Access or set a buffer-local symbol's default value. */ | |
1921 | |
1922 /* Return the default value of SYM, but don't check for voidness. | |
1923 Return Qunbound if it is void. */ | |
1924 | |
1925 static Lisp_Object | |
1926 default_value (Lisp_Object sym) | |
1927 { | |
1928 Lisp_Object valcontents; | |
1929 | |
1930 CHECK_SYMBOL (sym); | |
1931 | |
1932 retry: | |
1933 valcontents = XSYMBOL (sym)->value; | |
1934 | |
1935 retry_2: | |
1936 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1937 return valcontents; | |
1938 | |
1939 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
1940 { | |
1941 case SYMVAL_LISP_MAGIC: | |
1942 /* #### kludge */ | |
1943 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
1944 /* semi-change-o */ | |
1945 goto retry_2; | |
1946 | |
1947 case SYMVAL_VARALIAS: | |
1948 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); | |
1949 /* presto change-o! */ | |
1950 goto retry; | |
1951 | |
1952 case SYMVAL_UNBOUND_MARKER: | |
1953 return valcontents; | |
1954 | |
1955 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1956 { | |
442 | 1957 const struct symbol_value_forward *fwd |
428 | 1958 = XSYMBOL_VALUE_FORWARD (valcontents); |
1959 return (*((Lisp_Object *)((char *) XBUFFER (Vbuffer_defaults) | |
1960 + ((char *)symbol_value_forward_forward (fwd) | |
1961 - (char *)&buffer_local_flags)))); | |
1962 } | |
1963 | |
1964 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1965 { | |
442 | 1966 const struct symbol_value_forward *fwd |
428 | 1967 = XSYMBOL_VALUE_FORWARD (valcontents); |
1968 return (*((Lisp_Object *)((char *) XCONSOLE (Vconsole_defaults) | |
1969 + ((char *)symbol_value_forward_forward (fwd) | |
1970 - (char *)&console_local_flags)))); | |
1971 } | |
1972 | |
1973 case SYMVAL_BUFFER_LOCAL: | |
1974 case SYMVAL_SOME_BUFFER_LOCAL: | |
1975 { | |
1976 struct symbol_value_buffer_local *bfwd = | |
1977 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
1978 | |
1979 /* Handle user-created local variables. */ | |
1980 /* If var is set up for a buffer that lacks a local value for it, | |
1981 the current value is nominally the default value. | |
1982 But the current value slot may be more up to date, since | |
1983 ordinary setq stores just that slot. So use that. */ | |
1984 if (NILP (bfwd->current_alist_element)) | |
1985 return do_symval_forwarding (bfwd->current_value, current_buffer, | |
1986 XCONSOLE (Vselected_console)); | |
1987 else | |
1988 return bfwd->default_value; | |
1989 } | |
1990 default: | |
1991 /* For other variables, get the current value. */ | |
1992 return do_symval_forwarding (valcontents, current_buffer, | |
1993 XCONSOLE (Vselected_console)); | |
1994 } | |
1995 | |
1204 | 1996 RETURN_NOT_REACHED (Qnil); /* suppress compiler warning */ |
428 | 1997 } |
1998 | |
1999 DEFUN ("default-boundp", Fdefault_boundp, 1, 1, 0, /* | |
2000 Return t if SYMBOL has a non-void default value. | |
2001 This is the value that is seen in buffers that do not have their own values | |
2002 for this variable. | |
2003 */ | |
2004 (symbol)) | |
2005 { | |
2006 return UNBOUNDP (default_value (symbol)) ? Qnil : Qt; | |
2007 } | |
2008 | |
2009 DEFUN ("default-value", Fdefault_value, 1, 1, 0, /* | |
2010 Return SYMBOL's default value. | |
2011 This is the value that is seen in buffers that do not have their own values | |
2012 for this variable. The default value is meaningful for variables with | |
2013 local bindings in certain buffers. | |
2014 */ | |
2015 (symbol)) | |
2016 { | |
2017 Lisp_Object value = default_value (symbol); | |
2018 | |
2019 return UNBOUNDP (value) ? Fsignal (Qvoid_variable, list1 (symbol)) : value; | |
2020 } | |
2021 | |
2022 DEFUN ("set-default", Fset_default, 2, 2, 0, /* | |
444 | 2023 Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated. |
428 | 2024 The default value is seen in buffers that do not have their own values |
2025 for this variable. | |
2026 */ | |
2027 (symbol, value)) | |
2028 { | |
2029 Lisp_Object valcontents; | |
2030 | |
2031 CHECK_SYMBOL (symbol); | |
2032 | |
2033 retry: | |
2034 valcontents = XSYMBOL (symbol)->value; | |
2035 | |
2036 retry_2: | |
2037 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2038 return Fset (symbol, value); | |
2039 | |
2040 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2041 { | |
2042 case SYMVAL_LISP_MAGIC: | |
2043 RETURN_IF_NOT_UNBOUND (maybe_call_magic_handler (symbol, Qset_default, 1, | |
2044 value)); | |
2045 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2046 /* semi-change-o */ | |
2047 goto retry_2; | |
2048 | |
2049 case SYMVAL_VARALIAS: | |
2050 symbol = follow_varalias_pointers (symbol, Qset_default); | |
2051 /* presto change-o! */ | |
2052 goto retry; | |
2053 | |
2054 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2055 set_default_buffer_slot_variable (symbol, value); | |
2056 return value; | |
2057 | |
2058 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
2059 set_default_console_slot_variable (symbol, value); | |
2060 return value; | |
2061 | |
2062 case SYMVAL_BUFFER_LOCAL: | |
2063 case SYMVAL_SOME_BUFFER_LOCAL: | |
2064 { | |
2065 /* Store new value into the DEFAULT-VALUE slot */ | |
2066 struct symbol_value_buffer_local *bfwd | |
2067 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2068 | |
2069 bfwd->default_value = value; | |
2070 /* If current-buffer doesn't shadow default_value, | |
2071 * we must set the CURRENT-VALUE slot too */ | |
2072 if (NILP (bfwd->current_alist_element)) | |
2073 store_symval_forwarding (symbol, bfwd->current_value, value); | |
2074 return value; | |
2075 } | |
2076 | |
2077 default: | |
2078 return Fset (symbol, value); | |
2079 } | |
2080 } | |
2081 | |
2082 DEFUN ("setq-default", Fsetq_default, 0, UNEVALLED, 0, /* | |
2083 Set the default value of variable SYMBOL to VALUE. | |
2084 SYMBOL, the variable name, is literal (not evaluated); | |
2085 VALUE is an expression and it is evaluated. | |
2086 The default value of a variable is seen in buffers | |
2087 that do not have their own values for the variable. | |
2088 | |
2089 More generally, you can use multiple variables and values, as in | |
2090 (setq-default SYMBOL VALUE SYMBOL VALUE...) | |
2091 This sets each SYMBOL's default value to the corresponding VALUE. | |
2092 The VALUE for the Nth SYMBOL can refer to the new default values | |
2093 of previous SYMBOLs. | |
2094 */ | |
2095 (args)) | |
2096 { | |
2097 /* This function can GC */ | |
2098 int nargs; | |
2421 | 2099 Lisp_Object retval = Qnil; |
428 | 2100 |
2101 GET_LIST_LENGTH (args, nargs); | |
2102 | |
2103 if (nargs & 1) /* Odd number of arguments? */ | |
2104 Fsignal (Qwrong_number_of_arguments, | |
2105 list2 (Qsetq_default, make_int (nargs))); | |
2106 | |
2421 | 2107 GC_PROPERTY_LIST_LOOP_3 (symbol, val, args) |
428 | 2108 { |
2109 val = Feval (val); | |
2110 Fset_default (symbol, val); | |
2421 | 2111 retval = val; |
428 | 2112 } |
2113 | |
2421 | 2114 END_GC_PROPERTY_LIST_LOOP (symbol); |
2115 return retval; | |
428 | 2116 } |
2117 | |
2118 /* Lisp functions for creating and removing buffer-local variables. */ | |
2119 | |
2120 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, 1, 1, | |
2121 "vMake Variable Buffer Local: ", /* | |
2122 Make VARIABLE have a separate value for each buffer. | |
2123 At any time, the value for the current buffer is in effect. | |
2124 There is also a default value which is seen in any buffer which has not yet | |
2125 set its own value. | |
2126 Using `set' or `setq' to set the variable causes it to have a separate value | |
2127 for the current buffer if it was previously using the default value. | |
2128 The function `default-value' gets the default value and `set-default' | |
2129 sets it. | |
2130 */ | |
2131 (variable)) | |
2132 { | |
2133 Lisp_Object valcontents; | |
2134 | |
2135 CHECK_SYMBOL (variable); | |
2136 | |
2137 retry: | |
2138 verify_ok_for_buffer_local (variable, Qmake_variable_buffer_local); | |
2139 | |
2140 valcontents = XSYMBOL (variable)->value; | |
2141 | |
2142 retry_2: | |
2143 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2144 { | |
2145 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2146 { | |
2147 case SYMVAL_LISP_MAGIC: | |
2148 if (!UNBOUNDP (maybe_call_magic_handler | |
2149 (variable, Qmake_variable_buffer_local, 0))) | |
2150 return variable; | |
2151 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2152 /* semi-change-o */ | |
2153 goto retry_2; | |
2154 | |
2155 case SYMVAL_VARALIAS: | |
2156 variable = follow_varalias_pointers (variable, | |
2157 Qmake_variable_buffer_local); | |
2158 /* presto change-o! */ | |
2159 goto retry; | |
2160 | |
2161 case SYMVAL_FIXNUM_FORWARD: | |
2162 case SYMVAL_BOOLEAN_FORWARD: | |
2163 case SYMVAL_OBJECT_FORWARD: | |
2164 case SYMVAL_UNBOUND_MARKER: | |
2165 break; | |
2166 | |
2167 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2168 case SYMVAL_BUFFER_LOCAL: | |
2169 /* Already per-each-buffer */ | |
2170 return variable; | |
2171 | |
2172 case SYMVAL_SOME_BUFFER_LOCAL: | |
2173 /* Transmogrify */ | |
2174 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents)->magic.type = | |
2175 SYMVAL_BUFFER_LOCAL; | |
2176 return variable; | |
2177 | |
2178 default: | |
2500 | 2179 ABORT (); |
428 | 2180 } |
2181 } | |
2182 | |
2183 { | |
2184 struct symbol_value_buffer_local *bfwd | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2185 = XSYMBOL_VALUE_BUFFER_LOCAL |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2186 (ALLOC_LISP_OBJECT (symbol_value_buffer_local)); |
428 | 2187 Lisp_Object foo; |
2188 bfwd->magic.type = SYMVAL_BUFFER_LOCAL; | |
2189 | |
2190 bfwd->default_value = find_symbol_value (variable); | |
2191 bfwd->current_value = valcontents; | |
2192 bfwd->current_alist_element = Qnil; | |
2193 bfwd->current_buffer = Fcurrent_buffer (); | |
793 | 2194 foo = wrap_symbol_value_magic (bfwd); |
428 | 2195 *value_slot_past_magic (variable) = foo; |
2196 #if 1 /* #### Yuck! FSFmacs bug-compatibility*/ | |
2197 /* This sets the default-value of any make-variable-buffer-local to nil. | |
2198 That just sucks. User can just use setq-default to effect that, | |
2199 but there's no way to do makunbound-default to undo this lossage. */ | |
2200 if (UNBOUNDP (valcontents)) | |
2201 bfwd->default_value = Qnil; | |
2202 #endif | |
2203 #if 0 /* #### Yuck! */ | |
2204 /* This sets the value to nil in this buffer. | |
2205 User could use (setq variable nil) to do this. | |
2206 It isn't as egregious to do this automatically | |
2207 as it is to do so to the default-value, but it's | |
2208 still really dubious. */ | |
2209 if (UNBOUNDP (valcontents)) | |
2210 Fset (variable, Qnil); | |
2211 #endif | |
2212 return variable; | |
2213 } | |
2214 } | |
2215 | |
2216 DEFUN ("make-local-variable", Fmake_local_variable, 1, 1, | |
2217 "vMake Local Variable: ", /* | |
2218 Make VARIABLE have a separate value in the current buffer. | |
2219 Other buffers will continue to share a common default value. | |
2220 \(The buffer-local value of VARIABLE starts out as the same value | |
2221 VARIABLE previously had. If VARIABLE was void, it remains void.) | |
2222 See also `make-variable-buffer-local'. | |
2223 | |
2224 If the variable is already arranged to become local when set, | |
2225 this function causes a local value to exist for this buffer, | |
2226 just as setting the variable would do. | |
2227 | |
2228 Do not use `make-local-variable' to make a hook variable buffer-local. | |
2229 Use `make-local-hook' instead. | |
2230 */ | |
2231 (variable)) | |
2232 { | |
2233 Lisp_Object valcontents; | |
2234 struct symbol_value_buffer_local *bfwd; | |
2235 | |
2236 CHECK_SYMBOL (variable); | |
2237 | |
2238 retry: | |
2239 verify_ok_for_buffer_local (variable, Qmake_local_variable); | |
2240 | |
2241 valcontents = XSYMBOL (variable)->value; | |
2242 | |
2243 retry_2: | |
2244 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2245 { | |
2246 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2247 { | |
2248 case SYMVAL_LISP_MAGIC: | |
2249 if (!UNBOUNDP (maybe_call_magic_handler | |
2250 (variable, Qmake_local_variable, 0))) | |
2251 return variable; | |
2252 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2253 /* semi-change-o */ | |
2254 goto retry_2; | |
2255 | |
2256 case SYMVAL_VARALIAS: | |
2257 variable = follow_varalias_pointers (variable, Qmake_local_variable); | |
2258 /* presto change-o! */ | |
2259 goto retry; | |
2260 | |
2261 case SYMVAL_FIXNUM_FORWARD: | |
2262 case SYMVAL_BOOLEAN_FORWARD: | |
2263 case SYMVAL_OBJECT_FORWARD: | |
2264 case SYMVAL_UNBOUND_MARKER: | |
2265 break; | |
2266 | |
2267 case SYMVAL_BUFFER_LOCAL: | |
2268 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2269 { | |
2270 /* Make sure the symbol has a local value in this particular | |
2271 buffer, by setting it to the same value it already has. */ | |
2272 Fset (variable, find_symbol_value (variable)); | |
2273 return variable; | |
2274 } | |
2275 | |
2276 case SYMVAL_SOME_BUFFER_LOCAL: | |
2277 { | |
2278 if (!NILP (buffer_local_alist_element (current_buffer, | |
2279 variable, | |
2280 (XSYMBOL_VALUE_BUFFER_LOCAL | |
2281 (valcontents))))) | |
2282 goto already_local_to_current_buffer; | |
2283 else | |
2284 goto already_local_to_some_other_buffer; | |
2285 } | |
2286 | |
2287 default: | |
2500 | 2288 ABORT (); |
428 | 2289 } |
2290 } | |
2291 | |
2292 /* Make sure variable is set up to hold per-buffer values */ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2293 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2294 (ALLOC_LISP_OBJECT (symbol_value_buffer_local)); |
428 | 2295 bfwd->magic.type = SYMVAL_SOME_BUFFER_LOCAL; |
2296 | |
2297 bfwd->current_buffer = Qnil; | |
2298 bfwd->current_alist_element = Qnil; | |
2299 bfwd->current_value = valcontents; | |
2300 /* passing 0 is OK because this should never be a | |
2301 SYMVAL_CURRENT_BUFFER_FORWARD or SYMVAL_SELECTED_CONSOLE_FORWARD | |
2302 variable. */ | |
2303 bfwd->default_value = do_symval_forwarding (valcontents, 0, 0); | |
2304 | |
2305 #if 0 | |
2306 if (UNBOUNDP (bfwd->default_value)) | |
2307 bfwd->default_value = Qnil; /* Yuck! */ | |
2308 #endif | |
2309 | |
793 | 2310 valcontents = wrap_symbol_value_magic (bfwd); |
428 | 2311 *value_slot_past_magic (variable) = valcontents; |
2312 | |
2313 already_local_to_some_other_buffer: | |
2314 | |
2315 /* Make sure this buffer has its own value of variable */ | |
2316 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2317 | |
2318 if (UNBOUNDP (bfwd->default_value)) | |
2319 { | |
2320 /* If default value is unbound, set local value to nil. */ | |
793 | 2321 bfwd->current_buffer = wrap_buffer (current_buffer); |
428 | 2322 bfwd->current_alist_element = Fcons (variable, Qnil); |
2323 current_buffer->local_var_alist = | |
2324 Fcons (bfwd->current_alist_element, current_buffer->local_var_alist); | |
2325 store_symval_forwarding (variable, bfwd->current_value, Qnil); | |
2326 return variable; | |
2327 } | |
2328 | |
2329 current_buffer->local_var_alist | |
2330 = Fcons (Fcons (variable, bfwd->default_value), | |
2331 current_buffer->local_var_alist); | |
2332 | |
2333 /* Make sure symbol does not think it is set up for this buffer; | |
2334 force it to look once again for this buffer's value */ | |
2335 if (!NILP (bfwd->current_buffer) && | |
2336 current_buffer == XBUFFER (bfwd->current_buffer)) | |
2337 bfwd->current_buffer = Qnil; | |
2338 | |
2339 already_local_to_current_buffer: | |
2340 | |
2341 /* If the symbol forwards into a C variable, then swap in the | |
2342 variable for this buffer immediately. If C code modifies the | |
2343 variable before we swap in, then that new value will clobber the | |
2344 default value the next time we swap. */ | |
2345 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2346 if (SYMBOL_VALUE_MAGIC_P (bfwd->current_value)) | |
2347 { | |
2348 switch (XSYMBOL_VALUE_MAGIC_TYPE (bfwd->current_value)) | |
2349 { | |
2350 case SYMVAL_FIXNUM_FORWARD: | |
2351 case SYMVAL_BOOLEAN_FORWARD: | |
2352 case SYMVAL_OBJECT_FORWARD: | |
2353 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
2354 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); | |
2355 break; | |
2356 | |
2357 case SYMVAL_UNBOUND_MARKER: | |
2358 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2359 break; | |
2360 | |
2361 default: | |
2500 | 2362 ABORT (); |
428 | 2363 } |
2364 } | |
2365 | |
2366 return variable; | |
2367 } | |
2368 | |
2369 DEFUN ("kill-local-variable", Fkill_local_variable, 1, 1, | |
2370 "vKill Local Variable: ", /* | |
2371 Make VARIABLE no longer have a separate value in the current buffer. | |
2372 From now on the default value will apply in this buffer. | |
2373 */ | |
2374 (variable)) | |
2375 { | |
2376 Lisp_Object valcontents; | |
2377 | |
2378 CHECK_SYMBOL (variable); | |
2379 | |
2380 retry: | |
2381 valcontents = XSYMBOL (variable)->value; | |
2382 | |
2383 retry_2: | |
2384 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2385 return variable; | |
2386 | |
2387 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2388 { | |
2389 case SYMVAL_LISP_MAGIC: | |
2390 if (!UNBOUNDP (maybe_call_magic_handler | |
2391 (variable, Qkill_local_variable, 0))) | |
2392 return variable; | |
2393 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2394 /* semi-change-o */ | |
2395 goto retry_2; | |
2396 | |
2397 case SYMVAL_VARALIAS: | |
2398 variable = follow_varalias_pointers (variable, Qkill_local_variable); | |
2399 /* presto change-o! */ | |
2400 goto retry; | |
2401 | |
2402 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2403 { | |
442 | 2404 const struct symbol_value_forward *fwd |
428 | 2405 = XSYMBOL_VALUE_FORWARD (valcontents); |
2406 int offset = ((char *) symbol_value_forward_forward (fwd) | |
2407 - (char *) &buffer_local_flags); | |
2408 int mask = | |
2409 XINT (*((Lisp_Object *) symbol_value_forward_forward (fwd))); | |
2410 | |
2411 if (mask > 0) | |
2412 { | |
2413 int (*magicfun) (Lisp_Object sym, Lisp_Object *val, | |
2414 Lisp_Object in_object, int flags) = | |
2415 symbol_value_forward_magicfun (fwd); | |
2416 Lisp_Object oldval = * (Lisp_Object *) | |
2417 (offset + (char *) XBUFFER (Vbuffer_defaults)); | |
2418 if (magicfun) | |
771 | 2419 (magicfun) (variable, &oldval, wrap_buffer (current_buffer), 0); |
428 | 2420 *(Lisp_Object *) (offset + (char *) current_buffer) |
2421 = oldval; | |
2422 current_buffer->local_var_flags &= ~mask; | |
2423 } | |
2424 return variable; | |
2425 } | |
2426 | |
2427 case SYMVAL_BUFFER_LOCAL: | |
2428 case SYMVAL_SOME_BUFFER_LOCAL: | |
2429 { | |
2430 /* Get rid of this buffer's alist element, if any */ | |
2431 struct symbol_value_buffer_local *bfwd | |
2432 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2433 Lisp_Object alist = current_buffer->local_var_alist; | |
2434 Lisp_Object alist_element | |
2435 = buffer_local_alist_element (current_buffer, variable, bfwd); | |
2436 | |
2437 if (!NILP (alist_element)) | |
2438 current_buffer->local_var_alist = Fdelq (alist_element, alist); | |
2439 | |
2440 /* Make sure symbol does not think it is set up for this buffer; | |
2441 force it to look once again for this buffer's value */ | |
2442 if (!NILP (bfwd->current_buffer) && | |
2443 current_buffer == XBUFFER (bfwd->current_buffer)) | |
2444 bfwd->current_buffer = Qnil; | |
2445 | |
2446 /* We just changed the value in the current_buffer. If this | |
2447 variable forwards to a C variable, we need to change the | |
2448 value of the C variable. set_up_buffer_local_cache() | |
2449 will do this. It doesn't hurt to do it always, | |
2450 so just go ahead and do that. */ | |
2451 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); | |
2452 } | |
2453 return variable; | |
2454 | |
2455 default: | |
2456 return variable; | |
2457 } | |
1204 | 2458 RETURN_NOT_REACHED(Qnil); /* suppress compiler warning */ |
428 | 2459 } |
2460 | |
2461 | |
2462 DEFUN ("kill-console-local-variable", Fkill_console_local_variable, 1, 1, | |
2463 "vKill Console Local Variable: ", /* | |
2464 Make VARIABLE no longer have a separate value in the selected console. | |
2465 From now on the default value will apply in this console. | |
2466 */ | |
2467 (variable)) | |
2468 { | |
2469 Lisp_Object valcontents; | |
2470 | |
2471 CHECK_SYMBOL (variable); | |
2472 | |
2473 retry: | |
2474 valcontents = XSYMBOL (variable)->value; | |
2475 | |
2476 retry_2: | |
2477 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2478 return variable; | |
2479 | |
2480 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2481 { | |
2482 case SYMVAL_LISP_MAGIC: | |
2483 if (!UNBOUNDP (maybe_call_magic_handler | |
2484 (variable, Qkill_console_local_variable, 0))) | |
2485 return variable; | |
2486 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2487 /* semi-change-o */ | |
2488 goto retry_2; | |
2489 | |
2490 case SYMVAL_VARALIAS: | |
2491 variable = follow_varalias_pointers (variable, | |
2492 Qkill_console_local_variable); | |
2493 /* presto change-o! */ | |
2494 goto retry; | |
2495 | |
2496 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
2497 { | |
442 | 2498 const struct symbol_value_forward *fwd |
428 | 2499 = XSYMBOL_VALUE_FORWARD (valcontents); |
2500 int offset = ((char *) symbol_value_forward_forward (fwd) | |
2501 - (char *) &console_local_flags); | |
2502 int mask = | |
2503 XINT (*((Lisp_Object *) symbol_value_forward_forward (fwd))); | |
2504 | |
2505 if (mask > 0) | |
2506 { | |
2507 int (*magicfun) (Lisp_Object sym, Lisp_Object *val, | |
2508 Lisp_Object in_object, int flags) = | |
2509 symbol_value_forward_magicfun (fwd); | |
2510 Lisp_Object oldval = * (Lisp_Object *) | |
2511 (offset + (char *) XCONSOLE (Vconsole_defaults)); | |
2512 if (magicfun) | |
2513 magicfun (variable, &oldval, Vselected_console, 0); | |
2514 *(Lisp_Object *) (offset + (char *) XCONSOLE (Vselected_console)) | |
2515 = oldval; | |
2516 XCONSOLE (Vselected_console)->local_var_flags &= ~mask; | |
2517 } | |
2518 return variable; | |
2519 } | |
2520 | |
2521 default: | |
2522 return variable; | |
2523 } | |
2524 } | |
2525 | |
2526 /* Used by specbind to determine what effects it might have. Returns: | |
2527 * 0 if symbol isn't buffer-local, and wouldn't be after it is set | |
2528 * <0 if symbol isn't presently buffer-local, but set would make it so | |
2529 * >0 if symbol is presently buffer-local | |
2530 */ | |
2531 int | |
2532 symbol_value_buffer_local_info (Lisp_Object symbol, struct buffer *buffer) | |
2533 { | |
2534 Lisp_Object valcontents; | |
2535 | |
2536 retry: | |
2537 valcontents = XSYMBOL (symbol)->value; | |
2538 | |
2539 retry_2: | |
2540 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2541 { | |
2542 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2543 { | |
2544 case SYMVAL_LISP_MAGIC: | |
2545 /* #### kludge */ | |
2546 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2547 /* semi-change-o */ | |
2548 goto retry_2; | |
2549 | |
2550 case SYMVAL_VARALIAS: | |
2551 symbol = follow_varalias_pointers (symbol, Qt /* #### kludge */); | |
2552 /* presto change-o! */ | |
2553 goto retry; | |
2554 | |
2555 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2556 { | |
442 | 2557 const struct symbol_value_forward *fwd |
428 | 2558 = XSYMBOL_VALUE_FORWARD (valcontents); |
2559 int mask = XINT (*((Lisp_Object *) | |
2560 symbol_value_forward_forward (fwd))); | |
2561 if ((mask <= 0) || (buffer && (buffer->local_var_flags & mask))) | |
2562 /* Already buffer-local */ | |
2563 return 1; | |
2564 else | |
2565 /* Would be buffer-local after set */ | |
2566 return -1; | |
2567 } | |
2568 case SYMVAL_BUFFER_LOCAL: | |
2569 case SYMVAL_SOME_BUFFER_LOCAL: | |
2570 { | |
2571 struct symbol_value_buffer_local *bfwd | |
2572 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2573 if (buffer | |
2574 && !NILP (buffer_local_alist_element (buffer, symbol, bfwd))) | |
2575 return 1; | |
2576 else | |
2577 /* Automatically becomes local when set */ | |
2578 return bfwd->magic.type == SYMVAL_BUFFER_LOCAL ? -1 : 0; | |
2579 } | |
2580 default: | |
2581 return 0; | |
2582 } | |
2583 } | |
2584 return 0; | |
2585 } | |
2586 | |
2587 | |
2588 DEFUN ("symbol-value-in-buffer", Fsymbol_value_in_buffer, 2, 3, 0, /* | |
2589 Return the value of SYMBOL in BUFFER, or UNBOUND-VALUE if it is unbound. | |
2590 */ | |
2591 (symbol, buffer, unbound_value)) | |
2592 { | |
2593 Lisp_Object value; | |
2594 CHECK_SYMBOL (symbol); | |
2595 CHECK_BUFFER (buffer); | |
2596 value = symbol_value_in_buffer (symbol, buffer); | |
2597 return UNBOUNDP (value) ? unbound_value : value; | |
2598 } | |
2599 | |
2600 DEFUN ("symbol-value-in-console", Fsymbol_value_in_console, 2, 3, 0, /* | |
2601 Return the value of SYMBOL in CONSOLE, or UNBOUND-VALUE if it is unbound. | |
2602 */ | |
2603 (symbol, console, unbound_value)) | |
2604 { | |
2605 Lisp_Object value; | |
2606 CHECK_SYMBOL (symbol); | |
2607 CHECK_CONSOLE (console); | |
2608 value = symbol_value_in_console (symbol, console); | |
2609 return UNBOUNDP (value) ? unbound_value : value; | |
2610 } | |
2611 | |
2612 DEFUN ("built-in-variable-type", Fbuilt_in_variable_type, 1, 1, 0, /* | |
2613 If SYMBOL is a built-in variable, return info about this; else return nil. | |
2614 The returned info will be a symbol, one of | |
2615 | |
2616 `object' A simple built-in variable. | |
2617 `const-object' Same, but cannot be set. | |
2618 `integer' A built-in integer variable. | |
2619 `const-integer' Same, but cannot be set. | |
2620 `boolean' A built-in boolean variable. | |
2621 `const-boolean' Same, but cannot be set. | |
2622 `const-specifier' Always contains a specifier; e.g. `has-modeline-p'. | |
2623 `current-buffer' A built-in buffer-local variable. | |
2624 `const-current-buffer' Same, but cannot be set. | |
2625 `default-buffer' Forwards to the default value of a built-in | |
2626 buffer-local variable. | |
2627 `selected-console' A built-in console-local variable. | |
2628 `const-selected-console' Same, but cannot be set. | |
2629 `default-console' Forwards to the default value of a built-in | |
2630 console-local variable. | |
2631 */ | |
2632 (symbol)) | |
2633 { | |
2634 REGISTER Lisp_Object valcontents; | |
2635 | |
2636 CHECK_SYMBOL (symbol); | |
2637 | |
2638 retry: | |
2639 valcontents = XSYMBOL (symbol)->value; | |
2640 | |
2641 retry_2: | |
2642 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2643 return Qnil; | |
2644 | |
2645 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2646 { | |
2647 case SYMVAL_LISP_MAGIC: | |
2648 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2649 /* semi-change-o */ | |
2650 goto retry_2; | |
2651 | |
2652 case SYMVAL_VARALIAS: | |
2653 symbol = follow_varalias_pointers (symbol, Qt); | |
2654 /* presto change-o! */ | |
2655 goto retry; | |
2656 | |
2657 case SYMVAL_BUFFER_LOCAL: | |
2658 case SYMVAL_SOME_BUFFER_LOCAL: | |
2659 valcontents = | |
2660 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents)->current_value; | |
2661 /* semi-change-o */ | |
2662 goto retry_2; | |
2663 | |
2664 case SYMVAL_FIXNUM_FORWARD: return Qinteger; | |
2665 case SYMVAL_CONST_FIXNUM_FORWARD: return Qconst_integer; | |
2666 case SYMVAL_BOOLEAN_FORWARD: return Qboolean; | |
2667 case SYMVAL_CONST_BOOLEAN_FORWARD: return Qconst_boolean; | |
2668 case SYMVAL_OBJECT_FORWARD: return Qobject; | |
2669 case SYMVAL_CONST_OBJECT_FORWARD: return Qconst_object; | |
2670 case SYMVAL_CONST_SPECIFIER_FORWARD: return Qconst_specifier; | |
2671 case SYMVAL_DEFAULT_BUFFER_FORWARD: return Qdefault_buffer; | |
2672 case SYMVAL_CURRENT_BUFFER_FORWARD: return Qcurrent_buffer; | |
2673 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: return Qconst_current_buffer; | |
2674 case SYMVAL_DEFAULT_CONSOLE_FORWARD: return Qdefault_console; | |
2675 case SYMVAL_SELECTED_CONSOLE_FORWARD: return Qselected_console; | |
2676 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: return Qconst_selected_console; | |
2677 case SYMVAL_UNBOUND_MARKER: return Qnil; | |
2678 | |
2679 default: | |
2500 | 2680 ABORT (); return Qnil; |
428 | 2681 } |
2682 } | |
2683 | |
2684 | |
2685 DEFUN ("local-variable-p", Flocal_variable_p, 2, 3, 0, /* | |
2686 Return t if SYMBOL's value is local to BUFFER. | |
444 | 2687 If optional third arg AFTER-SET is non-nil, return t if SYMBOL would be |
428 | 2688 buffer-local after it is set, regardless of whether it is so presently. |
2689 A nil value for BUFFER is *not* the same as (current-buffer), but means | |
2690 "no buffer". Specifically: | |
2691 | |
2692 -- If BUFFER is nil and AFTER-SET is nil, a return value of t indicates that | |
2693 the variable is one of the special built-in variables that is always | |
2694 buffer-local. (This includes `buffer-file-name', `buffer-read-only', | |
2695 `buffer-undo-list', and others.) | |
2696 | |
2697 -- If BUFFER is nil and AFTER-SET is t, a return value of t indicates that | |
2698 the variable has had `make-variable-buffer-local' applied to it. | |
2699 */ | |
2700 (symbol, buffer, after_set)) | |
2701 { | |
2702 int local_info; | |
2703 | |
2704 CHECK_SYMBOL (symbol); | |
2705 if (!NILP (buffer)) | |
2706 { | |
2707 buffer = get_buffer (buffer, 1); | |
2708 local_info = symbol_value_buffer_local_info (symbol, XBUFFER (buffer)); | |
2709 } | |
2710 else | |
2711 { | |
2712 local_info = symbol_value_buffer_local_info (symbol, 0); | |
2713 } | |
2714 | |
2715 if (NILP (after_set)) | |
2716 return local_info > 0 ? Qt : Qnil; | |
2717 else | |
2718 return local_info != 0 ? Qt : Qnil; | |
2719 } | |
2720 | |
2721 | |
2722 /* | |
2723 I've gone ahead and partially implemented this because it's | |
2724 super-useful for dealing with the compatibility problems in supporting | |
2725 the old pointer-shape variables, and preventing people from `setq'ing | |
2726 the new variables. Any other way of handling this problem is way | |
2727 ugly, likely to be slow, and generally not something I want to waste | |
2728 my time worrying about. | |
2729 | |
2730 The interface and/or function name is sure to change before this | |
2731 gets into its final form. I currently like the way everything is | |
2732 set up and it has all the features I want it to have, except for | |
2733 one: I really want to be able to have multiple nested handlers, | |
2734 to implement an `advice'-like capability. This would allow, | |
2735 for example, a clean way of implementing `debug-if-set' or | |
2736 `debug-if-referenced' and such. | |
2737 | |
2738 NOTE NOTE NOTE NOTE NOTE NOTE NOTE: | |
2739 ************************************************************ | |
2740 **Only** the `set-value', `make-unbound', and `make-local' | |
2741 handler types are currently implemented. Implementing the | |
2742 get-value and bound-predicate handlers is somewhat tricky | |
2743 because there are lots of subfunctions (e.g. find_symbol_value()). | |
2744 find_symbol_value(), in fact, is called from outside of | |
2745 this module. You'd have to have it do this: | |
2746 | |
2747 -- check for a `bound-predicate' handler, call that if so; | |
2748 if it returns nil, return Qunbound | |
2749 -- check for a `get-value' handler and call it and return | |
2750 that value | |
2751 | |
2752 It gets even trickier when you have to deal with | |
2753 sub-subfunctions like find_symbol_value_1(), and esp. | |
2754 when you have to properly handle variable aliases, which | |
2755 can lead to lots of tricky situations. So I've just | |
2756 punted on this, since the interface isn't officially | |
2757 exported and we can get by with just a `set-value' | |
2758 handler. | |
2759 | |
2760 Actions in unimplemented handler types will correctly | |
2761 ignore any handlers, and will not fuck anything up or | |
2762 go awry. | |
2763 | |
2764 WARNING WARNING: If you do go and implement another | |
2765 type of handler, make *sure* to change | |
2766 would_be_magic_handled() so it knows about this, | |
2767 or dire things could result. | |
2768 ************************************************************ | |
2769 NOTE NOTE NOTE NOTE NOTE NOTE NOTE | |
2770 | |
2771 Real documentation is as follows. | |
2772 | |
2773 Set a magic handler for VARIABLE. | |
2774 This allows you to specify arbitrary behavior that results from | |
2775 accessing or setting a variable. For example, retrieving the | |
2776 variable's value might actually retrieve the first element off of | |
2777 a list stored in another variable, and setting the variable's value | |
2778 might add an element to the front of that list. (This is how the | |
2779 obsolete variable `unread-command-event' is implemented.) | |
2780 | |
2781 In general it is NOT good programming practice to use magic variables | |
2782 in a new package that you are designing. If you feel the need to | |
2783 do this, it's almost certainly a sign that you should be using a | |
2784 function instead of a variable. This facility is provided to allow | |
2785 a package to support obsolete variables and provide compatibility | |
2786 with similar packages with different variable names and semantics. | |
2787 By using magic handlers, you can cleanly provide obsoleteness and | |
2788 compatibility support and separate this support from the core | |
2789 routines in a package. | |
2790 | |
2791 VARIABLE should be a symbol naming the variable for which the | |
2792 magic behavior is provided. HANDLER-TYPE is a symbol specifying | |
2793 which behavior is being controlled, and HANDLER is the function | |
2794 that will be called to control this behavior. HARG is a | |
2795 value that will be passed to HANDLER but is otherwise | |
2796 uninterpreted. KEEP-EXISTING specifies what to do with existing | |
2797 handlers of the same type; nil means "erase them all", t means | |
2798 "keep them but insert at the beginning", the list (t) means | |
2799 "keep them but insert at the end", a function means "keep | |
2800 them but insert before the specified function", a list containing | |
2801 a function means "keep them but insert after the specified | |
2802 function". | |
2803 | |
2804 You can specify magic behavior for any type of variable at all, | |
2805 and for any handler types that are unspecified, the standard | |
2806 behavior applies. This allows you, for example, to use | |
2807 `defvaralias' in conjunction with this function. (For that | |
2808 matter, `defvaralias' could be implemented using this function.) | |
2809 | |
2810 The behaviors that can be specified in HANDLER-TYPE are | |
2811 | |
2812 get-value (SYM ARGS FUN HARG HANDLERS) | |
2813 This means that one of the functions `symbol-value', | |
2814 `default-value', `symbol-value-in-buffer', or | |
2815 `symbol-value-in-console' was called on SYM. | |
2816 | |
2817 set-value (SYM ARGS FUN HARG HANDLERS) | |
2818 This means that one of the functions `set' or `set-default' | |
2819 was called on SYM. | |
2820 | |
2821 bound-predicate (SYM ARGS FUN HARG HANDLERS) | |
2822 This means that one of the functions `boundp', `globally-boundp', | |
2823 or `default-boundp' was called on SYM. | |
2824 | |
2825 make-unbound (SYM ARGS FUN HARG HANDLERS) | |
2826 This means that the function `makunbound' was called on SYM. | |
2827 | |
2828 local-predicate (SYM ARGS FUN HARG HANDLERS) | |
2829 This means that the function `local-variable-p' was called | |
2830 on SYM. | |
2831 | |
2832 make-local (SYM ARGS FUN HARG HANDLERS) | |
2833 This means that one of the functions `make-local-variable', | |
2834 `make-variable-buffer-local', `kill-local-variable', | |
2835 or `kill-console-local-variable' was called on SYM. | |
2836 | |
2837 The meanings of the arguments are as follows: | |
2838 | |
2839 SYM is the symbol on which the function was called, and is always | |
2840 the first argument to the function. | |
2841 | |
2842 ARGS are the remaining arguments in the original call (i.e. all | |
2843 but the first). In the case of `set-value' in particular, | |
2844 the first element of ARGS is the value to which the variable | |
2845 is being set. In some cases, ARGS is sanitized from what was | |
2846 actually given. For example, whenever `nil' is passed to an | |
2847 argument and it means `current-buffer', the current buffer is | |
2848 substituted instead. | |
2849 | |
2850 FUN is a symbol indicating which function is being called. | |
2851 For many of the functions, you can determine the corresponding | |
2852 function of a different class using | |
2853 `symbol-function-corresponding-function'. | |
2854 | |
2855 HARG is the argument that was given in the call | |
2856 to `set-symbol-value-handler' for SYM and HANDLER-TYPE. | |
2857 | |
2858 HANDLERS is a structure containing the remaining handlers | |
2859 for the variable; to call one of them, use | |
2860 `chain-to-symbol-value-handler'. | |
2861 | |
2862 NOTE: You may *not* modify the list in ARGS, and if you want to | |
2863 keep it around after the handler function exits, you must make | |
2864 a copy using `copy-sequence'. (Same caveats for HANDLERS also.) | |
2865 */ | |
2866 | |
2867 static enum lisp_magic_handler | |
2868 decode_magic_handler_type (Lisp_Object symbol) | |
2869 { | |
2870 if (EQ (symbol, Qget_value)) return MAGIC_HANDLER_GET_VALUE; | |
2871 if (EQ (symbol, Qset_value)) return MAGIC_HANDLER_SET_VALUE; | |
2872 if (EQ (symbol, Qbound_predicate)) return MAGIC_HANDLER_BOUND_PREDICATE; | |
2873 if (EQ (symbol, Qmake_unbound)) return MAGIC_HANDLER_MAKE_UNBOUND; | |
2874 if (EQ (symbol, Qlocal_predicate)) return MAGIC_HANDLER_LOCAL_PREDICATE; | |
2875 if (EQ (symbol, Qmake_local)) return MAGIC_HANDLER_MAKE_LOCAL; | |
2876 | |
563 | 2877 invalid_constant ("Unrecognized symbol value handler type", symbol); |
1204 | 2878 RETURN_NOT_REACHED (MAGIC_HANDLER_MAX); |
428 | 2879 } |
2880 | |
2881 static enum lisp_magic_handler | |
2882 handler_type_from_function_symbol (Lisp_Object funsym, int abort_if_not_found) | |
2883 { | |
2884 if (EQ (funsym, Qsymbol_value) | |
2885 || EQ (funsym, Qdefault_value) | |
2886 || EQ (funsym, Qsymbol_value_in_buffer) | |
2887 || EQ (funsym, Qsymbol_value_in_console)) | |
2888 return MAGIC_HANDLER_GET_VALUE; | |
2889 | |
2890 if (EQ (funsym, Qset) | |
2891 || EQ (funsym, Qset_default)) | |
2892 return MAGIC_HANDLER_SET_VALUE; | |
2893 | |
2894 if (EQ (funsym, Qboundp) | |
2895 || EQ (funsym, Qglobally_boundp) | |
2896 || EQ (funsym, Qdefault_boundp)) | |
2897 return MAGIC_HANDLER_BOUND_PREDICATE; | |
2898 | |
2899 if (EQ (funsym, Qmakunbound)) | |
2900 return MAGIC_HANDLER_MAKE_UNBOUND; | |
2901 | |
2902 if (EQ (funsym, Qlocal_variable_p)) | |
2903 return MAGIC_HANDLER_LOCAL_PREDICATE; | |
2904 | |
2905 if (EQ (funsym, Qmake_variable_buffer_local) | |
2906 || EQ (funsym, Qmake_local_variable)) | |
2907 return MAGIC_HANDLER_MAKE_LOCAL; | |
2908 | |
2909 if (abort_if_not_found) | |
2500 | 2910 ABORT (); |
563 | 2911 invalid_argument ("Unrecognized symbol-value function", funsym); |
1204 | 2912 RETURN_NOT_REACHED (MAGIC_HANDLER_MAX); |
428 | 2913 } |
2914 | |
2915 static int | |
2916 would_be_magic_handled (Lisp_Object sym, Lisp_Object funsym) | |
2917 { | |
2918 /* does not take into account variable aliasing. */ | |
2919 Lisp_Object valcontents = XSYMBOL (sym)->value; | |
2920 enum lisp_magic_handler slot; | |
2921 | |
2922 if (!SYMBOL_VALUE_LISP_MAGIC_P (valcontents)) | |
2923 return 0; | |
2924 slot = handler_type_from_function_symbol (funsym, 1); | |
2925 if (slot != MAGIC_HANDLER_SET_VALUE && slot != MAGIC_HANDLER_MAKE_UNBOUND | |
2926 && slot != MAGIC_HANDLER_MAKE_LOCAL) | |
2927 /* #### temporary kludge because we haven't implemented | |
2928 lisp-magic variables completely */ | |
2929 return 0; | |
2930 return !NILP (XSYMBOL_VALUE_LISP_MAGIC (valcontents)->handler[slot]); | |
2931 } | |
2932 | |
2933 static Lisp_Object | |
2934 fetch_value_maybe_past_magic (Lisp_Object sym, | |
2935 Lisp_Object follow_past_lisp_magic) | |
2936 { | |
2937 Lisp_Object value = XSYMBOL (sym)->value; | |
2938 if (SYMBOL_VALUE_LISP_MAGIC_P (value) | |
2939 && (EQ (follow_past_lisp_magic, Qt) | |
2940 || (!NILP (follow_past_lisp_magic) | |
2941 && !would_be_magic_handled (sym, follow_past_lisp_magic)))) | |
2942 value = XSYMBOL_VALUE_LISP_MAGIC (value)->shadowed; | |
2943 return value; | |
2944 } | |
2945 | |
2946 static Lisp_Object * | |
2947 value_slot_past_magic (Lisp_Object sym) | |
2948 { | |
2949 Lisp_Object *store_pointer = &XSYMBOL (sym)->value; | |
2950 | |
2951 if (SYMBOL_VALUE_LISP_MAGIC_P (*store_pointer)) | |
2952 store_pointer = &XSYMBOL_VALUE_LISP_MAGIC (sym)->shadowed; | |
2953 return store_pointer; | |
2954 } | |
2955 | |
2956 static Lisp_Object | |
2957 maybe_call_magic_handler (Lisp_Object sym, Lisp_Object funsym, int nargs, ...) | |
2958 { | |
2959 va_list vargs; | |
2960 Lisp_Object args[20]; /* should be enough ... */ | |
2961 int i; | |
2962 enum lisp_magic_handler htype; | |
2963 Lisp_Object legerdemain; | |
2964 struct symbol_value_lisp_magic *bfwd; | |
2965 | |
440 | 2966 assert (nargs >= 0 && nargs < countof (args)); |
428 | 2967 legerdemain = XSYMBOL (sym)->value; |
2968 assert (SYMBOL_VALUE_LISP_MAGIC_P (legerdemain)); | |
2969 bfwd = XSYMBOL_VALUE_LISP_MAGIC (legerdemain); | |
2970 | |
2971 va_start (vargs, nargs); | |
2972 for (i = 0; i < nargs; i++) | |
2973 args[i] = va_arg (vargs, Lisp_Object); | |
2974 va_end (vargs); | |
2975 | |
2976 htype = handler_type_from_function_symbol (funsym, 1); | |
2977 if (NILP (bfwd->handler[htype])) | |
2978 return Qunbound; | |
2979 /* #### should be reusing the arglist, not always consing anew. | |
2980 Repeated handler invocations should not cause repeated consing. | |
2981 Doesn't matter for now, because this is just a quick implementation | |
2982 for obsolescence support. */ | |
2983 return call5 (bfwd->handler[htype], sym, Flist (nargs, args), funsym, | |
2984 bfwd->harg[htype], Qnil); | |
2985 } | |
2986 | |
2987 DEFUN ("dontusethis-set-symbol-value-handler", Fdontusethis_set_symbol_value_handler, | |
2988 3, 5, 0, /* | |
2989 Don't you dare use this. | |
2990 If you do, suffer the wrath of Ben, who is likely to rename | |
2991 this function (or change the semantics of its arguments) without | |
2992 pity, thereby invalidating your code. | |
2993 */ | |
2286 | 2994 (variable, handler_type, handler, harg, |
2995 UNUSED (keep_existing))) | |
428 | 2996 { |
2997 Lisp_Object valcontents; | |
2998 struct symbol_value_lisp_magic *bfwd; | |
2999 enum lisp_magic_handler htype; | |
3000 int i; | |
3001 | |
3002 /* #### WARNING, only some handler types are implemented. See above. | |
3003 Actions of other types will ignore a handler if it's there. | |
3004 | |
3005 #### Also, `chain-to-symbol-value-handler' and | |
3006 `symbol-function-corresponding-function' are not implemented. */ | |
3007 CHECK_SYMBOL (variable); | |
3008 CHECK_SYMBOL (handler_type); | |
3009 htype = decode_magic_handler_type (handler_type); | |
3010 valcontents = XSYMBOL (variable)->value; | |
3011 if (!SYMBOL_VALUE_LISP_MAGIC_P (valcontents)) | |
3012 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3013 bfwd = |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3014 XSYMBOL_VALUE_LISP_MAGIC |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3015 (ALLOC_LISP_OBJECT (symbol_value_lisp_magic)); |
428 | 3016 bfwd->magic.type = SYMVAL_LISP_MAGIC; |
3017 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
3018 { | |
3019 bfwd->handler[i] = Qnil; | |
3020 bfwd->harg[i] = Qnil; | |
3021 } | |
3022 bfwd->shadowed = valcontents; | |
793 | 3023 XSYMBOL (variable)->value = wrap_symbol_value_magic (bfwd); |
428 | 3024 } |
3025 else | |
3026 bfwd = XSYMBOL_VALUE_LISP_MAGIC (valcontents); | |
3027 bfwd->handler[htype] = handler; | |
3028 bfwd->harg[htype] = harg; | |
3029 | |
3030 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
3031 if (!NILP (bfwd->handler[i])) | |
3032 break; | |
3033 | |
3034 if (i == MAGIC_HANDLER_MAX) | |
3035 /* there are no remaining handlers, so remove the structure. */ | |
3036 XSYMBOL (variable)->value = bfwd->shadowed; | |
3037 | |
3038 return Qnil; | |
3039 } | |
3040 | |
3041 | |
3042 /* functions for working with variable aliases. */ | |
3043 | |
3044 /* Follow the chain of variable aliases for SYMBOL. Return the | |
3045 resulting symbol, whose value cell is guaranteed not to be a | |
3046 symbol-value-varalias. | |
3047 | |
3048 Also maybe follow past symbol-value-lisp-magic -> symbol-value-varalias. | |
3049 If FUNSYM is t, always follow in such a case. If FUNSYM is nil, | |
3050 never follow; stop right there. Otherwise FUNSYM should be a | |
3051 recognized symbol-value function symbol; this means, follow | |
3052 unless there is a special handler for the named function. | |
3053 | |
3054 OK, there is at least one reason why it's necessary for | |
3055 FOLLOW-PAST-LISP-MAGIC to be specified correctly: So that we | |
3056 can always be sure to catch cyclic variable aliasing. If we never | |
3057 follow past Lisp magic, then if the following is done: | |
3058 | |
3059 (defvaralias 'a 'b) | |
3060 add some magic behavior to a, but not a "get-value" handler | |
3061 (defvaralias 'b 'a) | |
3062 | |
3063 then an attempt to retrieve a's or b's value would cause infinite | |
3064 looping in `symbol-value'. | |
3065 | |
3066 We (of course) can't always follow past Lisp magic, because then | |
3067 we make any variable that is lisp-magic -> varalias behave as if | |
3068 the lisp-magic is not present at all. | |
3069 */ | |
3070 | |
3071 static Lisp_Object | |
3072 follow_varalias_pointers (Lisp_Object symbol, | |
3073 Lisp_Object follow_past_lisp_magic) | |
3074 { | |
3075 #define VARALIAS_INDIRECTION_SUSPICION_LENGTH 16 | |
3076 Lisp_Object tortoise, hare, val; | |
3077 int count; | |
3078 | |
3079 /* quick out just in case */ | |
3080 if (!SYMBOL_VALUE_MAGIC_P (XSYMBOL (symbol)->value)) | |
3081 return symbol; | |
3082 | |
3083 /* Compare implementation of indirect_function(). */ | |
3084 for (hare = tortoise = symbol, count = 0; | |
3085 val = fetch_value_maybe_past_magic (hare, follow_past_lisp_magic), | |
3086 SYMBOL_VALUE_VARALIAS_P (val); | |
3087 hare = symbol_value_varalias_aliasee (XSYMBOL_VALUE_VARALIAS (val)), | |
3088 count++) | |
3089 { | |
3090 if (count < VARALIAS_INDIRECTION_SUSPICION_LENGTH) continue; | |
3091 | |
3092 if (count & 1) | |
3093 tortoise = symbol_value_varalias_aliasee | |
3094 (XSYMBOL_VALUE_VARALIAS (fetch_value_maybe_past_magic | |
3095 (tortoise, follow_past_lisp_magic))); | |
3096 if (EQ (hare, tortoise)) | |
3097 return Fsignal (Qcyclic_variable_indirection, list1 (symbol)); | |
3098 } | |
3099 | |
3100 return hare; | |
3101 } | |
3102 | |
3103 DEFUN ("defvaralias", Fdefvaralias, 2, 2, 0, /* | |
3104 Define a variable as an alias for another variable. | |
3105 Thenceforth, any operations performed on VARIABLE will actually be | |
3106 performed on ALIAS. Both VARIABLE and ALIAS should be symbols. | |
3107 If ALIAS is nil, remove any aliases for VARIABLE. | |
3108 ALIAS can itself be aliased, and the chain of variable aliases | |
3109 will be followed appropriately. | |
3110 If VARIABLE already has a value, this value will be shadowed | |
3111 until the alias is removed, at which point it will be restored. | |
3112 Currently VARIABLE cannot be a built-in variable, a variable that | |
3113 has a buffer-local value in any buffer, or the symbols nil or t. | |
3114 \(ALIAS, however, can be any type of variable.) | |
3115 */ | |
3116 (variable, alias)) | |
3117 { | |
3118 struct symbol_value_varalias *bfwd; | |
3119 Lisp_Object valcontents; | |
3120 | |
3121 CHECK_SYMBOL (variable); | |
3122 reject_constant_symbols (variable, Qunbound, 0, Qt); | |
3123 | |
3124 valcontents = XSYMBOL (variable)->value; | |
3125 | |
3126 if (NILP (alias)) | |
3127 { | |
3128 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) | |
3129 { | |
3130 XSYMBOL (variable)->value = | |
3131 symbol_value_varalias_shadowed | |
3132 (XSYMBOL_VALUE_VARALIAS (valcontents)); | |
3133 } | |
3134 return Qnil; | |
3135 } | |
3136 | |
3137 CHECK_SYMBOL (alias); | |
3138 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) | |
3139 { | |
3140 /* transmogrify */ | |
3141 XSYMBOL_VALUE_VARALIAS (valcontents)->aliasee = alias; | |
3142 return Qnil; | |
3143 } | |
3144 | |
3145 if (SYMBOL_VALUE_MAGIC_P (valcontents) | |
3146 && !UNBOUNDP (valcontents)) | |
563 | 3147 invalid_change ("Variable is magic and cannot be aliased", variable); |
428 | 3148 reject_constant_symbols (variable, Qunbound, 0, Qt); |
3149 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3150 bfwd = |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3151 XSYMBOL_VALUE_VARALIAS (ALLOC_LISP_OBJECT (symbol_value_varalias)); |
428 | 3152 bfwd->magic.type = SYMVAL_VARALIAS; |
3153 bfwd->aliasee = alias; | |
3154 bfwd->shadowed = valcontents; | |
3155 | |
793 | 3156 valcontents = wrap_symbol_value_magic (bfwd); |
428 | 3157 XSYMBOL (variable)->value = valcontents; |
3158 return Qnil; | |
3159 } | |
3160 | |
3161 DEFUN ("variable-alias", Fvariable_alias, 1, 2, 0, /* | |
3162 If VARIABLE is aliased to another variable, return that variable. | |
3163 VARIABLE should be a symbol. If VARIABLE is not aliased, return nil. | |
3164 Variable aliases are created with `defvaralias'. See also | |
3165 `indirect-variable'. | |
3166 */ | |
3167 (variable, follow_past_lisp_magic)) | |
3168 { | |
3169 Lisp_Object valcontents; | |
3170 | |
3171 CHECK_SYMBOL (variable); | |
3172 if (!NILP (follow_past_lisp_magic) && !EQ (follow_past_lisp_magic, Qt)) | |
3173 { | |
3174 CHECK_SYMBOL (follow_past_lisp_magic); | |
3175 handler_type_from_function_symbol (follow_past_lisp_magic, 0); | |
3176 } | |
3177 | |
3178 valcontents = fetch_value_maybe_past_magic (variable, | |
3179 follow_past_lisp_magic); | |
3180 | |
3181 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) | |
3182 return symbol_value_varalias_aliasee | |
3183 (XSYMBOL_VALUE_VARALIAS (valcontents)); | |
3184 else | |
3185 return Qnil; | |
3186 } | |
3187 | |
3188 DEFUN ("indirect-variable", Findirect_variable, 1, 2, 0, /* | |
3189 Return the variable at the end of OBJECT's variable-alias chain. | |
3190 If OBJECT is a symbol, follow all variable aliases and return | |
3191 the final (non-aliased) symbol. Variable aliases are created with | |
3192 the function `defvaralias'. | |
3193 If OBJECT is not a symbol, just return it. | |
3194 Signal a cyclic-variable-indirection error if there is a loop in the | |
3195 variable chain of symbols. | |
3196 */ | |
3197 (object, follow_past_lisp_magic)) | |
3198 { | |
3199 if (!SYMBOLP (object)) | |
3200 return object; | |
3201 if (!NILP (follow_past_lisp_magic) && !EQ (follow_past_lisp_magic, Qt)) | |
3202 { | |
3203 CHECK_SYMBOL (follow_past_lisp_magic); | |
3204 handler_type_from_function_symbol (follow_past_lisp_magic, 0); | |
3205 } | |
3206 return follow_varalias_pointers (object, follow_past_lisp_magic); | |
3207 } | |
3208 | |
1674 | 3209 DEFUN ("variable-binding-locus", Fvariable_binding_locus, 1, 1, 0, /* |
3210 Return a value indicating where VARIABLE's current binding comes from. | |
3211 If the current binding is buffer-local, the value is the current buffer. | |
3212 If the current binding is global (the default), the value is nil. | |
3213 */ | |
3214 (variable)) | |
3215 { | |
3216 Lisp_Object valcontents; | |
3217 | |
3218 CHECK_SYMBOL (variable); | |
3219 variable = Findirect_variable (variable, Qnil); | |
3220 | |
3221 /* Make sure the current binding is actually swapped in. */ | |
3222 find_symbol_value (variable); | |
3223 | |
3224 valcontents = XSYMBOL (variable)->value; | |
3225 | |
3226 if (SYMBOL_VALUE_MAGIC_P (valcontents) | |
3227 && ((XSYMBOL_VALUE_MAGIC_TYPE (valcontents) == SYMVAL_BUFFER_LOCAL) | |
3228 || (XSYMBOL_VALUE_MAGIC_TYPE (valcontents) == SYMVAL_SOME_BUFFER_LOCAL)) | |
3229 && (!NILP (Flocal_variable_p (variable, Fcurrent_buffer (), Qnil)))) | |
3230 return Fcurrent_buffer (); | |
3231 else | |
3232 return Qnil; | |
3233 } | |
428 | 3234 |
3235 /************************************************************************/ | |
3236 /* initialization */ | |
3237 /************************************************************************/ | |
3238 | |
3239 /* A dumped XEmacs image has a lot more than 1511 symbols. Last | |
3240 estimate was that there were actually around 6300. So let's try | |
3241 making this bigger and see if we get better hashing behavior. */ | |
3242 #define OBARRAY_SIZE 16411 | |
3243 | |
3244 #ifndef Qzero | |
3245 Lisp_Object Qzero; | |
3246 #endif | |
3247 #ifndef Qnull_pointer | |
3248 Lisp_Object Qnull_pointer; | |
3249 #endif | |
3250 | |
2720 | 3251 #ifndef MC_ALLOC |
428 | 3252 /* some losing systems can't have static vars at function scope... */ |
442 | 3253 static const struct symbol_value_magic guts_of_unbound_marker = |
3254 { /* struct symbol_value_magic */ | |
3024 | 3255 { /* struct old_lcrecord_header */ |
442 | 3256 { /* struct lrecord_header */ |
3257 lrecord_type_symbol_value_forward, /* lrecord_type_index */ | |
3258 1, /* mark bit */ | |
3259 1, /* c_readonly bit */ | |
3260 1, /* lisp_readonly bit */ | |
3261 }, | |
3262 0, /* next */ | |
3263 0, /* uid */ | |
3264 0, /* free */ | |
3265 }, | |
3266 0, /* value */ | |
3267 SYMVAL_UNBOUND_MARKER | |
3268 }; | |
2720 | 3269 #endif /* not MC_ALLOC */ |
428 | 3270 |
3271 void | |
3272 init_symbols_once_early (void) | |
3273 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3274 INIT_LISP_OBJECT (symbol); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3275 INIT_LISP_OBJECT (symbol_value_forward); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3276 INIT_LISP_OBJECT (symbol_value_buffer_local); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3277 INIT_LISP_OBJECT (symbol_value_lisp_magic); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3278 INIT_LISP_OBJECT (symbol_value_varalias); |
442 | 3279 |
1204 | 3280 reinit_symbols_early (); |
428 | 3281 |
3282 /* Bootstrapping problem: Qnil isn't set when make_string_nocopy is | |
3283 called the first time. */ | |
867 | 3284 Qnil = Fmake_symbol (make_string_nocopy ((const Ibyte *) "nil", 3)); |
793 | 3285 XSTRING_PLIST (XSYMBOL (Qnil)->name) = Qnil; |
428 | 3286 XSYMBOL (Qnil)->value = Qnil; /* Nihil ex nihil */ |
3287 XSYMBOL (Qnil)->plist = Qnil; | |
3288 | |
3289 Vobarray = make_vector (OBARRAY_SIZE, Qzero); | |
3290 initial_obarray = Vobarray; | |
3291 staticpro (&initial_obarray); | |
3292 /* Intern nil in the obarray */ | |
3293 { | |
793 | 3294 unsigned int hash = hash_string (XSTRING_DATA (XSYMBOL (Qnil)->name), 3); |
428 | 3295 XVECTOR_DATA (Vobarray)[hash % OBARRAY_SIZE] = Qnil; |
3296 } | |
3297 | |
3298 { | |
3299 /* Required to get around a GCC syntax error on certain | |
3300 architectures */ | |
2720 | 3301 #ifdef MC_ALLOC |
3302 struct symbol_value_magic *tem = (struct symbol_value_magic *) | |
3303 mc_alloc (sizeof (struct symbol_value_magic)); | |
3304 MARK_LRECORD_AS_LISP_READONLY (tem); | |
3305 MARK_LRECORD_AS_NOT_FREE (tem); | |
3306 tem->header.type = lrecord_type_symbol_value_forward; | |
3307 mcpro (wrap_pointer_1 (tem)); | |
3308 tem->value = 0; | |
3309 tem->type = SYMVAL_UNBOUND_MARKER; | |
2994 | 3310 #ifdef ALLOC_TYPE_STATS |
2775 | 3311 inc_lrecord_stats (sizeof (struct symbol_value_magic), |
3312 (const struct lrecord_header *) tem); | |
2994 | 3313 #endif /* ALLOC_TYPE_STATS */ |
2720 | 3314 #else /* not MC_ALLOC */ |
442 | 3315 const struct symbol_value_magic *tem = &guts_of_unbound_marker; |
2720 | 3316 #endif /* not MC_ALLOC */ |
428 | 3317 |
793 | 3318 Qunbound = wrap_symbol_value_magic (tem); |
428 | 3319 } |
3320 | |
3321 XSYMBOL (Qnil)->function = Qunbound; | |
3322 | |
563 | 3323 DEFSYMBOL (Qt); |
444 | 3324 XSYMBOL (Qt)->value = Qt; /* Veritas aeterna */ |
428 | 3325 Vquit_flag = Qnil; |
3326 | |
1204 | 3327 dump_add_root_lisp_object (&Qnil); |
3328 dump_add_root_lisp_object (&Qunbound); | |
3329 dump_add_root_lisp_object (&Vquit_flag); | |
428 | 3330 } |
3331 | |
3332 void | |
1204 | 3333 reinit_symbols_early (void) |
440 | 3334 { |
3335 } | |
3336 | |
442 | 3337 static void |
3338 defsymbol_massage_name_1 (Lisp_Object *location, const char *name, int dump_p, | |
3339 int multiword_predicate_p) | |
3340 { | |
3341 char temp[500]; | |
3342 int len = strlen (name) - 1; | |
3343 int i; | |
3344 | |
3345 if (multiword_predicate_p) | |
647 | 3346 assert (len + 1 < (int) sizeof (temp)); |
442 | 3347 else |
647 | 3348 assert (len < (int) sizeof (temp)); |
442 | 3349 strcpy (temp, name + 1); /* Remove initial Q */ |
3350 if (multiword_predicate_p) | |
3351 { | |
3352 strcpy (temp + len - 1, "_p"); | |
3353 len++; | |
3354 } | |
3355 for (i = 0; i < len; i++) | |
3356 if (temp[i] == '_') | |
3357 temp[i] = '-'; | |
867 | 3358 *location = Fintern (make_string ((const Ibyte *) temp, len), Qnil); |
442 | 3359 if (dump_p) |
3360 staticpro (location); | |
3361 else | |
3362 staticpro_nodump (location); | |
3363 } | |
3364 | |
440 | 3365 void |
442 | 3366 defsymbol_massage_name_nodump (Lisp_Object *location, const char *name) |
3367 { | |
3368 defsymbol_massage_name_1 (location, name, 0, 0); | |
3369 } | |
3370 | |
3371 void | |
3372 defsymbol_massage_name (Lisp_Object *location, const char *name) | |
428 | 3373 { |
442 | 3374 defsymbol_massage_name_1 (location, name, 1, 0); |
3375 } | |
3376 | |
3377 void | |
3378 defsymbol_massage_multiword_predicate_nodump (Lisp_Object *location, | |
3379 const char *name) | |
3380 { | |
3381 defsymbol_massage_name_1 (location, name, 0, 1); | |
3382 } | |
3383 | |
3384 void | |
3385 defsymbol_massage_multiword_predicate (Lisp_Object *location, const char *name) | |
3386 { | |
3387 defsymbol_massage_name_1 (location, name, 1, 1); | |
3388 } | |
3389 | |
3390 void | |
3391 defsymbol_nodump (Lisp_Object *location, const char *name) | |
3392 { | |
867 | 3393 *location = Fintern (make_string_nocopy ((const Ibyte *) name, |
428 | 3394 strlen (name)), |
3395 Qnil); | |
3396 staticpro_nodump (location); | |
3397 } | |
3398 | |
3399 void | |
442 | 3400 defsymbol (Lisp_Object *location, const char *name) |
428 | 3401 { |
867 | 3402 *location = Fintern (make_string_nocopy ((const Ibyte *) name, |
428 | 3403 strlen (name)), |
3404 Qnil); | |
3405 staticpro (location); | |
3406 } | |
3407 | |
3408 void | |
442 | 3409 defkeyword (Lisp_Object *location, const char *name) |
428 | 3410 { |
3411 defsymbol (location, name); | |
3412 Fset (*location, *location); | |
3413 } | |
3414 | |
442 | 3415 void |
3416 defkeyword_massage_name (Lisp_Object *location, const char *name) | |
3417 { | |
3418 char temp[500]; | |
3419 int len = strlen (name); | |
3420 | |
647 | 3421 assert (len < (int) sizeof (temp)); |
442 | 3422 strcpy (temp, name); |
3423 temp[1] = ':'; /* it's an underscore in the C variable */ | |
3424 | |
3425 defsymbol_massage_name (location, temp); | |
3426 Fset (*location, *location); | |
3427 } | |
3428 | |
428 | 3429 #ifdef DEBUG_XEMACS |
930 | 3430 /* Check that nobody spazzed writing a builtin (non-module) DEFUN. */ |
428 | 3431 static void |
3432 check_sane_subr (Lisp_Subr *subr, Lisp_Object sym) | |
3433 { | |
930 | 3434 if (!initialized) { |
3435 assert (subr->min_args >= 0); | |
3436 assert (subr->min_args <= SUBR_MAX_ARGS); | |
3437 | |
3438 if (subr->max_args != MANY && | |
3439 subr->max_args != UNEVALLED) | |
3440 { | |
3441 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ | |
3442 assert (subr->max_args <= SUBR_MAX_ARGS); | |
3443 assert (subr->min_args <= subr->max_args); | |
3444 } | |
3445 assert (UNBOUNDP (XSYMBOL (sym)->function)); | |
3446 } | |
428 | 3447 } |
3448 #else | |
3449 #define check_sane_subr(subr, sym) /* nothing */ | |
3450 #endif | |
3451 | |
3452 #ifdef HAVE_SHLIB | |
2963 | 3453 #ifndef MC_ALLOC |
428 | 3454 /* |
3455 * If we are not in a pure undumped Emacs, we need to make a duplicate of | |
3456 * the subr. This is because the only time this function will be called | |
3457 * in a running Emacs is when a dynamically loaded module is adding a | |
3458 * subr, and we need to make sure that the subr is in allocated, Lisp- | |
3459 * accessible memory. The address assigned to the static subr struct | |
3460 * in the shared object will be a trampoline address, so we need to create | |
3461 * a copy here to ensure that a real address is used. | |
3462 * | |
3463 * Once we have copied everything across, we re-use the original static | |
3464 * structure to store a pointer to the newly allocated one. This will be | |
3465 * used in emodules.c by emodules_doc_subr() to find a pointer to the | |
442 | 3466 * allocated object so that we can set its doc string properly. |
428 | 3467 * |
442 | 3468 * NOTE: We don't actually use the DOC pointer here any more, but we did |
428 | 3469 * in an earlier implementation of module support. There is no harm in |
3470 * setting it here in case we ever need it in future implementations. | |
3471 * subr->doc will point to the new subr structure that was allocated. | |
442 | 3472 * Code can then get this value from the static subr structure and use |
428 | 3473 * it if required. |
3474 * | |
442 | 3475 * FIXME: Should newsubr be staticpro()'ed? I don't think so but I need |
428 | 3476 * a guru to check. |
3477 */ | |
930 | 3478 #define check_module_subr(subr) \ |
3479 do { \ | |
3480 if (initialized) { \ | |
3481 Lisp_Subr *newsubr; \ | |
3482 Lisp_Object f; \ | |
3483 \ | |
3484 if (subr->min_args < 0) \ | |
3485 signal_ferror (Qdll_error, "%s min_args (%hd) too small", \ | |
3486 subr_name (subr), subr->min_args); \ | |
3487 if (subr->min_args > SUBR_MAX_ARGS) \ | |
3488 signal_ferror (Qdll_error, "%s min_args (%hd) too big (max = %d)", \ | |
3489 subr_name (subr), subr->min_args, SUBR_MAX_ARGS); \ | |
3490 \ | |
3491 if (subr->max_args != MANY && \ | |
3492 subr->max_args != UNEVALLED) \ | |
3493 { \ | |
3494 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ \ | |
3495 if (subr->max_args > SUBR_MAX_ARGS) \ | |
3496 signal_ferror (Qdll_error, "%s max_args (%hd) too big (max = %d)", \ | |
3497 subr_name (subr), subr->max_args, SUBR_MAX_ARGS); \ | |
3498 if (subr->min_args > subr->max_args) \ | |
3499 signal_ferror (Qdll_error, "%s min_args (%hd) > max_args (%hd)", \ | |
3500 subr_name (subr), subr->min_args, subr->max_args); \ | |
3501 } \ | |
3502 \ | |
3503 f = XSYMBOL (sym)->function; \ | |
3504 if (!UNBOUNDP (f) && (!CONSP (f) || !EQ (XCAR (f), Qautoload))) \ | |
3505 signal_ferror (Qdll_error, "Attempt to redefine %s", subr_name (subr)); \ | |
3506 \ | |
2367 | 3507 newsubr = xnew (Lisp_Subr); \ |
930 | 3508 memcpy (newsubr, subr, sizeof (Lisp_Subr)); \ |
3509 subr->doc = (const char *)newsubr; \ | |
3510 subr = newsubr; \ | |
3511 } \ | |
428 | 3512 } while (0) |
2963 | 3513 #else /* MC_ALLOC */ |
3514 /* | |
3515 * If we have the new allocator enabled, we do not need to make a | |
3516 * duplicate of the subr. The new allocator already does allocate all | |
3517 * subrs in Lisp-accessible memory rather than have it in the static | |
3518 * subr struct. | |
3519 * | |
3520 * NOTE: The DOC pointer is not set here as described above. | |
3521 */ | |
3522 #define check_module_subr(subr) \ | |
3523 do { \ | |
3524 if (initialized) { \ | |
3525 Lisp_Object f; \ | |
3526 \ | |
3527 if (subr->min_args < 0) \ | |
3528 signal_ferror (Qdll_error, "%s min_args (%hd) too small", \ | |
3529 subr_name (subr), subr->min_args); \ | |
3530 if (subr->min_args > SUBR_MAX_ARGS) \ | |
3531 signal_ferror (Qdll_error, "%s min_args (%hd) too big (max = %d)", \ | |
3532 subr_name (subr), subr->min_args, SUBR_MAX_ARGS); \ | |
3533 \ | |
3534 if (subr->max_args != MANY && \ | |
3535 subr->max_args != UNEVALLED) \ | |
3536 { \ | |
3537 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ \ | |
3538 if (subr->max_args > SUBR_MAX_ARGS) \ | |
3539 signal_ferror (Qdll_error, "%s max_args (%hd) too big (max = %d)", \ | |
3540 subr_name (subr), subr->max_args, SUBR_MAX_ARGS); \ | |
3541 if (subr->min_args > subr->max_args) \ | |
3542 signal_ferror (Qdll_error, "%s min_args (%hd) > max_args (%hd)", \ | |
3543 subr_name (subr), subr->min_args, subr->max_args); \ | |
3544 } \ | |
3545 \ | |
3546 f = XSYMBOL (sym)->function; \ | |
3547 if (!UNBOUNDP (f) && (!CONSP (f) || !EQ (XCAR (f), Qautoload))) \ | |
3548 signal_ferror (Qdll_error, "Attempt to redefine %s", subr_name (subr)); \ | |
3549 } \ | |
3550 } while (0) | |
3551 #endif /* MC_ALLOC */ | |
428 | 3552 #else /* ! HAVE_SHLIB */ |
930 | 3553 #define check_module_subr(subr) |
428 | 3554 #endif |
3555 | |
3556 void | |
3557 defsubr (Lisp_Subr *subr) | |
3558 { | |
3559 Lisp_Object sym = intern (subr_name (subr)); | |
3560 Lisp_Object fun; | |
3561 | |
3562 check_sane_subr (subr, sym); | |
930 | 3563 check_module_subr (subr); |
428 | 3564 |
793 | 3565 fun = wrap_subr (subr); |
428 | 3566 XSYMBOL (sym)->function = fun; |
996 | 3567 |
3568 #ifdef HAVE_SHLIB | |
3569 /* If it is declared in a module, update the load history */ | |
3570 if (initialized) | |
3571 LOADHIST_ATTACH (sym); | |
3572 #endif | |
428 | 3573 } |
3574 | |
3575 /* Define a lisp macro using a Lisp_Subr. */ | |
3576 void | |
3577 defsubr_macro (Lisp_Subr *subr) | |
3578 { | |
3579 Lisp_Object sym = intern (subr_name (subr)); | |
3580 Lisp_Object fun; | |
3581 | |
3582 check_sane_subr (subr, sym); | |
930 | 3583 check_module_subr (subr); |
428 | 3584 |
793 | 3585 fun = wrap_subr (subr); |
428 | 3586 XSYMBOL (sym)->function = Fcons (Qmacro, fun); |
996 | 3587 |
3588 #ifdef HAVE_SHLIB | |
3589 /* If it is declared in a module, update the load history */ | |
3590 if (initialized) | |
3591 LOADHIST_ATTACH (sym); | |
3592 #endif | |
428 | 3593 } |
3594 | |
442 | 3595 static void |
3596 deferror_1 (Lisp_Object *symbol, const char *name, const char *messuhhj, | |
3597 Lisp_Object inherits_from, int massage_p) | |
428 | 3598 { |
3599 Lisp_Object conds; | |
442 | 3600 if (massage_p) |
3601 defsymbol_massage_name (symbol, name); | |
3602 else | |
3603 defsymbol (symbol, name); | |
428 | 3604 |
3605 assert (SYMBOLP (inherits_from)); | |
3606 conds = Fget (inherits_from, Qerror_conditions, Qnil); | |
3607 Fput (*symbol, Qerror_conditions, Fcons (*symbol, conds)); | |
771 | 3608 /* NOT build_msg_string (). This function is called at load time |
428 | 3609 and the string needs to get translated at run time. (This happens |
3610 in the function (display-error) in cmdloop.el.) */ | |
771 | 3611 Fput (*symbol, Qerror_message, build_msg_string (messuhhj)); |
428 | 3612 } |
3613 | |
3614 void | |
442 | 3615 deferror (Lisp_Object *symbol, const char *name, const char *messuhhj, |
3616 Lisp_Object inherits_from) | |
3617 { | |
3618 deferror_1 (symbol, name, messuhhj, inherits_from, 0); | |
3619 } | |
3620 | |
3621 void | |
3622 deferror_massage_name (Lisp_Object *symbol, const char *name, | |
3623 const char *messuhhj, Lisp_Object inherits_from) | |
3624 { | |
3625 deferror_1 (symbol, name, messuhhj, inherits_from, 1); | |
3626 } | |
3627 | |
3628 void | |
3629 deferror_massage_name_and_message (Lisp_Object *symbol, const char *name, | |
3630 Lisp_Object inherits_from) | |
3631 { | |
3632 char temp[500]; | |
3633 int i; | |
3634 int len = strlen (name) - 1; | |
3635 | |
647 | 3636 assert (len < (int) sizeof (temp)); |
442 | 3637 strcpy (temp, name + 1); /* Remove initial Q */ |
3638 temp[0] = toupper (temp[0]); | |
3639 for (i = 0; i < len; i++) | |
3640 if (temp[i] == '_') | |
3641 temp[i] = ' '; | |
3642 | |
3643 deferror_1 (symbol, name, temp, inherits_from, 1); | |
3644 } | |
3645 | |
3646 void | |
428 | 3647 syms_of_symbols (void) |
3648 { | |
442 | 3649 DEFSYMBOL (Qvariable_documentation); |
3650 DEFSYMBOL (Qvariable_domain); /* I18N3 */ | |
3651 DEFSYMBOL (Qad_advice_info); | |
3652 DEFSYMBOL (Qad_activate); | |
3653 | |
3654 DEFSYMBOL (Qget_value); | |
3655 DEFSYMBOL (Qset_value); | |
3656 DEFSYMBOL (Qbound_predicate); | |
3657 DEFSYMBOL (Qmake_unbound); | |
3658 DEFSYMBOL (Qlocal_predicate); | |
3659 DEFSYMBOL (Qmake_local); | |
3660 | |
3661 DEFSYMBOL (Qboundp); | |
3662 DEFSYMBOL (Qglobally_boundp); | |
3663 DEFSYMBOL (Qmakunbound); | |
3664 DEFSYMBOL (Qsymbol_value); | |
3665 DEFSYMBOL (Qset); | |
3666 DEFSYMBOL (Qsetq_default); | |
3667 DEFSYMBOL (Qdefault_boundp); | |
3668 DEFSYMBOL (Qdefault_value); | |
3669 DEFSYMBOL (Qset_default); | |
3670 DEFSYMBOL (Qmake_variable_buffer_local); | |
3671 DEFSYMBOL (Qmake_local_variable); | |
3672 DEFSYMBOL (Qkill_local_variable); | |
3673 DEFSYMBOL (Qkill_console_local_variable); | |
3674 DEFSYMBOL (Qsymbol_value_in_buffer); | |
3675 DEFSYMBOL (Qsymbol_value_in_console); | |
3676 DEFSYMBOL (Qlocal_variable_p); | |
3677 DEFSYMBOL (Qconst_integer); | |
3678 DEFSYMBOL (Qconst_boolean); | |
3679 DEFSYMBOL (Qconst_object); | |
3680 DEFSYMBOL (Qconst_specifier); | |
3681 DEFSYMBOL (Qdefault_buffer); | |
3682 DEFSYMBOL (Qcurrent_buffer); | |
3683 DEFSYMBOL (Qconst_current_buffer); | |
3684 DEFSYMBOL (Qdefault_console); | |
3685 DEFSYMBOL (Qselected_console); | |
3686 DEFSYMBOL (Qconst_selected_console); | |
428 | 3687 |
3688 DEFSUBR (Fintern); | |
3689 DEFSUBR (Fintern_soft); | |
3690 DEFSUBR (Funintern); | |
3691 DEFSUBR (Fmapatoms); | |
3692 DEFSUBR (Fapropos_internal); | |
3693 | |
3694 DEFSUBR (Fsymbol_function); | |
3695 DEFSUBR (Fsymbol_plist); | |
3696 DEFSUBR (Fsymbol_name); | |
3697 DEFSUBR (Fmakunbound); | |
3698 DEFSUBR (Ffmakunbound); | |
3699 DEFSUBR (Fboundp); | |
3700 DEFSUBR (Fglobally_boundp); | |
3701 DEFSUBR (Ffboundp); | |
3702 DEFSUBR (Ffset); | |
3703 DEFSUBR (Fdefine_function); | |
3704 Ffset (intern ("defalias"), intern ("define-function")); | |
3705 DEFSUBR (Fsetplist); | |
3706 DEFSUBR (Fsymbol_value_in_buffer); | |
3707 DEFSUBR (Fsymbol_value_in_console); | |
3708 DEFSUBR (Fbuilt_in_variable_type); | |
3709 DEFSUBR (Fsymbol_value); | |
3710 DEFSUBR (Fset); | |
3711 DEFSUBR (Fdefault_boundp); | |
3712 DEFSUBR (Fdefault_value); | |
3713 DEFSUBR (Fset_default); | |
3714 DEFSUBR (Fsetq_default); | |
3715 DEFSUBR (Fmake_variable_buffer_local); | |
3716 DEFSUBR (Fmake_local_variable); | |
3717 DEFSUBR (Fkill_local_variable); | |
3718 DEFSUBR (Fkill_console_local_variable); | |
3719 DEFSUBR (Flocal_variable_p); | |
3720 DEFSUBR (Fdefvaralias); | |
3721 DEFSUBR (Fvariable_alias); | |
3722 DEFSUBR (Findirect_variable); | |
1674 | 3723 DEFSUBR (Fvariable_binding_locus); |
428 | 3724 DEFSUBR (Fdontusethis_set_symbol_value_handler); |
3725 } | |
3726 | |
3727 /* Create and initialize a Lisp variable whose value is forwarded to C data */ | |
3728 void | |
442 | 3729 defvar_magic (const char *symbol_name, const struct symbol_value_forward *magic) |
428 | 3730 { |
442 | 3731 Lisp_Object sym; |
428 | 3732 |
996 | 3733 #ifdef HAVE_SHLIB |
428 | 3734 /* |
3735 * As with defsubr(), this will only be called in a dumped Emacs when | |
3736 * we are adding variables from a dynamically loaded module. That means | |
3737 * we can't use purespace. Take that into account. | |
3738 */ | |
3739 if (initialized) | |
996 | 3740 { |
3741 sym = Fintern (build_string (symbol_name), Qnil); | |
3742 LOADHIST_ATTACH (sym); | |
3743 } | |
428 | 3744 else |
3745 #endif | |
867 | 3746 sym = Fintern (make_string_nocopy ((const Ibyte *) symbol_name, |
428 | 3747 strlen (symbol_name)), Qnil); |
3748 | |
793 | 3749 XSYMBOL (sym)->value = wrap_pointer_1 (magic); |
428 | 3750 } |
3751 | |
3752 void | |
3753 vars_of_symbols (void) | |
3754 { | |
3755 DEFVAR_LISP ("obarray", &Vobarray /* | |
3756 Symbol table for use by `intern' and `read'. | |
3757 It is a vector whose length ought to be prime for best results. | |
3758 The vector's contents don't make sense if examined from Lisp programs; | |
3759 to find all the symbols in an obarray, use `mapatoms'. | |
3760 */ ); | |
3761 /* obarray has been initialized long before */ | |
3762 } |