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