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