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