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