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