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