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