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