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