Mercurial > hg > xemacs-beta
annotate src/symbols.c @ 5940:c608d4b0b75e cygwin64 tip
rescue lost branch from 64bit.backup
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 16 Dec 2021 18:48:58 +0000 |
parents | 72c5d36ba3b6 |
children |
rev | line source |
---|---|
428 | 1 /* "intern" and friends -- moved here from lread.c and data.c |
2 Copyright (C) 1985-1989, 1992-1994 Free Software Foundation, Inc. | |
4940
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
3 Copyright (C) 1995, 2000, 2001, 2002, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
10 option) any later version. |
428 | 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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: FSF 19.30. */ | |
21 | |
22 /* This file has been Mule-ized. */ | |
23 | |
24 /* NOTE: | |
25 | |
26 The value cell of a symbol can contain a simple value or one of | |
27 various symbol-value-magic objects. Some of these objects can | |
28 chain into other kinds of objects. Here is a table of possibilities: | |
29 | |
30 1a) simple value | |
31 1b) Qunbound | |
32 1c) symbol-value-forward, excluding Qunbound | |
33 2) symbol-value-buffer-local -> 1a or 1b or 1c | |
34 3) symbol-value-lisp-magic -> 1a or 1b or 1c | |
35 4) symbol-value-lisp-magic -> symbol-value-buffer-local -> 1a or 1b or 1c | |
36 5) symbol-value-varalias | |
37 6) symbol-value-lisp-magic -> symbol-value-varalias | |
38 | |
39 The "chain" of a symbol-value-buffer-local is its current_value slot. | |
40 | |
41 The "chain" of a symbol-value-lisp-magic is its shadowed slot, which | |
42 applies for handler types without associated handlers. | |
43 | |
44 All other fields in all the structures (including the "shadowed" slot | |
45 in a symbol-value-varalias) can *only* contain a simple value or Qunbound. | |
46 | |
47 */ | |
48 | |
49 /* #### Ugh, though, this file does awful things with symbol-value-magic | |
50 objects. This ought to be cleaned up. */ | |
51 | |
52 #include <config.h> | |
53 #include "lisp.h" | |
54 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
55 #include "bytecode.h" /* for COMPILED_FUNCTION_ANNOTATION_HACK, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
56 defined in bytecode.h and used here. */ |
428 | 57 #include "buffer.h" /* for Vbuffer_defaults */ |
872 | 58 #include "console-impl.h" |
428 | 59 #include "elhash.h" |
60 | |
61 Lisp_Object Qad_advice_info, Qad_activate; | |
62 | |
63 Lisp_Object Qget_value, Qset_value, Qbound_predicate, Qmake_unbound; | |
64 Lisp_Object Qlocal_predicate, Qmake_local; | |
65 | |
66 Lisp_Object Qboundp, Qglobally_boundp, Qmakunbound; | |
67 Lisp_Object Qsymbol_value, Qset, Qdefault_boundp, Qdefault_value; | |
68 Lisp_Object Qset_default, Qsetq_default; | |
69 Lisp_Object Qmake_variable_buffer_local, Qmake_local_variable; | |
70 Lisp_Object Qkill_local_variable, Qkill_console_local_variable; | |
71 Lisp_Object Qsymbol_value_in_buffer, Qsymbol_value_in_console; | |
72 Lisp_Object Qlocal_variable_p; | |
73 | |
74 Lisp_Object Qconst_integer, Qconst_boolean, Qconst_object; | |
75 Lisp_Object Qconst_specifier; | |
76 Lisp_Object Qdefault_buffer, Qcurrent_buffer, Qconst_current_buffer; | |
77 Lisp_Object Qdefault_console, Qselected_console, Qconst_selected_console; | |
78 | |
79 static Lisp_Object maybe_call_magic_handler (Lisp_Object sym, | |
80 Lisp_Object funsym, | |
81 int nargs, ...); | |
82 static Lisp_Object fetch_value_maybe_past_magic (Lisp_Object sym, | |
83 Lisp_Object follow_past_lisp_magic); | |
84 static Lisp_Object *value_slot_past_magic (Lisp_Object sym); | |
85 static Lisp_Object follow_varalias_pointers (Lisp_Object symbol, | |
86 Lisp_Object follow_past_lisp_magic); | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
87 static Lisp_Object map_varalias_chain (Lisp_Object symbol, |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
88 Lisp_Object follow_past_lisp_magic, |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
89 Lisp_Object (*fn) (Lisp_Object arg)); |
428 | 90 |
91 | |
92 static Lisp_Object | |
93 mark_symbol (Lisp_Object obj) | |
94 { | |
440 | 95 Lisp_Symbol *sym = XSYMBOL (obj); |
428 | 96 |
97 mark_object (sym->value); | |
98 mark_object (sym->function); | |
793 | 99 mark_object (sym->name); |
428 | 100 if (!symbol_next (sym)) |
101 return sym->plist; | |
102 else | |
103 { | |
104 mark_object (sym->plist); | |
105 /* Mark the rest of the symbols in the obarray hash-chain */ | |
106 sym = symbol_next (sym); | |
793 | 107 return wrap_symbol (sym); |
428 | 108 } |
109 } | |
110 | |
1204 | 111 static const struct memory_description symbol_description[] = { |
440 | 112 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, next) }, |
113 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, name) }, | |
114 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, value) }, | |
115 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, function) }, | |
116 { XD_LISP_OBJECT, offsetof (Lisp_Symbol, plist) }, | |
428 | 117 { XD_END } |
118 }; | |
119 | |
442 | 120 /* Symbol plists are directly accessible, so we need to protect against |
121 invalid property list structure */ | |
122 | |
123 static Lisp_Object | |
124 symbol_getprop (Lisp_Object symbol, Lisp_Object property) | |
125 { | |
126 return external_plist_get (&XSYMBOL (symbol)->plist, property, 0, ERROR_ME); | |
127 } | |
128 | |
129 static int | |
130 symbol_putprop (Lisp_Object symbol, Lisp_Object property, Lisp_Object value) | |
131 { | |
132 external_plist_put (&XSYMBOL (symbol)->plist, property, value, 0, ERROR_ME); | |
133 return 1; | |
134 } | |
135 | |
136 static int | |
137 symbol_remprop (Lisp_Object symbol, Lisp_Object property) | |
138 { | |
139 return external_remprop (&XSYMBOL (symbol)->plist, property, 0, ERROR_ME); | |
140 } | |
141 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
142 static void |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
143 symbol_print_preprocess (Lisp_Object UNUSED (symbol), |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
144 Lisp_Object UNUSED (print_number_table), |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
145 Elemcount * UNUSED (seen_object_count)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
146 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
147 /* This method is empty; symbols are handled specially in |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
148 print_preprocess, because print_preprocess_inchash_eq() is conditional |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
149 for them, rather than a given. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
150 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
151 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
152 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("symbol", symbol, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
153 mark_symbol, print_symbol, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
154 0, 0, 0, symbol_description, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
155 Lisp_Symbol); |
428 | 156 |
157 /**********************************************************************/ | |
158 /* Intern */ | |
159 /**********************************************************************/ | |
160 | |
161 /* #### using a vector here is way bogus. Use a hash table instead. */ | |
162 | |
163 Lisp_Object Vobarray; | |
164 | |
165 static Lisp_Object initial_obarray; | |
166 | |
167 /* oblookup stores the bucket number here, for the sake of Funintern. */ | |
168 | |
169 static int oblookup_last_bucket_number; | |
170 | |
171 static Lisp_Object | |
172 check_obarray (Lisp_Object obarray) | |
173 { | |
174 while (!VECTORP (obarray) || XVECTOR_LENGTH (obarray) == 0) | |
175 { | |
176 /* If Vobarray is now invalid, force it to be valid. */ | |
177 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; | |
178 | |
179 obarray = wrong_type_argument (Qvectorp, obarray); | |
180 } | |
181 return obarray; | |
182 } | |
183 | |
184 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
185 intern_istring (const Ibyte *str) |
428 | 186 { |
771 | 187 Bytecount len = qxestrlen (str); |
428 | 188 Lisp_Object obarray = Vobarray; |
189 | |
190 if (!VECTORP (obarray) || XVECTOR_LENGTH (obarray) == 0) | |
191 obarray = check_obarray (obarray); | |
192 | |
193 { | |
771 | 194 Lisp_Object tem = oblookup (obarray, str, len); |
428 | 195 if (SYMBOLP (tem)) |
196 return tem; | |
197 } | |
198 | |
771 | 199 return Fintern (make_string (str, len), obarray); |
200 } | |
201 | |
202 Lisp_Object | |
867 | 203 intern (const CIbyte *str) |
771 | 204 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
205 return intern_istring ((Ibyte *) str); |
428 | 206 } |
207 | |
814 | 208 Lisp_Object |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
209 intern_massaging_name (const CIbyte *str) |
814 | 210 { |
211 Bytecount len = strlen (str); | |
867 | 212 CIbyte *tmp = alloca_extbytes (len + 1); |
814 | 213 Bytecount i; |
214 strcpy (tmp, str); | |
215 for (i = 0; i < len; i++) | |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
216 { |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
217 if (tmp[i] == '_') |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
218 { |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
219 tmp[i] = '-'; |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
220 } |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
221 else if (tmp[i] == 'X') |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
222 { |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
223 tmp[i] = '*'; |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
224 } |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5255
diff
changeset
|
225 } |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
226 return intern_istring ((Ibyte *) tmp); |
814 | 227 } |
228 | |
428 | 229 DEFUN ("intern", Fintern, 1, 2, 0, /* |
230 Return the canonical symbol whose name is STRING. | |
231 If there is none, one is created by this function and returned. | |
444 | 232 Optional second argument OBARRAY specifies the obarray to use; |
233 it defaults to the value of the variable `obarray'. | |
428 | 234 */ |
235 (string, obarray)) | |
236 { | |
237 Lisp_Object object, *ptr; | |
793 | 238 Lisp_Object symbol; |
428 | 239 Bytecount len; |
240 | |
241 if (NILP (obarray)) obarray = Vobarray; | |
242 obarray = check_obarray (obarray); | |
243 | |
244 CHECK_STRING (string); | |
245 | |
246 len = XSTRING_LENGTH (string); | |
247 object = oblookup (obarray, XSTRING_DATA (string), len); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
248 if (!FIXNUMP (object)) |
428 | 249 /* Found it */ |
250 return object; | |
251 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
252 ptr = &XVECTOR_DATA (obarray)[XFIXNUM (object)]; |
428 | 253 |
254 object = Fmake_symbol (string); | |
793 | 255 symbol = object; |
428 | 256 |
257 if (SYMBOLP (*ptr)) | |
793 | 258 XSYMBOL_NEXT (symbol) = XSYMBOL (*ptr); |
428 | 259 else |
793 | 260 XSYMBOL_NEXT (symbol) = 0; |
428 | 261 *ptr = object; |
262 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
263 XSYMBOL (object)->u.v.package_count = 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
264 XSYMBOL (object)->u.v.first_package_id = (EQ (obarray, Vobarray)) ? 1 : 2; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
265 |
826 | 266 if (string_byte (XSYMBOL_NAME (symbol), 0) == ':' && EQ (obarray, Vobarray)) |
428 | 267 { |
268 /* The LISP way is to put keywords in their own package, but we | |
269 don't have packages, so we do something simpler. Someday, | |
270 maybe we'll have packages and then this will be reworked. | |
271 --Stig. */ | |
793 | 272 XSYMBOL_VALUE (symbol) = object; |
428 | 273 } |
274 | |
275 return object; | |
276 } | |
277 | |
4355
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4337
diff
changeset
|
278 DEFUN ("intern-soft", Fintern_soft, 1, 3, 0, /* |
428 | 279 Return the canonical symbol named NAME, or nil if none exists. |
280 NAME may be a string or a symbol. If it is a symbol, that exact | |
281 symbol is searched for. | |
444 | 282 Optional second argument OBARRAY specifies the obarray to use; |
283 it defaults to the value of the variable `obarray'. | |
4355
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4337
diff
changeset
|
284 Optional third argument DEFAULT says what Lisp object to return if there is |
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4337
diff
changeset
|
285 no canonical symbol named NAME, and defaults to nil. |
428 | 286 */ |
4355
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4337
diff
changeset
|
287 (name, obarray, default_)) |
428 | 288 { |
289 Lisp_Object tem; | |
793 | 290 Lisp_Object string; |
428 | 291 |
292 if (NILP (obarray)) obarray = Vobarray; | |
293 obarray = check_obarray (obarray); | |
294 | |
295 if (!SYMBOLP (name)) | |
296 { | |
297 CHECK_STRING (name); | |
793 | 298 string = name; |
428 | 299 } |
300 else | |
301 string = symbol_name (XSYMBOL (name)); | |
302 | |
793 | 303 tem = oblookup (obarray, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
304 if (FIXNUMP (tem) || (SYMBOLP (name) && !EQ (name, tem))) |
4355
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4337
diff
changeset
|
305 return default_; |
428 | 306 else |
307 return tem; | |
308 } | |
309 | |
310 DEFUN ("unintern", Funintern, 1, 2, 0, /* | |
311 Delete the symbol named NAME, if any, from OBARRAY. | |
312 The value is t if a symbol was found and deleted, nil otherwise. | |
313 NAME may be a string or a symbol. If it is a symbol, that symbol | |
314 is deleted, if it belongs to OBARRAY--no other symbol is deleted. | |
444 | 315 OBARRAY defaults to the value of the variable `obarray'. |
428 | 316 */ |
317 (name, obarray)) | |
318 { | |
319 Lisp_Object tem; | |
793 | 320 Lisp_Object string; |
428 | 321 int hash; |
322 | |
323 if (NILP (obarray)) obarray = Vobarray; | |
324 obarray = check_obarray (obarray); | |
325 | |
326 if (SYMBOLP (name)) | |
327 string = symbol_name (XSYMBOL (name)); | |
328 else | |
329 { | |
330 CHECK_STRING (name); | |
793 | 331 string = name; |
428 | 332 } |
333 | |
793 | 334 tem = oblookup (obarray, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
335 if (FIXNUMP (tem)) |
428 | 336 return Qnil; |
337 /* If arg was a symbol, don't delete anything but that symbol itself. */ | |
338 if (SYMBOLP (name) && !EQ (name, tem)) | |
339 return Qnil; | |
340 | |
341 hash = oblookup_last_bucket_number; | |
342 | |
343 if (EQ (XVECTOR_DATA (obarray)[hash], tem)) | |
344 { | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
345 unsigned int package_count = XSYMBOL (tem)->u.v.package_count; |
428 | 346 if (XSYMBOL (tem)->next) |
793 | 347 XVECTOR_DATA (obarray)[hash] = wrap_symbol (XSYMBOL (tem)->next); |
428 | 348 else |
349 XVECTOR_DATA (obarray)[hash] = Qzero; | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
350 if (package_count > 0) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
351 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
352 if (1 == package_count) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
353 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
354 XSYMBOL (tem)->u.v.first_package_id = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
355 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
356 XSYMBOL (tem)->u.v.package_count = package_count - 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
357 } |
428 | 358 } |
359 else | |
360 { | |
361 Lisp_Object tail, following; | |
362 | |
363 for (tail = XVECTOR_DATA (obarray)[hash]; | |
364 XSYMBOL (tail)->next; | |
365 tail = following) | |
366 { | |
793 | 367 following = wrap_symbol (XSYMBOL (tail)->next); |
428 | 368 if (EQ (following, tem)) |
369 { | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
370 unsigned int package_count = XSYMBOL (tem)->u.v.package_count; |
428 | 371 XSYMBOL (tail)->next = XSYMBOL (following)->next; |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
372 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
373 if (package_count > 0) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
374 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
375 if (1 == package_count) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
376 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
377 XSYMBOL (tem)->u.v.first_package_id = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
378 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
379 XSYMBOL (tem)->u.v.package_count = package_count - 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
380 } |
428 | 381 break; |
382 } | |
383 } | |
384 } | |
385 return Qt; | |
386 } | |
387 | |
388 /* Return the symbol in OBARRAY whose names matches the string | |
389 of SIZE characters at PTR. If there is no such symbol in OBARRAY, | |
390 return the index into OBARRAY that the string hashes to. | |
391 | |
392 Also store the bucket number in oblookup_last_bucket_number. */ | |
393 | |
394 Lisp_Object | |
867 | 395 oblookup (Lisp_Object obarray, const Ibyte *ptr, Bytecount size) |
428 | 396 { |
490 | 397 unsigned int hash, obsize; |
440 | 398 Lisp_Symbol *tail; |
428 | 399 Lisp_Object bucket; |
400 | |
401 if (!VECTORP (obarray) || | |
402 (obsize = XVECTOR_LENGTH (obarray)) == 0) | |
403 { | |
404 obarray = check_obarray (obarray); | |
405 obsize = XVECTOR_LENGTH (obarray); | |
406 } | |
407 hash = hash_string (ptr, size) % obsize; | |
408 oblookup_last_bucket_number = hash; | |
409 bucket = XVECTOR_DATA (obarray)[hash]; | |
410 if (ZEROP (bucket)) | |
411 ; | |
412 else if (!SYMBOLP (bucket)) | |
563 | 413 signal_error (Qinvalid_state, "Bad data in guts of obarray", Qunbound); /* Like CADR error message */ |
428 | 414 else |
415 for (tail = XSYMBOL (bucket); ;) | |
416 { | |
793 | 417 if (XSTRING_LENGTH (tail->name) == size && |
418 !memcmp (XSTRING_DATA (tail->name), ptr, size)) | |
428 | 419 { |
793 | 420 return wrap_symbol (tail); |
428 | 421 } |
422 tail = symbol_next (tail); | |
423 if (!tail) | |
424 break; | |
425 } | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
426 return make_fixnum (hash); |
428 | 427 } |
428 | |
490 | 429 /* An excellent string hashing function. |
430 Adapted from glib's g_str_hash(). | |
431 Investigation by Karl Nelson <kenelson@ece.ucdavis.edu>. | |
432 Do a web search for "g_str_hash X31_HASH" if you want to know more. */ | |
433 unsigned int | |
867 | 434 hash_string (const Ibyte *ptr, Bytecount len) |
428 | 435 { |
490 | 436 unsigned int hash; |
437 | |
438 for (hash = 0; len; len--, ptr++) | |
439 /* (31 * hash) will probably be optimized to ((hash << 5) - hash). */ | |
440 hash = 31 * hash + *ptr; | |
441 | |
442 return hash; | |
428 | 443 } |
444 | |
445 /* Map FN over OBARRAY. The mapping is stopped when FN returns a | |
446 non-zero value. */ | |
447 void | |
448 map_obarray (Lisp_Object obarray, | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
449 int (*fn) (Lisp_Object, Lisp_Object, void *), void *arg) |
428 | 450 { |
451 REGISTER int i; | |
452 | |
453 CHECK_VECTOR (obarray); | |
454 for (i = XVECTOR_LENGTH (obarray) - 1; i >= 0; i--) | |
455 { | |
456 Lisp_Object tail = XVECTOR_DATA (obarray)[i]; | |
457 if (SYMBOLP (tail)) | |
458 while (1) | |
459 { | |
440 | 460 Lisp_Symbol *next; |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
461 if ((*fn) (XSYMBOL_NAME (tail), tail, arg)) |
428 | 462 return; |
463 next = symbol_next (XSYMBOL (tail)); | |
464 if (!next) | |
465 break; | |
793 | 466 tail = wrap_symbol (next); |
428 | 467 } |
468 } | |
469 } | |
470 | |
471 static int | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
472 mapatoms_1 (Lisp_Object UNUSED (key), Lisp_Object sym, void *arg) |
428 | 473 { |
474 call1 (*(Lisp_Object *)arg, sym); | |
475 return 0; | |
476 } | |
477 | |
478 DEFUN ("mapatoms", Fmapatoms, 1, 2, 0, /* | |
479 Call FUNCTION on every symbol in OBARRAY. | |
480 OBARRAY defaults to the value of `obarray'. | |
481 */ | |
482 (function, obarray)) | |
483 { | |
442 | 484 struct gcpro gcpro1; |
485 | |
428 | 486 if (NILP (obarray)) |
487 obarray = Vobarray; | |
488 obarray = check_obarray (obarray); | |
489 | |
442 | 490 GCPRO1 (obarray); |
428 | 491 map_obarray (obarray, mapatoms_1, &function); |
442 | 492 UNGCPRO; |
428 | 493 return Qnil; |
494 } | |
495 | |
496 | |
497 /**********************************************************************/ | |
498 /* Apropos */ | |
499 /**********************************************************************/ | |
500 | |
501 struct appropos_mapper_closure | |
502 { | |
503 Lisp_Object regexp; | |
504 Lisp_Object predicate; | |
505 Lisp_Object accumulation; | |
506 }; | |
507 | |
508 static int | |
5634
2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
509 apropos_mapper (Lisp_Object UNUSED (key), Lisp_Object symbol, void *arg) |
428 | 510 { |
511 struct appropos_mapper_closure *closure = | |
512 (struct appropos_mapper_closure *) arg; | |
513 Bytecount match = fast_lisp_string_match (closure->regexp, | |
514 Fsymbol_name (symbol)); | |
515 | |
516 if (match >= 0 && | |
517 (NILP (closure->predicate) || | |
518 !NILP (call1 (closure->predicate, symbol)))) | |
519 closure->accumulation = Fcons (symbol, closure->accumulation); | |
520 | |
521 return 0; | |
522 } | |
523 | |
524 DEFUN ("apropos-internal", Fapropos_internal, 1, 2, 0, /* | |
444 | 525 Return a list of all symbols whose names contain match for REGEXP. |
526 If optional 2nd arg PREDICATE is non-nil, only symbols for which | |
527 \(funcall PREDICATE SYMBOL) returns non-nil are returned. | |
428 | 528 */ |
529 (regexp, predicate)) | |
530 { | |
531 struct appropos_mapper_closure closure; | |
442 | 532 struct gcpro gcpro1; |
428 | 533 |
534 CHECK_STRING (regexp); | |
535 | |
536 closure.regexp = regexp; | |
537 closure.predicate = predicate; | |
538 closure.accumulation = Qnil; | |
442 | 539 GCPRO1 (closure.accumulation); |
428 | 540 map_obarray (Vobarray, apropos_mapper, &closure); |
5351
b5561bfd5061
Supply check_string_lessp_nokey explicitly to list_sort(), #'apropos-internal
Aidan Kehoe <kehoea@parhasard.net>
parents:
5338
diff
changeset
|
541 closure.accumulation = list_sort (closure.accumulation, |
b5561bfd5061
Supply check_string_lessp_nokey explicitly to list_sort(), #'apropos-internal
Aidan Kehoe <kehoea@parhasard.net>
parents:
5338
diff
changeset
|
542 check_string_lessp_nokey, Qnil, Qnil); |
442 | 543 UNGCPRO; |
428 | 544 return closure.accumulation; |
545 } | |
546 | |
547 | |
548 /* Extract and set components of symbols */ | |
549 | |
550 static void set_up_buffer_local_cache (Lisp_Object sym, | |
551 struct symbol_value_buffer_local *bfwd, | |
552 struct buffer *buf, | |
553 Lisp_Object new_alist_el, | |
554 int set_it_p); | |
555 | |
556 DEFUN ("boundp", Fboundp, 1, 1, 0, /* | |
557 Return t if SYMBOL's value is not void. | |
558 */ | |
559 (symbol)) | |
560 { | |
561 CHECK_SYMBOL (symbol); | |
562 return UNBOUNDP (find_symbol_value (symbol)) ? Qnil : Qt; | |
563 } | |
564 | |
565 DEFUN ("globally-boundp", Fglobally_boundp, 1, 1, 0, /* | |
566 Return t if SYMBOL has a global (non-bound) value. | |
567 This is for the byte-compiler; you really shouldn't be using this. | |
568 */ | |
569 (symbol)) | |
570 { | |
571 CHECK_SYMBOL (symbol); | |
572 return UNBOUNDP (top_level_value (symbol)) ? Qnil : Qt; | |
573 } | |
574 | |
575 DEFUN ("fboundp", Ffboundp, 1, 1, 0, /* | |
576 Return t if SYMBOL's function definition is not void. | |
577 */ | |
578 (symbol)) | |
579 { | |
580 CHECK_SYMBOL (symbol); | |
581 return UNBOUNDP (XSYMBOL (symbol)->function) ? Qnil : Qt; | |
582 } | |
583 | |
584 /* Return non-zero if SYM's value or function (the current contents of | |
585 which should be passed in as VAL) is constant, i.e. unsettable. */ | |
586 | |
587 static int | |
588 symbol_is_constant (Lisp_Object sym, Lisp_Object val) | |
589 { | |
590 /* #### - I wonder if it would be better to just have a new magic value | |
591 type and make nil, t, and all keywords have that same magic | |
592 constant_symbol value. This test is awfully specific about what is | |
593 constant and what isn't. --Stig */ | |
594 if (EQ (sym, Qnil) || | |
595 EQ (sym, Qt)) | |
596 return 1; | |
597 | |
598 if (SYMBOL_VALUE_MAGIC_P (val)) | |
599 switch (XSYMBOL_VALUE_MAGIC_TYPE (val)) | |
600 { | |
601 case SYMVAL_CONST_OBJECT_FORWARD: | |
602 case SYMVAL_CONST_SPECIFIER_FORWARD: | |
603 case SYMVAL_CONST_FIXNUM_FORWARD: | |
604 case SYMVAL_CONST_BOOLEAN_FORWARD: | |
605 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
606 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
607 return 1; | |
608 default: break; /* Warning suppression */ | |
609 } | |
610 | |
611 /* We don't return true for keywords here because they are handled | |
612 specially by reject_constant_symbols(). */ | |
613 return 0; | |
614 } | |
615 | |
616 /* We are setting SYM's value slot (or function slot, if FUNCTION_P is | |
617 non-zero) to NEWVAL. Make sure this is allowed. | |
618 FOLLOW_PAST_LISP_MAGIC specifies whether we delve past | |
619 symbol-value-lisp-magic objects. */ | |
620 | |
621 void | |
622 reject_constant_symbols (Lisp_Object sym, Lisp_Object newval, int function_p, | |
623 Lisp_Object follow_past_lisp_magic) | |
624 { | |
625 Lisp_Object val = | |
626 (function_p ? XSYMBOL (sym)->function | |
627 : fetch_value_maybe_past_magic (sym, follow_past_lisp_magic)); | |
628 | |
629 if (SYMBOL_VALUE_MAGIC_P (val) && | |
630 XSYMBOL_VALUE_MAGIC_TYPE (val) == SYMVAL_CONST_SPECIFIER_FORWARD) | |
563 | 631 invalid_change ("Use `set-specifier' to change a specifier's value", |
632 sym); | |
428 | 633 |
996 | 634 if ( |
635 #ifdef HAVE_SHLIB | |
636 !(unloading_module && UNBOUNDP(newval)) && | |
637 #endif | |
638 (symbol_is_constant (sym, val) | |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
639 #ifdef NEED_TO_HANDLE_21_4_CODE |
4793
8b50bee3c88c
Remove attempted support for 1996-era emacs without self-quoting keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
640 || (SYMBOL_IS_KEYWORD (sym) && !EQ (newval, sym)) |
8b50bee3c88c
Remove attempted support for 1996-era emacs without self-quoting keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
641 #endif |
8b50bee3c88c
Remove attempted support for 1996-era emacs without self-quoting keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
642 )) |
563 | 643 signal_error_1 (Qsetting_constant, |
644 UNBOUNDP (newval) ? list1 (sym) : list2 (sym, newval)); | |
428 | 645 } |
646 | |
647 /* Verify that it's ok to make SYM buffer-local. This rejects | |
648 constants and default-buffer-local variables. FOLLOW_PAST_LISP_MAGIC | |
649 specifies whether we delve into symbol-value-lisp-magic objects. | |
650 (Should be a symbol indicating what action is being taken; that way, | |
651 we don't delve if there's a handler for that action, but do otherwise.) */ | |
652 | |
653 static void | |
654 verify_ok_for_buffer_local (Lisp_Object sym, | |
655 Lisp_Object follow_past_lisp_magic) | |
656 { | |
657 Lisp_Object val = fetch_value_maybe_past_magic (sym, follow_past_lisp_magic); | |
658 | |
659 if (symbol_is_constant (sym, val)) | |
660 goto not_ok; | |
661 if (SYMBOL_VALUE_MAGIC_P (val)) | |
662 switch (XSYMBOL_VALUE_MAGIC_TYPE (val)) | |
663 { | |
664 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
665 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
666 /* #### It's theoretically possible for it to be reasonable | |
667 to have both console-local and buffer-local variables, | |
668 but I don't want to consider that right now. */ | |
669 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
670 goto not_ok; | |
671 default: break; /* Warning suppression */ | |
672 } | |
673 | |
674 return; | |
675 | |
676 not_ok: | |
563 | 677 invalid_change ("Symbol may not be buffer-local", sym); |
428 | 678 } |
679 | |
680 DEFUN ("makunbound", Fmakunbound, 1, 1, 0, /* | |
681 Make SYMBOL's value be void. | |
682 */ | |
683 (symbol)) | |
684 { | |
685 Fset (symbol, Qunbound); | |
686 return symbol; | |
687 } | |
688 | |
689 DEFUN ("fmakunbound", Ffmakunbound, 1, 1, 0, /* | |
690 Make SYMBOL's function definition be void. | |
691 */ | |
692 (symbol)) | |
693 { | |
694 CHECK_SYMBOL (symbol); | |
695 reject_constant_symbols (symbol, Qunbound, 1, Qt); | |
696 XSYMBOL (symbol)->function = Qunbound; | |
697 return symbol; | |
698 } | |
699 | |
700 DEFUN ("symbol-function", Fsymbol_function, 1, 1, 0, /* | |
701 Return SYMBOL's function definition. Error if that is void. | |
702 */ | |
703 (symbol)) | |
704 { | |
705 CHECK_SYMBOL (symbol); | |
706 if (UNBOUNDP (XSYMBOL (symbol)->function)) | |
707 signal_void_function_error (symbol); | |
708 return XSYMBOL (symbol)->function; | |
709 } | |
710 | |
711 DEFUN ("symbol-plist", Fsymbol_plist, 1, 1, 0, /* | |
712 Return SYMBOL's property list. | |
713 */ | |
714 (symbol)) | |
715 { | |
716 CHECK_SYMBOL (symbol); | |
717 return XSYMBOL (symbol)->plist; | |
718 } | |
719 | |
720 DEFUN ("symbol-name", Fsymbol_name, 1, 1, 0, /* | |
721 Return SYMBOL's name, a string. | |
722 */ | |
723 (symbol)) | |
724 { | |
725 CHECK_SYMBOL (symbol); | |
793 | 726 return XSYMBOL (symbol)->name; |
428 | 727 } |
728 | |
729 DEFUN ("fset", Ffset, 2, 2, 0, /* | |
730 Set SYMBOL's function definition to NEWDEF, and return NEWDEF. | |
731 */ | |
732 (symbol, newdef)) | |
733 { | |
734 /* This function can GC */ | |
735 CHECK_SYMBOL (symbol); | |
736 reject_constant_symbols (symbol, newdef, 1, Qt); | |
737 if (!NILP (Vautoload_queue) && !UNBOUNDP (XSYMBOL (symbol)->function)) | |
738 Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function), | |
739 Vautoload_queue); | |
740 XSYMBOL (symbol)->function = newdef; | |
741 /* Handle automatic advice activation */ | |
742 if (CONSP (XSYMBOL (symbol)->plist) && | |
743 !NILP (Fget (symbol, Qad_advice_info, Qnil))) | |
744 { | |
745 call2 (Qad_activate, symbol, Qnil); | |
746 newdef = XSYMBOL (symbol)->function; | |
747 } | |
748 return newdef; | |
749 } | |
750 | |
751 /* FSFmacs */ | |
5789
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
752 DEFUN ("define-function", Fdefine_function, 2, 3, 0, /* |
428 | 753 Set SYMBOL's function definition to NEWDEF, and return NEWDEF. |
754 Associates the function with the current load file, if any. | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
755 If NEWDEF is a compiled-function object, stores the function name in |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
756 the `annotated' slot of the compiled-function (retrievable using |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
757 `compiled-function-annotation'). |
428 | 758 */ |
5789
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
759 (symbol, newdef, docstring)) |
428 | 760 { |
761 /* This function can GC */ | |
762 Ffset (symbol, newdef); | |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4503
diff
changeset
|
763 LOADHIST_ATTACH (Fcons (Qdefun, symbol)); |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
764 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
765 if (COMPILED_FUNCTIONP (newdef)) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
766 XCOMPILED_FUNCTION (newdef)->annotated = symbol; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4905
diff
changeset
|
767 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ |
5789
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
768 |
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
769 if (!NILP (docstring)) |
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
770 Fput (symbol, Qfunction_documentation, docstring); |
72c5d36ba3b6
Make `define-function' accept docstring, as in GNU Emacs.
Mike Sperber <sperber@deinprogramm.de>
parents:
5634
diff
changeset
|
771 |
428 | 772 return newdef; |
773 } | |
774 | |
3368 | 775 DEFUN ("subr-name", Fsubr_name, 1, 1, 0, /* |
776 Return name of function SUBR. | |
777 SUBR must be a built-in function. | |
778 */ | |
779 (subr)) | |
780 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
781 const Ascbyte *name; |
3497 | 782 CHECK_SUBR (subr); |
783 | |
3368 | 784 name = XSUBR (subr)->name; |
3379 | 785 return make_string ((const Ibyte *)name, strlen (name)); |
3368 | 786 } |
428 | 787 |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
788 DEFUN ("special-operator-p", Fspecial_operator_p, 1, 1, 0, /* |
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
789 Return whether SUBR is a special operator. |
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
790 |
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
791 A special operator is a built-in function (a subr, that is a function |
4337
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
792 implemented in C, not Lisp) which does not necessarily evaluate all its |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
793 arguments. Much of the basic XEmacs Lisp syntax is implemented by means of |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
794 special operators; examples are `let', `condition-case', `setq', and so |
4337
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
795 on. |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
796 |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
797 If you intend to write a Lisp function that does not necessarily evaluate |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
798 all its arguments, the portable (across emacs variants, and across Lisp |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
799 implementations) way to go about it is to write a macro instead. See |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
800 `defmacro' and `backquote'. |
4336
cdc2f70d4319
Provide #'special-form-p, for the use of advice.el, perhaps other files.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3497
diff
changeset
|
801 */ |
cdc2f70d4319
Provide #'special-form-p, for the use of advice.el, perhaps other files.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3497
diff
changeset
|
802 (subr)) |
cdc2f70d4319
Provide #'special-form-p, for the use of advice.el, perhaps other files.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3497
diff
changeset
|
803 { |
4337
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
804 subr = indirect_function (subr, 0); |
c32e4dca0296
#'special-form-p; don't error (thank you Jerry James); flesh out docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4336
diff
changeset
|
805 return (SUBRP (subr) && XSUBR (subr)->max_args == UNEVALLED) ? Qt : Qnil; |
4336
cdc2f70d4319
Provide #'special-form-p, for the use of advice.el, perhaps other files.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3497
diff
changeset
|
806 } |
cdc2f70d4319
Provide #'special-form-p, for the use of advice.el, perhaps other files.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3497
diff
changeset
|
807 |
428 | 808 DEFUN ("setplist", Fsetplist, 2, 2, 0, /* |
809 Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. | |
810 */ | |
811 (symbol, newplist)) | |
812 { | |
813 CHECK_SYMBOL (symbol); | |
814 | |
815 XSYMBOL (symbol)->plist = newplist; | |
816 return newplist; | |
817 } | |
818 | |
819 | |
820 /**********************************************************************/ | |
821 /* symbol-value */ | |
822 /**********************************************************************/ | |
823 | |
4940
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
824 /* |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
825 NOTE NOTE NOTE: |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
826 --------------- |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
827 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
828 There are various different uses of "magic" with regard to symbols, |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
829 and they need to be distinguished: |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
830 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
831 1. `symbol-value-magic' class of objects (struct symbol_value_magic): |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
832 A set of Lisp object types used as the value of a variable with any |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
833 behavior other than just a plain repository of a value. This |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
834 includes buffer-local variables, console-local variables, read-only |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
835 variables, variable aliases, variables that are linked to a C |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
836 variable, etc. The more specific types are: |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
837 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
838 -- `symbol-value-forward': Variables that forward to a C variable. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
839 NOTE:This includes built-in buffer-local and console-local |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
840 variables, since they forward to an element in a buffer or |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
841 console structure. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
842 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
843 -- `symbol-value-buffer-local': Variables on which |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
844 `make-local-variable' or `make-variable-buffer-local' have |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
845 been called. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
846 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
847 -- `symbol-value-lisp-magic': See below. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
848 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
849 -- `symbol-value-varalias': Variable aliases. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
850 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
851 2. `symbol-value-lisp-magic': Variables on which |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
852 `dontusethis-set-symbol-value-handler' have been called. These |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
853 variables are extra-magic in that operations that would normally |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
854 change their value instead get forwarded out to Lisp handlers, |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
855 which can do anything they want. (NOTE: Handlers for getting a |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
856 variable's value aren't implemented yet.) |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
857 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
858 3. "magicfun" handlers on C-forwarding variables, declared with any |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
859 of the following: |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
860 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
861 -- DEFVAR_LISP_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
862 -- DEFVAR_INT_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
863 -- DEFVAR_BOOL_MAGIC, |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
864 -- DEFVAR_BUFFER_LOCAL_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
865 -- DEFVAR_BUFFER_DEFAULTS_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
866 -- DEFVAR_CONSOLE_LOCAL_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
867 -- DEFVAR_CONSOLE_DEFAULTS_MAGIC |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
868 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
869 Here, the "magic function" is a handler that is notified whenever the |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
870 value of a variable is changed, so that some other updating can take |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
871 place (e.g. setting redisplay-related dirty bits, updating a cache, |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
872 etc.). |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
873 |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
874 Note that DEFVAR_LISP_MAGIC does *NOT* have anything to do with |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
875 `symbol-value-lisp-magic'. The former refers to variables that can |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
876 hold an arbitrary Lisp object and forward to a C variable declared |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
877 `Lisp_Object foo', and have a "magicfun" as just described; the |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
878 latter are variables that have Lisp-level handlers that function |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
879 in *PLACE* of normal variable-setting mechanisms, and are established |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
880 with `dontusethis-set-symbol-value-handler', as described above. |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
881 */ |
9113c5044de8
(for main branch) add long comment about types of magic symbols
Ben Wing <ben@xemacs.org>
parents:
4793
diff
changeset
|
882 |
428 | 883 /* If the contents of the value cell of a symbol is one of the following |
884 three types of objects, then the symbol is "magic" in that setting | |
885 and retrieving its value doesn't just set or retrieve the raw | |
886 contents of the value cell. None of these objects can escape to | |
887 the user level, so there is no loss of generality. | |
888 | |
889 If a symbol is "unbound", then the contents of its value cell is | |
890 Qunbound. Despite appearances, this is *not* a symbol, but is a | |
891 symbol-value-forward object. This is so that printing it results | |
892 in "INTERNAL OBJECT (XEmacs bug?)", in case it leaks to Lisp, somehow. | |
893 | |
894 Logically all of the following objects are "symbol-value-magic" | |
895 objects, and there are some games played w.r.t. this (#### this | |
896 should be cleaned up). SYMBOL_VALUE_MAGIC_P is true for all of | |
897 the object types. XSYMBOL_VALUE_MAGIC_TYPE returns the type of | |
898 symbol-value-magic object. There are more than three types | |
899 returned by this macro: in particular, symbol-value-forward | |
900 has eight subtypes, and symbol-value-buffer-local has two. See | |
901 symeval.h. | |
902 | |
903 1. symbol-value-forward | |
904 | |
905 symbol-value-forward is used for variables whose actual contents | |
906 are stored in a C variable of some sort, and for Qunbound. The | |
907 lcheader.next field (which is only used to chain together free | |
908 lcrecords) holds a pointer to the actual C variable. Included | |
909 in this type are "buffer-local" variables that are actually | |
910 stored in the buffer object itself; in this case, the "pointer" | |
911 is an offset into the struct buffer structure. | |
912 | |
913 The subtypes are as follows: | |
914 | |
915 SYMVAL_OBJECT_FORWARD: | |
916 (declare with DEFVAR_LISP) | |
917 The value of this variable is stored in a C variable of type | |
918 "Lisp_Object". Setting this variable sets the C variable. | |
919 Accessing this variable retrieves a value from the C variable. | |
920 These variables can be buffer-local -- in this case, the | |
921 raw symbol-value field gets converted into a | |
922 symbol-value-buffer-local, whose "current_value" slot contains | |
923 the symbol-value-forward. (See below.) | |
924 | |
925 SYMVAL_FIXNUM_FORWARD: | |
458 | 926 (declare with DEFVAR_INT) |
927 Similar to SYMVAL_OBJECT_FORWARD except that the C variable | |
928 is of type "Fixnum", a typedef for "EMACS_INT", and the corresponding | |
929 lisp variable is always the corresponding integer. | |
930 | |
428 | 931 SYMVAL_BOOLEAN_FORWARD: |
458 | 932 (declare with DEFVAR_BOOL) |
428 | 933 Similar to SYMVAL_OBJECT_FORWARD except that the C variable |
458 | 934 is of type "int" and is a boolean. |
428 | 935 |
936 SYMVAL_CONST_OBJECT_FORWARD: | |
937 SYMVAL_CONST_FIXNUM_FORWARD: | |
938 SYMVAL_CONST_BOOLEAN_FORWARD: | |
939 (declare with DEFVAR_CONST_LISP, DEFVAR_CONST_INT, or | |
940 DEFVAR_CONST_BOOL) | |
941 Similar to SYMVAL_OBJECT_FORWARD, SYMVAL_FIXNUM_FORWARD, or | |
942 SYMVAL_BOOLEAN_FORWARD, respectively, except that the value cannot | |
943 be changed. | |
944 | |
945 SYMVAL_CONST_SPECIFIER_FORWARD: | |
946 (declare with DEFVAR_SPECIFIER) | |
440 | 947 Exactly like SYMVAL_CONST_OBJECT_FORWARD except that the error |
948 message you get when attempting to set the value says to use | |
428 | 949 `set-specifier' instead. |
950 | |
951 SYMVAL_CURRENT_BUFFER_FORWARD: | |
952 (declare with DEFVAR_BUFFER_LOCAL) | |
953 This is used for built-in buffer-local variables -- i.e. | |
954 Lisp variables whose value is stored in the "struct buffer". | |
955 Variables of this sort always forward into C "Lisp_Object" | |
956 fields (although there's no reason in principle that other | |
957 types for ints and booleans couldn't be added). Note that | |
958 some of these variables are automatically local in each | |
959 buffer, while some are only local when they become set | |
960 (similar to `make-variable-buffer-local'). In these latter | |
961 cases, of course, the default value shows through in all | |
962 buffers in which the variable doesn't have a local value. | |
963 This is implemented by making sure the "struct buffer" field | |
964 always contains the correct value (whether it's local or | |
965 a default) and maintaining a mask in the "struct buffer" | |
966 indicating which fields are local. When `set-default' is | |
967 called on a variable that's not always local to all buffers, | |
968 it loops through each buffer and sets the corresponding | |
969 field in each buffer without a local value for the field, | |
970 according to the mask. | |
971 | |
972 Calling `make-local-variable' on a variable of this sort | |
973 only has the effect of maybe changing the current buffer's mask. | |
974 Calling `make-variable-buffer-local' on a variable of this | |
975 sort has no effect at all. | |
976 | |
977 SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
978 (declare with DEFVAR_CONST_BUFFER_LOCAL) | |
979 Same as SYMVAL_CURRENT_BUFFER_FORWARD except that the | |
980 value cannot be set. | |
981 | |
982 SYMVAL_DEFAULT_BUFFER_FORWARD: | |
983 (declare with DEFVAR_BUFFER_DEFAULTS) | |
984 This is used for the Lisp variables that contain the | |
985 default values of built-in buffer-local variables. Setting | |
986 or referencing one of these variables forwards into a slot | |
987 in the special struct buffer Vbuffer_defaults. | |
988 | |
989 SYMVAL_UNBOUND_MARKER: | |
990 This is used for only one object, Qunbound. | |
991 | |
992 SYMVAL_SELECTED_CONSOLE_FORWARD: | |
993 (declare with DEFVAR_CONSOLE_LOCAL) | |
994 This is used for built-in console-local variables -- i.e. | |
995 Lisp variables whose value is stored in the "struct console". | |
996 These work just like built-in buffer-local variables. | |
997 However, calling `make-local-variable' or | |
998 `make-variable-buffer-local' on one of these variables | |
999 is currently disallowed because that would entail having | |
1000 both console-local and buffer-local variables, which is | |
1001 trickier to implement. | |
1002 | |
1003 SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
1004 (declare with DEFVAR_CONST_CONSOLE_LOCAL) | |
1005 Same as SYMVAL_SELECTED_CONSOLE_FORWARD except that the | |
1006 value cannot be set. | |
1007 | |
1008 SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1009 (declare with DEFVAR_CONSOLE_DEFAULTS) | |
1010 This is used for the Lisp variables that contain the | |
1011 default values of built-in console-local variables. Setting | |
1012 or referencing one of these variables forwards into a slot | |
1013 in the special struct console Vconsole_defaults. | |
1014 | |
1015 | |
1016 2. symbol-value-buffer-local | |
1017 | |
1018 symbol-value-buffer-local is used for variables that have had | |
1019 `make-local-variable' or `make-variable-buffer-local' applied | |
1020 to them. This object contains an alist mapping buffers to | |
1021 values. In addition, the object contains a "current value", | |
1022 which is the value in some buffer. Whenever you access the | |
1023 variable with `symbol-value' or set it with `set' or `setq', | |
1024 things are switched around so that the "current value" | |
1025 refers to the current buffer, if it wasn't already. This | |
1026 way, repeated references to a variable in the same buffer | |
1027 are almost as efficient as if the variable weren't buffer | |
1028 local. Note that the alist may not be up-to-date w.r.t. | |
1029 the buffer whose value is current, as the "current value" | |
1030 cache is normally only flushed into the alist when the | |
1031 buffer it refers to changes. | |
1032 | |
1033 Note also that it is possible for `make-local-variable' | |
1034 or `make-variable-buffer-local' to be called on a variable | |
1035 that forwards into a C variable (i.e. a variable whose | |
1036 value cell is a symbol-value-forward). In this case, | |
1037 the value cell becomes a symbol-value-buffer-local (as | |
1038 always), and the symbol-value-forward moves into | |
1039 the "current value" cell in this object. Also, in | |
1040 this case the "current value" *always* refers to the | |
1041 current buffer, so that the values of the C variable | |
1042 always is the correct value for the current buffer. | |
1043 set_buffer_internal() automatically updates the current-value | |
1044 cells of all buffer-local variables that forward into C | |
1045 variables. (There is a list of all buffer-local variables | |
1046 that is maintained for this and other purposes.) | |
1047 | |
1048 Note that only certain types of `symbol-value-forward' objects | |
1049 can find their way into the "current value" cell of a | |
1050 `symbol-value-buffer-local' object: SYMVAL_OBJECT_FORWARD, | |
1051 SYMVAL_FIXNUM_FORWARD, SYMVAL_BOOLEAN_FORWARD, and | |
1052 SYMVAL_UNBOUND_MARKER. The SYMVAL_CONST_*_FORWARD cannot | |
1053 be buffer-local because they are unsettable; | |
1054 SYMVAL_DEFAULT_*_FORWARD cannot be buffer-local because that | |
1055 makes no sense; making SYMVAL_CURRENT_BUFFER_FORWARD buffer-local | |
1056 does not have much of an effect (it's already buffer-local); and | |
1057 SYMVAL_SELECTED_CONSOLE_FORWARD cannot be buffer-local because | |
1058 that's not currently implemented. | |
1059 | |
1060 | |
1061 3. symbol-value-varalias | |
1062 | |
1063 A symbol-value-varalias object is used for variables that | |
1064 are aliases for other variables. This object contains | |
1065 the symbol that this variable is aliased to. | |
1066 symbol-value-varalias objects cannot occur anywhere within | |
1067 a symbol-value-buffer-local object, and most of the | |
1068 low-level functions below do not accept them; you need | |
1069 to call follow_varalias_pointers to get the actual | |
1070 symbol to operate on. */ | |
1071 | |
1204 | 1072 static const struct memory_description symbol_value_buffer_local_description[] = { |
1073 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, default_value) }, | |
1074 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_value) }, | |
1075 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_buffer) }, | |
1076 { XD_LISP_OBJECT, offsetof (struct symbol_value_buffer_local, current_alist_element) }, | |
1077 { XD_END } | |
1078 }; | |
1079 | |
428 | 1080 static Lisp_Object |
1081 mark_symbol_value_buffer_local (Lisp_Object obj) | |
1082 { | |
1083 struct symbol_value_buffer_local *bfwd; | |
1084 | |
800 | 1085 #ifdef ERROR_CHECK_TYPES |
428 | 1086 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_BUFFER_LOCAL || |
1087 XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_SOME_BUFFER_LOCAL); | |
1088 #endif | |
1089 | |
1090 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (obj); | |
1091 mark_object (bfwd->default_value); | |
1092 mark_object (bfwd->current_value); | |
1093 mark_object (bfwd->current_buffer); | |
1094 return bfwd->current_alist_element; | |
1095 } | |
1096 | |
1204 | 1097 |
1098 static const struct memory_description symbol_value_lisp_magic_description[] = { | |
1099 { XD_LISP_OBJECT_ARRAY, offsetof (struct symbol_value_lisp_magic, handler), MAGIC_HANDLER_MAX }, | |
1100 { XD_LISP_OBJECT_ARRAY, offsetof (struct symbol_value_lisp_magic, harg), MAGIC_HANDLER_MAX }, | |
1101 { XD_LISP_OBJECT, offsetof (struct symbol_value_lisp_magic, shadowed) }, | |
1102 { XD_END } | |
1103 }; | |
1104 | |
428 | 1105 static Lisp_Object |
1106 mark_symbol_value_lisp_magic (Lisp_Object obj) | |
1107 { | |
1108 struct symbol_value_lisp_magic *bfwd; | |
1109 int i; | |
1110 | |
1111 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_LISP_MAGIC); | |
1112 | |
1113 bfwd = XSYMBOL_VALUE_LISP_MAGIC (obj); | |
1114 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
1115 { | |
1116 mark_object (bfwd->handler[i]); | |
1117 mark_object (bfwd->harg[i]); | |
1118 } | |
1119 return bfwd->shadowed; | |
1120 } | |
1121 | |
1204 | 1122 static const struct memory_description symbol_value_varalias_description[] = { |
1123 { XD_LISP_OBJECT, offsetof (struct symbol_value_varalias, aliasee) }, | |
1124 { XD_LISP_OBJECT, offsetof (struct symbol_value_varalias, shadowed) }, | |
1125 { XD_END } | |
1126 }; | |
1127 | |
428 | 1128 static Lisp_Object |
1129 mark_symbol_value_varalias (Lisp_Object obj) | |
1130 { | |
1131 struct symbol_value_varalias *bfwd; | |
1132 | |
1133 assert (XSYMBOL_VALUE_MAGIC_TYPE (obj) == SYMVAL_VARALIAS); | |
1134 | |
1135 bfwd = XSYMBOL_VALUE_VARALIAS (obj); | |
1136 mark_object (bfwd->shadowed); | |
1137 return bfwd->aliasee; | |
1138 } | |
1139 | |
1140 /* Should never, ever be called. (except by an external debugger) */ | |
1141 void | |
2286 | 1142 print_symbol_value_magic (Lisp_Object obj, Lisp_Object printcharfun, |
1143 int UNUSED (escapeflag)) | |
428 | 1144 { |
800 | 1145 write_fmt_string (printcharfun, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1146 "#<INTERNAL OBJECT (XEmacs bug?) (%s type %d) 0x%x>", |
800 | 1147 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, |
1148 XSYMBOL_VALUE_MAGIC_TYPE (obj), | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1149 LISP_OBJECT_UID (obj)); |
428 | 1150 } |
1151 | |
1204 | 1152 static const struct memory_description symbol_value_forward_description[] = { |
428 | 1153 { XD_END } |
1154 }; | |
1155 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1156 DEFINE_DUMPABLE_LISP_OBJECT ("symbol-value-forward", |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1157 symbol_value_forward, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1158 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1159 print_symbol_value_magic, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1160 symbol_value_forward_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1161 struct symbol_value_forward); |
934 | 1162 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1163 DEFINE_DUMPABLE_LISP_OBJECT ("symbol-value-buffer-local", |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1164 symbol_value_buffer_local, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1165 mark_symbol_value_buffer_local, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1166 print_symbol_value_magic, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1167 symbol_value_buffer_local_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1168 struct symbol_value_buffer_local); |
934 | 1169 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1170 DEFINE_DUMPABLE_LISP_OBJECT ("symbol-value-lisp-magic", |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1171 symbol_value_lisp_magic, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1172 mark_symbol_value_lisp_magic, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1173 print_symbol_value_magic, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1174 symbol_value_lisp_magic_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1175 struct symbol_value_lisp_magic); |
934 | 1176 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1177 DEFINE_DUMPABLE_LISP_OBJECT ("symbol-value-varalias", |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1178 symbol_value_varalias, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1179 mark_symbol_value_varalias, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1180 print_symbol_value_magic, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1181 symbol_value_varalias_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1182 struct symbol_value_varalias); |
934 | 1183 |
428 | 1184 |
1185 /* Getting and setting values of symbols */ | |
1186 | |
1187 /* Given the raw contents of a symbol value cell, return the Lisp value of | |
1188 the symbol. However, VALCONTENTS cannot be a symbol-value-buffer-local, | |
1189 symbol-value-lisp-magic, or symbol-value-varalias. | |
1190 | |
1191 BUFFER specifies a buffer, and is used for built-in buffer-local | |
1192 variables, which are of type SYMVAL_CURRENT_BUFFER_FORWARD. | |
1193 Note that such variables are never encapsulated in a | |
1194 symbol-value-buffer-local structure. | |
1195 | |
1196 CONSOLE specifies a console, and is used for built-in console-local | |
1197 variables, which are of type SYMVAL_SELECTED_CONSOLE_FORWARD. | |
1198 Note that such variables are (currently) never encapsulated in a | |
1199 symbol-value-buffer-local structure. | |
1200 */ | |
1201 | |
1202 static Lisp_Object | |
1203 do_symval_forwarding (Lisp_Object valcontents, struct buffer *buffer, | |
1204 struct console *console) | |
1205 { | |
442 | 1206 const struct symbol_value_forward *fwd; |
428 | 1207 |
1208 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1209 return valcontents; | |
1210 | |
1211 fwd = XSYMBOL_VALUE_FORWARD (valcontents); | |
1212 switch (fwd->magic.type) | |
1213 { | |
1214 case SYMVAL_FIXNUM_FORWARD: | |
1215 case SYMVAL_CONST_FIXNUM_FORWARD: | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1216 return make_fixnum (*((Fixnum *)symbol_value_forward_forward (fwd))); |
428 | 1217 |
1218 case SYMVAL_BOOLEAN_FORWARD: | |
1219 case SYMVAL_CONST_BOOLEAN_FORWARD: | |
1220 return *((int *)symbol_value_forward_forward (fwd)) ? Qt : Qnil; | |
1221 | |
1222 case SYMVAL_OBJECT_FORWARD: | |
1223 case SYMVAL_CONST_OBJECT_FORWARD: | |
1224 case SYMVAL_CONST_SPECIFIER_FORWARD: | |
1225 return *((Lisp_Object *)symbol_value_forward_forward (fwd)); | |
1226 | |
1227 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1228 return (*((Lisp_Object *)((Rawbyte *) XBUFFER (Vbuffer_defaults) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1229 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1230 - (Rawbyte *)&buffer_local_flags)))); |
428 | 1231 |
1232 | |
1233 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1234 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: | |
1235 assert (buffer); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1236 return (*((Lisp_Object *)((Rawbyte *)buffer |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1237 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1238 - (Rawbyte *)&buffer_local_flags)))); |
428 | 1239 |
1240 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1241 return (*((Lisp_Object *)((Rawbyte *) XCONSOLE (Vconsole_defaults) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1242 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1243 - (Rawbyte *)&console_local_flags)))); |
428 | 1244 |
1245 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1246 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: | |
1247 assert (console); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1248 return (*((Lisp_Object *)((Rawbyte *)console |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1249 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1250 - (Rawbyte *)&console_local_flags)))); |
428 | 1251 |
1252 case SYMVAL_UNBOUND_MARKER: | |
1253 return valcontents; | |
1254 | |
1255 default: | |
2500 | 1256 ABORT (); |
428 | 1257 } |
1258 return Qnil; /* suppress compiler warning */ | |
1259 } | |
1260 | |
1261 /* Set the value of default-buffer-local variable SYM to VALUE. */ | |
1262 | |
1263 static void | |
1264 set_default_buffer_slot_variable (Lisp_Object sym, | |
1265 Lisp_Object value) | |
1266 { | |
1267 /* Handle variables like case-fold-search that have special slots in | |
1268 the buffer. Make them work apparently like buffer_local variables. | |
1269 */ | |
1270 /* At this point, the value cell may not contain a symbol-value-varalias | |
1271 or symbol-value-buffer-local, and if there's a handler, we should | |
1272 have already called it. */ | |
1273 Lisp_Object valcontents = fetch_value_maybe_past_magic (sym, Qt); | |
442 | 1274 const struct symbol_value_forward *fwd |
428 | 1275 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1276 int offset = ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1277 - (Rawbyte *) &buffer_local_flags); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1278 int mask = XFIXNUM (*((Lisp_Object *) symbol_value_forward_forward (fwd))); |
428 | 1279 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, Lisp_Object in_object, |
1280 int flags) = symbol_value_forward_magicfun (fwd); | |
1281 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1282 *((Lisp_Object *) (offset + (Rawbyte *) XBUFFER (Vbuffer_defaults))) |
428 | 1283 = value; |
1284 | |
1285 if (mask > 0) /* Not always per-buffer */ | |
1286 { | |
1287 /* Set value in each buffer which hasn't shadowed the default */ | |
1288 LIST_LOOP_2 (elt, Vbuffer_alist) | |
1289 { | |
1290 struct buffer *b = XBUFFER (XCDR (elt)); | |
1291 if (!(b->local_var_flags & mask)) | |
1292 { | |
1293 if (magicfun) | |
771 | 1294 magicfun (sym, &value, wrap_buffer (b), 0); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1295 *((Lisp_Object *) (offset + (Rawbyte *) b)) = value; |
428 | 1296 } |
1297 } | |
1298 } | |
1299 } | |
1300 | |
1301 /* Set the value of default-console-local variable SYM to VALUE. */ | |
1302 | |
1303 static void | |
1304 set_default_console_slot_variable (Lisp_Object sym, | |
1305 Lisp_Object value) | |
1306 { | |
1307 /* Handle variables like case-fold-search that have special slots in | |
1308 the console. Make them work apparently like console_local variables. | |
1309 */ | |
1310 /* At this point, the value cell may not contain a symbol-value-varalias | |
1311 or symbol-value-buffer-local, and if there's a handler, we should | |
1312 have already called it. */ | |
1313 Lisp_Object valcontents = fetch_value_maybe_past_magic (sym, Qt); | |
442 | 1314 const struct symbol_value_forward *fwd |
428 | 1315 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1316 int offset = ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1317 - (Rawbyte *) &console_local_flags); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1318 int mask = XFIXNUM (*((Lisp_Object *) symbol_value_forward_forward (fwd))); |
428 | 1319 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, Lisp_Object in_object, |
1320 int flags) = symbol_value_forward_magicfun (fwd); | |
1321 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1322 *((Lisp_Object *) (offset + (Rawbyte *) XCONSOLE (Vconsole_defaults))) |
428 | 1323 = value; |
1324 | |
1325 if (mask > 0) /* Not always per-console */ | |
1326 { | |
1327 /* Set value in each console which hasn't shadowed the default */ | |
1328 LIST_LOOP_2 (console, Vconsole_list) | |
1329 { | |
1330 struct console *d = XCONSOLE (console); | |
1331 if (!(d->local_var_flags & mask)) | |
1332 { | |
1333 if (magicfun) | |
1334 magicfun (sym, &value, console, 0); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1335 *((Lisp_Object *) (offset + (Rawbyte *) d)) = value; |
428 | 1336 } |
1337 } | |
1338 } | |
1339 } | |
1340 | |
1341 /* Store NEWVAL into SYM. | |
1342 | |
1343 SYM's value slot may *not* be types (5) or (6) above, | |
1344 i.e. no symbol-value-varalias objects. (You should have | |
1345 forwarded past all of these.) | |
1346 | |
1347 SYM should not be an unsettable symbol or a symbol with | |
1348 a magic `set-value' handler (unless you want to explicitly | |
1349 ignore this handler). | |
1350 | |
1351 OVALUE is the current value of SYM, but forwarded past any | |
1352 symbol-value-buffer-local and symbol-value-lisp-magic objects. | |
1353 (i.e. if SYM is a symbol-value-buffer-local, OVALUE should be | |
1354 the contents of its current-value cell.) NEWVAL may only be | |
1355 a simple value or Qunbound. If SYM is a symbol-value-buffer-local, | |
1356 this function will only modify its current-value cell, which should | |
1357 already be set up to point to the current buffer. | |
1358 */ | |
1359 | |
1360 static void | |
1361 store_symval_forwarding (Lisp_Object sym, Lisp_Object ovalue, | |
1362 Lisp_Object newval) | |
1363 { | |
1364 if (!SYMBOL_VALUE_MAGIC_P (ovalue) || UNBOUNDP (ovalue)) | |
1365 { | |
1366 Lisp_Object *store_pointer = value_slot_past_magic (sym); | |
1367 | |
1368 if (SYMBOL_VALUE_BUFFER_LOCAL_P (*store_pointer)) | |
1369 store_pointer = | |
1370 &XSYMBOL_VALUE_BUFFER_LOCAL (*store_pointer)->current_value; | |
1371 | |
1372 assert (UNBOUNDP (*store_pointer) | |
1373 || !SYMBOL_VALUE_MAGIC_P (*store_pointer)); | |
1374 *store_pointer = newval; | |
1375 } | |
1376 else | |
1377 { | |
442 | 1378 const struct symbol_value_forward *fwd = XSYMBOL_VALUE_FORWARD (ovalue); |
428 | 1379 int (*magicfun) (Lisp_Object simm, Lisp_Object *val, |
1380 Lisp_Object in_object, int flags) | |
1381 = symbol_value_forward_magicfun (fwd); | |
1382 | |
1383 switch (XSYMBOL_VALUE_MAGIC_TYPE (ovalue)) | |
1384 { | |
1385 case SYMVAL_FIXNUM_FORWARD: | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1386 CHECK_FIXNUM (newval); |
428 | 1387 if (magicfun) |
1388 magicfun (sym, &newval, Qnil, 0); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1389 *((Fixnum *) symbol_value_forward_forward (fwd)) = XFIXNUM (newval); |
428 | 1390 return; |
1391 | |
1392 case SYMVAL_BOOLEAN_FORWARD: | |
1393 if (magicfun) | |
1394 magicfun (sym, &newval, Qnil, 0); | |
1395 *((int *) symbol_value_forward_forward (fwd)) | |
1396 = !NILP (newval); | |
1397 return; | |
1398 | |
1399 case SYMVAL_OBJECT_FORWARD: | |
1400 if (magicfun) | |
1401 magicfun (sym, &newval, Qnil, 0); | |
1402 *((Lisp_Object *) symbol_value_forward_forward (fwd)) = newval; | |
1403 return; | |
1404 | |
1405 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
1406 set_default_buffer_slot_variable (sym, newval); | |
1407 return; | |
1408 | |
1409 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1410 if (magicfun) | |
771 | 1411 magicfun (sym, &newval, wrap_buffer (current_buffer), 0); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1412 *((Lisp_Object *) ((Rawbyte *) current_buffer |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1413 + ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1414 - (Rawbyte *) &buffer_local_flags))) |
428 | 1415 = newval; |
1416 return; | |
1417 | |
1418 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1419 set_default_console_slot_variable (sym, newval); | |
1420 return; | |
1421 | |
1422 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1423 if (magicfun) | |
1424 magicfun (sym, &newval, Vselected_console, 0); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1425 *((Lisp_Object *) ((Rawbyte *) XCONSOLE (Vselected_console) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1426 + ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
1427 - (Rawbyte *) &console_local_flags))) |
428 | 1428 = newval; |
1429 return; | |
1430 | |
1431 default: | |
2500 | 1432 ABORT (); |
428 | 1433 } |
1434 } | |
1435 } | |
1436 | |
1437 /* Given a per-buffer variable SYMBOL and its raw value-cell contents | |
1438 BFWD, locate and return a pointer to the element in BUFFER's | |
1439 local_var_alist for SYMBOL. The return value will be Qnil if | |
1440 BUFFER does not have its own value for SYMBOL (i.e. the default | |
1441 value is seen in that buffer). | |
1442 */ | |
1443 | |
1444 static Lisp_Object | |
1445 buffer_local_alist_element (struct buffer *buffer, Lisp_Object symbol, | |
1446 struct symbol_value_buffer_local *bfwd) | |
1447 { | |
1448 if (!NILP (bfwd->current_buffer) && | |
1449 XBUFFER (bfwd->current_buffer) == buffer) | |
1450 /* This is just an optimization of the below. */ | |
1451 return bfwd->current_alist_element; | |
1452 else | |
1453 return assq_no_quit (symbol, buffer->local_var_alist); | |
1454 } | |
1455 | |
1456 /* [Remember that the slot that mirrors CURRENT-VALUE in the | |
1457 symbol-value-buffer-local of a per-buffer variable -- i.e. the | |
1458 slot in CURRENT-BUFFER's local_var_alist, or the DEFAULT-VALUE | |
1459 slot -- may be out of date.] | |
1460 | |
1461 Write out any cached value in buffer-local variable SYMBOL's | |
1462 buffer-local structure, which is passed in as BFWD. | |
1463 */ | |
1464 | |
1465 static void | |
2286 | 1466 write_out_buffer_local_cache (Lisp_Object UNUSED (symbol), |
428 | 1467 struct symbol_value_buffer_local *bfwd) |
1468 { | |
1469 if (!NILP (bfwd->current_buffer)) | |
1470 { | |
1471 /* We pass 0 for BUFFER because only SYMVAL_CURRENT_BUFFER_FORWARD | |
1472 uses it, and that type cannot be inside a symbol-value-buffer-local */ | |
1473 Lisp_Object cval = do_symval_forwarding (bfwd->current_value, 0, 0); | |
1474 if (NILP (bfwd->current_alist_element)) | |
1475 /* current_value may be updated more recently than default_value */ | |
1476 bfwd->default_value = cval; | |
1477 else | |
1478 Fsetcdr (bfwd->current_alist_element, cval); | |
1479 } | |
1480 } | |
1481 | |
1482 /* SYM is a buffer-local variable, and BFWD is its buffer-local structure. | |
1483 Set up BFWD's cache for validity in buffer BUF. This assumes that | |
1484 the cache is currently in a consistent state (this can include | |
1485 not having any value cached, if BFWD->CURRENT_BUFFER is nil). | |
1486 | |
1487 If the cache is already set up for BUF, this function does nothing | |
1488 at all. | |
1489 | |
1490 Otherwise, if SYM forwards out to a C variable, this also forwards | |
1491 SYM's value in BUF out to the variable. Therefore, you generally | |
1492 only want to call this when BUF is, or is about to become, the | |
1493 current buffer. | |
1494 | |
1495 (Otherwise, you can just retrieve the value without changing the | |
1496 cache, at the expense of slower retrieval.) | |
1497 */ | |
1498 | |
1499 static void | |
1500 set_up_buffer_local_cache (Lisp_Object sym, | |
1501 struct symbol_value_buffer_local *bfwd, | |
1502 struct buffer *buf, | |
1503 Lisp_Object new_alist_el, | |
1504 int set_it_p) | |
1505 { | |
1506 Lisp_Object new_val; | |
1507 | |
1508 if (!NILP (bfwd->current_buffer) | |
1509 && buf == XBUFFER (bfwd->current_buffer)) | |
1510 /* Cache is already set up. */ | |
1511 return; | |
1512 | |
1513 /* Flush out the old cache. */ | |
1514 write_out_buffer_local_cache (sym, bfwd); | |
1515 | |
1516 /* Retrieve the new alist element and new value. */ | |
1517 if (NILP (new_alist_el) | |
1518 && set_it_p) | |
1519 new_alist_el = buffer_local_alist_element (buf, sym, bfwd); | |
1520 | |
1521 if (NILP (new_alist_el)) | |
1522 new_val = bfwd->default_value; | |
1523 else | |
1524 new_val = Fcdr (new_alist_el); | |
1525 | |
1526 bfwd->current_alist_element = new_alist_el; | |
793 | 1527 bfwd->current_buffer = wrap_buffer (buf); |
428 | 1528 |
1529 /* Now store the value into the current-value slot. | |
1530 We don't simply write it there, because the current-value | |
1531 slot might be a forwarding pointer, in which case we need | |
1532 to instead write the value into the C variable. | |
1533 | |
1534 We might also want to call a magic function. | |
1535 | |
1536 So instead, we call this function. */ | |
1537 store_symval_forwarding (sym, bfwd->current_value, new_val); | |
1538 } | |
1539 | |
446 | 1540 |
1541 /* SYM is a buffer-local variable, and BFWD is its buffer-local structure. | |
1542 Flush the cache. BFWD->CURRENT_BUFFER will be nil after this operation. | |
1543 */ | |
1544 | |
1545 static void | |
1546 flush_buffer_local_cache (Lisp_Object sym, | |
1547 struct symbol_value_buffer_local *bfwd) | |
1548 { | |
1549 if (NILP (bfwd->current_buffer)) | |
1550 /* Cache is already flushed. */ | |
1551 return; | |
1552 | |
1553 /* Flush out the old cache. */ | |
1554 write_out_buffer_local_cache (sym, bfwd); | |
1555 | |
1556 bfwd->current_alist_element = Qnil; | |
1557 bfwd->current_buffer = Qnil; | |
1558 | |
1559 /* Now store default the value into the current-value slot. | |
1560 We don't simply write it there, because the current-value | |
1561 slot might be a forwarding pointer, in which case we need | |
1562 to instead write the value into the C variable. | |
1563 | |
1564 We might also want to call a magic function. | |
1565 | |
1566 So instead, we call this function. */ | |
1567 store_symval_forwarding (sym, bfwd->current_value, bfwd->default_value); | |
1568 } | |
1569 | |
1570 /* Flush all the buffer-local variable caches. Whoever has a | |
1571 non-interned buffer-local variable will be spanked. Whoever has a | |
1572 magic variable that interns or uninterns symbols... I don't even | |
1573 want to think about it. | |
1574 */ | |
1575 | |
1576 void | |
1577 flush_all_buffer_local_cache (void) | |
1578 { | |
1579 Lisp_Object *syms = XVECTOR_DATA (Vobarray); | |
1580 long count = XVECTOR_LENGTH (Vobarray); | |
1581 long i; | |
1582 | |
1583 for (i=0; i<count; i++) | |
1584 { | |
1585 Lisp_Object sym = syms[i]; | |
1586 Lisp_Object value; | |
1587 | |
1588 if (!ZEROP (sym)) | |
1589 for(;;) | |
1590 { | |
1591 Lisp_Symbol *next; | |
1592 assert (SYMBOLP (sym)); | |
1593 value = fetch_value_maybe_past_magic (sym, Qt); | |
1594 if (SYMBOL_VALUE_BUFFER_LOCAL_P (value)) | |
1595 flush_buffer_local_cache (sym, XSYMBOL_VALUE_BUFFER_LOCAL (value)); | |
1596 | |
1597 next = symbol_next (XSYMBOL (sym)); | |
1598 if (!next) | |
1599 break; | |
793 | 1600 sym = wrap_symbol (next); |
446 | 1601 } |
1602 } | |
1603 } | |
1604 | |
428 | 1605 |
1606 void | |
1607 kill_buffer_local_variables (struct buffer *buf) | |
1608 { | |
1609 Lisp_Object prev = Qnil; | |
1610 Lisp_Object alist; | |
1611 | |
1612 /* Any which are supposed to be permanent, | |
1613 make local again, with the same values they had. */ | |
1614 | |
1615 for (alist = buf->local_var_alist; !NILP (alist); alist = XCDR (alist)) | |
1616 { | |
1617 Lisp_Object sym = XCAR (XCAR (alist)); | |
1618 struct symbol_value_buffer_local *bfwd; | |
1619 /* Variables with a symbol-value-varalias should not be here | |
1620 (we should have forwarded past them) and there must be a | |
1621 symbol-value-buffer-local. If there's a symbol-value-lisp-magic, | |
1622 just forward past it; if the variable has a handler, it was | |
1623 already called. */ | |
1624 Lisp_Object value = fetch_value_maybe_past_magic (sym, Qt); | |
1625 | |
1626 assert (SYMBOL_VALUE_BUFFER_LOCAL_P (value)); | |
1627 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (value); | |
1628 | |
1629 if (!NILP (Fget (sym, Qpermanent_local, Qnil))) | |
1630 /* prev points to the last alist element that is still | |
1631 staying around, so *only* update it now. This didn't | |
1632 used to be the case; this bug has been around since | |
1633 mly's rewrite two years ago! */ | |
1634 prev = alist; | |
1635 else | |
1636 { | |
1637 /* Really truly kill it. */ | |
1638 if (!NILP (prev)) | |
1639 XCDR (prev) = XCDR (alist); | |
1640 else | |
1641 buf->local_var_alist = XCDR (alist); | |
1642 | |
1643 /* We just effectively changed the value for this variable | |
1644 in BUF. So: */ | |
1645 | |
1646 /* (1) If the cache is caching BUF, invalidate the cache. */ | |
1647 if (!NILP (bfwd->current_buffer) && | |
1648 buf == XBUFFER (bfwd->current_buffer)) | |
1649 bfwd->current_buffer = Qnil; | |
1650 | |
1651 /* (2) If we changed the value in current_buffer and this | |
1652 variable forwards to a C variable, we need to change the | |
1653 value of the C variable. set_up_buffer_local_cache() | |
1654 will do this. It doesn't hurt to do it whenever | |
1655 BUF == current_buffer, so just go ahead and do that. */ | |
1656 if (buf == current_buffer) | |
1657 set_up_buffer_local_cache (sym, bfwd, buf, Qnil, 0); | |
1658 } | |
1659 } | |
1660 } | |
1661 | |
1662 static Lisp_Object | |
1663 find_symbol_value_1 (Lisp_Object sym, struct buffer *buf, | |
1664 struct console *con, int swap_it_in, | |
1665 Lisp_Object symcons, int set_it_p) | |
1666 { | |
1667 Lisp_Object valcontents; | |
1668 | |
1669 retry: | |
1670 valcontents = XSYMBOL (sym)->value; | |
1671 | |
1672 retry_2: | |
1673 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1674 return valcontents; | |
1675 | |
1676 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
1677 { | |
1678 case SYMVAL_LISP_MAGIC: | |
1679 /* #### kludge */ | |
1680 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
1681 /* semi-change-o */ | |
1682 goto retry_2; | |
1683 | |
1684 case SYMVAL_VARALIAS: | |
1685 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); | |
1686 symcons = Qnil; | |
1687 /* presto change-o! */ | |
1688 goto retry; | |
1689 | |
1690 case SYMVAL_BUFFER_LOCAL: | |
1691 case SYMVAL_SOME_BUFFER_LOCAL: | |
1692 { | |
1693 struct symbol_value_buffer_local *bfwd | |
1694 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
1695 | |
1696 if (swap_it_in) | |
1697 { | |
1698 set_up_buffer_local_cache (sym, bfwd, buf, symcons, set_it_p); | |
1699 valcontents = bfwd->current_value; | |
1700 } | |
1701 else | |
1702 { | |
1703 if (!NILP (bfwd->current_buffer) && | |
1704 buf == XBUFFER (bfwd->current_buffer)) | |
1705 valcontents = bfwd->current_value; | |
1706 else if (NILP (symcons)) | |
1707 { | |
1708 if (set_it_p) | |
1709 valcontents = assq_no_quit (sym, buf->local_var_alist); | |
1710 if (NILP (valcontents)) | |
1711 valcontents = bfwd->default_value; | |
1712 else | |
1713 valcontents = XCDR (valcontents); | |
1714 } | |
1715 else | |
1716 valcontents = XCDR (symcons); | |
1717 } | |
1718 break; | |
1719 } | |
1720 | |
1721 default: | |
1722 break; | |
1723 } | |
1724 return do_symval_forwarding (valcontents, buf, con); | |
1725 } | |
1726 | |
1727 | |
1728 /* Find the value of a symbol in BUFFER, returning Qunbound if it's not | |
1729 bound. Note that it must not be possible to QUIT within this | |
1730 function. */ | |
1731 | |
1732 Lisp_Object | |
1733 symbol_value_in_buffer (Lisp_Object sym, Lisp_Object buffer) | |
1734 { | |
1735 struct buffer *buf; | |
1736 | |
1737 CHECK_SYMBOL (sym); | |
1738 | |
1739 if (NILP (buffer)) | |
1740 buf = current_buffer; | |
1741 else | |
1742 { | |
1743 CHECK_BUFFER (buffer); | |
1744 buf = XBUFFER (buffer); | |
1745 } | |
1746 | |
1747 return find_symbol_value_1 (sym, buf, | |
1748 /* If it bombs out at startup due to a | |
1749 Lisp error, this may be nil. */ | |
1750 CONSOLEP (Vselected_console) | |
1751 ? XCONSOLE (Vselected_console) : 0, 0, Qnil, 1); | |
1752 } | |
1753 | |
1754 static Lisp_Object | |
1755 symbol_value_in_console (Lisp_Object sym, Lisp_Object console) | |
1756 { | |
1757 CHECK_SYMBOL (sym); | |
1758 | |
1759 if (NILP (console)) | |
1760 console = Vselected_console; | |
1761 else | |
1762 CHECK_CONSOLE (console); | |
1763 | |
1764 return find_symbol_value_1 (sym, current_buffer, XCONSOLE (console), 0, | |
1765 Qnil, 1); | |
1766 } | |
1767 | |
1768 /* Return the current value of SYM. The difference between this function | |
1769 and calling symbol_value_in_buffer with a BUFFER of Qnil is that | |
1770 this updates the CURRENT_VALUE slot of buffer-local variables to | |
1771 point to the current buffer, while symbol_value_in_buffer doesn't. */ | |
1772 | |
1773 Lisp_Object | |
1774 find_symbol_value (Lisp_Object sym) | |
1775 { | |
1776 /* WARNING: This function can be called when current_buffer is 0 | |
1777 and Vselected_console is Qnil, early in initialization. */ | |
1778 struct console *con; | |
1779 Lisp_Object valcontents; | |
1780 | |
1781 CHECK_SYMBOL (sym); | |
1782 | |
1783 valcontents = XSYMBOL (sym)->value; | |
1784 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1785 return valcontents; | |
1786 | |
1787 if (CONSOLEP (Vselected_console)) | |
1788 con = XCONSOLE (Vselected_console); | |
1789 else | |
1790 { | |
1791 /* This can also get called while we're preparing to shutdown. | |
1792 #### What should really happen in that case? Should we | |
1793 actually fix things so we can't get here in that case? */ | |
1794 #ifndef PDUMP | |
1795 assert (!initialized || preparing_for_armageddon); | |
1796 #endif | |
1797 con = 0; | |
1798 } | |
1799 | |
1800 return find_symbol_value_1 (sym, current_buffer, con, 1, Qnil, 1); | |
1801 } | |
1802 | |
1803 /* This is an optimized function for quick lookup of buffer local symbols | |
1804 by avoiding O(n) search. This will work when either: | |
1805 a) We have already found the symbol e.g. by traversing local_var_alist. | |
1806 or | |
1807 b) We know that the symbol will not be found in the current buffer's | |
1808 list of local variables. | |
1809 In the former case, find_it_p is 1 and symbol_cons is the element from | |
1810 local_var_alist. In the latter case, find_it_p is 0 and symbol_cons | |
1811 is the symbol. | |
1812 | |
1813 This function is called from set_buffer_internal which does both of these | |
1814 things. */ | |
1815 | |
1816 Lisp_Object | |
1817 find_symbol_value_quickly (Lisp_Object symbol_cons, int find_it_p) | |
1818 { | |
1819 /* WARNING: This function can be called when current_buffer is 0 | |
1820 and Vselected_console is Qnil, early in initialization. */ | |
1821 struct console *con; | |
1822 Lisp_Object sym = find_it_p ? XCAR (symbol_cons) : symbol_cons; | |
1823 | |
1824 CHECK_SYMBOL (sym); | |
1825 if (CONSOLEP (Vselected_console)) | |
1826 con = XCONSOLE (Vselected_console); | |
1827 else | |
1828 { | |
1829 /* This can also get called while we're preparing to shutdown. | |
1830 #### What should really happen in that case? Should we | |
1831 actually fix things so we can't get here in that case? */ | |
1832 #ifndef PDUMP | |
1833 assert (!initialized || preparing_for_armageddon); | |
1834 #endif | |
1835 con = 0; | |
1836 } | |
1837 | |
1838 return find_symbol_value_1 (sym, current_buffer, con, 1, | |
1839 find_it_p ? symbol_cons : Qnil, | |
1840 find_it_p); | |
1841 } | |
1842 | |
1843 DEFUN ("symbol-value", Fsymbol_value, 1, 1, 0, /* | |
1844 Return SYMBOL's value. Error if that is void. | |
1845 */ | |
1846 (symbol)) | |
1847 { | |
1848 Lisp_Object val = find_symbol_value (symbol); | |
1849 | |
1850 if (UNBOUNDP (val)) | |
1851 return Fsignal (Qvoid_variable, list1 (symbol)); | |
1852 else | |
1853 return val; | |
1854 } | |
1855 | |
1856 DEFUN ("set", Fset, 2, 2, 0, /* | |
1857 Set SYMBOL's value to NEWVAL, and return NEWVAL. | |
1858 */ | |
1859 (symbol, newval)) | |
1860 { | |
1861 REGISTER Lisp_Object valcontents; | |
440 | 1862 Lisp_Symbol *sym; |
428 | 1863 /* remember, we're called by Fmakunbound() as well */ |
1864 | |
1865 CHECK_SYMBOL (symbol); | |
1866 | |
1867 retry: | |
1868 sym = XSYMBOL (symbol); | |
1869 valcontents = sym->value; | |
1870 | |
1871 if (EQ (symbol, Qnil) || | |
1872 EQ (symbol, Qt) || | |
1873 SYMBOL_IS_KEYWORD (symbol)) | |
1874 reject_constant_symbols (symbol, newval, 0, | |
1875 UNBOUNDP (newval) ? Qmakunbound : Qset); | |
1876 | |
1877 if (!SYMBOL_VALUE_MAGIC_P (valcontents) || UNBOUNDP (valcontents)) | |
1878 { | |
1879 sym->value = newval; | |
1880 return newval; | |
1881 } | |
1882 | |
1883 reject_constant_symbols (symbol, newval, 0, | |
1884 UNBOUNDP (newval) ? Qmakunbound : Qset); | |
1885 | |
1886 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
1887 { | |
1888 case SYMVAL_LISP_MAGIC: | |
1889 { | |
1890 if (UNBOUNDP (newval)) | |
440 | 1891 { |
1892 maybe_call_magic_handler (symbol, Qmakunbound, 0); | |
1893 return XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed = Qunbound; | |
1894 } | |
428 | 1895 else |
440 | 1896 { |
1897 maybe_call_magic_handler (symbol, Qset, 1, newval); | |
1898 return XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed = newval; | |
1899 } | |
428 | 1900 } |
1901 | |
1902 case SYMVAL_VARALIAS: | |
1903 symbol = follow_varalias_pointers (symbol, | |
1904 UNBOUNDP (newval) | |
1905 ? Qmakunbound : Qset); | |
1906 /* presto change-o! */ | |
1907 goto retry; | |
1908 | |
1909 case SYMVAL_FIXNUM_FORWARD: | |
996 | 1910 case SYMVAL_CONST_FIXNUM_FORWARD: |
428 | 1911 case SYMVAL_BOOLEAN_FORWARD: |
996 | 1912 case SYMVAL_CONST_BOOLEAN_FORWARD: |
428 | 1913 case SYMVAL_DEFAULT_BUFFER_FORWARD: |
1914 case SYMVAL_DEFAULT_CONSOLE_FORWARD: | |
1915 if (UNBOUNDP (newval)) | |
996 | 1916 { |
1917 #ifdef HAVE_SHLIB | |
1918 if (unloading_module) | |
1919 { | |
1920 sym->value = newval; | |
1921 return newval; | |
1922 } | |
1923 else | |
1924 #endif | |
1925 invalid_change ("Cannot makunbound", symbol); | |
1926 } | |
1927 break; | |
1928 | |
1929 case SYMVAL_OBJECT_FORWARD: | |
1930 case SYMVAL_CONST_OBJECT_FORWARD: | |
1931 if (UNBOUNDP (newval)) | |
1932 { | |
1933 #ifdef HAVE_SHLIB | |
1934 if (unloading_module) | |
1935 { | |
1111 | 1936 unstaticpro_nodump ((Lisp_Object *) |
1937 symbol_value_forward_forward | |
996 | 1938 (XSYMBOL_VALUE_FORWARD (valcontents))); |
1939 sym->value = newval; | |
1940 return newval; | |
1941 } | |
1942 else | |
1943 #endif | |
1944 invalid_change ("Cannot makunbound", symbol); | |
1945 } | |
428 | 1946 break; |
1947 | |
1948 /* case SYMVAL_UNBOUND_MARKER: break; */ | |
1949 | |
1950 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
1951 { | |
442 | 1952 const struct symbol_value_forward *fwd |
428 | 1953 = XSYMBOL_VALUE_FORWARD (valcontents); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1954 int mask = XFIXNUM (*((Lisp_Object *) |
428 | 1955 symbol_value_forward_forward (fwd))); |
1956 if (mask > 0) | |
1957 /* Setting this variable makes it buffer-local */ | |
1958 current_buffer->local_var_flags |= mask; | |
1959 break; | |
1960 } | |
1961 | |
1962 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
1963 { | |
442 | 1964 const struct symbol_value_forward *fwd |
428 | 1965 = XSYMBOL_VALUE_FORWARD (valcontents); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1966 int mask = XFIXNUM (*((Lisp_Object *) |
428 | 1967 symbol_value_forward_forward (fwd))); |
1968 if (mask > 0) | |
1969 /* Setting this variable makes it console-local */ | |
1970 XCONSOLE (Vselected_console)->local_var_flags |= mask; | |
1971 break; | |
1972 } | |
1973 | |
1974 case SYMVAL_BUFFER_LOCAL: | |
1975 case SYMVAL_SOME_BUFFER_LOCAL: | |
1976 { | |
1977 /* If we want to examine or set the value and | |
1978 CURRENT-BUFFER is current, we just examine or set | |
1979 CURRENT-VALUE. If CURRENT-BUFFER is not current, we | |
1980 store the current CURRENT-VALUE value into | |
1981 CURRENT-ALIST- ELEMENT, then find the appropriate alist | |
1982 element for the buffer now current and set up | |
1983 CURRENT-ALIST-ELEMENT. Then we set CURRENT-VALUE out | |
1984 of that element, and store into CURRENT-BUFFER. | |
1985 | |
1986 If we are setting the variable and the current buffer does | |
1987 not have an alist entry for this variable, an alist entry is | |
1988 created. | |
1989 | |
1990 Note that CURRENT-VALUE can be a forwarding pointer. | |
1991 Each time it is examined or set, forwarding must be | |
1992 done. */ | |
1993 struct symbol_value_buffer_local *bfwd | |
1994 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
1995 int some_buffer_local_p = | |
1996 (bfwd->magic.type == SYMVAL_SOME_BUFFER_LOCAL); | |
1997 /* What value are we caching right now? */ | |
1998 Lisp_Object aelt = bfwd->current_alist_element; | |
1999 | |
2000 if (!NILP (bfwd->current_buffer) && | |
2001 current_buffer == XBUFFER (bfwd->current_buffer) | |
2002 && ((some_buffer_local_p) | |
2003 ? 1 /* doesn't automatically become local */ | |
2004 : !NILP (aelt) /* already local */ | |
2005 )) | |
2006 { | |
2007 /* Cache is valid */ | |
2008 valcontents = bfwd->current_value; | |
2009 } | |
2010 else | |
2011 { | |
2012 /* If the current buffer is not the buffer whose binding is | |
2013 currently cached, or if it's a SYMVAL_BUFFER_LOCAL and | |
2014 we're looking at the default value, the cache is invalid; we | |
2015 need to write it out, and find the new CURRENT-ALIST-ELEMENT | |
2016 */ | |
2017 | |
2018 /* Write out the cached value for the old buffer; copy it | |
2019 back to its alist element. This works if the current | |
2020 buffer only sees the default value, too. */ | |
2021 write_out_buffer_local_cache (symbol, bfwd); | |
2022 | |
2023 /* Find the new value for CURRENT-ALIST-ELEMENT. */ | |
2024 aelt = buffer_local_alist_element (current_buffer, symbol, bfwd); | |
2025 if (NILP (aelt)) | |
2026 { | |
2027 /* This buffer is still seeing the default value. */ | |
2028 if (!some_buffer_local_p) | |
2029 { | |
2030 /* If it's a SYMVAL_BUFFER_LOCAL, give this buffer a | |
2031 new assoc for a local value and set | |
2032 CURRENT-ALIST-ELEMENT to point to that. */ | |
2033 aelt = | |
2034 do_symval_forwarding (bfwd->current_value, | |
2035 current_buffer, | |
2036 XCONSOLE (Vselected_console)); | |
2037 aelt = Fcons (symbol, aelt); | |
2038 current_buffer->local_var_alist | |
2039 = Fcons (aelt, current_buffer->local_var_alist); | |
2040 } | |
2041 else | |
2042 { | |
2043 /* If the variable is a SYMVAL_SOME_BUFFER_LOCAL, | |
2044 we're currently seeing the default value. */ | |
2045 ; | |
2046 } | |
2047 } | |
2048 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */ | |
2049 bfwd->current_alist_element = aelt; | |
2050 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */ | |
793 | 2051 bfwd->current_buffer = wrap_buffer (current_buffer); |
428 | 2052 valcontents = bfwd->current_value; |
2053 } | |
2054 break; | |
2055 } | |
2056 default: | |
2500 | 2057 ABORT (); |
428 | 2058 } |
2059 store_symval_forwarding (symbol, valcontents, newval); | |
2060 | |
2061 return newval; | |
2062 } | |
2063 | |
2064 | |
2065 /* Access or set a buffer-local symbol's default value. */ | |
2066 | |
2067 /* Return the default value of SYM, but don't check for voidness. | |
2068 Return Qunbound if it is void. */ | |
2069 | |
2070 static Lisp_Object | |
2071 default_value (Lisp_Object sym) | |
2072 { | |
2073 Lisp_Object valcontents; | |
2074 | |
2075 CHECK_SYMBOL (sym); | |
2076 | |
2077 retry: | |
2078 valcontents = XSYMBOL (sym)->value; | |
2079 | |
2080 retry_2: | |
2081 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2082 return valcontents; | |
2083 | |
2084 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2085 { | |
2086 case SYMVAL_LISP_MAGIC: | |
2087 /* #### kludge */ | |
2088 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2089 /* semi-change-o */ | |
2090 goto retry_2; | |
2091 | |
2092 case SYMVAL_VARALIAS: | |
2093 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); | |
2094 /* presto change-o! */ | |
2095 goto retry; | |
2096 | |
2097 case SYMVAL_UNBOUND_MARKER: | |
2098 return valcontents; | |
2099 | |
2100 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2101 { | |
442 | 2102 const struct symbol_value_forward *fwd |
428 | 2103 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2104 return (*((Lisp_Object *)((Rawbyte *) XBUFFER (Vbuffer_defaults) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2105 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2106 - (Rawbyte *)&buffer_local_flags)))); |
428 | 2107 } |
2108 | |
2109 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
2110 { | |
442 | 2111 const struct symbol_value_forward *fwd |
428 | 2112 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2113 return (*((Lisp_Object *)((Rawbyte *) XCONSOLE (Vconsole_defaults) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2114 + ((Rawbyte *)symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2115 - (Rawbyte *)&console_local_flags)))); |
428 | 2116 } |
2117 | |
2118 case SYMVAL_BUFFER_LOCAL: | |
2119 case SYMVAL_SOME_BUFFER_LOCAL: | |
2120 { | |
2121 struct symbol_value_buffer_local *bfwd = | |
2122 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2123 | |
2124 /* Handle user-created local variables. */ | |
2125 /* If var is set up for a buffer that lacks a local value for it, | |
2126 the current value is nominally the default value. | |
2127 But the current value slot may be more up to date, since | |
2128 ordinary setq stores just that slot. So use that. */ | |
2129 if (NILP (bfwd->current_alist_element)) | |
2130 return do_symval_forwarding (bfwd->current_value, current_buffer, | |
2131 XCONSOLE (Vselected_console)); | |
2132 else | |
2133 return bfwd->default_value; | |
2134 } | |
2135 default: | |
2136 /* For other variables, get the current value. */ | |
2137 return do_symval_forwarding (valcontents, current_buffer, | |
2138 XCONSOLE (Vselected_console)); | |
2139 } | |
2140 | |
1204 | 2141 RETURN_NOT_REACHED (Qnil); /* suppress compiler warning */ |
428 | 2142 } |
2143 | |
2144 DEFUN ("default-boundp", Fdefault_boundp, 1, 1, 0, /* | |
2145 Return t if SYMBOL has a non-void default value. | |
2146 This is the value that is seen in buffers that do not have their own values | |
2147 for this variable. | |
2148 */ | |
2149 (symbol)) | |
2150 { | |
2151 return UNBOUNDP (default_value (symbol)) ? Qnil : Qt; | |
2152 } | |
2153 | |
2154 DEFUN ("default-value", Fdefault_value, 1, 1, 0, /* | |
2155 Return SYMBOL's default value. | |
2156 This is the value that is seen in buffers that do not have their own values | |
2157 for this variable. The default value is meaningful for variables with | |
2158 local bindings in certain buffers. | |
2159 */ | |
2160 (symbol)) | |
2161 { | |
2162 Lisp_Object value = default_value (symbol); | |
2163 | |
2164 return UNBOUNDP (value) ? Fsignal (Qvoid_variable, list1 (symbol)) : value; | |
2165 } | |
2166 | |
2167 DEFUN ("set-default", Fset_default, 2, 2, 0, /* | |
444 | 2168 Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated. |
428 | 2169 The default value is seen in buffers that do not have their own values |
2170 for this variable. | |
2171 */ | |
2172 (symbol, value)) | |
2173 { | |
2174 Lisp_Object valcontents; | |
2175 | |
2176 CHECK_SYMBOL (symbol); | |
2177 | |
2178 retry: | |
2179 valcontents = XSYMBOL (symbol)->value; | |
2180 | |
2181 retry_2: | |
2182 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2183 return Fset (symbol, value); | |
2184 | |
2185 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2186 { | |
2187 case SYMVAL_LISP_MAGIC: | |
2188 RETURN_IF_NOT_UNBOUND (maybe_call_magic_handler (symbol, Qset_default, 1, | |
2189 value)); | |
2190 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2191 /* semi-change-o */ | |
2192 goto retry_2; | |
2193 | |
2194 case SYMVAL_VARALIAS: | |
2195 symbol = follow_varalias_pointers (symbol, Qset_default); | |
2196 /* presto change-o! */ | |
2197 goto retry; | |
2198 | |
2199 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2200 set_default_buffer_slot_variable (symbol, value); | |
2201 return value; | |
2202 | |
2203 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
2204 set_default_console_slot_variable (symbol, value); | |
2205 return value; | |
2206 | |
2207 case SYMVAL_BUFFER_LOCAL: | |
2208 case SYMVAL_SOME_BUFFER_LOCAL: | |
2209 { | |
2210 /* Store new value into the DEFAULT-VALUE slot */ | |
2211 struct symbol_value_buffer_local *bfwd | |
2212 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2213 | |
2214 bfwd->default_value = value; | |
2215 /* If current-buffer doesn't shadow default_value, | |
2216 * we must set the CURRENT-VALUE slot too */ | |
2217 if (NILP (bfwd->current_alist_element)) | |
2218 store_symval_forwarding (symbol, bfwd->current_value, value); | |
2219 return value; | |
2220 } | |
2221 | |
2222 default: | |
2223 return Fset (symbol, value); | |
2224 } | |
2225 } | |
2226 | |
2227 DEFUN ("setq-default", Fsetq_default, 0, UNEVALLED, 0, /* | |
2228 Set the default value of variable SYMBOL to VALUE. | |
2229 SYMBOL, the variable name, is literal (not evaluated); | |
2230 VALUE is an expression and it is evaluated. | |
2231 The default value of a variable is seen in buffers | |
2232 that do not have their own values for the variable. | |
2233 | |
2234 More generally, you can use multiple variables and values, as in | |
2235 (setq-default SYMBOL VALUE SYMBOL VALUE...) | |
2236 This sets each SYMBOL's default value to the corresponding VALUE. | |
2237 The VALUE for the Nth SYMBOL can refer to the new default values | |
2238 of previous SYMBOLs. | |
2239 */ | |
2240 (args)) | |
2241 { | |
2242 /* This function can GC */ | |
2243 int nargs; | |
2421 | 2244 Lisp_Object retval = Qnil; |
428 | 2245 |
2246 GET_LIST_LENGTH (args, nargs); | |
2247 | |
2248 if (nargs & 1) /* Odd number of arguments? */ | |
2249 Fsignal (Qwrong_number_of_arguments, | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2250 list2 (Qsetq_default, make_fixnum (nargs))); |
428 | 2251 |
2421 | 2252 GC_PROPERTY_LIST_LOOP_3 (symbol, val, args) |
428 | 2253 { |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4642
diff
changeset
|
2254 val = IGNORE_MULTIPLE_VALUES (Feval (val)); |
428 | 2255 Fset_default (symbol, val); |
2421 | 2256 retval = val; |
428 | 2257 } |
2258 | |
2421 | 2259 END_GC_PROPERTY_LIST_LOOP (symbol); |
2260 return retval; | |
428 | 2261 } |
2262 | |
2263 /* Lisp functions for creating and removing buffer-local variables. */ | |
2264 | |
2265 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, 1, 1, | |
2266 "vMake Variable Buffer Local: ", /* | |
2267 Make VARIABLE have a separate value for each buffer. | |
2268 At any time, the value for the current buffer is in effect. | |
2269 There is also a default value which is seen in any buffer which has not yet | |
2270 set its own value. | |
2271 Using `set' or `setq' to set the variable causes it to have a separate value | |
2272 for the current buffer if it was previously using the default value. | |
2273 The function `default-value' gets the default value and `set-default' | |
2274 sets it. | |
2275 */ | |
2276 (variable)) | |
2277 { | |
2278 Lisp_Object valcontents; | |
2279 | |
2280 CHECK_SYMBOL (variable); | |
2281 | |
2282 retry: | |
2283 verify_ok_for_buffer_local (variable, Qmake_variable_buffer_local); | |
2284 | |
2285 valcontents = XSYMBOL (variable)->value; | |
2286 | |
2287 retry_2: | |
2288 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2289 { | |
2290 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2291 { | |
2292 case SYMVAL_LISP_MAGIC: | |
2293 if (!UNBOUNDP (maybe_call_magic_handler | |
2294 (variable, Qmake_variable_buffer_local, 0))) | |
2295 return variable; | |
2296 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2297 /* semi-change-o */ | |
2298 goto retry_2; | |
2299 | |
2300 case SYMVAL_VARALIAS: | |
2301 variable = follow_varalias_pointers (variable, | |
2302 Qmake_variable_buffer_local); | |
2303 /* presto change-o! */ | |
2304 goto retry; | |
2305 | |
2306 case SYMVAL_FIXNUM_FORWARD: | |
2307 case SYMVAL_BOOLEAN_FORWARD: | |
2308 case SYMVAL_OBJECT_FORWARD: | |
2309 case SYMVAL_UNBOUND_MARKER: | |
2310 break; | |
2311 | |
2312 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2313 case SYMVAL_BUFFER_LOCAL: | |
2314 /* Already per-each-buffer */ | |
2315 return variable; | |
2316 | |
2317 case SYMVAL_SOME_BUFFER_LOCAL: | |
2318 /* Transmogrify */ | |
2319 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents)->magic.type = | |
2320 SYMVAL_BUFFER_LOCAL; | |
2321 return variable; | |
2322 | |
2323 default: | |
2500 | 2324 ABORT (); |
428 | 2325 } |
2326 } | |
2327 | |
2328 { | |
2329 struct symbol_value_buffer_local *bfwd | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2330 = XSYMBOL_VALUE_BUFFER_LOCAL |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
2331 (ALLOC_NORMAL_LISP_OBJECT (symbol_value_buffer_local)); |
428 | 2332 Lisp_Object foo; |
2333 bfwd->magic.type = SYMVAL_BUFFER_LOCAL; | |
2334 | |
2335 bfwd->default_value = find_symbol_value (variable); | |
2336 bfwd->current_value = valcontents; | |
2337 bfwd->current_alist_element = Qnil; | |
2338 bfwd->current_buffer = Fcurrent_buffer (); | |
793 | 2339 foo = wrap_symbol_value_magic (bfwd); |
428 | 2340 *value_slot_past_magic (variable) = foo; |
2341 #if 1 /* #### Yuck! FSFmacs bug-compatibility*/ | |
2342 /* This sets the default-value of any make-variable-buffer-local to nil. | |
2343 That just sucks. User can just use setq-default to effect that, | |
2344 but there's no way to do makunbound-default to undo this lossage. */ | |
2345 if (UNBOUNDP (valcontents)) | |
2346 bfwd->default_value = Qnil; | |
2347 #endif | |
2348 #if 0 /* #### Yuck! */ | |
2349 /* This sets the value to nil in this buffer. | |
2350 User could use (setq variable nil) to do this. | |
2351 It isn't as egregious to do this automatically | |
2352 as it is to do so to the default-value, but it's | |
2353 still really dubious. */ | |
2354 if (UNBOUNDP (valcontents)) | |
2355 Fset (variable, Qnil); | |
2356 #endif | |
2357 return variable; | |
2358 } | |
2359 } | |
2360 | |
2361 DEFUN ("make-local-variable", Fmake_local_variable, 1, 1, | |
2362 "vMake Local Variable: ", /* | |
2363 Make VARIABLE have a separate value in the current buffer. | |
2364 Other buffers will continue to share a common default value. | |
2365 \(The buffer-local value of VARIABLE starts out as the same value | |
2366 VARIABLE previously had. If VARIABLE was void, it remains void.) | |
2367 See also `make-variable-buffer-local'. | |
2368 | |
2369 If the variable is already arranged to become local when set, | |
2370 this function causes a local value to exist for this buffer, | |
2371 just as setting the variable would do. | |
2372 | |
2373 Do not use `make-local-variable' to make a hook variable buffer-local. | |
2374 Use `make-local-hook' instead. | |
2375 */ | |
2376 (variable)) | |
2377 { | |
2378 Lisp_Object valcontents; | |
2379 struct symbol_value_buffer_local *bfwd; | |
2380 | |
2381 CHECK_SYMBOL (variable); | |
2382 | |
2383 retry: | |
2384 verify_ok_for_buffer_local (variable, Qmake_local_variable); | |
2385 | |
2386 valcontents = XSYMBOL (variable)->value; | |
2387 | |
2388 retry_2: | |
2389 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2390 { | |
2391 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2392 { | |
2393 case SYMVAL_LISP_MAGIC: | |
2394 if (!UNBOUNDP (maybe_call_magic_handler | |
2395 (variable, Qmake_local_variable, 0))) | |
2396 return variable; | |
2397 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2398 /* semi-change-o */ | |
2399 goto retry_2; | |
2400 | |
2401 case SYMVAL_VARALIAS: | |
2402 variable = follow_varalias_pointers (variable, Qmake_local_variable); | |
2403 /* presto change-o! */ | |
2404 goto retry; | |
2405 | |
2406 case SYMVAL_FIXNUM_FORWARD: | |
2407 case SYMVAL_BOOLEAN_FORWARD: | |
2408 case SYMVAL_OBJECT_FORWARD: | |
2409 case SYMVAL_UNBOUND_MARKER: | |
2410 break; | |
2411 | |
2412 case SYMVAL_BUFFER_LOCAL: | |
2413 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2414 { | |
2415 /* Make sure the symbol has a local value in this particular | |
2416 buffer, by setting it to the same value it already has. */ | |
2417 Fset (variable, find_symbol_value (variable)); | |
2418 return variable; | |
2419 } | |
2420 | |
2421 case SYMVAL_SOME_BUFFER_LOCAL: | |
2422 { | |
2423 if (!NILP (buffer_local_alist_element (current_buffer, | |
2424 variable, | |
2425 (XSYMBOL_VALUE_BUFFER_LOCAL | |
2426 (valcontents))))) | |
2427 goto already_local_to_current_buffer; | |
2428 else | |
2429 goto already_local_to_some_other_buffer; | |
2430 } | |
2431 | |
2432 default: | |
2500 | 2433 ABORT (); |
428 | 2434 } |
2435 } | |
2436 | |
2437 /* Make sure variable is set up to hold per-buffer values */ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2438 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
2439 (ALLOC_NORMAL_LISP_OBJECT (symbol_value_buffer_local)); |
428 | 2440 bfwd->magic.type = SYMVAL_SOME_BUFFER_LOCAL; |
2441 | |
2442 bfwd->current_buffer = Qnil; | |
2443 bfwd->current_alist_element = Qnil; | |
2444 bfwd->current_value = valcontents; | |
2445 /* passing 0 is OK because this should never be a | |
2446 SYMVAL_CURRENT_BUFFER_FORWARD or SYMVAL_SELECTED_CONSOLE_FORWARD | |
2447 variable. */ | |
2448 bfwd->default_value = do_symval_forwarding (valcontents, 0, 0); | |
2449 | |
2450 #if 0 | |
2451 if (UNBOUNDP (bfwd->default_value)) | |
2452 bfwd->default_value = Qnil; /* Yuck! */ | |
2453 #endif | |
2454 | |
793 | 2455 valcontents = wrap_symbol_value_magic (bfwd); |
428 | 2456 *value_slot_past_magic (variable) = valcontents; |
2457 | |
2458 already_local_to_some_other_buffer: | |
2459 | |
2460 /* Make sure this buffer has its own value of variable */ | |
2461 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2462 | |
2463 if (UNBOUNDP (bfwd->default_value)) | |
2464 { | |
2465 /* If default value is unbound, set local value to nil. */ | |
793 | 2466 bfwd->current_buffer = wrap_buffer (current_buffer); |
428 | 2467 bfwd->current_alist_element = Fcons (variable, Qnil); |
2468 current_buffer->local_var_alist = | |
2469 Fcons (bfwd->current_alist_element, current_buffer->local_var_alist); | |
2470 store_symval_forwarding (variable, bfwd->current_value, Qnil); | |
2471 return variable; | |
2472 } | |
2473 | |
2474 current_buffer->local_var_alist | |
2475 = Fcons (Fcons (variable, bfwd->default_value), | |
2476 current_buffer->local_var_alist); | |
2477 | |
2478 /* Make sure symbol does not think it is set up for this buffer; | |
2479 force it to look once again for this buffer's value */ | |
2480 if (!NILP (bfwd->current_buffer) && | |
2481 current_buffer == XBUFFER (bfwd->current_buffer)) | |
2482 bfwd->current_buffer = Qnil; | |
2483 | |
2484 already_local_to_current_buffer: | |
2485 | |
2486 /* If the symbol forwards into a C variable, then swap in the | |
2487 variable for this buffer immediately. If C code modifies the | |
2488 variable before we swap in, then that new value will clobber the | |
2489 default value the next time we swap. */ | |
2490 bfwd = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2491 if (SYMBOL_VALUE_MAGIC_P (bfwd->current_value)) | |
2492 { | |
2493 switch (XSYMBOL_VALUE_MAGIC_TYPE (bfwd->current_value)) | |
2494 { | |
2495 case SYMVAL_FIXNUM_FORWARD: | |
2496 case SYMVAL_BOOLEAN_FORWARD: | |
2497 case SYMVAL_OBJECT_FORWARD: | |
2498 case SYMVAL_DEFAULT_BUFFER_FORWARD: | |
2499 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); | |
2500 break; | |
2501 | |
2502 case SYMVAL_UNBOUND_MARKER: | |
2503 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2504 break; | |
2505 | |
2506 default: | |
2500 | 2507 ABORT (); |
428 | 2508 } |
2509 } | |
2510 | |
2511 return variable; | |
2512 } | |
2513 | |
2514 DEFUN ("kill-local-variable", Fkill_local_variable, 1, 1, | |
2515 "vKill Local Variable: ", /* | |
2516 Make VARIABLE no longer have a separate value in the current buffer. | |
2517 From now on the default value will apply in this buffer. | |
2518 */ | |
2519 (variable)) | |
2520 { | |
2521 Lisp_Object valcontents; | |
2522 | |
2523 CHECK_SYMBOL (variable); | |
2524 | |
2525 retry: | |
2526 valcontents = XSYMBOL (variable)->value; | |
2527 | |
2528 retry_2: | |
2529 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2530 return variable; | |
2531 | |
2532 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2533 { | |
2534 case SYMVAL_LISP_MAGIC: | |
2535 if (!UNBOUNDP (maybe_call_magic_handler | |
2536 (variable, Qkill_local_variable, 0))) | |
2537 return variable; | |
2538 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2539 /* semi-change-o */ | |
2540 goto retry_2; | |
2541 | |
2542 case SYMVAL_VARALIAS: | |
2543 variable = follow_varalias_pointers (variable, Qkill_local_variable); | |
2544 /* presto change-o! */ | |
2545 goto retry; | |
2546 | |
2547 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2548 { | |
442 | 2549 const struct symbol_value_forward *fwd |
428 | 2550 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2551 int offset = ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2552 - (Rawbyte *) &buffer_local_flags); |
428 | 2553 int mask = |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2554 XFIXNUM (*((Lisp_Object *) symbol_value_forward_forward (fwd))); |
428 | 2555 |
2556 if (mask > 0) | |
2557 { | |
2558 int (*magicfun) (Lisp_Object sym, Lisp_Object *val, | |
2559 Lisp_Object in_object, int flags) = | |
2560 symbol_value_forward_magicfun (fwd); | |
2561 Lisp_Object oldval = * (Lisp_Object *) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2562 (offset + (Rawbyte *) XBUFFER (Vbuffer_defaults)); |
428 | 2563 if (magicfun) |
771 | 2564 (magicfun) (variable, &oldval, wrap_buffer (current_buffer), 0); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2565 *(Lisp_Object *) (offset + (Rawbyte *) current_buffer) |
428 | 2566 = oldval; |
2567 current_buffer->local_var_flags &= ~mask; | |
2568 } | |
2569 return variable; | |
2570 } | |
2571 | |
2572 case SYMVAL_BUFFER_LOCAL: | |
2573 case SYMVAL_SOME_BUFFER_LOCAL: | |
2574 { | |
2575 /* Get rid of this buffer's alist element, if any */ | |
2576 struct symbol_value_buffer_local *bfwd | |
2577 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2578 Lisp_Object alist = current_buffer->local_var_alist; | |
2579 Lisp_Object alist_element | |
2580 = buffer_local_alist_element (current_buffer, variable, bfwd); | |
2581 | |
2582 if (!NILP (alist_element)) | |
5338
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2583 current_buffer->local_var_alist = delq_no_quit (alist_element, |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5277
diff
changeset
|
2584 alist); |
428 | 2585 |
2586 /* Make sure symbol does not think it is set up for this buffer; | |
2587 force it to look once again for this buffer's value */ | |
2588 if (!NILP (bfwd->current_buffer) && | |
2589 current_buffer == XBUFFER (bfwd->current_buffer)) | |
2590 bfwd->current_buffer = Qnil; | |
2591 | |
2592 /* We just changed the value in the current_buffer. If this | |
2593 variable forwards to a C variable, we need to change the | |
2594 value of the C variable. set_up_buffer_local_cache() | |
2595 will do this. It doesn't hurt to do it always, | |
2596 so just go ahead and do that. */ | |
2597 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); | |
2598 } | |
2599 return variable; | |
2600 | |
2601 default: | |
2602 return variable; | |
2603 } | |
1204 | 2604 RETURN_NOT_REACHED(Qnil); /* suppress compiler warning */ |
428 | 2605 } |
2606 | |
2607 | |
2608 DEFUN ("kill-console-local-variable", Fkill_console_local_variable, 1, 1, | |
2609 "vKill Console Local Variable: ", /* | |
2610 Make VARIABLE no longer have a separate value in the selected console. | |
2611 From now on the default value will apply in this console. | |
2612 */ | |
2613 (variable)) | |
2614 { | |
2615 Lisp_Object valcontents; | |
2616 | |
2617 CHECK_SYMBOL (variable); | |
2618 | |
2619 retry: | |
2620 valcontents = XSYMBOL (variable)->value; | |
2621 | |
2622 retry_2: | |
2623 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2624 return variable; | |
2625 | |
2626 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2627 { | |
2628 case SYMVAL_LISP_MAGIC: | |
2629 if (!UNBOUNDP (maybe_call_magic_handler | |
2630 (variable, Qkill_console_local_variable, 0))) | |
2631 return variable; | |
2632 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2633 /* semi-change-o */ | |
2634 goto retry_2; | |
2635 | |
2636 case SYMVAL_VARALIAS: | |
2637 variable = follow_varalias_pointers (variable, | |
2638 Qkill_console_local_variable); | |
2639 /* presto change-o! */ | |
2640 goto retry; | |
2641 | |
2642 case SYMVAL_SELECTED_CONSOLE_FORWARD: | |
2643 { | |
442 | 2644 const struct symbol_value_forward *fwd |
428 | 2645 = XSYMBOL_VALUE_FORWARD (valcontents); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2646 int offset = ((Rawbyte *) symbol_value_forward_forward (fwd) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2647 - (Rawbyte *) &console_local_flags); |
428 | 2648 int mask = |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2649 XFIXNUM (*((Lisp_Object *) symbol_value_forward_forward (fwd))); |
428 | 2650 |
2651 if (mask > 0) | |
2652 { | |
2653 int (*magicfun) (Lisp_Object sym, Lisp_Object *val, | |
2654 Lisp_Object in_object, int flags) = | |
2655 symbol_value_forward_magicfun (fwd); | |
2656 Lisp_Object oldval = * (Lisp_Object *) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2657 (offset + (Rawbyte *) XCONSOLE (Vconsole_defaults)); |
428 | 2658 if (magicfun) |
2659 magicfun (variable, &oldval, Vselected_console, 0); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
2660 *(Lisp_Object *) (offset + (Rawbyte *) XCONSOLE (Vselected_console)) |
428 | 2661 = oldval; |
2662 XCONSOLE (Vselected_console)->local_var_flags &= ~mask; | |
2663 } | |
2664 return variable; | |
2665 } | |
2666 | |
2667 default: | |
2668 return variable; | |
2669 } | |
2670 } | |
2671 | |
2672 /* Used by specbind to determine what effects it might have. Returns: | |
2673 * 0 if symbol isn't buffer-local, and wouldn't be after it is set | |
2674 * <0 if symbol isn't presently buffer-local, but set would make it so | |
2675 * >0 if symbol is presently buffer-local | |
2676 */ | |
2677 int | |
2678 symbol_value_buffer_local_info (Lisp_Object symbol, struct buffer *buffer) | |
2679 { | |
2680 Lisp_Object valcontents; | |
2681 | |
2682 retry: | |
2683 valcontents = XSYMBOL (symbol)->value; | |
2684 | |
2685 retry_2: | |
2686 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2687 { | |
2688 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2689 { | |
2690 case SYMVAL_LISP_MAGIC: | |
2691 /* #### kludge */ | |
2692 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2693 /* semi-change-o */ | |
2694 goto retry_2; | |
2695 | |
2696 case SYMVAL_VARALIAS: | |
2697 symbol = follow_varalias_pointers (symbol, Qt /* #### kludge */); | |
2698 /* presto change-o! */ | |
2699 goto retry; | |
2700 | |
2701 case SYMVAL_CURRENT_BUFFER_FORWARD: | |
2702 { | |
442 | 2703 const struct symbol_value_forward *fwd |
428 | 2704 = XSYMBOL_VALUE_FORWARD (valcontents); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2705 int mask = XFIXNUM (*((Lisp_Object *) |
428 | 2706 symbol_value_forward_forward (fwd))); |
2707 if ((mask <= 0) || (buffer && (buffer->local_var_flags & mask))) | |
2708 /* Already buffer-local */ | |
2709 return 1; | |
2710 else | |
2711 /* Would be buffer-local after set */ | |
2712 return -1; | |
2713 } | |
2714 case SYMVAL_BUFFER_LOCAL: | |
2715 case SYMVAL_SOME_BUFFER_LOCAL: | |
2716 { | |
2717 struct symbol_value_buffer_local *bfwd | |
2718 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | |
2719 if (buffer | |
2720 && !NILP (buffer_local_alist_element (buffer, symbol, bfwd))) | |
2721 return 1; | |
2722 else | |
2723 /* Automatically becomes local when set */ | |
2724 return bfwd->magic.type == SYMVAL_BUFFER_LOCAL ? -1 : 0; | |
2725 } | |
2726 default: | |
2727 return 0; | |
2728 } | |
2729 } | |
2730 return 0; | |
2731 } | |
2732 | |
2733 | |
2734 DEFUN ("symbol-value-in-buffer", Fsymbol_value_in_buffer, 2, 3, 0, /* | |
2735 Return the value of SYMBOL in BUFFER, or UNBOUND-VALUE if it is unbound. | |
2736 */ | |
2737 (symbol, buffer, unbound_value)) | |
2738 { | |
2739 Lisp_Object value; | |
2740 CHECK_SYMBOL (symbol); | |
2741 CHECK_BUFFER (buffer); | |
2742 value = symbol_value_in_buffer (symbol, buffer); | |
2743 return UNBOUNDP (value) ? unbound_value : value; | |
2744 } | |
2745 | |
2746 DEFUN ("symbol-value-in-console", Fsymbol_value_in_console, 2, 3, 0, /* | |
2747 Return the value of SYMBOL in CONSOLE, or UNBOUND-VALUE if it is unbound. | |
2748 */ | |
2749 (symbol, console, unbound_value)) | |
2750 { | |
2751 Lisp_Object value; | |
2752 CHECK_SYMBOL (symbol); | |
2753 CHECK_CONSOLE (console); | |
2754 value = symbol_value_in_console (symbol, console); | |
2755 return UNBOUNDP (value) ? unbound_value : value; | |
2756 } | |
2757 | |
2758 DEFUN ("built-in-variable-type", Fbuilt_in_variable_type, 1, 1, 0, /* | |
2759 If SYMBOL is a built-in variable, return info about this; else return nil. | |
2760 The returned info will be a symbol, one of | |
2761 | |
2762 `object' A simple built-in variable. | |
2763 `const-object' Same, but cannot be set. | |
2764 `integer' A built-in integer variable. | |
2765 `const-integer' Same, but cannot be set. | |
2766 `boolean' A built-in boolean variable. | |
2767 `const-boolean' Same, but cannot be set. | |
2768 `const-specifier' Always contains a specifier; e.g. `has-modeline-p'. | |
2769 `current-buffer' A built-in buffer-local variable. | |
2770 `const-current-buffer' Same, but cannot be set. | |
2771 `default-buffer' Forwards to the default value of a built-in | |
2772 buffer-local variable. | |
2773 `selected-console' A built-in console-local variable. | |
2774 `const-selected-console' Same, but cannot be set. | |
2775 `default-console' Forwards to the default value of a built-in | |
2776 console-local variable. | |
2777 */ | |
2778 (symbol)) | |
2779 { | |
2780 REGISTER Lisp_Object valcontents; | |
2781 | |
2782 CHECK_SYMBOL (symbol); | |
2783 | |
2784 retry: | |
2785 valcontents = XSYMBOL (symbol)->value; | |
2786 | |
2787 retry_2: | |
2788 if (!SYMBOL_VALUE_MAGIC_P (valcontents)) | |
2789 return Qnil; | |
2790 | |
2791 switch (XSYMBOL_VALUE_MAGIC_TYPE (valcontents)) | |
2792 { | |
2793 case SYMVAL_LISP_MAGIC: | |
2794 valcontents = XSYMBOL_VALUE_LISP_MAGIC (valcontents)->shadowed; | |
2795 /* semi-change-o */ | |
2796 goto retry_2; | |
2797 | |
2798 case SYMVAL_VARALIAS: | |
2799 symbol = follow_varalias_pointers (symbol, Qt); | |
2800 /* presto change-o! */ | |
2801 goto retry; | |
2802 | |
2803 case SYMVAL_BUFFER_LOCAL: | |
2804 case SYMVAL_SOME_BUFFER_LOCAL: | |
2805 valcontents = | |
2806 XSYMBOL_VALUE_BUFFER_LOCAL (valcontents)->current_value; | |
2807 /* semi-change-o */ | |
2808 goto retry_2; | |
2809 | |
2810 case SYMVAL_FIXNUM_FORWARD: return Qinteger; | |
2811 case SYMVAL_CONST_FIXNUM_FORWARD: return Qconst_integer; | |
2812 case SYMVAL_BOOLEAN_FORWARD: return Qboolean; | |
2813 case SYMVAL_CONST_BOOLEAN_FORWARD: return Qconst_boolean; | |
2814 case SYMVAL_OBJECT_FORWARD: return Qobject; | |
2815 case SYMVAL_CONST_OBJECT_FORWARD: return Qconst_object; | |
2816 case SYMVAL_CONST_SPECIFIER_FORWARD: return Qconst_specifier; | |
2817 case SYMVAL_DEFAULT_BUFFER_FORWARD: return Qdefault_buffer; | |
2818 case SYMVAL_CURRENT_BUFFER_FORWARD: return Qcurrent_buffer; | |
2819 case SYMVAL_CONST_CURRENT_BUFFER_FORWARD: return Qconst_current_buffer; | |
2820 case SYMVAL_DEFAULT_CONSOLE_FORWARD: return Qdefault_console; | |
2821 case SYMVAL_SELECTED_CONSOLE_FORWARD: return Qselected_console; | |
2822 case SYMVAL_CONST_SELECTED_CONSOLE_FORWARD: return Qconst_selected_console; | |
2823 case SYMVAL_UNBOUND_MARKER: return Qnil; | |
2824 | |
2825 default: | |
2500 | 2826 ABORT (); return Qnil; |
428 | 2827 } |
2828 } | |
2829 | |
2830 | |
2831 DEFUN ("local-variable-p", Flocal_variable_p, 2, 3, 0, /* | |
2832 Return t if SYMBOL's value is local to BUFFER. | |
444 | 2833 If optional third arg AFTER-SET is non-nil, return t if SYMBOL would be |
428 | 2834 buffer-local after it is set, regardless of whether it is so presently. |
2835 A nil value for BUFFER is *not* the same as (current-buffer), but means | |
2836 "no buffer". Specifically: | |
2837 | |
2838 -- If BUFFER is nil and AFTER-SET is nil, a return value of t indicates that | |
2839 the variable is one of the special built-in variables that is always | |
2840 buffer-local. (This includes `buffer-file-name', `buffer-read-only', | |
2841 `buffer-undo-list', and others.) | |
2842 | |
2843 -- If BUFFER is nil and AFTER-SET is t, a return value of t indicates that | |
2844 the variable has had `make-variable-buffer-local' applied to it. | |
2845 */ | |
2846 (symbol, buffer, after_set)) | |
2847 { | |
2848 int local_info; | |
2849 | |
2850 CHECK_SYMBOL (symbol); | |
2851 if (!NILP (buffer)) | |
2852 { | |
2853 buffer = get_buffer (buffer, 1); | |
2854 local_info = symbol_value_buffer_local_info (symbol, XBUFFER (buffer)); | |
2855 } | |
2856 else | |
2857 { | |
2858 local_info = symbol_value_buffer_local_info (symbol, 0); | |
2859 } | |
2860 | |
2861 if (NILP (after_set)) | |
2862 return local_info > 0 ? Qt : Qnil; | |
2863 else | |
2864 return local_info != 0 ? Qt : Qnil; | |
2865 } | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2866 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2867 DEFUN ("custom-variable-p", Fcustom_variable_p, 1, 1, 0, /* |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2868 Return non-nil if SYMBOL names a custom variable. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2869 Does not follow the variable alias chain. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2870 */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2871 (symbol)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2872 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2873 return (!(NILP (Fget(symbol, intern ("standard-value"), Qnil))) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2874 || !(NILP (Fget(symbol, intern ("custom-autoload"), Qnil)))) ? |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2875 Qt: Qnil; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2876 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2877 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2878 static Lisp_Object |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2879 user_variable_alias_check_fun (Lisp_Object symbol) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2880 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2881 Lisp_Object documentation = Fget (symbol, Qvariable_documentation, Qnil); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2882 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2883 if ((FIXNUMP (documentation) && XFIXNUM (documentation) < 0) || |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2884 (STRINGP (documentation) && |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2885 (string_byte (documentation, 0) == '*')) || |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2886 /* If (STRING . INTEGER), a negative integer means a user variable. */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2887 (CONSP (documentation) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2888 && STRINGP (XCAR (documentation)) |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2889 && FIXNUMP (XCDR (documentation)) |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2890 && XFIXNUM (XCDR (documentation)) < 0) || |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2891 !NILP (Fcustom_variable_p (symbol))) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2892 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2893 return make_fixnum(1); |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2894 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2895 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2896 return Qzero; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2897 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2898 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2899 DEFUN ("user-variable-p", Fuser_variable_p, 1, 1, 0, /* |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2900 Return t if SYMBOL names a variable intended to be set and modified by users. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2901 \(The alternative is a variable used internally in a Lisp program.) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2902 A symbol names a user variable if |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2903 \(1) the first character of its documentation is `*', or |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2904 \(2) it is customizable (`custom-variable-p' gives t), or |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2905 \(3) it names a variable alias that eventually resolves to another user variable. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2906 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2907 The GNU Emacs implementation of `user-variable-p' returns nil if there is a |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2908 loop in the chain of symbols. Since this is indistinguishable from the case |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2909 where a symbol names a non-user variable, XEmacs signals a |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2910 `cyclic-variable-indirection' error instead; use `condition-case' to catch |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2911 this error if you really want to avoid this. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2912 */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2913 (symbol)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2914 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2915 Lisp_Object mapped; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2916 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2917 if (!SYMBOLP (symbol)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2918 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2919 return Qnil; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2920 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2921 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2922 /* Called for its side-effects, we want it to signal if there's a loop. */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2923 follow_varalias_pointers (symbol, Qt); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2924 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2925 /* Look through the various aliases. */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2926 mapped = map_varalias_chain (symbol, Qt, user_variable_alias_check_fun); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2927 if (EQ (Qzero, mapped)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2928 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2929 return Qnil; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2930 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2931 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2932 assert (EQ (make_fixnum (1), mapped)); |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2933 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2934 return Qt; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2935 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2936 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
2937 |
428 | 2938 |
2939 | |
2940 /* | |
2941 I've gone ahead and partially implemented this because it's | |
2942 super-useful for dealing with the compatibility problems in supporting | |
2943 the old pointer-shape variables, and preventing people from `setq'ing | |
2944 the new variables. Any other way of handling this problem is way | |
2945 ugly, likely to be slow, and generally not something I want to waste | |
2946 my time worrying about. | |
2947 | |
2948 The interface and/or function name is sure to change before this | |
2949 gets into its final form. I currently like the way everything is | |
2950 set up and it has all the features I want it to have, except for | |
2951 one: I really want to be able to have multiple nested handlers, | |
2952 to implement an `advice'-like capability. This would allow, | |
2953 for example, a clean way of implementing `debug-if-set' or | |
2954 `debug-if-referenced' and such. | |
2955 | |
2956 NOTE NOTE NOTE NOTE NOTE NOTE NOTE: | |
2957 ************************************************************ | |
2958 **Only** the `set-value', `make-unbound', and `make-local' | |
2959 handler types are currently implemented. Implementing the | |
2960 get-value and bound-predicate handlers is somewhat tricky | |
2961 because there are lots of subfunctions (e.g. find_symbol_value()). | |
2962 find_symbol_value(), in fact, is called from outside of | |
2963 this module. You'd have to have it do this: | |
2964 | |
2965 -- check for a `bound-predicate' handler, call that if so; | |
2966 if it returns nil, return Qunbound | |
2967 -- check for a `get-value' handler and call it and return | |
2968 that value | |
2969 | |
2970 It gets even trickier when you have to deal with | |
2971 sub-subfunctions like find_symbol_value_1(), and esp. | |
2972 when you have to properly handle variable aliases, which | |
2973 can lead to lots of tricky situations. So I've just | |
2974 punted on this, since the interface isn't officially | |
2975 exported and we can get by with just a `set-value' | |
2976 handler. | |
2977 | |
2978 Actions in unimplemented handler types will correctly | |
2979 ignore any handlers, and will not fuck anything up or | |
2980 go awry. | |
2981 | |
2982 WARNING WARNING: If you do go and implement another | |
2983 type of handler, make *sure* to change | |
2984 would_be_magic_handled() so it knows about this, | |
2985 or dire things could result. | |
2986 ************************************************************ | |
2987 NOTE NOTE NOTE NOTE NOTE NOTE NOTE | |
2988 | |
2989 Real documentation is as follows. | |
2990 | |
2991 Set a magic handler for VARIABLE. | |
2992 This allows you to specify arbitrary behavior that results from | |
2993 accessing or setting a variable. For example, retrieving the | |
2994 variable's value might actually retrieve the first element off of | |
2995 a list stored in another variable, and setting the variable's value | |
2996 might add an element to the front of that list. (This is how the | |
2997 obsolete variable `unread-command-event' is implemented.) | |
2998 | |
2999 In general it is NOT good programming practice to use magic variables | |
3000 in a new package that you are designing. If you feel the need to | |
3001 do this, it's almost certainly a sign that you should be using a | |
3002 function instead of a variable. This facility is provided to allow | |
3003 a package to support obsolete variables and provide compatibility | |
3004 with similar packages with different variable names and semantics. | |
3005 By using magic handlers, you can cleanly provide obsoleteness and | |
3006 compatibility support and separate this support from the core | |
3007 routines in a package. | |
3008 | |
3009 VARIABLE should be a symbol naming the variable for which the | |
3010 magic behavior is provided. HANDLER-TYPE is a symbol specifying | |
3011 which behavior is being controlled, and HANDLER is the function | |
3012 that will be called to control this behavior. HARG is a | |
3013 value that will be passed to HANDLER but is otherwise | |
3014 uninterpreted. KEEP-EXISTING specifies what to do with existing | |
3015 handlers of the same type; nil means "erase them all", t means | |
3016 "keep them but insert at the beginning", the list (t) means | |
3017 "keep them but insert at the end", a function means "keep | |
3018 them but insert before the specified function", a list containing | |
3019 a function means "keep them but insert after the specified | |
3020 function". | |
3021 | |
3022 You can specify magic behavior for any type of variable at all, | |
3023 and for any handler types that are unspecified, the standard | |
3024 behavior applies. This allows you, for example, to use | |
3025 `defvaralias' in conjunction with this function. (For that | |
3026 matter, `defvaralias' could be implemented using this function.) | |
3027 | |
3028 The behaviors that can be specified in HANDLER-TYPE are | |
3029 | |
3030 get-value (SYM ARGS FUN HARG HANDLERS) | |
3031 This means that one of the functions `symbol-value', | |
3032 `default-value', `symbol-value-in-buffer', or | |
3033 `symbol-value-in-console' was called on SYM. | |
3034 | |
3035 set-value (SYM ARGS FUN HARG HANDLERS) | |
3036 This means that one of the functions `set' or `set-default' | |
3037 was called on SYM. | |
3038 | |
3039 bound-predicate (SYM ARGS FUN HARG HANDLERS) | |
3040 This means that one of the functions `boundp', `globally-boundp', | |
3041 or `default-boundp' was called on SYM. | |
3042 | |
3043 make-unbound (SYM ARGS FUN HARG HANDLERS) | |
3044 This means that the function `makunbound' was called on SYM. | |
3045 | |
3046 local-predicate (SYM ARGS FUN HARG HANDLERS) | |
3047 This means that the function `local-variable-p' was called | |
3048 on SYM. | |
3049 | |
3050 make-local (SYM ARGS FUN HARG HANDLERS) | |
3051 This means that one of the functions `make-local-variable', | |
3052 `make-variable-buffer-local', `kill-local-variable', | |
3053 or `kill-console-local-variable' was called on SYM. | |
3054 | |
3055 The meanings of the arguments are as follows: | |
3056 | |
3057 SYM is the symbol on which the function was called, and is always | |
3058 the first argument to the function. | |
3059 | |
3060 ARGS are the remaining arguments in the original call (i.e. all | |
3061 but the first). In the case of `set-value' in particular, | |
3062 the first element of ARGS is the value to which the variable | |
3063 is being set. In some cases, ARGS is sanitized from what was | |
3064 actually given. For example, whenever `nil' is passed to an | |
3065 argument and it means `current-buffer', the current buffer is | |
3066 substituted instead. | |
3067 | |
3068 FUN is a symbol indicating which function is being called. | |
3069 For many of the functions, you can determine the corresponding | |
3070 function of a different class using | |
3071 `symbol-function-corresponding-function'. | |
3072 | |
3073 HARG is the argument that was given in the call | |
3074 to `set-symbol-value-handler' for SYM and HANDLER-TYPE. | |
3075 | |
3076 HANDLERS is a structure containing the remaining handlers | |
3077 for the variable; to call one of them, use | |
3078 `chain-to-symbol-value-handler'. | |
3079 | |
3080 NOTE: You may *not* modify the list in ARGS, and if you want to | |
3081 keep it around after the handler function exits, you must make | |
3082 a copy using `copy-sequence'. (Same caveats for HANDLERS also.) | |
3083 */ | |
3084 | |
3085 static enum lisp_magic_handler | |
3086 decode_magic_handler_type (Lisp_Object symbol) | |
3087 { | |
3088 if (EQ (symbol, Qget_value)) return MAGIC_HANDLER_GET_VALUE; | |
3089 if (EQ (symbol, Qset_value)) return MAGIC_HANDLER_SET_VALUE; | |
3090 if (EQ (symbol, Qbound_predicate)) return MAGIC_HANDLER_BOUND_PREDICATE; | |
3091 if (EQ (symbol, Qmake_unbound)) return MAGIC_HANDLER_MAKE_UNBOUND; | |
3092 if (EQ (symbol, Qlocal_predicate)) return MAGIC_HANDLER_LOCAL_PREDICATE; | |
3093 if (EQ (symbol, Qmake_local)) return MAGIC_HANDLER_MAKE_LOCAL; | |
3094 | |
563 | 3095 invalid_constant ("Unrecognized symbol value handler type", symbol); |
1204 | 3096 RETURN_NOT_REACHED (MAGIC_HANDLER_MAX); |
428 | 3097 } |
3098 | |
3099 static enum lisp_magic_handler | |
3100 handler_type_from_function_symbol (Lisp_Object funsym, int abort_if_not_found) | |
3101 { | |
3102 if (EQ (funsym, Qsymbol_value) | |
3103 || EQ (funsym, Qdefault_value) | |
3104 || EQ (funsym, Qsymbol_value_in_buffer) | |
3105 || EQ (funsym, Qsymbol_value_in_console)) | |
3106 return MAGIC_HANDLER_GET_VALUE; | |
3107 | |
3108 if (EQ (funsym, Qset) | |
3109 || EQ (funsym, Qset_default)) | |
3110 return MAGIC_HANDLER_SET_VALUE; | |
3111 | |
3112 if (EQ (funsym, Qboundp) | |
3113 || EQ (funsym, Qglobally_boundp) | |
3114 || EQ (funsym, Qdefault_boundp)) | |
3115 return MAGIC_HANDLER_BOUND_PREDICATE; | |
3116 | |
3117 if (EQ (funsym, Qmakunbound)) | |
3118 return MAGIC_HANDLER_MAKE_UNBOUND; | |
3119 | |
3120 if (EQ (funsym, Qlocal_variable_p)) | |
3121 return MAGIC_HANDLER_LOCAL_PREDICATE; | |
3122 | |
3123 if (EQ (funsym, Qmake_variable_buffer_local) | |
3124 || EQ (funsym, Qmake_local_variable)) | |
3125 return MAGIC_HANDLER_MAKE_LOCAL; | |
3126 | |
3127 if (abort_if_not_found) | |
2500 | 3128 ABORT (); |
563 | 3129 invalid_argument ("Unrecognized symbol-value function", funsym); |
1204 | 3130 RETURN_NOT_REACHED (MAGIC_HANDLER_MAX); |
428 | 3131 } |
3132 | |
3133 static int | |
3134 would_be_magic_handled (Lisp_Object sym, Lisp_Object funsym) | |
3135 { | |
3136 /* does not take into account variable aliasing. */ | |
3137 Lisp_Object valcontents = XSYMBOL (sym)->value; | |
3138 enum lisp_magic_handler slot; | |
3139 | |
3140 if (!SYMBOL_VALUE_LISP_MAGIC_P (valcontents)) | |
3141 return 0; | |
3142 slot = handler_type_from_function_symbol (funsym, 1); | |
3143 if (slot != MAGIC_HANDLER_SET_VALUE && slot != MAGIC_HANDLER_MAKE_UNBOUND | |
3144 && slot != MAGIC_HANDLER_MAKE_LOCAL) | |
3145 /* #### temporary kludge because we haven't implemented | |
3146 lisp-magic variables completely */ | |
3147 return 0; | |
3148 return !NILP (XSYMBOL_VALUE_LISP_MAGIC (valcontents)->handler[slot]); | |
3149 } | |
3150 | |
3151 static Lisp_Object | |
3152 fetch_value_maybe_past_magic (Lisp_Object sym, | |
3153 Lisp_Object follow_past_lisp_magic) | |
3154 { | |
3155 Lisp_Object value = XSYMBOL (sym)->value; | |
3156 if (SYMBOL_VALUE_LISP_MAGIC_P (value) | |
3157 && (EQ (follow_past_lisp_magic, Qt) | |
3158 || (!NILP (follow_past_lisp_magic) | |
3159 && !would_be_magic_handled (sym, follow_past_lisp_magic)))) | |
3160 value = XSYMBOL_VALUE_LISP_MAGIC (value)->shadowed; | |
3161 return value; | |
3162 } | |
3163 | |
3164 static Lisp_Object * | |
3165 value_slot_past_magic (Lisp_Object sym) | |
3166 { | |
3167 Lisp_Object *store_pointer = &XSYMBOL (sym)->value; | |
3168 | |
3169 if (SYMBOL_VALUE_LISP_MAGIC_P (*store_pointer)) | |
3170 store_pointer = &XSYMBOL_VALUE_LISP_MAGIC (sym)->shadowed; | |
3171 return store_pointer; | |
3172 } | |
3173 | |
3174 static Lisp_Object | |
3175 maybe_call_magic_handler (Lisp_Object sym, Lisp_Object funsym, int nargs, ...) | |
3176 { | |
3177 va_list vargs; | |
3178 Lisp_Object args[20]; /* should be enough ... */ | |
3179 int i; | |
3180 enum lisp_magic_handler htype; | |
3181 Lisp_Object legerdemain; | |
3182 struct symbol_value_lisp_magic *bfwd; | |
3183 | |
440 | 3184 assert (nargs >= 0 && nargs < countof (args)); |
428 | 3185 legerdemain = XSYMBOL (sym)->value; |
3186 assert (SYMBOL_VALUE_LISP_MAGIC_P (legerdemain)); | |
3187 bfwd = XSYMBOL_VALUE_LISP_MAGIC (legerdemain); | |
3188 | |
3189 va_start (vargs, nargs); | |
3190 for (i = 0; i < nargs; i++) | |
3191 args[i] = va_arg (vargs, Lisp_Object); | |
3192 va_end (vargs); | |
3193 | |
3194 htype = handler_type_from_function_symbol (funsym, 1); | |
3195 if (NILP (bfwd->handler[htype])) | |
3196 return Qunbound; | |
3197 /* #### should be reusing the arglist, not always consing anew. | |
3198 Repeated handler invocations should not cause repeated consing. | |
3199 Doesn't matter for now, because this is just a quick implementation | |
3200 for obsolescence support. */ | |
3201 return call5 (bfwd->handler[htype], sym, Flist (nargs, args), funsym, | |
3202 bfwd->harg[htype], Qnil); | |
3203 } | |
3204 | |
3205 DEFUN ("dontusethis-set-symbol-value-handler", Fdontusethis_set_symbol_value_handler, | |
3206 3, 5, 0, /* | |
3207 Don't you dare use this. | |
3208 If you do, suffer the wrath of Ben, who is likely to rename | |
3209 this function (or change the semantics of its arguments) without | |
3210 pity, thereby invalidating your code. | |
3211 */ | |
2286 | 3212 (variable, handler_type, handler, harg, |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
3213 UNUSED (keep_existing ))) |
428 | 3214 { |
3215 Lisp_Object valcontents; | |
3216 struct symbol_value_lisp_magic *bfwd; | |
3217 enum lisp_magic_handler htype; | |
3218 int i; | |
3219 | |
3220 /* #### WARNING, only some handler types are implemented. See above. | |
3221 Actions of other types will ignore a handler if it's there. | |
3222 | |
3223 #### Also, `chain-to-symbol-value-handler' and | |
3224 `symbol-function-corresponding-function' are not implemented. */ | |
3225 CHECK_SYMBOL (variable); | |
3226 CHECK_SYMBOL (handler_type); | |
3227 htype = decode_magic_handler_type (handler_type); | |
3228 valcontents = XSYMBOL (variable)->value; | |
3229 if (!SYMBOL_VALUE_LISP_MAGIC_P (valcontents)) | |
3230 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3231 bfwd = |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3232 XSYMBOL_VALUE_LISP_MAGIC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
3233 (ALLOC_NORMAL_LISP_OBJECT (symbol_value_lisp_magic)); |
428 | 3234 bfwd->magic.type = SYMVAL_LISP_MAGIC; |
3235 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
3236 { | |
3237 bfwd->handler[i] = Qnil; | |
3238 bfwd->harg[i] = Qnil; | |
3239 } | |
3240 bfwd->shadowed = valcontents; | |
793 | 3241 XSYMBOL (variable)->value = wrap_symbol_value_magic (bfwd); |
428 | 3242 } |
3243 else | |
3244 bfwd = XSYMBOL_VALUE_LISP_MAGIC (valcontents); | |
3245 bfwd->handler[htype] = handler; | |
3246 bfwd->harg[htype] = harg; | |
3247 | |
3248 for (i = 0; i < MAGIC_HANDLER_MAX; i++) | |
3249 if (!NILP (bfwd->handler[i])) | |
3250 break; | |
3251 | |
3252 if (i == MAGIC_HANDLER_MAX) | |
3253 /* there are no remaining handlers, so remove the structure. */ | |
3254 XSYMBOL (variable)->value = bfwd->shadowed; | |
3255 | |
3256 return Qnil; | |
3257 } | |
3258 | |
3259 | |
3260 /* functions for working with variable aliases. */ | |
3261 | |
3262 /* Follow the chain of variable aliases for SYMBOL. Return the | |
3263 resulting symbol, whose value cell is guaranteed not to be a | |
3264 symbol-value-varalias. | |
3265 | |
3266 Also maybe follow past symbol-value-lisp-magic -> symbol-value-varalias. | |
3267 If FUNSYM is t, always follow in such a case. If FUNSYM is nil, | |
3268 never follow; stop right there. Otherwise FUNSYM should be a | |
3269 recognized symbol-value function symbol; this means, follow | |
3270 unless there is a special handler for the named function. | |
3271 | |
3272 OK, there is at least one reason why it's necessary for | |
3273 FOLLOW-PAST-LISP-MAGIC to be specified correctly: So that we | |
3274 can always be sure to catch cyclic variable aliasing. If we never | |
3275 follow past Lisp magic, then if the following is done: | |
3276 | |
3277 (defvaralias 'a 'b) | |
3278 add some magic behavior to a, but not a "get-value" handler | |
3279 (defvaralias 'b 'a) | |
3280 | |
3281 then an attempt to retrieve a's or b's value would cause infinite | |
3282 looping in `symbol-value'. | |
3283 | |
3284 We (of course) can't always follow past Lisp magic, because then | |
3285 we make any variable that is lisp-magic -> varalias behave as if | |
3286 the lisp-magic is not present at all. | |
3287 */ | |
3288 | |
3289 static Lisp_Object | |
3290 follow_varalias_pointers (Lisp_Object symbol, | |
3291 Lisp_Object follow_past_lisp_magic) | |
3292 { | |
3293 #define VARALIAS_INDIRECTION_SUSPICION_LENGTH 16 | |
3294 Lisp_Object tortoise, hare, val; | |
3295 int count; | |
3296 | |
3297 /* quick out just in case */ | |
3298 if (!SYMBOL_VALUE_MAGIC_P (XSYMBOL (symbol)->value)) | |
3299 return symbol; | |
3300 | |
3301 /* Compare implementation of indirect_function(). */ | |
3302 for (hare = tortoise = symbol, count = 0; | |
3303 val = fetch_value_maybe_past_magic (hare, follow_past_lisp_magic), | |
3304 SYMBOL_VALUE_VARALIAS_P (val); | |
3305 hare = symbol_value_varalias_aliasee (XSYMBOL_VALUE_VARALIAS (val)), | |
3306 count++) | |
3307 { | |
3308 if (count < VARALIAS_INDIRECTION_SUSPICION_LENGTH) continue; | |
3309 | |
3310 if (count & 1) | |
3311 tortoise = symbol_value_varalias_aliasee | |
3312 (XSYMBOL_VALUE_VARALIAS (fetch_value_maybe_past_magic | |
3313 (tortoise, follow_past_lisp_magic))); | |
3314 if (EQ (hare, tortoise)) | |
3315 return Fsignal (Qcyclic_variable_indirection, list1 (symbol)); | |
3316 } | |
3317 | |
3318 return hare; | |
3319 } | |
3320 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3321 /* Map FN over the chain of variable aliases for SYMBOL. If FN returns |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3322 something other than Qzero for some link in the chain, return that |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3323 immediately. Otherwise return Qzero (which is not a symbol). |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3324 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3325 FN may be called twice on the same symbol if the varalias chain is |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3326 cyclic. Prevent this by calling follow_varalias_pointers first for its |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3327 side-effects. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3328 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3329 Signals a cyclic-variable-indirection error if a cyclic structure is |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3330 detected. */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3331 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3332 static Lisp_Object |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3333 map_varalias_chain (Lisp_Object symbol, |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3334 Lisp_Object follow_past_lisp_magic, |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3335 Lisp_Object (*fn) (Lisp_Object arg)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3336 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3337 #define VARALIAS_INDIRECTION_SUSPICION_LENGTH 16 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3338 Lisp_Object tortoise, hare, val, res; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3339 int count; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3340 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3341 assert (fn); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3342 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3343 /* quick out just in case */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3344 if (!SYMBOL_VALUE_MAGIC_P (XSYMBOL (symbol)->value)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3345 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3346 return (fn)(symbol); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3347 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3348 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3349 /* Compare implementation of indirect_function(). */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3350 for (hare = tortoise = symbol, count = 0; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3351 val = fetch_value_maybe_past_magic (hare, follow_past_lisp_magic), |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3352 SYMBOL_VALUE_VARALIAS_P (val); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3353 hare = symbol_value_varalias_aliasee (XSYMBOL_VALUE_VARALIAS (val)), |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3354 count++) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3355 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3356 res = (fn) (hare); |
4503
af95657e0bfd
Use EQ() and !EQ() in symbols.c, thank you Robert Delius Royar.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4502
diff
changeset
|
3357 if (!EQ (Qzero, res)) |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3358 { |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3359 return res; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3360 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3361 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3362 if (count < VARALIAS_INDIRECTION_SUSPICION_LENGTH) continue; |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3363 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3364 if (count & 1) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3365 tortoise = symbol_value_varalias_aliasee |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3366 (XSYMBOL_VALUE_VARALIAS (fetch_value_maybe_past_magic |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3367 (tortoise, follow_past_lisp_magic))); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3368 if (EQ (hare, tortoise)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3369 return Fsignal (Qcyclic_variable_indirection, list1 (symbol)); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3370 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3371 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3372 return (fn) (hare); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3373 } |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3374 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3375 /* |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3376 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3377 OED entry, 2nd edition, IPA transliterated using Kirshenbaum: |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3378 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3379 alias ('eIlI@s, '&lI@s), adv. and n. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3380 [...] |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3381 B. n. (with pl. aliases.) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3382 1. Another name, an assumed name. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3383 1605 Camden Rem. (1614) 147 An Alias or double name cannot preiudice the honest. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3384 1831 Edin. Rev. LIII. 364 He has been assuming various aliases. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3385 1861 Macaulay Hist. Eng. V. 92 The monk who was sometimes called Harrison |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3386 and sometimes went by the alias of Johnson. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3387 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3388 The alias is the fake name. Let's try to follow that usage in our |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3389 documentation. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3390 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3391 */ |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3392 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3393 DEFUN ("defvaralias", Fdefvaralias, 2, 3, 0, /* |
428 | 3394 Define a variable as an alias for another variable. |
3395 Thenceforth, any operations performed on VARIABLE will actually be | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3396 performed on ALIASED. Both VARIABLE and ALIASED should be symbols. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3397 If ALIASED is nil and VARIABLE is an existing alias, remove that alias. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3398 ALIASED can itself be an alias, and the chain of variable aliases |
428 | 3399 will be followed appropriately. |
3400 If VARIABLE already has a value, this value will be shadowed | |
3401 until the alias is removed, at which point it will be restored. | |
3402 Currently VARIABLE cannot be a built-in variable, a variable that | |
3403 has a buffer-local value in any buffer, or the symbols nil or t. | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3404 \(ALIASED, however, can be any type of variable.) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3405 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3406 Optional argument DOCSTRING is documentation for VARIABLE in its use as an |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3407 alias for ALIASED. The XEmacs help code ignores this documentation, using |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3408 the documentation of ALIASED instead, and the docstring, if specified, is |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3409 not shadowed in the same way that the value is. Only use it if you know |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3410 what you're doing. |
428 | 3411 */ |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3412 (variable, aliased, docstring)) |
428 | 3413 { |
3414 struct symbol_value_varalias *bfwd; | |
3415 Lisp_Object valcontents; | |
3416 | |
3417 CHECK_SYMBOL (variable); | |
3418 reject_constant_symbols (variable, Qunbound, 0, Qt); | |
3419 | |
3420 valcontents = XSYMBOL (variable)->value; | |
3421 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3422 if (NILP (aliased)) |
428 | 3423 { |
3424 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) | |
3425 { | |
3426 XSYMBOL (variable)->value = | |
3427 symbol_value_varalias_shadowed | |
3428 (XSYMBOL_VALUE_VARALIAS (valcontents)); | |
3429 } | |
3430 return Qnil; | |
3431 } | |
3432 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3433 CHECK_SYMBOL (aliased); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3434 |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3435 if (!NILP (docstring)) |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3436 Fput (variable, Qvariable_documentation, docstring); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3437 |
428 | 3438 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) |
3439 { | |
3440 /* transmogrify */ | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3441 XSYMBOL_VALUE_VARALIAS (valcontents)->aliasee = aliased; |
428 | 3442 return Qnil; |
3443 } | |
3444 | |
3445 if (SYMBOL_VALUE_MAGIC_P (valcontents) | |
3446 && !UNBOUNDP (valcontents)) | |
563 | 3447 invalid_change ("Variable is magic and cannot be aliased", variable); |
428 | 3448 reject_constant_symbols (variable, Qunbound, 0, Qt); |
3449 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3450 bfwd = |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
3451 XSYMBOL_VALUE_VARALIAS (ALLOC_NORMAL_LISP_OBJECT (symbol_value_varalias)); |
428 | 3452 bfwd->magic.type = SYMVAL_VARALIAS; |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3453 bfwd->aliasee = aliased; |
428 | 3454 bfwd->shadowed = valcontents; |
3455 | |
793 | 3456 valcontents = wrap_symbol_value_magic (bfwd); |
428 | 3457 XSYMBOL (variable)->value = valcontents; |
3458 return Qnil; | |
3459 } | |
3460 | |
3461 DEFUN ("variable-alias", Fvariable_alias, 1, 2, 0, /* | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3462 If VARIABLE is an alias of another variable, return that variable. |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3463 VARIABLE should be a symbol. If VARIABLE is not an alias, return nil. |
428 | 3464 Variable aliases are created with `defvaralias'. See also |
3465 `indirect-variable'. | |
3466 */ | |
3467 (variable, follow_past_lisp_magic)) | |
3468 { | |
3469 Lisp_Object valcontents; | |
3470 | |
3471 CHECK_SYMBOL (variable); | |
3472 if (!NILP (follow_past_lisp_magic) && !EQ (follow_past_lisp_magic, Qt)) | |
3473 { | |
3474 CHECK_SYMBOL (follow_past_lisp_magic); | |
3475 handler_type_from_function_symbol (follow_past_lisp_magic, 0); | |
3476 } | |
3477 | |
3478 valcontents = fetch_value_maybe_past_magic (variable, | |
3479 follow_past_lisp_magic); | |
3480 | |
3481 if (SYMBOL_VALUE_VARALIAS_P (valcontents)) | |
3482 return symbol_value_varalias_aliasee | |
3483 (XSYMBOL_VALUE_VARALIAS (valcontents)); | |
3484 else | |
3485 return Qnil; | |
3486 } | |
3487 | |
3488 DEFUN ("indirect-variable", Findirect_variable, 1, 2, 0, /* | |
3489 Return the variable at the end of OBJECT's variable-alias chain. | |
3490 If OBJECT is a symbol, follow all variable aliases and return | |
3491 the final (non-aliased) symbol. Variable aliases are created with | |
3492 the function `defvaralias'. | |
3493 If OBJECT is not a symbol, just return it. | |
3494 Signal a cyclic-variable-indirection error if there is a loop in the | |
3495 variable chain of symbols. | |
3496 */ | |
3497 (object, follow_past_lisp_magic)) | |
3498 { | |
3499 if (!SYMBOLP (object)) | |
3500 return object; | |
3501 if (!NILP (follow_past_lisp_magic) && !EQ (follow_past_lisp_magic, Qt)) | |
3502 { | |
3503 CHECK_SYMBOL (follow_past_lisp_magic); | |
3504 handler_type_from_function_symbol (follow_past_lisp_magic, 0); | |
3505 } | |
3506 return follow_varalias_pointers (object, follow_past_lisp_magic); | |
3507 } | |
3508 | |
1674 | 3509 DEFUN ("variable-binding-locus", Fvariable_binding_locus, 1, 1, 0, /* |
3510 Return a value indicating where VARIABLE's current binding comes from. | |
3511 If the current binding is buffer-local, the value is the current buffer. | |
3512 If the current binding is global (the default), the value is nil. | |
3513 */ | |
3514 (variable)) | |
3515 { | |
3516 Lisp_Object valcontents; | |
3517 | |
3518 CHECK_SYMBOL (variable); | |
3519 variable = Findirect_variable (variable, Qnil); | |
3520 | |
3521 /* Make sure the current binding is actually swapped in. */ | |
3522 find_symbol_value (variable); | |
3523 | |
3524 valcontents = XSYMBOL (variable)->value; | |
3525 | |
3526 if (SYMBOL_VALUE_MAGIC_P (valcontents) | |
3527 && ((XSYMBOL_VALUE_MAGIC_TYPE (valcontents) == SYMVAL_BUFFER_LOCAL) | |
3528 || (XSYMBOL_VALUE_MAGIC_TYPE (valcontents) == SYMVAL_SOME_BUFFER_LOCAL)) | |
3529 && (!NILP (Flocal_variable_p (variable, Fcurrent_buffer (), Qnil)))) | |
3530 return Fcurrent_buffer (); | |
3531 else | |
3532 return Qnil; | |
3533 } | |
428 | 3534 |
3535 /************************************************************************/ | |
3536 /* initialization */ | |
3537 /************************************************************************/ | |
3538 | |
3539 /* A dumped XEmacs image has a lot more than 1511 symbols. Last | |
3540 estimate was that there were actually around 6300. So let's try | |
3541 making this bigger and see if we get better hashing behavior. */ | |
3542 #define OBARRAY_SIZE 16411 | |
3543 | |
3544 #ifndef Qzero | |
3545 Lisp_Object Qzero; | |
3546 #endif | |
3547 #ifndef Qnull_pointer | |
3548 Lisp_Object Qnull_pointer; | |
3549 #endif | |
3550 | |
3263 | 3551 #ifndef NEW_GC |
428 | 3552 /* some losing systems can't have static vars at function scope... */ |
442 | 3553 static const struct symbol_value_magic guts_of_unbound_marker = |
3554 { /* struct symbol_value_magic */ | |
3024 | 3555 { /* struct old_lcrecord_header */ |
442 | 3556 { /* struct lrecord_header */ |
3557 lrecord_type_symbol_value_forward, /* lrecord_type_index */ | |
3558 1, /* mark bit */ | |
3559 1, /* c_readonly bit */ | |
3560 1, /* lisp_readonly bit */ | |
3561 }, | |
3562 0, /* next */ | |
3563 }, | |
3564 0, /* value */ | |
3565 SYMVAL_UNBOUND_MARKER | |
3566 }; | |
3263 | 3567 #endif /* not NEW_GC */ |
428 | 3568 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3569 static void |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3570 reinit_symbol_objects_early (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3571 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3572 OBJECT_HAS_METHOD (symbol, getprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3573 OBJECT_HAS_METHOD (symbol, putprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3574 OBJECT_HAS_METHOD (symbol, remprop); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
3575 OBJECT_HAS_METHOD (symbol, print_preprocess); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3576 OBJECT_HAS_NAMED_METHOD (symbol, plist, Fsymbol_plist); |
5255
b5611afbcc76
Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5222
diff
changeset
|
3577 OBJECT_HAS_NAMED_METHOD (symbol, setplist, Fsetplist); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3578 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3579 |
428 | 3580 void |
3581 init_symbols_once_early (void) | |
3582 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3583 INIT_LISP_OBJECT (symbol); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3584 INIT_LISP_OBJECT (symbol_value_forward); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3585 INIT_LISP_OBJECT (symbol_value_buffer_local); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3586 INIT_LISP_OBJECT (symbol_value_lisp_magic); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
3587 INIT_LISP_OBJECT (symbol_value_varalias); |
442 | 3588 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3589 reinit_symbol_objects_early (); |
428 | 3590 |
3591 /* Bootstrapping problem: Qnil isn't set when make_string_nocopy is | |
3592 called the first time. */ | |
867 | 3593 Qnil = Fmake_symbol (make_string_nocopy ((const Ibyte *) "nil", 3)); |
793 | 3594 XSTRING_PLIST (XSYMBOL (Qnil)->name) = Qnil; |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3595 XSYMBOL (Qnil)->value = Qnil; /* Nihil ex nihilo */ |
428 | 3596 XSYMBOL (Qnil)->plist = Qnil; |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
3597 XSYMBOL (Qnil)->u.v.package_count = 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5470
diff
changeset
|
3598 XSYMBOL (Qnil)->u.v.first_package_id = 1; |
428 | 3599 |
3600 Vobarray = make_vector (OBARRAY_SIZE, Qzero); | |
3601 initial_obarray = Vobarray; | |
3602 staticpro (&initial_obarray); | |
3603 /* Intern nil in the obarray */ | |
3604 { | |
793 | 3605 unsigned int hash = hash_string (XSTRING_DATA (XSYMBOL (Qnil)->name), 3); |
428 | 3606 XVECTOR_DATA (Vobarray)[hash % OBARRAY_SIZE] = Qnil; |
3607 } | |
3608 | |
3609 { | |
3610 /* Required to get around a GCC syntax error on certain | |
3611 architectures */ | |
3263 | 3612 #ifdef NEW_GC |
2720 | 3613 struct symbol_value_magic *tem = (struct symbol_value_magic *) |
3614 mc_alloc (sizeof (struct symbol_value_magic)); | |
3615 MARK_LRECORD_AS_LISP_READONLY (tem); | |
3616 MARK_LRECORD_AS_NOT_FREE (tem); | |
3617 tem->header.type = lrecord_type_symbol_value_forward; | |
3618 mcpro (wrap_pointer_1 (tem)); | |
3619 tem->value = 0; | |
3620 tem->type = SYMVAL_UNBOUND_MARKER; | |
2994 | 3621 #ifdef ALLOC_TYPE_STATS |
2775 | 3622 inc_lrecord_stats (sizeof (struct symbol_value_magic), |
3623 (const struct lrecord_header *) tem); | |
2994 | 3624 #endif /* ALLOC_TYPE_STATS */ |
3263 | 3625 #else /* not NEW_GC */ |
442 | 3626 const struct symbol_value_magic *tem = &guts_of_unbound_marker; |
3263 | 3627 #endif /* not NEW_GC */ |
428 | 3628 |
793 | 3629 Qunbound = wrap_symbol_value_magic (tem); |
428 | 3630 } |
3631 | |
3632 XSYMBOL (Qnil)->function = Qunbound; | |
3633 | |
563 | 3634 DEFSYMBOL (Qt); |
444 | 3635 XSYMBOL (Qt)->value = Qt; /* Veritas aeterna */ |
428 | 3636 Vquit_flag = Qnil; |
3637 | |
1204 | 3638 dump_add_root_lisp_object (&Qnil); |
3639 dump_add_root_lisp_object (&Qunbound); | |
3640 dump_add_root_lisp_object (&Vquit_flag); | |
428 | 3641 } |
3642 | |
3643 void | |
1204 | 3644 reinit_symbols_early (void) |
440 | 3645 { |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3646 reinit_symbol_objects_early (); |
440 | 3647 } |
3648 | |
442 | 3649 static void |
4979
4234fd5a7b17
fix bug #668 (compile error, not --with-debug)
Ben Wing <ben@xemacs.org>
parents:
4971
diff
changeset
|
3650 defsymbol_massage_name_1 (Lisp_Object *location, const Ascbyte *name, |
4234fd5a7b17
fix bug #668 (compile error, not --with-debug)
Ben Wing <ben@xemacs.org>
parents:
4971
diff
changeset
|
3651 int dump_p, int multiword_predicate_p) |
442 | 3652 { |
3653 char temp[500]; | |
3654 int len = strlen (name) - 1; | |
3655 int i; | |
3656 | |
3657 if (multiword_predicate_p) | |
647 | 3658 assert (len + 1 < (int) sizeof (temp)); |
442 | 3659 else |
647 | 3660 assert (len < (int) sizeof (temp)); |
442 | 3661 strcpy (temp, name + 1); /* Remove initial Q */ |
3662 if (multiword_predicate_p) | |
3663 { | |
3664 strcpy (temp + len - 1, "_p"); | |
3665 len++; | |
3666 } | |
3667 for (i = 0; i < len; i++) | |
3668 if (temp[i] == '_') | |
3669 temp[i] = '-'; | |
867 | 3670 *location = Fintern (make_string ((const Ibyte *) temp, len), Qnil); |
442 | 3671 if (dump_p) |
4971
bcdf496e49d0
put back patch to get more informative staticpro debugging
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3672 staticpro_1 (location, name); |
442 | 3673 else |
4971
bcdf496e49d0
put back patch to get more informative staticpro debugging
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3674 staticpro_nodump_1 (location, name); |
442 | 3675 } |
3676 | |
440 | 3677 void |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3678 defsymbol_massage_name_nodump (Lisp_Object *location, const Ascbyte *name) |
442 | 3679 { |
3680 defsymbol_massage_name_1 (location, name, 0, 0); | |
3681 } | |
3682 | |
3683 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3684 defsymbol_massage_name (Lisp_Object *location, const Ascbyte *name) |
428 | 3685 { |
442 | 3686 defsymbol_massage_name_1 (location, name, 1, 0); |
3687 } | |
3688 | |
3689 void | |
3690 defsymbol_massage_multiword_predicate_nodump (Lisp_Object *location, | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3691 const Ascbyte *name) |
442 | 3692 { |
3693 defsymbol_massage_name_1 (location, name, 0, 1); | |
3694 } | |
3695 | |
3696 void | |
4979
4234fd5a7b17
fix bug #668 (compile error, not --with-debug)
Ben Wing <ben@xemacs.org>
parents:
4971
diff
changeset
|
3697 defsymbol_massage_multiword_predicate (Lisp_Object *location, |
4234fd5a7b17
fix bug #668 (compile error, not --with-debug)
Ben Wing <ben@xemacs.org>
parents:
4971
diff
changeset
|
3698 const Ascbyte *name) |
442 | 3699 { |
3700 defsymbol_massage_name_1 (location, name, 1, 1); | |
3701 } | |
3702 | |
3703 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3704 defsymbol_nodump (Lisp_Object *location, const Ascbyte *name) |
442 | 3705 { |
867 | 3706 *location = Fintern (make_string_nocopy ((const Ibyte *) name, |
428 | 3707 strlen (name)), |
3708 Qnil); | |
4971
bcdf496e49d0
put back patch to get more informative staticpro debugging
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3709 staticpro_nodump_1 (location, name); |
428 | 3710 } |
3711 | |
3712 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3713 defsymbol (Lisp_Object *location, const Ascbyte *name) |
428 | 3714 { |
867 | 3715 *location = Fintern (make_string_nocopy ((const Ibyte *) name, |
428 | 3716 strlen (name)), |
3717 Qnil); | |
4971
bcdf496e49d0
put back patch to get more informative staticpro debugging
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3718 staticpro_1 (location, name); |
428 | 3719 } |
3720 | |
3721 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3722 defkeyword (Lisp_Object *location, const Ascbyte *name) |
428 | 3723 { |
3724 defsymbol (location, name); | |
3725 Fset (*location, *location); | |
3726 } | |
3727 | |
442 | 3728 void |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3729 defkeyword_massage_name (Lisp_Object *location, const Ascbyte *name) |
442 | 3730 { |
3731 char temp[500]; | |
3732 int len = strlen (name); | |
3733 | |
647 | 3734 assert (len < (int) sizeof (temp)); |
442 | 3735 strcpy (temp, name); |
3736 temp[1] = ':'; /* it's an underscore in the C variable */ | |
3737 | |
3738 defsymbol_massage_name (location, temp); | |
3739 Fset (*location, *location); | |
3740 } | |
3741 | |
428 | 3742 #ifdef DEBUG_XEMACS |
930 | 3743 /* Check that nobody spazzed writing a builtin (non-module) DEFUN. */ |
428 | 3744 static void |
3745 check_sane_subr (Lisp_Subr *subr, Lisp_Object sym) | |
3746 { | |
930 | 3747 if (!initialized) { |
3748 assert (subr->min_args >= 0); | |
3749 assert (subr->min_args <= SUBR_MAX_ARGS); | |
3750 | |
3751 if (subr->max_args != MANY && | |
3752 subr->max_args != UNEVALLED) | |
3753 { | |
3754 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ | |
3755 assert (subr->max_args <= SUBR_MAX_ARGS); | |
3756 assert (subr->min_args <= subr->max_args); | |
3757 } | |
3758 assert (UNBOUNDP (XSYMBOL (sym)->function)); | |
3759 } | |
428 | 3760 } |
3761 #else | |
3762 #define check_sane_subr(subr, sym) /* nothing */ | |
3763 #endif | |
3764 | |
3765 #ifdef HAVE_SHLIB | |
3263 | 3766 #ifndef NEW_GC |
428 | 3767 /* |
3768 * If we are not in a pure undumped Emacs, we need to make a duplicate of | |
3769 * the subr. This is because the only time this function will be called | |
3770 * in a running Emacs is when a dynamically loaded module is adding a | |
3771 * subr, and we need to make sure that the subr is in allocated, Lisp- | |
3772 * accessible memory. The address assigned to the static subr struct | |
3773 * in the shared object will be a trampoline address, so we need to create | |
3774 * a copy here to ensure that a real address is used. | |
3775 * | |
3776 * Once we have copied everything across, we re-use the original static | |
3777 * structure to store a pointer to the newly allocated one. This will be | |
3778 * used in emodules.c by emodules_doc_subr() to find a pointer to the | |
442 | 3779 * allocated object so that we can set its doc string properly. |
428 | 3780 * |
442 | 3781 * NOTE: We don't actually use the DOC pointer here any more, but we did |
428 | 3782 * in an earlier implementation of module support. There is no harm in |
3783 * setting it here in case we ever need it in future implementations. | |
3784 * subr->doc will point to the new subr structure that was allocated. | |
442 | 3785 * Code can then get this value from the static subr structure and use |
428 | 3786 * it if required. |
3787 * | |
442 | 3788 * FIXME: Should newsubr be staticpro()'ed? I don't think so but I need |
428 | 3789 * a guru to check. |
3790 */ | |
930 | 3791 #define check_module_subr(subr) \ |
3792 do { \ | |
3793 if (initialized) { \ | |
3794 Lisp_Subr *newsubr; \ | |
3795 Lisp_Object f; \ | |
3796 \ | |
3797 if (subr->min_args < 0) \ | |
3798 signal_ferror (Qdll_error, "%s min_args (%hd) too small", \ | |
3799 subr_name (subr), subr->min_args); \ | |
3800 if (subr->min_args > SUBR_MAX_ARGS) \ | |
3801 signal_ferror (Qdll_error, "%s min_args (%hd) too big (max = %d)", \ | |
3802 subr_name (subr), subr->min_args, SUBR_MAX_ARGS); \ | |
3803 \ | |
3804 if (subr->max_args != MANY && \ | |
3805 subr->max_args != UNEVALLED) \ | |
3806 { \ | |
3807 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ \ | |
3808 if (subr->max_args > SUBR_MAX_ARGS) \ | |
3809 signal_ferror (Qdll_error, "%s max_args (%hd) too big (max = %d)", \ | |
3810 subr_name (subr), subr->max_args, SUBR_MAX_ARGS); \ | |
3811 if (subr->min_args > subr->max_args) \ | |
3812 signal_ferror (Qdll_error, "%s min_args (%hd) > max_args (%hd)", \ | |
3813 subr_name (subr), subr->min_args, subr->max_args); \ | |
3814 } \ | |
3815 \ | |
3816 f = XSYMBOL (sym)->function; \ | |
3817 if (!UNBOUNDP (f) && (!CONSP (f) || !EQ (XCAR (f), Qautoload))) \ | |
3818 signal_ferror (Qdll_error, "Attempt to redefine %s", subr_name (subr)); \ | |
3819 \ | |
2367 | 3820 newsubr = xnew (Lisp_Subr); \ |
930 | 3821 memcpy (newsubr, subr, sizeof (Lisp_Subr)); \ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3822 subr->doc = (const CIbyte *)newsubr; \ |
930 | 3823 subr = newsubr; \ |
3824 } \ | |
428 | 3825 } while (0) |
3263 | 3826 #else /* NEW_GC */ |
2963 | 3827 /* |
3828 * If we have the new allocator enabled, we do not need to make a | |
3829 * duplicate of the subr. The new allocator already does allocate all | |
3830 * subrs in Lisp-accessible memory rather than have it in the static | |
3831 * subr struct. | |
3832 * | |
3833 * NOTE: The DOC pointer is not set here as described above. | |
3834 */ | |
3835 #define check_module_subr(subr) \ | |
3836 do { \ | |
3837 if (initialized) { \ | |
3838 Lisp_Object f; \ | |
3839 \ | |
3840 if (subr->min_args < 0) \ | |
3841 signal_ferror (Qdll_error, "%s min_args (%hd) too small", \ | |
3842 subr_name (subr), subr->min_args); \ | |
3843 if (subr->min_args > SUBR_MAX_ARGS) \ | |
3844 signal_ferror (Qdll_error, "%s min_args (%hd) too big (max = %d)", \ | |
3845 subr_name (subr), subr->min_args, SUBR_MAX_ARGS); \ | |
3846 \ | |
3847 if (subr->max_args != MANY && \ | |
3848 subr->max_args != UNEVALLED) \ | |
3849 { \ | |
3850 /* Need to fix lisp.h and eval.c if SUBR_MAX_ARGS too small */ \ | |
3851 if (subr->max_args > SUBR_MAX_ARGS) \ | |
3852 signal_ferror (Qdll_error, "%s max_args (%hd) too big (max = %d)", \ | |
3853 subr_name (subr), subr->max_args, SUBR_MAX_ARGS); \ | |
3854 if (subr->min_args > subr->max_args) \ | |
3855 signal_ferror (Qdll_error, "%s min_args (%hd) > max_args (%hd)", \ | |
3856 subr_name (subr), subr->min_args, subr->max_args); \ | |
3857 } \ | |
3858 \ | |
3859 f = XSYMBOL (sym)->function; \ | |
3860 if (!UNBOUNDP (f) && (!CONSP (f) || !EQ (XCAR (f), Qautoload))) \ | |
3861 signal_ferror (Qdll_error, "Attempt to redefine %s", subr_name (subr)); \ | |
3862 } \ | |
3863 } while (0) | |
3263 | 3864 #endif /* NEW_GC */ |
428 | 3865 #else /* ! HAVE_SHLIB */ |
930 | 3866 #define check_module_subr(subr) |
428 | 3867 #endif |
3868 | |
3869 void | |
3870 defsubr (Lisp_Subr *subr) | |
3871 { | |
3872 Lisp_Object sym = intern (subr_name (subr)); | |
3873 Lisp_Object fun; | |
3874 | |
3875 check_sane_subr (subr, sym); | |
930 | 3876 check_module_subr (subr); |
428 | 3877 |
793 | 3878 fun = wrap_subr (subr); |
428 | 3879 XSYMBOL (sym)->function = fun; |
996 | 3880 |
3881 #ifdef HAVE_SHLIB | |
3882 /* If it is declared in a module, update the load history */ | |
3883 if (initialized) | |
3884 LOADHIST_ATTACH (sym); | |
3885 #endif | |
428 | 3886 } |
3887 | |
3888 /* Define a lisp macro using a Lisp_Subr. */ | |
3889 void | |
3890 defsubr_macro (Lisp_Subr *subr) | |
3891 { | |
3892 Lisp_Object sym = intern (subr_name (subr)); | |
3893 Lisp_Object fun; | |
3894 | |
3895 check_sane_subr (subr, sym); | |
930 | 3896 check_module_subr (subr); |
428 | 3897 |
793 | 3898 fun = wrap_subr (subr); |
428 | 3899 XSYMBOL (sym)->function = Fcons (Qmacro, fun); |
996 | 3900 |
3901 #ifdef HAVE_SHLIB | |
3902 /* If it is declared in a module, update the load history */ | |
3903 if (initialized) | |
3904 LOADHIST_ATTACH (sym); | |
3905 #endif | |
428 | 3906 } |
3907 | |
442 | 3908 static void |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3909 deferror_1 (Lisp_Object *symbol, const Ascbyte *name, const Ascbyte *messuhhj, |
442 | 3910 Lisp_Object inherits_from, int massage_p) |
428 | 3911 { |
3912 Lisp_Object conds; | |
442 | 3913 if (massage_p) |
3914 defsymbol_massage_name (symbol, name); | |
3915 else | |
3916 defsymbol (symbol, name); | |
428 | 3917 |
3918 assert (SYMBOLP (inherits_from)); | |
3919 conds = Fget (inherits_from, Qerror_conditions, Qnil); | |
3920 Fput (*symbol, Qerror_conditions, Fcons (*symbol, conds)); | |
771 | 3921 /* NOT build_msg_string (). This function is called at load time |
428 | 3922 and the string needs to get translated at run time. (This happens |
3923 in the function (display-error) in cmdloop.el.) */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3924 Fput (*symbol, Qerror_message, build_defer_string (messuhhj)); |
428 | 3925 } |
3926 | |
3927 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3928 deferror (Lisp_Object *symbol, const Ascbyte *name, const Ascbyte *messuhhj, |
442 | 3929 Lisp_Object inherits_from) |
3930 { | |
3931 deferror_1 (symbol, name, messuhhj, inherits_from, 0); | |
3932 } | |
3933 | |
3934 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3935 deferror_massage_name (Lisp_Object *symbol, const Ascbyte *name, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3936 const Ascbyte *messuhhj, Lisp_Object inherits_from) |
442 | 3937 { |
3938 deferror_1 (symbol, name, messuhhj, inherits_from, 1); | |
3939 } | |
3940 | |
3941 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
3942 deferror_massage_name_and_message (Lisp_Object *symbol, const Ascbyte *name, |
442 | 3943 Lisp_Object inherits_from) |
3944 { | |
3945 char temp[500]; | |
3946 int i; | |
3947 int len = strlen (name) - 1; | |
3948 | |
647 | 3949 assert (len < (int) sizeof (temp)); |
442 | 3950 strcpy (temp, name + 1); /* Remove initial Q */ |
3951 temp[0] = toupper (temp[0]); | |
3952 for (i = 0; i < len; i++) | |
3953 if (temp[i] == '_') | |
3954 temp[i] = ' '; | |
3955 | |
3956 deferror_1 (symbol, name, temp, inherits_from, 1); | |
3957 } | |
3958 | |
3959 void | |
428 | 3960 syms_of_symbols (void) |
3961 { | |
442 | 3962 DEFSYMBOL (Qvariable_documentation); |
3963 DEFSYMBOL (Qvariable_domain); /* I18N3 */ | |
3964 DEFSYMBOL (Qad_advice_info); | |
3965 DEFSYMBOL (Qad_activate); | |
3966 | |
3967 DEFSYMBOL (Qget_value); | |
3968 DEFSYMBOL (Qset_value); | |
3969 DEFSYMBOL (Qbound_predicate); | |
3970 DEFSYMBOL (Qmake_unbound); | |
3971 DEFSYMBOL (Qlocal_predicate); | |
3972 DEFSYMBOL (Qmake_local); | |
3973 | |
3974 DEFSYMBOL (Qboundp); | |
3975 DEFSYMBOL (Qglobally_boundp); | |
3976 DEFSYMBOL (Qmakunbound); | |
3977 DEFSYMBOL (Qsymbol_value); | |
3978 DEFSYMBOL (Qset); | |
3979 DEFSYMBOL (Qsetq_default); | |
3980 DEFSYMBOL (Qdefault_boundp); | |
3981 DEFSYMBOL (Qdefault_value); | |
3982 DEFSYMBOL (Qset_default); | |
3983 DEFSYMBOL (Qmake_variable_buffer_local); | |
3984 DEFSYMBOL (Qmake_local_variable); | |
3985 DEFSYMBOL (Qkill_local_variable); | |
3986 DEFSYMBOL (Qkill_console_local_variable); | |
3987 DEFSYMBOL (Qsymbol_value_in_buffer); | |
3988 DEFSYMBOL (Qsymbol_value_in_console); | |
3989 DEFSYMBOL (Qlocal_variable_p); | |
3990 DEFSYMBOL (Qconst_integer); | |
3991 DEFSYMBOL (Qconst_boolean); | |
3992 DEFSYMBOL (Qconst_object); | |
3993 DEFSYMBOL (Qconst_specifier); | |
3994 DEFSYMBOL (Qdefault_buffer); | |
3995 DEFSYMBOL (Qcurrent_buffer); | |
3996 DEFSYMBOL (Qconst_current_buffer); | |
3997 DEFSYMBOL (Qdefault_console); | |
3998 DEFSYMBOL (Qselected_console); | |
3999 DEFSYMBOL (Qconst_selected_console); | |
428 | 4000 |
4001 DEFSUBR (Fintern); | |
4002 DEFSUBR (Fintern_soft); | |
4003 DEFSUBR (Funintern); | |
4004 DEFSUBR (Fmapatoms); | |
4005 DEFSUBR (Fapropos_internal); | |
4006 | |
4007 DEFSUBR (Fsymbol_function); | |
4008 DEFSUBR (Fsymbol_plist); | |
4009 DEFSUBR (Fsymbol_name); | |
4010 DEFSUBR (Fmakunbound); | |
4011 DEFSUBR (Ffmakunbound); | |
4012 DEFSUBR (Fboundp); | |
4013 DEFSUBR (Fglobally_boundp); | |
4014 DEFSUBR (Ffboundp); | |
4015 DEFSUBR (Ffset); | |
4016 DEFSUBR (Fdefine_function); | |
4017 Ffset (intern ("defalias"), intern ("define-function")); | |
3368 | 4018 DEFSUBR (Fsubr_name); |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
4019 DEFSUBR (Fspecial_operator_p); |
428 | 4020 DEFSUBR (Fsetplist); |
4021 DEFSUBR (Fsymbol_value_in_buffer); | |
4022 DEFSUBR (Fsymbol_value_in_console); | |
4023 DEFSUBR (Fbuilt_in_variable_type); | |
4024 DEFSUBR (Fsymbol_value); | |
4025 DEFSUBR (Fset); | |
4026 DEFSUBR (Fdefault_boundp); | |
4027 DEFSUBR (Fdefault_value); | |
4028 DEFSUBR (Fset_default); | |
4029 DEFSUBR (Fsetq_default); | |
4030 DEFSUBR (Fmake_variable_buffer_local); | |
4031 DEFSUBR (Fmake_local_variable); | |
4032 DEFSUBR (Fkill_local_variable); | |
4033 DEFSUBR (Fkill_console_local_variable); | |
4034 DEFSUBR (Flocal_variable_p); | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
4035 DEFSUBR (Fcustom_variable_p); |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
4036 DEFSUBR (Fuser_variable_p); |
428 | 4037 DEFSUBR (Fdefvaralias); |
4038 DEFSUBR (Fvariable_alias); | |
4039 DEFSUBR (Findirect_variable); | |
1674 | 4040 DEFSUBR (Fvariable_binding_locus); |
428 | 4041 DEFSUBR (Fdontusethis_set_symbol_value_handler); |
4042 } | |
4043 | |
4044 /* Create and initialize a Lisp variable whose value is forwarded to C data */ | |
4045 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
4046 defvar_magic (const Ascbyte *symbol_name, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
4047 const struct symbol_value_forward *magic) |
428 | 4048 { |
442 | 4049 Lisp_Object sym; |
428 | 4050 |
996 | 4051 #ifdef HAVE_SHLIB |
428 | 4052 /* |
4053 * As with defsubr(), this will only be called in a dumped Emacs when | |
4054 * we are adding variables from a dynamically loaded module. That means | |
4055 * we can't use purespace. Take that into account. | |
4056 */ | |
4057 if (initialized) | |
996 | 4058 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4940
diff
changeset
|
4059 sym = Fintern (build_ascstring (symbol_name), Qnil); |
996 | 4060 LOADHIST_ATTACH (sym); |
4061 } | |
428 | 4062 else |
4063 #endif | |
867 | 4064 sym = Fintern (make_string_nocopy ((const Ibyte *) symbol_name, |
428 | 4065 strlen (symbol_name)), Qnil); |
4066 | |
793 | 4067 XSYMBOL (sym)->value = wrap_pointer_1 (magic); |
428 | 4068 } |
4069 | |
4070 void | |
4071 vars_of_symbols (void) | |
4072 { | |
4073 DEFVAR_LISP ("obarray", &Vobarray /* | |
4074 Symbol table for use by `intern' and `read'. | |
4075 It is a vector whose length ought to be prime for best results. | |
4076 The vector's contents don't make sense if examined from Lisp programs; | |
4077 to find all the symbols in an obarray, use `mapatoms'. | |
4078 */ ); | |
4079 /* obarray has been initialized long before */ | |
4080 } |