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