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