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