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