Mercurial > hg > xemacs-beta
annotate src/specifier.c @ 5117:3742ea8250b5 ben-lisp-object ben-lisp-object-final-ws-year-2005
Checking in final CVS version of workspace 'ben-lisp-object'
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 26 Dec 2009 00:20:27 -0600 |
parents | 1e7cc382eb16 |
children | e0db3c197671 |
rev | line source |
---|---|
428 | 1 /* Specifier implementation |
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. | |
2953 | 3 Copyright (C) 1995, 1996, 2002, 2005 Ben Wing. |
428 | 4 Copyright (C) 1995 Sun Microsystems, Inc. |
5 | |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Not in FSF. */ | |
24 | |
25 /* Design by Ben Wing; | |
2953 | 26 Written by Ben Wing based on prototype for 19.12 by Chuck Thompson. |
27 Magic specifiers by Kirill Katsnelson. | |
428 | 28 */ |
29 | |
30 #include <config.h> | |
31 #include "lisp.h" | |
32 | |
33 #include "buffer.h" | |
800 | 34 #include "chartab.h" |
872 | 35 #include "device-impl.h" |
428 | 36 #include "frame.h" |
800 | 37 #include "glyphs.h" |
428 | 38 #include "opaque.h" |
800 | 39 #include "rangetab.h" |
428 | 40 #include "specifier.h" |
41 #include "window.h" | |
42 | |
43 Lisp_Object Qspecifierp; | |
442 | 44 Lisp_Object Qremove_tag_set_prepend, Qremove_tag_set_append; |
45 Lisp_Object Qremove_locale, Qremove_locale_type; | |
428 | 46 |
47 Lisp_Object Qconsole_type, Qdevice_class; | |
48 | |
49 static Lisp_Object Vuser_defined_tags; | |
50 | |
51 typedef struct specifier_type_entry specifier_type_entry; | |
52 struct specifier_type_entry | |
53 { | |
54 Lisp_Object symbol; | |
55 struct specifier_methods *meths; | |
56 }; | |
57 | |
58 typedef struct | |
59 { | |
60 Dynarr_declare (specifier_type_entry); | |
61 } specifier_type_entry_dynarr; | |
62 | |
63 static specifier_type_entry_dynarr *the_specifier_type_entry_dynarr; | |
64 | |
1204 | 65 static const struct memory_description ste_description_1[] = { |
440 | 66 { XD_LISP_OBJECT, offsetof (specifier_type_entry, symbol) }, |
2367 | 67 { XD_BLOCK_PTR, offsetof (specifier_type_entry, meths), 1, |
2551 | 68 { &specifier_methods_description } }, |
428 | 69 { XD_END } |
70 }; | |
71 | |
1204 | 72 static const struct sized_memory_description ste_description = { |
440 | 73 sizeof (specifier_type_entry), |
428 | 74 ste_description_1 |
75 }; | |
76 | |
1204 | 77 static const struct memory_description sted_description_1[] = { |
440 | 78 XD_DYNARR_DESC (specifier_type_entry_dynarr, &ste_description), |
428 | 79 { XD_END } |
80 }; | |
81 | |
1204 | 82 static const struct sized_memory_description sted_description = { |
440 | 83 sizeof (specifier_type_entry_dynarr), |
428 | 84 sted_description_1 |
85 }; | |
86 | |
87 static Lisp_Object Vspecifier_type_list; | |
88 | |
89 static Lisp_Object Vcached_specifiers; | |
90 /* Do NOT mark through this, or specifiers will never be GC'd. */ | |
91 static Lisp_Object Vall_specifiers; | |
92 | |
93 static Lisp_Object Vunlock_ghost_specifiers; | |
94 | |
95 /* #### The purpose of this is to check for inheritance loops | |
96 in specifiers that can inherit from other specifiers, but it's | |
97 not yet implemented. | |
98 | |
99 #### Look into this for 19.14. */ | |
100 /* static Lisp_Object_dynarr current_specifiers; */ | |
101 | |
102 static void recompute_cached_specifier_everywhere (Lisp_Object specifier); | |
103 | |
104 EXFUN (Fspecifier_specs, 4); | |
105 EXFUN (Fremove_specifier, 4); | |
106 | |
107 | |
108 /************************************************************************/ | |
109 /* Specifier object methods */ | |
110 /************************************************************************/ | |
111 | |
112 /* Remove dead objects from the specified assoc list. */ | |
113 | |
114 static Lisp_Object | |
115 cleanup_assoc_list (Lisp_Object list) | |
116 { | |
117 Lisp_Object loop, prev, retval; | |
118 | |
119 loop = retval = list; | |
120 prev = Qnil; | |
121 | |
122 while (!NILP (loop)) | |
123 { | |
124 Lisp_Object entry = XCAR (loop); | |
125 Lisp_Object key = XCAR (entry); | |
126 | |
127 /* remember, dead windows can become alive again. */ | |
128 if (!WINDOWP (key) && object_dead_p (key)) | |
129 { | |
130 if (NILP (prev)) | |
131 { | |
132 /* Removing the head. */ | |
133 retval = XCDR (retval); | |
134 } | |
135 else | |
136 { | |
137 Fsetcdr (prev, XCDR (loop)); | |
138 } | |
139 } | |
140 else | |
141 prev = loop; | |
142 | |
143 loop = XCDR (loop); | |
144 } | |
145 | |
146 return retval; | |
147 } | |
148 | |
149 /* Remove dead objects from the various lists so that they | |
150 don't keep getting marked as long as this specifier exists and | |
151 therefore wasting memory. */ | |
152 | |
153 void | |
154 cleanup_specifiers (void) | |
155 { | |
156 Lisp_Object rest; | |
157 | |
158 for (rest = Vall_specifiers; | |
159 !NILP (rest); | |
160 rest = XSPECIFIER (rest)->next_specifier) | |
161 { | |
440 | 162 Lisp_Specifier *sp = XSPECIFIER (rest); |
428 | 163 /* This effectively changes the specifier specs. |
164 However, there's no need to call | |
165 recompute_cached_specifier_everywhere() or the | |
166 after-change methods because the only specs we | |
167 are removing are for dead objects, and they can | |
168 never have any effect on the specifier values: | |
169 specifiers can only be instantiated over live | |
170 objects, and you can't derive a dead object | |
171 from a live one. */ | |
172 sp->device_specs = cleanup_assoc_list (sp->device_specs); | |
173 sp->frame_specs = cleanup_assoc_list (sp->frame_specs); | |
174 sp->buffer_specs = cleanup_assoc_list (sp->buffer_specs); | |
175 /* windows are handled specially because dead windows | |
176 can be resurrected */ | |
177 } | |
178 } | |
179 | |
180 void | |
181 kill_specifier_buffer_locals (Lisp_Object buffer) | |
182 { | |
183 Lisp_Object rest; | |
184 | |
185 for (rest = Vall_specifiers; | |
186 !NILP (rest); | |
187 rest = XSPECIFIER (rest)->next_specifier) | |
188 { | |
440 | 189 Lisp_Specifier *sp = XSPECIFIER (rest); |
428 | 190 |
191 /* Make sure we're actually going to be changing something. | |
192 Fremove_specifier() always calls | |
193 recompute_cached_specifier_everywhere() (#### but should | |
194 be smarter about this). */ | |
195 if (!NILP (assq_no_quit (buffer, sp->buffer_specs))) | |
196 Fremove_specifier (rest, buffer, Qnil, Qnil); | |
197 } | |
198 } | |
199 | |
200 static Lisp_Object | |
201 mark_specifier (Lisp_Object obj) | |
202 { | |
440 | 203 Lisp_Specifier *specifier = XSPECIFIER (obj); |
428 | 204 |
205 mark_object (specifier->global_specs); | |
206 mark_object (specifier->device_specs); | |
207 mark_object (specifier->frame_specs); | |
208 mark_object (specifier->window_specs); | |
209 mark_object (specifier->buffer_specs); | |
210 mark_object (specifier->magic_parent); | |
211 mark_object (specifier->fallback); | |
212 if (!GHOST_SPECIFIER_P (XSPECIFIER (obj))) | |
213 MAYBE_SPECMETH (specifier, mark, (obj)); | |
214 return Qnil; | |
215 } | |
216 | |
217 /* The idea here is that the specifier specs point to locales | |
218 (windows, buffers, frames, and devices), and we want to make sure | |
219 that the specs disappear automatically when the associated locale | |
220 is no longer in use. For all but windows, "no longer in use" | |
221 corresponds exactly to when the object is deleted (non-deleted | |
222 objects are always held permanently in special lists, and deleted | |
223 objects are never on these lists and never reusable). To handle | |
224 this, we just have cleanup_specifiers() called periodically | |
225 (at the beginning of garbage collection); it removes all dead | |
226 objects. | |
227 | |
228 For windows, however, it's trickier because dead objects can be | |
229 converted to live ones again if the dead object is in a window | |
230 configuration. Therefore, for windows, "no longer in use" | |
231 corresponds to when the window object is garbage-collected. | |
232 We now use weak lists for this purpose. | |
233 | |
234 */ | |
235 | |
236 void | |
237 prune_specifiers (void) | |
238 { | |
239 Lisp_Object rest, prev = Qnil; | |
240 | |
241 for (rest = Vall_specifiers; | |
242 !NILP (rest); | |
243 rest = XSPECIFIER (rest)->next_specifier) | |
244 { | |
245 if (! marked_p (rest)) | |
246 { | |
440 | 247 Lisp_Specifier* sp = XSPECIFIER (rest); |
428 | 248 /* A bit of assertion that we're removing both parts of the |
249 magic one altogether */ | |
250 assert (!MAGIC_SPECIFIER_P(sp) | |
251 || (BODILY_SPECIFIER_P(sp) && marked_p (sp->fallback)) | |
252 || (GHOST_SPECIFIER_P(sp) && marked_p (sp->magic_parent))); | |
253 /* This specifier is garbage. Remove it from the list. */ | |
254 if (NILP (prev)) | |
255 Vall_specifiers = sp->next_specifier; | |
256 else | |
257 XSPECIFIER (prev)->next_specifier = sp->next_specifier; | |
258 } | |
259 else | |
260 prev = rest; | |
261 } | |
262 } | |
263 | |
264 static void | |
2286 | 265 print_specifier (Lisp_Object obj, Lisp_Object printcharfun, |
266 int UNUSED (escapeflag)) | |
428 | 267 { |
440 | 268 Lisp_Specifier *sp = XSPECIFIER (obj); |
428 | 269 int count = specpdl_depth (); |
270 Lisp_Object the_specs; | |
271 | |
272 if (print_readably) | |
563 | 273 printing_unreadable_object ("#<%s-specifier 0x%x>", |
274 sp->methods->name, sp->header.uid); | |
428 | 275 |
800 | 276 write_fmt_string (printcharfun, "#<%s-specifier global=", sp->methods->name); |
872 | 277 #if 0 |
278 /* #### Not obvious this is useful, and overrides user settings; if we | |
279 resurrect this, create variables like `print-specifier-length' so it | |
280 can be controlled. */ | |
428 | 281 specbind (Qprint_string_length, make_int (100)); |
282 specbind (Qprint_length, make_int (5)); | |
872 | 283 #endif |
428 | 284 the_specs = Fspecifier_specs (obj, Qglobal, Qnil, Qnil); |
285 if (NILP (the_specs)) | |
286 /* there are no global specs */ | |
826 | 287 write_c_string (printcharfun, "<unspecified>"); |
428 | 288 else |
289 print_internal (the_specs, printcharfun, 1); | |
290 if (!NILP (sp->fallback)) | |
291 { | |
800 | 292 write_fmt_string_lisp (printcharfun, " fallback=%S", 1, sp->fallback); |
428 | 293 } |
771 | 294 unbind_to (count); |
800 | 295 write_fmt_string (printcharfun, " 0x%x>", sp->header.uid); |
428 | 296 } |
297 | |
298 static void | |
299 finalize_specifier (void *header, int for_disksave) | |
300 { | |
440 | 301 Lisp_Specifier *sp = (Lisp_Specifier *) header; |
428 | 302 /* don't be snafued by the disksave finalization. */ |
303 if (!for_disksave && !GHOST_SPECIFIER_P(sp) && sp->caching) | |
304 { | |
1726 | 305 xfree (sp->caching, struct specifier_caching *); |
428 | 306 sp->caching = 0; |
307 } | |
308 } | |
309 | |
310 static int | |
311 specifier_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
312 { | |
440 | 313 Lisp_Specifier *s1 = XSPECIFIER (obj1); |
314 Lisp_Specifier *s2 = XSPECIFIER (obj2); | |
428 | 315 int retval; |
316 Lisp_Object old_inhibit_quit = Vinhibit_quit; | |
317 | |
318 /* This function can be called from within redisplay. | |
319 internal_equal can trigger a quit. That leads to Bad Things. */ | |
320 Vinhibit_quit = Qt; | |
321 | |
322 depth++; | |
323 retval = | |
324 (s1->methods == s2->methods && | |
325 internal_equal (s1->global_specs, s2->global_specs, depth) && | |
326 internal_equal (s1->device_specs, s2->device_specs, depth) && | |
327 internal_equal (s1->frame_specs, s2->frame_specs, depth) && | |
328 internal_equal (s1->window_specs, s2->window_specs, depth) && | |
329 internal_equal (s1->buffer_specs, s2->buffer_specs, depth) && | |
330 internal_equal (s1->fallback, s2->fallback, depth)); | |
331 | |
332 if (retval && HAS_SPECMETH_P (s1, equal)) | |
333 retval = SPECMETH (s1, equal, (obj1, obj2, depth - 1)); | |
334 | |
335 Vinhibit_quit = old_inhibit_quit; | |
336 return retval; | |
337 } | |
338 | |
2515 | 339 static Hashcode |
428 | 340 specifier_hash (Lisp_Object obj, int depth) |
341 { | |
440 | 342 Lisp_Specifier *s = XSPECIFIER (obj); |
428 | 343 |
344 /* specifier hashing is a bit problematic because there are so | |
345 many places where data can be stored. We pick what are perhaps | |
346 the most likely places where interesting stuff will be. */ | |
347 return HASH5 ((HAS_SPECMETH_P (s, hash) ? | |
348 SPECMETH (s, hash, (obj, depth)) : 0), | |
2515 | 349 (Hashcode) s->methods, |
428 | 350 internal_hash (s->global_specs, depth + 1), |
351 internal_hash (s->frame_specs, depth + 1), | |
352 internal_hash (s->buffer_specs, depth + 1)); | |
353 } | |
354 | |
665 | 355 inline static Bytecount |
356 aligned_sizeof_specifier (Bytecount specifier_type_specific_size) | |
456 | 357 { |
826 | 358 return MAX_ALIGN_SIZE (offsetof (Lisp_Specifier, data) |
359 + specifier_type_specific_size); | |
456 | 360 } |
361 | |
665 | 362 static Bytecount |
442 | 363 sizeof_specifier (const void *header) |
428 | 364 { |
456 | 365 const Lisp_Specifier *p = (const Lisp_Specifier *) header; |
366 return aligned_sizeof_specifier (GHOST_SPECIFIER_P (p) | |
367 ? 0 | |
368 : p->methods->extra_data_size); | |
428 | 369 } |
370 | |
1204 | 371 static const struct memory_description specifier_methods_description_1[] = { |
440 | 372 { XD_LISP_OBJECT, offsetof (struct specifier_methods, predicate_symbol) }, |
428 | 373 { XD_END } |
374 }; | |
375 | |
1204 | 376 const struct sized_memory_description specifier_methods_description = { |
440 | 377 sizeof (struct specifier_methods), |
428 | 378 specifier_methods_description_1 |
379 }; | |
380 | |
1204 | 381 static const struct memory_description specifier_caching_description_1[] = { |
428 | 382 { XD_END } |
383 }; | |
384 | |
1204 | 385 static const struct sized_memory_description specifier_caching_description = { |
440 | 386 sizeof (struct specifier_caching), |
428 | 387 specifier_caching_description_1 |
388 }; | |
389 | |
1204 | 390 static const struct sized_memory_description specifier_extra_description_map[] |
391 = { | |
392 { offsetof (Lisp_Specifier, methods) }, | |
393 { offsetof (struct specifier_methods, extra_description) }, | |
394 { -1 }, | |
395 }; | |
396 | |
397 const struct memory_description specifier_description[] = { | |
2367 | 398 { XD_BLOCK_PTR, offsetof (Lisp_Specifier, methods), 1, |
2551 | 399 { &specifier_methods_description } }, |
440 | 400 { XD_LO_LINK, offsetof (Lisp_Specifier, next_specifier) }, |
401 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, global_specs) }, | |
402 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, device_specs) }, | |
403 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, frame_specs) }, | |
404 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, window_specs) }, | |
405 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, buffer_specs) }, | |
2367 | 406 { XD_BLOCK_PTR, offsetof (Lisp_Specifier, caching), 1, |
2551 | 407 { &specifier_caching_description } }, |
440 | 408 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, magic_parent) }, |
409 { XD_LISP_OBJECT, offsetof (Lisp_Specifier, fallback) }, | |
2367 | 410 { XD_BLOCK_ARRAY, offsetof (Lisp_Specifier, data), 1, |
2551 | 411 { specifier_extra_description_map } }, |
428 | 412 { XD_END } |
413 }; | |
414 | |
1204 | 415 static const struct memory_description specifier_empty_extra_description_1[] = |
416 { | |
417 { XD_END } | |
418 }; | |
419 | |
420 const struct sized_memory_description specifier_empty_extra_description = { | |
421 0, specifier_empty_extra_description_1 | |
422 }; | |
423 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
424 DEFINE_SIZABLE_LISP_OBJECT ("specifier", specifier, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
425 mark_specifier, print_specifier, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
426 finalize_specifier, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
427 specifier_equal, specifier_hash, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
428 specifier_description, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
429 sizeof_specifier, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
430 Lisp_Specifier); |
428 | 431 |
432 /************************************************************************/ | |
433 /* Creating specifiers */ | |
434 /************************************************************************/ | |
435 | |
436 static struct specifier_methods * | |
578 | 437 decode_specifier_type (Lisp_Object type, Error_Behavior errb) |
428 | 438 { |
439 int i; | |
440 | |
441 for (i = 0; i < Dynarr_length (the_specifier_type_entry_dynarr); i++) | |
442 { | |
443 if (EQ (type, Dynarr_at (the_specifier_type_entry_dynarr, i).symbol)) | |
444 return Dynarr_at (the_specifier_type_entry_dynarr, i).meths; | |
445 } | |
446 | |
563 | 447 maybe_invalid_argument ("Invalid specifier type", |
442 | 448 type, Qspecifier, errb); |
428 | 449 |
450 return 0; | |
451 } | |
452 | |
453 static int | |
454 valid_specifier_type_p (Lisp_Object type) | |
455 { | |
456 return decode_specifier_type (type, ERROR_ME_NOT) != 0; | |
457 } | |
458 | |
459 DEFUN ("valid-specifier-type-p", Fvalid_specifier_type_p, 1, 1, 0, /* | |
460 Given a SPECIFIER-TYPE, return non-nil if it is valid. | |
2953 | 461 Valid types are `generic', `integer', `boolean', `color', `font', `image', |
462 `face-boolean', and `toolbar'. | |
428 | 463 */ |
464 (specifier_type)) | |
465 { | |
466 return valid_specifier_type_p (specifier_type) ? Qt : Qnil; | |
467 } | |
468 | |
469 DEFUN ("specifier-type-list", Fspecifier_type_list, 0, 0, 0, /* | |
470 Return a list of valid specifier types. | |
471 */ | |
472 ()) | |
473 { | |
474 return Fcopy_sequence (Vspecifier_type_list); | |
475 } | |
476 | |
477 void | |
478 add_entry_to_specifier_type_list (Lisp_Object symbol, | |
479 struct specifier_methods *meths) | |
480 { | |
481 struct specifier_type_entry entry; | |
482 | |
483 entry.symbol = symbol; | |
484 entry.meths = meths; | |
485 Dynarr_add (the_specifier_type_entry_dynarr, entry); | |
486 Vspecifier_type_list = Fcons (symbol, Vspecifier_type_list); | |
487 } | |
488 | |
489 static Lisp_Object | |
490 make_specifier_internal (struct specifier_methods *spec_meths, | |
665 | 491 Bytecount data_size, int call_create_meth) |
428 | 492 { |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
493 Lisp_Object specifier = |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
494 ALLOC_SIZED_LISP_OBJECT (aligned_sizeof_specifier (data_size), specifier); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
495 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 496 |
497 sp->methods = spec_meths; | |
498 sp->global_specs = Qnil; | |
499 sp->device_specs = Qnil; | |
500 sp->frame_specs = Qnil; | |
501 sp->window_specs = make_weak_list (WEAK_LIST_KEY_ASSOC); | |
502 sp->buffer_specs = Qnil; | |
503 sp->fallback = Qnil; | |
504 sp->magic_parent = Qnil; | |
505 sp->caching = 0; | |
506 sp->next_specifier = Vall_specifiers; | |
507 | |
508 Vall_specifiers = specifier; | |
509 | |
510 if (call_create_meth) | |
511 { | |
512 struct gcpro gcpro1; | |
513 GCPRO1 (specifier); | |
514 MAYBE_SPECMETH (XSPECIFIER (specifier), create, (specifier)); | |
515 UNGCPRO; | |
516 } | |
517 return specifier; | |
518 } | |
519 | |
520 static Lisp_Object | |
521 make_specifier (struct specifier_methods *meths) | |
522 { | |
523 return make_specifier_internal (meths, meths->extra_data_size, 1); | |
524 } | |
525 | |
526 Lisp_Object | |
527 make_magic_specifier (Lisp_Object type) | |
528 { | |
529 /* This function can GC */ | |
530 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); | |
531 Lisp_Object bodily, ghost; | |
532 struct gcpro gcpro1; | |
533 | |
534 bodily = make_specifier (meths); | |
535 GCPRO1 (bodily); | |
536 ghost = make_specifier_internal (meths, 0, 0); | |
537 UNGCPRO; | |
538 | |
539 /* Connect guys together */ | |
540 XSPECIFIER(bodily)->magic_parent = Qt; | |
541 XSPECIFIER(bodily)->fallback = ghost; | |
542 XSPECIFIER(ghost)->magic_parent = bodily; | |
543 | |
544 return bodily; | |
545 } | |
546 | |
547 DEFUN ("make-specifier", Fmake_specifier, 1, 1, 0, /* | |
548 Return a new specifier object of type TYPE. | |
549 | |
550 A specifier is an object that can be used to keep track of a property | |
551 whose value can be per-buffer, per-window, per-frame, or per-device, | |
442 | 552 and can further be restricted to a particular console-type or |
553 device-class. Specifiers are used, for example, for the various | |
554 built-in properties of a face; this allows a face to have different | |
555 values in different frames, buffers, etc. | |
556 | |
557 When speaking of the value of a specifier, it is important to | |
558 distinguish between the *setting* of a specifier, called an | |
559 \"instantiator\", and the *actual value*, called an \"instance\". You | |
560 put various possible instantiators (i.e. settings) into a specifier | |
561 and associate them with particular locales (buffer, window, frame, | |
562 device, global), and then the instance (i.e. actual value) is | |
563 retrieved in a specific domain (window, frame, device) by looking | |
564 through the possible instantiators (i.e. settings). This process is | |
565 called \"instantiation\". | |
444 | 566 |
442 | 567 To put settings into a specifier, use `set-specifier', or the |
568 lower-level functions `add-spec-to-specifier' and | |
569 `add-spec-list-to-specifier'. You can also temporarily bind a setting | |
570 to a specifier using `let-specifier'. To retrieve settings, use | |
571 `specifier-specs', or its lower-level counterpart | |
2953 | 572 `specifier-spec-list'. |
573 | |
574 To determine the actual value (i.e. the instance) in a particular domain, use | |
575 `specifier-instance'. To determine the corresponding setting that yielded | |
576 the value (i.e. the instantiator), use `specifier-instantiator'. | |
442 | 577 |
578 For more information, see `set-specifier', `specifier-instance', | |
428 | 579 `specifier-specs', and `add-spec-to-specifier'; or, for a detailed |
442 | 580 description of specifiers, including how exactly the instantiation |
581 process works, see the chapter on specifiers in the XEmacs Lisp | |
582 Reference Manual. | |
428 | 583 |
584 TYPE specifies the particular type of specifier, and should be one of | |
2953 | 585 the symbols `generic', `integer', `natnum', `boolean', `color', `font', |
586 `image', `face-boolean', `display-table', `gutter', `gutter-size', | |
587 `gutter-visible' or `toolbar'. | |
442 | 588 |
589 For more information on particular types of specifiers, see the | |
590 functions `make-generic-specifier', `make-integer-specifier', | |
591 `make-natnum-specifier', `make-boolean-specifier', | |
592 `make-color-specifier', `make-font-specifier', `make-image-specifier', | |
593 `make-face-boolean-specifier', `make-gutter-size-specifier', | |
594 `make-gutter-visible-specifier', `default-toolbar', `default-gutter', | |
595 and `current-display-table'. | |
428 | 596 */ |
597 (type)) | |
598 { | |
599 /* This function can GC */ | |
442 | 600 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); |
428 | 601 |
602 return make_specifier (meths); | |
603 } | |
604 | |
605 DEFUN ("specifierp", Fspecifierp, 1, 1, 0, /* | |
606 Return t if OBJECT is a specifier. | |
607 | |
608 A specifier is an object that can be used to keep track of a property | |
609 whose value can be per-buffer, per-window, per-frame, or per-device, | |
610 and can further be restricted to a particular console-type or device-class. | |
611 See `make-specifier'. | |
612 */ | |
613 (object)) | |
614 { | |
615 return SPECIFIERP (object) ? Qt : Qnil; | |
616 } | |
617 | |
618 DEFUN ("specifier-type", Fspecifier_type, 1, 1, 0, /* | |
619 Return the type of SPECIFIER. | |
620 */ | |
621 (specifier)) | |
622 { | |
623 CHECK_SPECIFIER (specifier); | |
624 return intern (XSPECIFIER (specifier)->methods->name); | |
625 } | |
626 | |
627 | |
628 /************************************************************************/ | |
629 /* Locales and domains */ | |
630 /************************************************************************/ | |
631 | |
632 DEFUN ("valid-specifier-locale-p", Fvalid_specifier_locale_p, 1, 1, 0, /* | |
633 Return t if LOCALE is a valid specifier locale. | |
2953 | 634 Valid locales are devices, frames, windows, buffers, and `global'. |
428 | 635 \(nil is not valid.) |
636 */ | |
637 (locale)) | |
638 { | |
639 /* This cannot GC. */ | |
640 return ((DEVICEP (locale) && DEVICE_LIVE_P (XDEVICE (locale))) || | |
641 (FRAMEP (locale) && FRAME_LIVE_P (XFRAME (locale))) || | |
642 (BUFFERP (locale) && BUFFER_LIVE_P (XBUFFER (locale))) || | |
643 /* dead windows are allowed because they may become live | |
644 windows again when a window configuration is restored */ | |
645 WINDOWP (locale) || | |
646 EQ (locale, Qglobal)) | |
647 ? Qt : Qnil; | |
648 } | |
649 | |
650 DEFUN ("valid-specifier-domain-p", Fvalid_specifier_domain_p, 1, 1, 0, /* | |
651 Return t if DOMAIN is a valid specifier domain. | |
2953 | 652 A domain is used to instantiate a specifier (i.e. determine the specifier's |
442 | 653 value in that domain). Valid domains are image instances, windows, frames, |
654 and devices. \(nil is not valid.) image instances are pseudo-domains since | |
655 instantiation will actually occur in the window the image instance itself is | |
656 instantiated in. | |
428 | 657 */ |
658 (domain)) | |
659 { | |
660 /* This cannot GC. */ | |
661 return ((DEVICEP (domain) && DEVICE_LIVE_P (XDEVICE (domain))) || | |
662 (FRAMEP (domain) && FRAME_LIVE_P (XFRAME (domain))) || | |
442 | 663 (WINDOWP (domain) && WINDOW_LIVE_P (XWINDOW (domain))) || |
664 /* #### get image instances out of domains! */ | |
665 IMAGE_INSTANCEP (domain)) | |
428 | 666 ? Qt : Qnil; |
667 } | |
668 | |
442 | 669 DEFUN ("valid-specifier-locale-type-p", Fvalid_specifier_locale_type_p, 1, 1, 0, |
670 /* | |
428 | 671 Given a specifier LOCALE-TYPE, return non-nil if it is valid. |
2953 | 672 Valid locale types are `global', `device', `frame', `window', and `buffer'. |
428 | 673 \(Note, however, that in functions that accept either a locale or a locale |
2953 | 674 type, `global' is considered an individual locale.) |
428 | 675 */ |
676 (locale_type)) | |
677 { | |
678 /* This cannot GC. */ | |
679 return (EQ (locale_type, Qglobal) || | |
680 EQ (locale_type, Qdevice) || | |
681 EQ (locale_type, Qframe) || | |
682 EQ (locale_type, Qwindow) || | |
683 EQ (locale_type, Qbuffer)) ? Qt : Qnil; | |
684 } | |
685 | |
686 static void | |
687 check_valid_locale_or_locale_type (Lisp_Object locale) | |
688 { | |
689 /* This cannot GC. */ | |
690 if (EQ (locale, Qall) || | |
691 !NILP (Fvalid_specifier_locale_p (locale)) || | |
692 !NILP (Fvalid_specifier_locale_type_p (locale))) | |
693 return; | |
563 | 694 invalid_argument ("Invalid specifier locale or locale type", locale); |
428 | 695 } |
696 | |
697 DEFUN ("specifier-locale-type-from-locale", Fspecifier_locale_type_from_locale, | |
698 1, 1, 0, /* | |
699 Given a specifier LOCALE, return its type. | |
700 */ | |
701 (locale)) | |
702 { | |
703 /* This cannot GC. */ | |
704 if (NILP (Fvalid_specifier_locale_p (locale))) | |
563 | 705 invalid_argument ("Invalid specifier locale", |
442 | 706 locale); |
428 | 707 if (DEVICEP (locale)) return Qdevice; |
708 if (FRAMEP (locale)) return Qframe; | |
709 if (WINDOWP (locale)) return Qwindow; | |
710 if (BUFFERP (locale)) return Qbuffer; | |
711 assert (EQ (locale, Qglobal)); | |
712 return Qglobal; | |
713 } | |
714 | |
715 static Lisp_Object | |
716 decode_locale (Lisp_Object locale) | |
717 { | |
718 /* This cannot GC. */ | |
719 if (NILP (locale)) | |
720 return Qglobal; | |
721 else if (!NILP (Fvalid_specifier_locale_p (locale))) | |
722 return locale; | |
723 else | |
563 | 724 invalid_argument ("Invalid specifier locale", |
442 | 725 locale); |
428 | 726 |
727 return Qnil; | |
728 } | |
729 | |
730 static enum spec_locale_type | |
731 decode_locale_type (Lisp_Object locale_type) | |
732 { | |
733 /* This cannot GC. */ | |
734 if (EQ (locale_type, Qglobal)) return LOCALE_GLOBAL; | |
735 if (EQ (locale_type, Qdevice)) return LOCALE_DEVICE; | |
736 if (EQ (locale_type, Qframe)) return LOCALE_FRAME; | |
737 if (EQ (locale_type, Qwindow)) return LOCALE_WINDOW; | |
738 if (EQ (locale_type, Qbuffer)) return LOCALE_BUFFER; | |
739 | |
563 | 740 invalid_argument ("Invalid specifier locale type", |
442 | 741 locale_type); |
1204 | 742 RETURN_NOT_REACHED (LOCALE_GLOBAL); |
428 | 743 } |
744 | |
745 Lisp_Object | |
746 decode_locale_list (Lisp_Object locale) | |
747 { | |
748 /* This cannot GC. */ | |
749 /* The return value of this function must be GCPRO'd. */ | |
750 if (NILP (locale)) | |
751 { | |
752 return list1 (Qall); | |
753 } | |
754 else if (CONSP (locale)) | |
755 { | |
756 EXTERNAL_LIST_LOOP_2 (elt, locale) | |
757 check_valid_locale_or_locale_type (elt); | |
758 return locale; | |
759 } | |
760 else | |
761 { | |
762 check_valid_locale_or_locale_type (locale); | |
763 return list1 (locale); | |
764 } | |
765 } | |
766 | |
767 static enum spec_locale_type | |
768 locale_type_from_locale (Lisp_Object locale) | |
769 { | |
770 return decode_locale_type (Fspecifier_locale_type_from_locale (locale)); | |
771 } | |
772 | |
773 static void | |
774 check_valid_domain (Lisp_Object domain) | |
775 { | |
776 if (NILP (Fvalid_specifier_domain_p (domain))) | |
563 | 777 invalid_argument ("Invalid specifier domain", |
442 | 778 domain); |
428 | 779 } |
780 | |
442 | 781 Lisp_Object |
428 | 782 decode_domain (Lisp_Object domain) |
783 { | |
784 if (NILP (domain)) | |
785 return Fselected_window (Qnil); | |
786 check_valid_domain (domain); | |
787 return domain; | |
788 } | |
789 | |
790 | |
791 /************************************************************************/ | |
792 /* Tags */ | |
793 /************************************************************************/ | |
794 | |
795 DEFUN ("valid-specifier-tag-p", Fvalid_specifier_tag_p, 1, 1, 0, /* | |
796 Return non-nil if TAG is a valid specifier tag. | |
797 See also `valid-specifier-tag-set-p'. | |
798 */ | |
799 (tag)) | |
800 { | |
801 return (valid_console_type_p (tag) || | |
802 valid_device_class_p (tag) || | |
803 !NILP (assq_no_quit (tag, Vuser_defined_tags))) ? Qt : Qnil; | |
804 } | |
805 | |
806 DEFUN ("valid-specifier-tag-set-p", Fvalid_specifier_tag_set_p, 1, 1, 0, /* | |
807 Return non-nil if TAG-SET is a valid specifier tag set. | |
808 | |
809 A specifier tag set is an entity that is attached to an instantiator | |
810 and can be used to restrict the scope of that instantiator to a | |
811 particular device class or device type and/or to mark instantiators | |
812 added by a particular package so that they can be later removed. | |
813 | |
814 A specifier tag set consists of a list of zero of more specifier tags, | |
815 each of which is a symbol that is recognized by XEmacs as a tag. | |
816 \(The valid device types and device classes are always tags, as are | |
817 any tags defined by `define-specifier-tag'.) It is called a "tag set" | |
818 \(as opposed to a list) because the order of the tags or the number of | |
819 times a particular tag occurs does not matter. | |
820 | |
821 Each tag has a predicate associated with it, which specifies whether | |
822 that tag applies to a particular device. The tags which are device types | |
823 and classes match devices of that type or class. User-defined tags can | |
824 have any predicate, or none (meaning that all devices match). When | |
2953 | 825 attempting to instantiate a specifier, a particular instantiator is only |
826 considered if the device of the domain being instantiated over matches | |
428 | 827 all tags in the tag set attached to that instantiator. |
828 | |
829 Most of the time, a tag set is not specified, and the instantiator | |
830 gets a null tag set, which matches all devices. | |
831 */ | |
832 (tag_set)) | |
833 { | |
834 Lisp_Object rest; | |
835 | |
836 for (rest = tag_set; !NILP (rest); rest = XCDR (rest)) | |
837 { | |
838 if (!CONSP (rest)) | |
839 return Qnil; | |
840 if (NILP (Fvalid_specifier_tag_p (XCAR (rest)))) | |
841 return Qnil; | |
842 QUIT; | |
843 } | |
844 return Qt; | |
845 } | |
846 | |
847 Lisp_Object | |
848 decode_specifier_tag_set (Lisp_Object tag_set) | |
849 { | |
850 /* The return value of this function must be GCPRO'd. */ | |
851 if (!NILP (Fvalid_specifier_tag_p (tag_set))) | |
852 return list1 (tag_set); | |
853 if (NILP (Fvalid_specifier_tag_set_p (tag_set))) | |
563 | 854 invalid_argument ("Invalid specifier tag-set", |
442 | 855 tag_set); |
428 | 856 return tag_set; |
857 } | |
858 | |
859 static Lisp_Object | |
860 canonicalize_tag_set (Lisp_Object tag_set) | |
861 { | |
862 int len = XINT (Flength (tag_set)); | |
863 Lisp_Object *tags, rest; | |
864 int i, j; | |
865 | |
866 /* We assume in this function that the tag_set has already been | |
867 validated, so there are no surprises. */ | |
868 | |
869 if (len == 0 || len == 1) | |
870 /* most common case */ | |
871 return tag_set; | |
872 | |
873 tags = alloca_array (Lisp_Object, len); | |
874 | |
875 i = 0; | |
876 LIST_LOOP (rest, tag_set) | |
877 tags[i++] = XCAR (rest); | |
878 | |
879 /* Sort the list of tags. We use a bubble sort here (copied from | |
880 extent_fragment_update()) -- reduces the function call overhead, | |
881 and is the fastest sort for small numbers of items. */ | |
882 | |
883 for (i = 1; i < len; i++) | |
884 { | |
885 j = i - 1; | |
886 while (j >= 0 && | |
793 | 887 qxestrcmp (XSTRING_DATA (XSYMBOL (tags[j])->name), |
888 XSTRING_DATA (XSYMBOL (tags[j+1])->name)) > 0) | |
428 | 889 { |
890 Lisp_Object tmp = tags[j]; | |
891 tags[j] = tags[j+1]; | |
892 tags[j+1] = tmp; | |
893 j--; | |
894 } | |
895 } | |
896 | |
897 /* Now eliminate duplicates. */ | |
898 | |
899 for (i = 1, j = 1; i < len; i++) | |
900 { | |
901 /* j holds the destination, i the source. */ | |
902 if (!EQ (tags[i], tags[i-1])) | |
903 tags[j++] = tags[i]; | |
904 } | |
905 | |
906 return Flist (j, tags); | |
907 } | |
908 | |
909 DEFUN ("canonicalize-tag-set", Fcanonicalize_tag_set, 1, 1, 0, /* | |
910 Canonicalize the given tag set. | |
911 Two canonicalized tag sets can be compared with `equal' to see if they | |
912 represent the same tag set. (Specifically, canonicalizing involves | |
913 sorting by symbol name and removing duplicates.) | |
914 */ | |
915 (tag_set)) | |
916 { | |
917 if (NILP (Fvalid_specifier_tag_set_p (tag_set))) | |
563 | 918 invalid_argument ("Invalid tag set", tag_set); |
428 | 919 return canonicalize_tag_set (tag_set); |
920 } | |
921 | |
922 static int | |
923 device_matches_specifier_tag_set_p (Lisp_Object device, Lisp_Object tag_set) | |
924 { | |
925 Lisp_Object devtype, devclass, rest; | |
926 struct device *d = XDEVICE (device); | |
927 | |
928 devtype = DEVICE_TYPE (d); | |
929 devclass = DEVICE_CLASS (d); | |
930 | |
931 LIST_LOOP (rest, tag_set) | |
932 { | |
933 Lisp_Object tag = XCAR (rest); | |
934 Lisp_Object assoc; | |
935 | |
936 if (EQ (tag, devtype) || EQ (tag, devclass)) | |
937 continue; | |
938 assoc = assq_no_quit (tag, DEVICE_USER_DEFINED_TAGS (d)); | |
939 /* other built-in tags (device types/classes) are not in | |
940 the user-defined-tags list. */ | |
941 if (NILP (assoc) || NILP (XCDR (assoc))) | |
942 return 0; | |
943 } | |
944 | |
945 return 1; | |
946 } | |
947 | |
442 | 948 DEFUN ("device-matches-specifier-tag-set-p", |
949 Fdevice_matches_specifier_tag_set_p, 2, 2, 0, /* | |
428 | 950 Return non-nil if DEVICE matches specifier tag set TAG-SET. |
951 This means that DEVICE matches each tag in the tag set. (Every | |
952 tag recognized by XEmacs has a predicate associated with it that | |
953 specifies which devices match it.) | |
954 */ | |
955 (device, tag_set)) | |
956 { | |
957 CHECK_LIVE_DEVICE (device); | |
958 | |
959 if (NILP (Fvalid_specifier_tag_set_p (tag_set))) | |
563 | 960 invalid_argument ("Invalid tag set", tag_set); |
428 | 961 |
962 return device_matches_specifier_tag_set_p (device, tag_set) ? Qt : Qnil; | |
963 } | |
964 | |
965 DEFUN ("define-specifier-tag", Fdefine_specifier_tag, 1, 2, 0, /* | |
966 Define a new specifier tag. | |
967 If PREDICATE is specified, it should be a function of one argument | |
968 \(a device) that specifies whether the tag matches that particular | |
969 device. If PREDICATE is omitted, the tag matches all devices. | |
970 | |
971 You can redefine an existing user-defined specifier tag. However, | |
972 you cannot redefine the built-in specifier tags (the device types | |
2953 | 973 and classes) or the symbols nil, t, `all', or `global'. |
428 | 974 */ |
975 (tag, predicate)) | |
976 { | |
977 Lisp_Object assoc, devcons, concons; | |
978 int recompute = 0; | |
979 | |
980 CHECK_SYMBOL (tag); | |
981 if (valid_device_class_p (tag) || | |
982 valid_console_type_p (tag)) | |
563 | 983 invalid_change ("Cannot redefine built-in specifier tags", tag); |
428 | 984 /* Try to prevent common instantiators and locales from being |
985 redefined, to reduce ambiguity */ | |
986 if (NILP (tag) || EQ (tag, Qt) || EQ (tag, Qall) || EQ (tag, Qglobal)) | |
2953 | 987 invalid_change ("Cannot define nil, t, `all', or `global'", tag); |
428 | 988 assoc = assq_no_quit (tag, Vuser_defined_tags); |
989 if (NILP (assoc)) | |
990 { | |
991 recompute = 1; | |
992 Vuser_defined_tags = Fcons (Fcons (tag, predicate), Vuser_defined_tags); | |
993 DEVICE_LOOP_NO_BREAK (devcons, concons) | |
994 { | |
995 struct device *d = XDEVICE (XCAR (devcons)); | |
996 /* Initially set the value to t in case of error | |
997 in predicate */ | |
998 DEVICE_USER_DEFINED_TAGS (d) = | |
999 Fcons (Fcons (tag, Qt), DEVICE_USER_DEFINED_TAGS (d)); | |
1000 } | |
1001 } | |
1002 else if (!NILP (predicate) && !NILP (XCDR (assoc))) | |
1003 { | |
1004 recompute = 1; | |
1005 XCDR (assoc) = predicate; | |
1006 } | |
1007 | |
1008 /* recompute the tag values for all devices. However, in the special | |
1009 case where both the old and new predicates are nil, we know that | |
1010 we don't have to do this. (It's probably common for people to | |
1011 call (define-specifier-tag) more than once on the same tag, | |
1012 and the most common case is where PREDICATE is not specified.) */ | |
1013 | |
1014 if (recompute) | |
1015 { | |
1016 DEVICE_LOOP_NO_BREAK (devcons, concons) | |
1017 { | |
1018 Lisp_Object device = XCAR (devcons); | |
1019 assoc = assq_no_quit (tag, | |
1020 DEVICE_USER_DEFINED_TAGS (XDEVICE (device))); | |
1021 assert (CONSP (assoc)); | |
1022 if (NILP (predicate)) | |
1023 XCDR (assoc) = Qt; | |
1024 else | |
1025 XCDR (assoc) = !NILP (call1 (predicate, device)) ? Qt : Qnil; | |
1026 } | |
1027 } | |
1028 | |
1029 return Qnil; | |
1030 } | |
1031 | |
1032 /* Called at device-creation time to initialize the user-defined | |
1033 tag values for the newly-created device. */ | |
1034 | |
1035 void | |
1036 setup_device_initial_specifier_tags (struct device *d) | |
1037 { | |
1038 Lisp_Object rest, rest2; | |
793 | 1039 Lisp_Object device = wrap_device (d); |
1040 | |
428 | 1041 DEVICE_USER_DEFINED_TAGS (d) = Fcopy_alist (Vuser_defined_tags); |
1042 | |
1043 /* Now set up the initial values */ | |
1044 LIST_LOOP (rest, DEVICE_USER_DEFINED_TAGS (d)) | |
1045 XCDR (XCAR (rest)) = Qt; | |
1046 | |
1047 for (rest = Vuser_defined_tags, rest2 = DEVICE_USER_DEFINED_TAGS (d); | |
1048 !NILP (rest); rest = XCDR (rest), rest2 = XCDR (rest2)) | |
1049 { | |
1050 Lisp_Object predicate = XCDR (XCAR (rest)); | |
1051 if (NILP (predicate)) | |
1052 XCDR (XCAR (rest2)) = Qt; | |
1053 else | |
872 | 1054 XCDR (XCAR (rest2)) = |
1055 !NILP (call_critical_lisp_code (d, predicate, device)) ? Qt : Qnil; | |
428 | 1056 } |
1057 } | |
1058 | |
442 | 1059 DEFUN ("device-matching-specifier-tag-list", |
1060 Fdevice_matching_specifier_tag_list, | |
428 | 1061 0, 1, 0, /* |
1062 Return a list of all specifier tags matching DEVICE. | |
1063 DEVICE defaults to the selected device if omitted. | |
1064 */ | |
1065 (device)) | |
1066 { | |
1067 struct device *d = decode_device (device); | |
1068 Lisp_Object rest, list = Qnil; | |
1069 struct gcpro gcpro1; | |
1070 | |
1071 GCPRO1 (list); | |
1072 | |
1073 LIST_LOOP (rest, DEVICE_USER_DEFINED_TAGS (d)) | |
1074 { | |
1075 if (!NILP (XCDR (XCAR (rest)))) | |
1076 list = Fcons (XCAR (XCAR (rest)), list); | |
1077 } | |
1078 | |
1079 list = Fnreverse (list); | |
1080 list = Fcons (DEVICE_CLASS (d), list); | |
1081 list = Fcons (DEVICE_TYPE (d), list); | |
1082 | |
1083 RETURN_UNGCPRO (list); | |
1084 } | |
1085 | |
1086 DEFUN ("specifier-tag-list", Fspecifier_tag_list, 0, 0, 0, /* | |
1087 Return a list of all currently-defined specifier tags. | |
1088 This includes the built-in ones (the device types and classes). | |
1089 */ | |
1090 ()) | |
1091 { | |
1092 Lisp_Object list = Qnil, rest; | |
1093 struct gcpro gcpro1; | |
1094 | |
1095 GCPRO1 (list); | |
1096 | |
1097 LIST_LOOP (rest, Vuser_defined_tags) | |
1098 list = Fcons (XCAR (XCAR (rest)), list); | |
1099 | |
1100 list = Fnreverse (list); | |
1101 list = nconc2 (Fcopy_sequence (Vdevice_class_list), list); | |
1102 list = nconc2 (Fcopy_sequence (Vconsole_type_list), list); | |
1103 | |
1104 RETURN_UNGCPRO (list); | |
1105 } | |
1106 | |
1107 DEFUN ("specifier-tag-predicate", Fspecifier_tag_predicate, 1, 1, 0, /* | |
1108 Return the predicate for the given specifier tag. | |
1109 */ | |
1110 (tag)) | |
1111 { | |
1112 /* The return value of this function must be GCPRO'd. */ | |
1113 CHECK_SYMBOL (tag); | |
1114 | |
1115 if (NILP (Fvalid_specifier_tag_p (tag))) | |
563 | 1116 invalid_argument ("Invalid specifier tag", |
442 | 1117 tag); |
428 | 1118 |
1119 /* Make up some predicates for the built-in types */ | |
1120 | |
1121 if (valid_console_type_p (tag)) | |
1122 return list3 (Qlambda, list1 (Qdevice), | |
1123 list3 (Qeq, list2 (Qquote, tag), | |
1124 list2 (Qconsole_type, Qdevice))); | |
1125 | |
1126 if (valid_device_class_p (tag)) | |
1127 return list3 (Qlambda, list1 (Qdevice), | |
1128 list3 (Qeq, list2 (Qquote, tag), | |
1129 list2 (Qdevice_class, Qdevice))); | |
1130 | |
1131 return XCDR (assq_no_quit (tag, Vuser_defined_tags)); | |
1132 } | |
1133 | |
1134 /* Return true if A "matches" B. If EXACT_P is 0, A must be a subset of B. | |
1135 Otherwise, A must be `equal' to B. The sets must be canonicalized. */ | |
1136 static int | |
1137 tag_sets_match_p (Lisp_Object a, Lisp_Object b, int exact_p) | |
1138 { | |
1139 if (!exact_p) | |
1140 { | |
1141 while (!NILP (a) && !NILP (b)) | |
1142 { | |
1143 if (EQ (XCAR (a), XCAR (b))) | |
1144 a = XCDR (a); | |
1145 b = XCDR (b); | |
1146 } | |
1147 | |
1148 return NILP (a); | |
1149 } | |
1150 else | |
1151 { | |
1152 while (!NILP (a) && !NILP (b)) | |
1153 { | |
1154 if (!EQ (XCAR (a), XCAR (b))) | |
1155 return 0; | |
1156 a = XCDR (a); | |
1157 b = XCDR (b); | |
1158 } | |
1159 | |
1160 return NILP (a) && NILP (b); | |
1161 } | |
1162 } | |
1163 | |
1164 | |
1165 /************************************************************************/ | |
1166 /* Spec-lists and inst-lists */ | |
1167 /************************************************************************/ | |
1168 | |
1169 static Lisp_Object | |
1170 call_validate_method (Lisp_Object boxed_method, Lisp_Object instantiator) | |
1171 { | |
1172 ((void (*)(Lisp_Object)) get_opaque_ptr (boxed_method)) (instantiator); | |
1173 return Qt; | |
1174 } | |
1175 | |
1176 static Lisp_Object | |
1177 check_valid_instantiator (Lisp_Object instantiator, | |
1178 struct specifier_methods *meths, | |
578 | 1179 Error_Behavior errb) |
428 | 1180 { |
1181 if (meths->validate_method) | |
1182 { | |
1183 Lisp_Object retval; | |
1184 | |
1185 if (ERRB_EQ (errb, ERROR_ME)) | |
1186 { | |
1187 (meths->validate_method) (instantiator); | |
1188 retval = Qt; | |
1189 } | |
1190 else | |
1191 { | |
1192 Lisp_Object opaque = make_opaque_ptr ((void *) | |
1193 meths->validate_method); | |
1194 struct gcpro gcpro1; | |
1195 | |
1196 GCPRO1 (opaque); | |
1197 retval = call_with_suspended_errors | |
1198 ((lisp_fn_t) call_validate_method, | |
1199 Qnil, Qspecifier, errb, 2, opaque, instantiator); | |
1200 | |
1201 free_opaque_ptr (opaque); | |
1202 UNGCPRO; | |
1203 } | |
1204 | |
1205 return retval; | |
1206 } | |
1207 return Qt; | |
1208 } | |
1209 | |
1210 DEFUN ("check-valid-instantiator", Fcheck_valid_instantiator, 2, 2, 0, /* | |
1211 Signal an error if INSTANTIATOR is invalid for SPECIFIER-TYPE. | |
1212 */ | |
1213 (instantiator, specifier_type)) | |
1214 { | |
1215 struct specifier_methods *meths = decode_specifier_type (specifier_type, | |
1216 ERROR_ME); | |
1217 | |
1218 return check_valid_instantiator (instantiator, meths, ERROR_ME); | |
1219 } | |
1220 | |
1221 DEFUN ("valid-instantiator-p", Fvalid_instantiator_p, 2, 2, 0, /* | |
1222 Return non-nil if INSTANTIATOR is valid for SPECIFIER-TYPE. | |
1223 */ | |
1224 (instantiator, specifier_type)) | |
1225 { | |
1226 struct specifier_methods *meths = decode_specifier_type (specifier_type, | |
1227 ERROR_ME); | |
1228 | |
1229 return check_valid_instantiator (instantiator, meths, ERROR_ME_NOT); | |
1230 } | |
1231 | |
1232 static Lisp_Object | |
1233 check_valid_inst_list (Lisp_Object inst_list, struct specifier_methods *meths, | |
578 | 1234 Error_Behavior errb) |
428 | 1235 { |
2159 | 1236 EXTERNAL_LIST_LOOP_2 (inst_pair, inst_list) |
428 | 1237 { |
2159 | 1238 Lisp_Object tag_set; |
1239 | |
1240 if (!CONSP (inst_pair)) | |
428 | 1241 { |
563 | 1242 maybe_sferror ( |
442 | 1243 "Invalid instantiator pair", inst_pair, |
428 | 1244 Qspecifier, errb); |
1245 return Qnil; | |
1246 } | |
1247 if (NILP (Fvalid_specifier_tag_set_p (tag_set = XCAR (inst_pair)))) | |
1248 { | |
563 | 1249 maybe_invalid_argument ( |
442 | 1250 "Invalid specifier tag", tag_set, |
428 | 1251 Qspecifier, errb); |
1252 return Qnil; | |
1253 } | |
1254 | |
1255 if (NILP (check_valid_instantiator (XCDR (inst_pair), meths, errb))) | |
1256 return Qnil; | |
1257 } | |
1258 | |
1259 return Qt; | |
1260 } | |
1261 | |
1262 DEFUN ("check-valid-inst-list", Fcheck_valid_inst_list, 2, 2, 0, /* | |
1263 Signal an error if INST-LIST is invalid for specifier type TYPE. | |
1264 */ | |
1265 (inst_list, type)) | |
1266 { | |
1267 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); | |
1268 | |
1269 return check_valid_inst_list (inst_list, meths, ERROR_ME); | |
1270 } | |
1271 | |
1272 DEFUN ("valid-inst-list-p", Fvalid_inst_list_p, 2, 2, 0, /* | |
1273 Return non-nil if INST-LIST is valid for specifier type TYPE. | |
1274 */ | |
1275 (inst_list, type)) | |
1276 { | |
1277 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); | |
1278 | |
1279 return check_valid_inst_list (inst_list, meths, ERROR_ME_NOT); | |
1280 } | |
1281 | |
1282 static Lisp_Object | |
1283 check_valid_spec_list (Lisp_Object spec_list, struct specifier_methods *meths, | |
578 | 1284 Error_Behavior errb) |
428 | 1285 { |
2159 | 1286 EXTERNAL_LIST_LOOP_2 (spec, spec_list) |
428 | 1287 { |
2159 | 1288 Lisp_Object locale; |
1289 if (!CONSP (spec)) | |
428 | 1290 { |
563 | 1291 maybe_sferror ( |
442 | 1292 "Invalid specification list", spec_list, |
428 | 1293 Qspecifier, errb); |
1294 return Qnil; | |
1295 } | |
1296 if (NILP (Fvalid_specifier_locale_p (locale = XCAR (spec)))) | |
1297 { | |
563 | 1298 maybe_invalid_argument ( |
442 | 1299 "Invalid specifier locale", locale, |
428 | 1300 Qspecifier, errb); |
1301 return Qnil; | |
1302 } | |
1303 | |
1304 if (NILP (check_valid_inst_list (XCDR (spec), meths, errb))) | |
1305 return Qnil; | |
1306 } | |
1307 | |
1308 return Qt; | |
1309 } | |
1310 | |
1311 DEFUN ("check-valid-spec-list", Fcheck_valid_spec_list, 2, 2, 0, /* | |
1312 Signal an error if SPEC-LIST is invalid for specifier type TYPE. | |
1313 */ | |
1314 (spec_list, type)) | |
1315 { | |
1316 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); | |
1317 | |
1318 return check_valid_spec_list (spec_list, meths, ERROR_ME); | |
1319 } | |
1320 | |
1321 DEFUN ("valid-spec-list-p", Fvalid_spec_list_p, 2, 2, 0, /* | |
1322 Return non-nil if SPEC-LIST is valid for specifier type TYPE. | |
1323 */ | |
1324 (spec_list, type)) | |
1325 { | |
1326 struct specifier_methods *meths = decode_specifier_type (type, ERROR_ME); | |
1327 | |
1328 return check_valid_spec_list (spec_list, meths, ERROR_ME_NOT); | |
1329 } | |
1330 | |
1331 enum spec_add_meth | |
1332 decode_how_to_add_specification (Lisp_Object how_to_add) | |
1333 { | |
1334 if (NILP (how_to_add) || EQ (Qremove_tag_set_prepend, how_to_add)) | |
1335 return SPEC_REMOVE_TAG_SET_PREPEND; | |
1336 if (EQ (Qremove_tag_set_append, how_to_add)) | |
1337 return SPEC_REMOVE_TAG_SET_APPEND; | |
1338 if (EQ (Qappend, how_to_add)) | |
1339 return SPEC_APPEND; | |
1340 if (EQ (Qprepend, how_to_add)) | |
1341 return SPEC_PREPEND; | |
1342 if (EQ (Qremove_locale, how_to_add)) | |
1343 return SPEC_REMOVE_LOCALE; | |
1344 if (EQ (Qremove_locale_type, how_to_add)) | |
1345 return SPEC_REMOVE_LOCALE_TYPE; | |
1346 if (EQ (Qremove_all, how_to_add)) | |
1347 return SPEC_REMOVE_ALL; | |
1348 | |
563 | 1349 invalid_constant ("Invalid `how-to-add' flag", how_to_add); |
428 | 1350 |
1204 | 1351 RETURN_NOT_REACHED (SPEC_PREPEND); |
428 | 1352 } |
1353 | |
1354 /* Given a specifier object SPEC, return bodily specifier if SPEC is a | |
1355 ghost specifier, otherwise return the object itself | |
1356 */ | |
1357 static Lisp_Object | |
1358 bodily_specifier (Lisp_Object spec) | |
1359 { | |
1360 return (GHOST_SPECIFIER_P (XSPECIFIER (spec)) | |
1361 ? XSPECIFIER(spec)->magic_parent : spec); | |
1362 } | |
1363 | |
1364 /* Signal error if (specifier SPEC is read-only. | |
1365 Read only are ghost specifiers unless Vunlock_ghost_specifiers is | |
1366 non-nil. All other specifiers are read-write. | |
1367 */ | |
1368 static void | |
1369 check_modifiable_specifier (Lisp_Object spec) | |
1370 { | |
1371 if (NILP (Vunlock_ghost_specifiers) | |
1372 && GHOST_SPECIFIER_P (XSPECIFIER (spec))) | |
563 | 1373 signal_error (Qsetting_constant, |
1374 "Attempt to modify read-only specifier", | |
1375 spec); | |
428 | 1376 } |
1377 | |
1378 int | |
1379 unlock_ghost_specifiers_protected (void) | |
1380 { | |
853 | 1381 return internal_bind_lisp_object (&Vunlock_ghost_specifiers, Qt); |
428 | 1382 } |
1383 | |
1384 /* This gets hit so much that the function call overhead had a | |
1385 measurable impact (according to Quantify). #### We should figure | |
1386 out the frequency with which this is called with the various types | |
1387 and reorder the check accordingly. */ | |
1388 #define SPECIFIER_GET_SPEC_LIST(specifier, type) \ | |
1389 (type == LOCALE_GLOBAL ? &(XSPECIFIER (specifier)->global_specs) : \ | |
1390 type == LOCALE_DEVICE ? &(XSPECIFIER (specifier)->device_specs) : \ | |
1391 type == LOCALE_FRAME ? &(XSPECIFIER (specifier)->frame_specs) : \ | |
1392 type == LOCALE_WINDOW ? &(XWEAK_LIST_LIST \ | |
1393 (XSPECIFIER (specifier)->window_specs)) : \ | |
1394 type == LOCALE_BUFFER ? &(XSPECIFIER (specifier)->buffer_specs) : \ | |
1395 0) | |
1396 | |
1397 static Lisp_Object * | |
1398 specifier_get_inst_list (Lisp_Object specifier, Lisp_Object locale, | |
1399 enum spec_locale_type type) | |
1400 { | |
1401 Lisp_Object *spec_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1402 Lisp_Object specification; | |
1403 | |
1404 if (type == LOCALE_GLOBAL) | |
1405 return spec_list; | |
1406 /* Calling assq_no_quit when it is just going to return nil anyhow | |
1407 is extremely expensive. So sayeth Quantify. */ | |
1408 if (!CONSP (*spec_list)) | |
1409 return 0; | |
1410 specification = assq_no_quit (locale, *spec_list); | |
1411 if (NILP (specification)) | |
1412 return 0; | |
1413 return &XCDR (specification); | |
1414 } | |
1415 | |
1416 /* For the given INST_LIST, return a new INST_LIST containing all elements | |
1417 where TAG-SET matches the element's tag set. EXACT_P indicates whether | |
1418 the match must be exact (as opposed to a subset). SHORT_P indicates | |
1419 that the short form (for `specifier-specs') should be returned if | |
1420 possible. If COPY_TREE_P, `copy-tree' is used to ensure that no | |
1421 elements of the new list are shared with the initial list. | |
1422 */ | |
1423 | |
1424 static Lisp_Object | |
1425 specifier_process_inst_list (Lisp_Object inst_list, | |
1426 Lisp_Object tag_set, int exact_p, | |
1427 int short_p, int copy_tree_p) | |
1428 { | |
1429 Lisp_Object retval = Qnil; | |
1430 Lisp_Object rest; | |
1431 struct gcpro gcpro1; | |
1432 | |
1433 GCPRO1 (retval); | |
1434 LIST_LOOP (rest, inst_list) | |
1435 { | |
1436 Lisp_Object tagged_inst = XCAR (rest); | |
1437 Lisp_Object tagged_inst_tag = XCAR (tagged_inst); | |
1438 if (tag_sets_match_p (tag_set, tagged_inst_tag, exact_p)) | |
1439 { | |
1440 if (short_p && NILP (tagged_inst_tag)) | |
1441 retval = Fcons (copy_tree_p ? | |
1442 Fcopy_tree (XCDR (tagged_inst), Qt) : | |
1443 XCDR (tagged_inst), | |
1444 retval); | |
1445 else | |
1446 retval = Fcons (copy_tree_p ? Fcopy_tree (tagged_inst, Qt) : | |
1447 tagged_inst, retval); | |
1448 } | |
1449 } | |
1450 retval = Fnreverse (retval); | |
1451 UNGCPRO; | |
1452 /* If there is a single instantiator and the short form is | |
1453 requested, return just the instantiator (rather than a one-element | |
1454 list of it) unless it is nil (so that it can be distinguished from | |
1455 no instantiators at all). */ | |
1456 if (short_p && CONSP (retval) && !NILP (XCAR (retval)) && | |
1457 NILP (XCDR (retval))) | |
1458 return XCAR (retval); | |
1459 else | |
1460 return retval; | |
1461 } | |
1462 | |
1463 static Lisp_Object | |
1464 specifier_get_external_inst_list (Lisp_Object specifier, Lisp_Object locale, | |
1465 enum spec_locale_type type, | |
1466 Lisp_Object tag_set, int exact_p, | |
1467 int short_p, int copy_tree_p) | |
1468 { | |
1469 Lisp_Object *inst_list = specifier_get_inst_list (specifier, locale, | |
1470 type); | |
1471 if (!inst_list || NILP (*inst_list)) | |
1472 { | |
2953 | 1473 /* nil for *inst_list should only occur in `global' */ |
428 | 1474 assert (!inst_list || EQ (locale, Qglobal)); |
1475 return Qnil; | |
1476 } | |
1477 | |
1478 return specifier_process_inst_list (*inst_list, tag_set, exact_p, | |
1479 short_p, copy_tree_p); | |
1480 } | |
1481 | |
1482 static Lisp_Object | |
1483 specifier_get_external_spec_list (Lisp_Object specifier, | |
1484 enum spec_locale_type type, | |
1485 Lisp_Object tag_set, int exact_p) | |
1486 { | |
1487 Lisp_Object *spec_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1488 Lisp_Object retval = Qnil; | |
1489 Lisp_Object rest; | |
1490 struct gcpro gcpro1; | |
1491 | |
1492 assert (type != LOCALE_GLOBAL); | |
1493 /* We're about to let stuff go external; make sure there aren't | |
1494 any dead objects */ | |
1495 *spec_list = cleanup_assoc_list (*spec_list); | |
1496 | |
1497 GCPRO1 (retval); | |
1498 LIST_LOOP (rest, *spec_list) | |
1499 { | |
1500 Lisp_Object spec = XCAR (rest); | |
1501 Lisp_Object inst_list = | |
1502 specifier_process_inst_list (XCDR (spec), tag_set, exact_p, 0, 1); | |
1503 if (!NILP (inst_list)) | |
1504 retval = Fcons (Fcons (XCAR (spec), inst_list), retval); | |
1505 } | |
1506 RETURN_UNGCPRO (Fnreverse (retval)); | |
1507 } | |
1508 | |
1509 static Lisp_Object * | |
1510 specifier_new_spec (Lisp_Object specifier, Lisp_Object locale, | |
1511 enum spec_locale_type type) | |
1512 { | |
1513 Lisp_Object *spec_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1514 Lisp_Object new_spec = Fcons (locale, Qnil); | |
1515 assert (type != LOCALE_GLOBAL); | |
1516 *spec_list = Fcons (new_spec, *spec_list); | |
1517 return &XCDR (new_spec); | |
1518 } | |
1519 | |
1520 /* For the given INST_LIST, return a new list comprised of elements | |
1521 where TAG_SET does not match the element's tag set. This operation | |
1522 is destructive. */ | |
1523 | |
1524 static Lisp_Object | |
1525 specifier_process_remove_inst_list (Lisp_Object inst_list, | |
1526 Lisp_Object tag_set, int exact_p, | |
1527 int *was_removed) | |
1528 { | |
1529 Lisp_Object prev = Qnil, rest; | |
1530 | |
1531 *was_removed = 0; | |
1532 | |
1533 LIST_LOOP (rest, inst_list) | |
1534 { | |
1535 if (tag_sets_match_p (tag_set, XCAR (XCAR (rest)), exact_p)) | |
1536 { | |
1537 /* time to remove. */ | |
1538 *was_removed = 1; | |
1539 if (NILP (prev)) | |
1540 inst_list = XCDR (rest); | |
1541 else | |
1542 XCDR (prev) = XCDR (rest); | |
1543 } | |
1544 else | |
1545 prev = rest; | |
1546 } | |
1547 | |
1548 return inst_list; | |
1549 } | |
1550 | |
1551 static void | |
1552 specifier_remove_spec (Lisp_Object specifier, Lisp_Object locale, | |
1553 enum spec_locale_type type, | |
1554 Lisp_Object tag_set, int exact_p) | |
1555 { | |
1556 Lisp_Object *spec_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1557 Lisp_Object assoc; | |
1558 int was_removed; | |
1559 | |
1560 if (type == LOCALE_GLOBAL) | |
1561 *spec_list = specifier_process_remove_inst_list (*spec_list, tag_set, | |
1562 exact_p, &was_removed); | |
1563 else | |
1564 { | |
1565 assoc = assq_no_quit (locale, *spec_list); | |
1566 if (NILP (assoc)) | |
1567 /* this locale is not found. */ | |
1568 return; | |
1569 XCDR (assoc) = specifier_process_remove_inst_list (XCDR (assoc), | |
1570 tag_set, exact_p, | |
1571 &was_removed); | |
1572 if (NILP (XCDR (assoc))) | |
1573 /* no inst-pairs left; remove this locale entirely. */ | |
1574 *spec_list = remassq_no_quit (locale, *spec_list); | |
1575 } | |
1576 | |
1577 if (was_removed) | |
1578 MAYBE_SPECMETH (XSPECIFIER (specifier), after_change, | |
1579 (bodily_specifier (specifier), locale)); | |
1580 } | |
1581 | |
1582 static void | |
1583 specifier_remove_locale_type (Lisp_Object specifier, | |
1584 enum spec_locale_type type, | |
1585 Lisp_Object tag_set, int exact_p) | |
1586 { | |
1587 Lisp_Object *spec_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1588 Lisp_Object prev = Qnil, rest; | |
1589 | |
1590 assert (type != LOCALE_GLOBAL); | |
1591 LIST_LOOP (rest, *spec_list) | |
1592 { | |
1593 int was_removed; | |
1594 int remove_spec = 0; | |
1595 Lisp_Object spec = XCAR (rest); | |
1596 | |
1597 /* There may be dead objects floating around */ | |
1598 /* remember, dead windows can become alive again. */ | |
1599 if (!WINDOWP (XCAR (spec)) && object_dead_p (XCAR (spec))) | |
1600 { | |
1601 remove_spec = 1; | |
1602 was_removed = 0; | |
1603 } | |
1604 else | |
1605 { | |
1606 XCDR (spec) = specifier_process_remove_inst_list (XCDR (spec), | |
1607 tag_set, exact_p, | |
1608 &was_removed); | |
1609 if (NILP (XCDR (spec))) | |
1610 remove_spec = 1; | |
1611 } | |
1612 | |
1613 if (remove_spec) | |
1614 { | |
1615 if (NILP (prev)) | |
1616 *spec_list = XCDR (rest); | |
1617 else | |
1618 XCDR (prev) = XCDR (rest); | |
1619 } | |
1620 else | |
1621 prev = rest; | |
1622 | |
1623 if (was_removed) | |
1624 MAYBE_SPECMETH (XSPECIFIER (specifier), after_change, | |
1625 (bodily_specifier (specifier), XCAR (spec))); | |
1626 } | |
1627 } | |
1628 | |
1629 /* NEW_LIST is going to be added to INST_LIST, with add method ADD_METH. | |
1630 Frob INST_LIST according to ADD_METH. No need to call an after-change | |
1631 function; the calling function will do this. Return either SPEC_PREPEND | |
1632 or SPEC_APPEND, indicating whether to prepend or append the NEW_LIST. */ | |
1633 | |
1634 static enum spec_add_meth | |
1635 handle_multiple_add_insts (Lisp_Object *inst_list, | |
1636 Lisp_Object new_list, | |
1637 enum spec_add_meth add_meth) | |
1638 { | |
1639 switch (add_meth) | |
1640 { | |
1641 case SPEC_REMOVE_TAG_SET_APPEND: | |
1642 add_meth = SPEC_APPEND; | |
1643 goto remove_tag_set; | |
1644 case SPEC_REMOVE_TAG_SET_PREPEND: | |
1645 add_meth = SPEC_PREPEND; | |
1646 remove_tag_set: | |
1647 { | |
1648 Lisp_Object rest; | |
1649 | |
1650 LIST_LOOP (rest, new_list) | |
1651 { | |
1652 Lisp_Object canontag = canonicalize_tag_set (XCAR (XCAR (rest))); | |
1653 struct gcpro gcpro1; | |
1654 | |
1655 GCPRO1 (canontag); | |
1656 /* pull out all elements from the existing list with the | |
1657 same tag as any tags in NEW_LIST. */ | |
1658 *inst_list = remassoc_no_quit (canontag, *inst_list); | |
1659 UNGCPRO; | |
1660 } | |
1661 } | |
1662 return add_meth; | |
1663 case SPEC_REMOVE_LOCALE: | |
1664 *inst_list = Qnil; | |
1665 return SPEC_PREPEND; | |
1666 case SPEC_APPEND: | |
1667 return add_meth; | |
1668 default: | |
1669 return SPEC_PREPEND; | |
1670 } | |
1671 } | |
1672 | |
1673 /* Given a LOCALE and INST_LIST that is going to be added to SPECIFIER, | |
1674 copy, canonicalize, and call the going_to_add methods as necessary | |
1675 to produce a new list that is the one that really will be added | |
1676 to the specifier. */ | |
1677 | |
1678 static Lisp_Object | |
1679 build_up_processed_list (Lisp_Object specifier, Lisp_Object locale, | |
1680 Lisp_Object inst_list) | |
1681 { | |
1682 /* The return value of this function must be GCPRO'd. */ | |
1683 Lisp_Object rest, list_to_build_up = Qnil; | |
440 | 1684 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 1685 struct gcpro gcpro1; |
1686 | |
1687 GCPRO1 (list_to_build_up); | |
1688 LIST_LOOP (rest, inst_list) | |
1689 { | |
1690 Lisp_Object tag_set = XCAR (XCAR (rest)); | |
1691 Lisp_Object sub_inst_list = Qnil; | |
434 | 1692 Lisp_Object instantiator; |
428 | 1693 struct gcpro ngcpro1, ngcpro2; |
1694 | |
434 | 1695 if (HAS_SPECMETH_P (sp, copy_instantiator)) |
1696 instantiator = SPECMETH (sp, copy_instantiator, | |
1697 (XCDR (XCAR (rest)))); | |
1698 else | |
1699 instantiator = Fcopy_tree (XCDR (XCAR (rest)), Qt); | |
1700 | |
428 | 1701 NGCPRO2 (instantiator, sub_inst_list); |
1702 /* call the will-add method; it may GC */ | |
1703 sub_inst_list = HAS_SPECMETH_P (sp, going_to_add) ? | |
1704 SPECMETH (sp, going_to_add, | |
1705 (bodily_specifier (specifier), locale, | |
1706 tag_set, instantiator)) : | |
1707 Qt; | |
1708 if (EQ (sub_inst_list, Qt)) | |
1709 /* no change here. */ | |
1710 sub_inst_list = list1 (Fcons (canonicalize_tag_set (tag_set), | |
1711 instantiator)); | |
1712 else | |
1713 { | |
1714 /* now canonicalize all the tag sets in the new objects */ | |
1715 Lisp_Object rest2; | |
1716 LIST_LOOP (rest2, sub_inst_list) | |
1717 XCAR (XCAR (rest2)) = canonicalize_tag_set (XCAR (XCAR (rest2))); | |
1718 } | |
1719 | |
1720 list_to_build_up = nconc2 (sub_inst_list, list_to_build_up); | |
1721 NUNGCPRO; | |
1722 } | |
1723 | |
1724 RETURN_UNGCPRO (Fnreverse (list_to_build_up)); | |
1725 } | |
1726 | |
1727 /* Add a specification (locale and instantiator list) to a specifier. | |
1728 ADD_METH specifies what to do with existing specifications in the | |
1729 specifier, and is an enum that corresponds to the values in | |
1730 `add-spec-to-specifier'. The calling routine is responsible for | |
1731 validating LOCALE and INST-LIST, but the tag-sets in INST-LIST | |
1732 do not need to be canonicalized. */ | |
1733 | |
1734 /* #### I really need to rethink the after-change | |
1735 functions to make them easier to use and more efficient. */ | |
1736 | |
1737 static void | |
1738 specifier_add_spec (Lisp_Object specifier, Lisp_Object locale, | |
1739 Lisp_Object inst_list, enum spec_add_meth add_meth) | |
1740 { | |
440 | 1741 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 1742 enum spec_locale_type type = locale_type_from_locale (locale); |
1743 Lisp_Object *orig_inst_list, tem; | |
1744 Lisp_Object list_to_build_up = Qnil; | |
1745 struct gcpro gcpro1; | |
1746 | |
1015 | 1747 if (NILP (inst_list)) |
1748 return; | |
1749 | |
428 | 1750 GCPRO1 (list_to_build_up); |
1751 list_to_build_up = build_up_processed_list (specifier, locale, inst_list); | |
1752 /* Now handle REMOVE_LOCALE_TYPE and REMOVE_ALL. These are the | |
1753 add-meth types that affect locales other than this one. */ | |
1754 if (add_meth == SPEC_REMOVE_LOCALE_TYPE) | |
1755 specifier_remove_locale_type (specifier, type, Qnil, 0); | |
1756 else if (add_meth == SPEC_REMOVE_ALL) | |
1757 { | |
1758 specifier_remove_locale_type (specifier, LOCALE_BUFFER, Qnil, 0); | |
1759 specifier_remove_locale_type (specifier, LOCALE_WINDOW, Qnil, 0); | |
1760 specifier_remove_locale_type (specifier, LOCALE_FRAME, Qnil, 0); | |
1761 specifier_remove_locale_type (specifier, LOCALE_DEVICE, Qnil, 0); | |
1762 specifier_remove_spec (specifier, Qglobal, LOCALE_GLOBAL, Qnil, 0); | |
1763 } | |
1764 | |
1765 orig_inst_list = specifier_get_inst_list (specifier, locale, type); | |
1766 if (!orig_inst_list) | |
1767 orig_inst_list = specifier_new_spec (specifier, locale, type); | |
1768 add_meth = handle_multiple_add_insts (orig_inst_list, list_to_build_up, | |
1769 add_meth); | |
1770 | |
1771 if (add_meth == SPEC_PREPEND) | |
1772 tem = nconc2 (list_to_build_up, *orig_inst_list); | |
1773 else if (add_meth == SPEC_APPEND) | |
1774 tem = nconc2 (*orig_inst_list, list_to_build_up); | |
1775 else | |
442 | 1776 { |
2500 | 1777 ABORT (); |
442 | 1778 tem = Qnil; |
1779 } | |
428 | 1780 |
1781 *orig_inst_list = tem; | |
1782 | |
1783 UNGCPRO; | |
1784 | |
1785 /* call the after-change method */ | |
1786 MAYBE_SPECMETH (sp, after_change, | |
1787 (bodily_specifier (specifier), locale)); | |
1788 } | |
1789 | |
1790 static void | |
1791 specifier_copy_spec (Lisp_Object specifier, Lisp_Object dest, | |
1792 Lisp_Object locale, enum spec_locale_type type, | |
1793 Lisp_Object tag_set, int exact_p, | |
1794 enum spec_add_meth add_meth) | |
1795 { | |
1796 Lisp_Object inst_list = | |
1797 specifier_get_external_inst_list (specifier, locale, type, tag_set, | |
1798 exact_p, 0, 0); | |
1799 specifier_add_spec (dest, locale, inst_list, add_meth); | |
1800 } | |
1801 | |
1802 static void | |
1803 specifier_copy_locale_type (Lisp_Object specifier, Lisp_Object dest, | |
1804 enum spec_locale_type type, | |
1805 Lisp_Object tag_set, int exact_p, | |
1806 enum spec_add_meth add_meth) | |
1807 { | |
1808 Lisp_Object *src_list = SPECIFIER_GET_SPEC_LIST (specifier, type); | |
1809 Lisp_Object rest; | |
1810 | |
1811 /* This algorithm is O(n^2) in running time. | |
1812 It's certainly possible to implement an O(n log n) algorithm, | |
1813 but I doubt there's any need to. */ | |
1814 | |
1815 LIST_LOOP (rest, *src_list) | |
1816 { | |
1817 Lisp_Object spec = XCAR (rest); | |
1818 /* There may be dead objects floating around */ | |
1819 /* remember, dead windows can become alive again. */ | |
1820 if (WINDOWP (XCAR (spec)) || !object_dead_p (XCAR (spec))) | |
1821 specifier_add_spec | |
1822 (dest, XCAR (spec), | |
1823 specifier_process_inst_list (XCDR (spec), tag_set, exact_p, 0, 0), | |
1824 add_meth); | |
1825 } | |
1826 } | |
1827 | |
1828 /* map MAPFUN over the locales in SPECIFIER that are given in LOCALE. | |
1829 CLOSURE is passed unchanged to MAPFUN. LOCALE can be one of | |
1830 | |
2953 | 1831 -- nil (same as `all') |
1832 -- a single locale, locale type, or `all' | |
1833 -- a list of locales, locale types, and/or `all' | |
1834 | |
1835 MAPFUN is called for each locale and locale type given; for `all', | |
1836 it is called for the locale `global' and for the four possible | |
428 | 1837 locale types. In each invocation, either LOCALE will be a locale |
1838 and LOCALE_TYPE will be the locale type of this locale, | |
1839 or LOCALE will be nil and LOCALE_TYPE will be a locale type. | |
1840 If MAPFUN ever returns non-zero, the mapping is halted and the | |
1841 value returned is returned from map_specifier(). Otherwise, the | |
1842 mapping proceeds to the end and map_specifier() returns 0. | |
1843 */ | |
1844 | |
1845 static int | |
1846 map_specifier (Lisp_Object specifier, Lisp_Object locale, | |
1847 int (*mapfun) (Lisp_Object specifier, | |
1848 Lisp_Object locale, | |
1849 enum spec_locale_type locale_type, | |
1850 Lisp_Object tag_set, | |
1851 int exact_p, | |
1852 void *closure), | |
1853 Lisp_Object tag_set, Lisp_Object exact_p, | |
1854 void *closure) | |
1855 { | |
1856 int retval = 0; | |
1857 Lisp_Object rest; | |
1858 struct gcpro gcpro1, gcpro2; | |
1859 | |
1860 GCPRO2 (tag_set, locale); | |
1861 locale = decode_locale_list (locale); | |
1862 tag_set = decode_specifier_tag_set (tag_set); | |
1863 tag_set = canonicalize_tag_set (tag_set); | |
1864 | |
1865 LIST_LOOP (rest, locale) | |
1866 { | |
1867 Lisp_Object theloc = XCAR (rest); | |
1868 if (!NILP (Fvalid_specifier_locale_p (theloc))) | |
1869 { | |
1870 retval = (*mapfun) (specifier, theloc, | |
1871 locale_type_from_locale (theloc), | |
1872 tag_set, !NILP (exact_p), closure); | |
1873 if (retval) | |
1874 break; | |
1875 } | |
1876 else if (!NILP (Fvalid_specifier_locale_type_p (theloc))) | |
1877 { | |
1878 retval = (*mapfun) (specifier, Qnil, | |
1879 decode_locale_type (theloc), tag_set, | |
1880 !NILP (exact_p), closure); | |
1881 if (retval) | |
1882 break; | |
1883 } | |
1884 else | |
1885 { | |
1886 assert (EQ (theloc, Qall)); | |
1887 retval = (*mapfun) (specifier, Qnil, LOCALE_BUFFER, tag_set, | |
1888 !NILP (exact_p), closure); | |
1889 if (retval) | |
1890 break; | |
1891 retval = (*mapfun) (specifier, Qnil, LOCALE_WINDOW, tag_set, | |
1892 !NILP (exact_p), closure); | |
1893 if (retval) | |
1894 break; | |
1895 retval = (*mapfun) (specifier, Qnil, LOCALE_FRAME, tag_set, | |
1896 !NILP (exact_p), closure); | |
1897 if (retval) | |
1898 break; | |
1899 retval = (*mapfun) (specifier, Qnil, LOCALE_DEVICE, tag_set, | |
1900 !NILP (exact_p), closure); | |
1901 if (retval) | |
1902 break; | |
1903 retval = (*mapfun) (specifier, Qglobal, LOCALE_GLOBAL, tag_set, | |
1904 !NILP (exact_p), closure); | |
1905 if (retval) | |
1906 break; | |
1907 } | |
1908 } | |
1909 | |
1910 UNGCPRO; | |
1911 return retval; | |
1912 } | |
1913 | |
1914 DEFUN ("add-spec-to-specifier", Fadd_spec_to_specifier, 2, 5, 0, /* | |
1915 Add a specification to SPECIFIER. | |
1916 The specification maps from LOCALE (which should be a window, buffer, | |
2953 | 1917 frame, device, or `global', and defaults to `global') to INSTANTIATOR, |
428 | 1918 whose allowed values depend on the type of the specifier. Optional |
1919 argument TAG-SET limits the instantiator to apply only to the specified | |
1920 tag set, which should be a list of tags all of which must match the | |
1921 device being instantiated over (tags are a device type, a device class, | |
1922 or tags defined with `define-specifier-tag'). Specifying a single | |
1923 symbol for TAG-SET is equivalent to specifying a one-element list | |
1924 containing that symbol. Optional argument HOW-TO-ADD specifies what to | |
1925 do if there are already specifications in the specifier. | |
1926 It should be one of | |
1927 | |
2953 | 1928 `prepend' Put at the beginning of the current list of |
428 | 1929 instantiators for LOCALE. |
2953 | 1930 `append' Add to the end of the current list of |
428 | 1931 instantiators for LOCALE. |
2953 | 1932 `remove-tag-set-prepend' (this is the default) |
428 | 1933 Remove any existing instantiators whose tag set is |
1934 the same as TAG-SET; then put the new instantiator | |
1935 at the beginning of the current list. ("Same tag | |
1936 set" means that they contain the same elements. | |
1937 The order may be different.) | |
2953 | 1938 `remove-tag-set-append' |
428 | 1939 Remove any existing instantiators whose tag set is |
1940 the same as TAG-SET; then put the new instantiator | |
1941 at the end of the current list. | |
2953 | 1942 `remove-locale' Remove all previous instantiators for this locale |
428 | 1943 before adding the new spec. |
2953 | 1944 `remove-locale-type' Remove all specifications for all locales of the |
428 | 1945 same type as LOCALE (this includes LOCALE itself) |
1946 before adding the new spec. | |
2953 | 1947 `remove-all' Remove all specifications from the specifier |
428 | 1948 before adding the new spec. |
1949 | |
1950 You can retrieve the specifications for a particular locale or locale type | |
1951 with the function `specifier-spec-list' or `specifier-specs'. | |
1952 */ | |
1953 (specifier, instantiator, locale, tag_set, how_to_add)) | |
1954 { | |
1955 enum spec_add_meth add_meth; | |
1956 Lisp_Object inst_list; | |
1957 struct gcpro gcpro1; | |
1958 | |
1959 CHECK_SPECIFIER (specifier); | |
1960 check_modifiable_specifier (specifier); | |
1961 | |
1962 locale = decode_locale (locale); | |
1963 check_valid_instantiator (instantiator, | |
1964 decode_specifier_type | |
1965 (Fspecifier_type (specifier), ERROR_ME), | |
1966 ERROR_ME); | |
1967 /* tag_set might be newly-created material, but it's part of inst_list | |
1968 so is properly GC-protected. */ | |
1969 tag_set = decode_specifier_tag_set (tag_set); | |
1970 add_meth = decode_how_to_add_specification (how_to_add); | |
1971 | |
1972 inst_list = list1 (Fcons (tag_set, instantiator)); | |
1973 GCPRO1 (inst_list); | |
1974 specifier_add_spec (specifier, locale, inst_list, add_meth); | |
1975 recompute_cached_specifier_everywhere (specifier); | |
1976 RETURN_UNGCPRO (Qnil); | |
1977 } | |
1978 | |
1979 DEFUN ("add-spec-list-to-specifier", Fadd_spec_list_to_specifier, 2, 3, 0, /* | |
444 | 1980 Add SPEC-LIST (a list of specifications) to SPECIFIER. |
1981 The format of SPEC-LIST is | |
428 | 1982 |
1983 ((LOCALE (TAG-SET . INSTANTIATOR) ...) ...) | |
1984 | |
1985 where | |
2953 | 1986 LOCALE := a window, a buffer, a frame, a device, or `global' |
428 | 1987 TAG-SET := an unordered list of zero or more TAGS, each of which |
1988 is a symbol | |
1989 TAG := a device class (see `valid-device-class-p'), a device type | |
1990 (see `valid-console-type-p'), or a tag defined with | |
1991 `define-specifier-tag' | |
1992 INSTANTIATOR := format determined by the type of specifier | |
1993 | |
1994 The pair (TAG-SET . INSTANTIATOR) is called an `inst-pair'. | |
1995 A list of inst-pairs is called an `inst-list'. | |
1996 The pair (LOCALE . INST-LIST) is called a `specification' or `spec'. | |
1997 A spec-list, then, can be viewed as a list of specifications. | |
1998 | |
1999 HOW-TO-ADD specifies how to combine the new specifications with | |
2000 the existing ones, and has the same semantics as for | |
2001 `add-spec-to-specifier'. | |
2002 | |
2003 In many circumstances, the higher-level function `set-specifier' is | |
2004 more convenient and should be used instead. | |
2005 */ | |
2006 (specifier, spec_list, how_to_add)) | |
2007 { | |
2008 enum spec_add_meth add_meth; | |
2009 Lisp_Object rest; | |
2010 | |
2011 CHECK_SPECIFIER (specifier); | |
2012 check_modifiable_specifier (specifier); | |
2013 | |
2014 check_valid_spec_list (spec_list, | |
2015 decode_specifier_type | |
2016 (Fspecifier_type (specifier), ERROR_ME), | |
2017 ERROR_ME); | |
2018 add_meth = decode_how_to_add_specification (how_to_add); | |
2019 | |
2020 LIST_LOOP (rest, spec_list) | |
2021 { | |
2022 /* Placating the GCC god. */ | |
2023 Lisp_Object specification = XCAR (rest); | |
2024 Lisp_Object locale = XCAR (specification); | |
2025 Lisp_Object inst_list = XCDR (specification); | |
2026 | |
2027 specifier_add_spec (specifier, locale, inst_list, add_meth); | |
2028 } | |
2029 recompute_cached_specifier_everywhere (specifier); | |
2030 return Qnil; | |
2031 } | |
2032 | |
2033 void | |
2034 add_spec_to_ghost_specifier (Lisp_Object specifier, Lisp_Object instantiator, | |
2035 Lisp_Object locale, Lisp_Object tag_set, | |
2036 Lisp_Object how_to_add) | |
2037 { | |
2038 int depth = unlock_ghost_specifiers_protected (); | |
2039 Fadd_spec_to_specifier (XSPECIFIER(specifier)->fallback, | |
2040 instantiator, locale, tag_set, how_to_add); | |
771 | 2041 unbind_to (depth); |
428 | 2042 } |
2043 | |
2044 struct specifier_spec_list_closure | |
2045 { | |
2046 Lisp_Object head, tail; | |
2047 }; | |
2048 | |
2049 static int | |
2050 specifier_spec_list_mapfun (Lisp_Object specifier, | |
2051 Lisp_Object locale, | |
2052 enum spec_locale_type locale_type, | |
2053 Lisp_Object tag_set, | |
2054 int exact_p, | |
2055 void *closure) | |
2056 { | |
2057 struct specifier_spec_list_closure *cl = | |
2058 (struct specifier_spec_list_closure *) closure; | |
2059 Lisp_Object partial; | |
2060 | |
2061 if (NILP (locale)) | |
2062 partial = specifier_get_external_spec_list (specifier, | |
2063 locale_type, | |
2064 tag_set, exact_p); | |
2065 else | |
2066 { | |
2067 partial = specifier_get_external_inst_list (specifier, locale, | |
2068 locale_type, tag_set, | |
2069 exact_p, 0, 1); | |
2070 if (!NILP (partial)) | |
2071 partial = list1 (Fcons (locale, partial)); | |
2072 } | |
2073 if (NILP (partial)) | |
2074 return 0; | |
2075 | |
2076 /* tack on the new list */ | |
2077 if (NILP (cl->tail)) | |
2078 cl->head = cl->tail = partial; | |
2079 else | |
2080 XCDR (cl->tail) = partial; | |
2081 /* find the new tail */ | |
2082 while (CONSP (XCDR (cl->tail))) | |
2083 cl->tail = XCDR (cl->tail); | |
2084 return 0; | |
2085 } | |
2086 | |
2087 /* For the given SPECIFIER create and return a list of all specs | |
2088 contained within it, subject to LOCALE. If LOCALE is a locale, only | |
2089 specs in that locale will be returned. If LOCALE is a locale type, | |
2090 all specs in all locales of that type will be returned. If LOCALE is | |
2091 nil, all specs will be returned. This always copies lists and never | |
2092 returns the actual lists, because we do not want someone manipulating | |
2093 the actual objects. This may cause a slight loss of potential | |
2094 functionality but if we were to allow it then a user could manage to | |
2095 violate our assertion that the specs contained in the actual | |
2096 specifier lists are all valid. */ | |
2097 | |
2098 DEFUN ("specifier-spec-list", Fspecifier_spec_list, 1, 4, 0, /* | |
2099 Return the spec-list of specifications for SPECIFIER in LOCALE. | |
2100 | |
2101 If LOCALE is a particular locale (a buffer, window, frame, device, | |
2953 | 2102 or `global'), a spec-list consisting of the specification for that |
428 | 2103 locale will be returned. |
2104 | |
2953 | 2105 If LOCALE is a locale type (i.e. `buffer', `window', `frame', or `device'), |
428 | 2106 a spec-list of the specifications for all locales of that type will be |
2107 returned. | |
2108 | |
2953 | 2109 If LOCALE is nil or `all', a spec-list of all specifications in SPECIFIER |
428 | 2110 will be returned. |
2111 | |
2953 | 2112 LOCALE can also be a list of locales, locale types, and/or `all'; the |
428 | 2113 result is as if `specifier-spec-list' were called on each element of the |
2114 list and the results concatenated together. | |
2115 | |
2116 Only instantiators where TAG-SET (a list of zero or more tags) is a | |
2117 subset of (or possibly equal to) the instantiator's tag set are returned. | |
2118 \(The default value of nil is a subset of all tag sets, so in this case | |
2119 no instantiators will be screened out.) If EXACT-P is non-nil, however, | |
2120 TAG-SET must be equal to an instantiator's tag set for the instantiator | |
2121 to be returned. | |
2122 */ | |
2123 (specifier, locale, tag_set, exact_p)) | |
2124 { | |
2125 struct specifier_spec_list_closure cl; | |
2126 struct gcpro gcpro1, gcpro2; | |
2127 | |
2128 CHECK_SPECIFIER (specifier); | |
2129 cl.head = cl.tail = Qnil; | |
2130 GCPRO2 (cl.head, cl.tail); | |
2131 map_specifier (specifier, locale, specifier_spec_list_mapfun, | |
2132 tag_set, exact_p, &cl); | |
2133 UNGCPRO; | |
2134 return cl.head; | |
2135 } | |
2136 | |
2137 | |
2138 DEFUN ("specifier-specs", Fspecifier_specs, 1, 4, 0, /* | |
2139 Return the specification(s) for SPECIFIER in LOCALE. | |
2140 | |
2141 If LOCALE is a single locale or is a list of one element containing a | |
2142 single locale, then a "short form" of the instantiators for that locale | |
2143 will be returned. Otherwise, this function is identical to | |
2144 `specifier-spec-list'. | |
2145 | |
2146 The "short form" is designed for readability and not for ease of use | |
2147 in Lisp programs, and is as follows: | |
2148 | |
2149 1. If there is only one instantiator, then an inst-pair (i.e. cons of | |
2150 tag and instantiator) will be returned; otherwise a list of | |
2151 inst-pairs will be returned. | |
2953 | 2152 2. For each inst-pair returned, if the instantiator's tag is `any', |
428 | 2153 the tag will be removed and the instantiator itself will be returned |
2154 instead of the inst-pair. | |
2155 3. If there is only one instantiator, its value is nil, and its tag is | |
2953 | 2156 `any', a one-element list containing nil will be returned rather |
428 | 2157 than just nil, to distinguish this case from there being no |
2158 instantiators at all. | |
2159 */ | |
2160 (specifier, locale, tag_set, exact_p)) | |
2161 { | |
2162 if (!NILP (Fvalid_specifier_locale_p (locale)) || | |
2163 (CONSP (locale) && !NILP (Fvalid_specifier_locale_p (XCAR (locale))) && | |
2164 NILP (XCDR (locale)))) | |
2165 { | |
2166 struct gcpro gcpro1; | |
2167 | |
2168 CHECK_SPECIFIER (specifier); | |
2169 if (CONSP (locale)) | |
2170 locale = XCAR (locale); | |
2171 GCPRO1 (tag_set); | |
2172 tag_set = decode_specifier_tag_set (tag_set); | |
2173 tag_set = canonicalize_tag_set (tag_set); | |
2174 RETURN_UNGCPRO | |
2175 (specifier_get_external_inst_list (specifier, locale, | |
2176 locale_type_from_locale (locale), | |
2177 tag_set, !NILP (exact_p), 1, 1)); | |
2178 } | |
2179 else | |
2180 return Fspecifier_spec_list (specifier, locale, tag_set, exact_p); | |
2181 } | |
2182 | |
2183 static int | |
2184 remove_specifier_mapfun (Lisp_Object specifier, | |
2185 Lisp_Object locale, | |
2186 enum spec_locale_type locale_type, | |
2187 Lisp_Object tag_set, | |
2188 int exact_p, | |
2286 | 2189 void *UNUSED (closure)) |
428 | 2190 { |
2191 if (NILP (locale)) | |
2192 specifier_remove_locale_type (specifier, locale_type, tag_set, exact_p); | |
2193 else | |
2194 specifier_remove_spec (specifier, locale, locale_type, tag_set, exact_p); | |
2195 return 0; | |
2196 } | |
2197 | |
2198 DEFUN ("remove-specifier", Fremove_specifier, 1, 4, 0, /* | |
2199 Remove specification(s) for SPECIFIER. | |
2200 | |
2201 If LOCALE is a particular locale (a window, buffer, frame, device, | |
2953 | 2202 or `global'), the specification for that locale will be removed. |
2203 | |
2204 If instead, LOCALE is a locale type (i.e. `window', `buffer', `frame', | |
2205 or `device'), the specifications for all locales of that type will be | |
428 | 2206 removed. |
2207 | |
2953 | 2208 If LOCALE is nil or `all', all specifications will be removed. |
2209 | |
2210 LOCALE can also be a list of locales, locale types, and/or `all'; this | |
428 | 2211 is equivalent to calling `remove-specifier' for each of the elements |
2212 in the list. | |
2213 | |
2214 Only instantiators where TAG-SET (a list of zero or more tags) is a | |
2215 subset of (or possibly equal to) the instantiator's tag set are removed. | |
2216 The default value of nil is a subset of all tag sets, so in this case | |
2217 no instantiators will be screened out. If EXACT-P is non-nil, however, | |
2218 TAG-SET must be equal to an instantiator's tag set for the instantiator | |
2219 to be removed. | |
2220 */ | |
2221 (specifier, locale, tag_set, exact_p)) | |
2222 { | |
2223 CHECK_SPECIFIER (specifier); | |
2224 check_modifiable_specifier (specifier); | |
2225 | |
2226 map_specifier (specifier, locale, remove_specifier_mapfun, | |
2227 tag_set, exact_p, 0); | |
2228 recompute_cached_specifier_everywhere (specifier); | |
2229 return Qnil; | |
2230 } | |
2231 | |
2232 void | |
2233 remove_ghost_specifier (Lisp_Object specifier, Lisp_Object locale, | |
2234 Lisp_Object tag_set, Lisp_Object exact_p) | |
2235 { | |
2236 int depth = unlock_ghost_specifiers_protected (); | |
2237 Fremove_specifier (XSPECIFIER(specifier)->fallback, | |
2238 locale, tag_set, exact_p); | |
771 | 2239 unbind_to (depth); |
428 | 2240 } |
2241 | |
2242 struct copy_specifier_closure | |
2243 { | |
2244 Lisp_Object dest; | |
2245 enum spec_add_meth add_meth; | |
2246 int add_meth_is_nil; | |
2247 }; | |
2248 | |
2249 static int | |
2250 copy_specifier_mapfun (Lisp_Object specifier, | |
2251 Lisp_Object locale, | |
2252 enum spec_locale_type locale_type, | |
2253 Lisp_Object tag_set, | |
2254 int exact_p, | |
2255 void *closure) | |
2256 { | |
2257 struct copy_specifier_closure *cl = | |
2258 (struct copy_specifier_closure *) closure; | |
2259 | |
2260 if (NILP (locale)) | |
2261 specifier_copy_locale_type (specifier, cl->dest, locale_type, | |
2262 tag_set, exact_p, | |
2263 cl->add_meth_is_nil ? | |
2264 SPEC_REMOVE_LOCALE_TYPE : | |
2265 cl->add_meth); | |
2266 else | |
2267 specifier_copy_spec (specifier, cl->dest, locale, locale_type, | |
2268 tag_set, exact_p, | |
2269 cl->add_meth_is_nil ? SPEC_REMOVE_LOCALE : | |
2270 cl->add_meth); | |
2271 return 0; | |
2272 } | |
2273 | |
2274 DEFUN ("copy-specifier", Fcopy_specifier, 1, 6, 0, /* | |
2275 Copy SPECIFIER to DEST, or create a new one if DEST is nil. | |
2276 | |
2277 If DEST is nil or omitted, a new specifier will be created and the | |
2278 specifications copied into it. Otherwise, the specifications will be | |
2279 copied into the existing specifier in DEST. | |
2280 | |
2953 | 2281 If LOCALE is nil or `all', all specifications will be copied. If LOCALE |
428 | 2282 is a particular locale, the specification for that particular locale will |
2283 be copied. If LOCALE is a locale type, the specifications for all locales | |
2284 of that type will be copied. LOCALE can also be a list of locales, | |
2953 | 2285 locale types, and/or `all'; this is equivalent to calling `copy-specifier' |
428 | 2286 for each of the elements of the list. See `specifier-spec-list' for more |
2287 information about LOCALE. | |
2288 | |
2289 Only instantiators where TAG-SET (a list of zero or more tags) is a | |
2290 subset of (or possibly equal to) the instantiator's tag set are copied. | |
2291 The default value of nil is a subset of all tag sets, so in this case | |
2292 no instantiators will be screened out. If EXACT-P is non-nil, however, | |
2293 TAG-SET must be equal to an instantiator's tag set for the instantiator | |
2294 to be copied. | |
2295 | |
2296 Optional argument HOW-TO-ADD specifies what to do with existing | |
2297 specifications in DEST. If nil, then whichever locales or locale types | |
2298 are copied will first be completely erased in DEST. Otherwise, it is | |
2299 the same as in `add-spec-to-specifier'. | |
2300 */ | |
2301 (specifier, dest, locale, tag_set, exact_p, how_to_add)) | |
2302 { | |
2303 struct gcpro gcpro1; | |
2304 struct copy_specifier_closure cl; | |
2305 | |
2306 CHECK_SPECIFIER (specifier); | |
2307 if (NILP (how_to_add)) | |
2308 cl.add_meth_is_nil = 1; | |
2309 else | |
2310 cl.add_meth_is_nil = 0; | |
2311 cl.add_meth = decode_how_to_add_specification (how_to_add); | |
2312 if (NILP (dest)) | |
2313 { | |
2314 /* #### What about copying the extra data? */ | |
2315 dest = make_specifier (XSPECIFIER (specifier)->methods); | |
2316 } | |
2317 else | |
2318 { | |
2319 CHECK_SPECIFIER (dest); | |
2320 check_modifiable_specifier (dest); | |
2321 if (XSPECIFIER (dest)->methods != XSPECIFIER (specifier)->methods) | |
563 | 2322 invalid_argument ("Specifiers not of same type", Qunbound); |
428 | 2323 } |
2324 | |
2325 cl.dest = dest; | |
2326 GCPRO1 (dest); | |
2327 map_specifier (specifier, locale, copy_specifier_mapfun, | |
2328 tag_set, exact_p, &cl); | |
2329 UNGCPRO; | |
2330 recompute_cached_specifier_everywhere (dest); | |
2331 return dest; | |
2332 } | |
2333 | |
2334 | |
2335 /************************************************************************/ | |
2953 | 2336 /* Instantiation */ |
428 | 2337 /************************************************************************/ |
2338 | |
2339 static Lisp_Object | |
2340 call_validate_matchspec_method (Lisp_Object boxed_method, | |
2341 Lisp_Object matchspec) | |
2342 { | |
2343 ((void (*)(Lisp_Object)) get_opaque_ptr (boxed_method)) (matchspec); | |
2344 return Qt; | |
2345 } | |
2346 | |
2347 static Lisp_Object | |
2348 check_valid_specifier_matchspec (Lisp_Object matchspec, | |
2349 struct specifier_methods *meths, | |
578 | 2350 Error_Behavior errb) |
428 | 2351 { |
2352 if (meths->validate_matchspec_method) | |
2353 { | |
2354 Lisp_Object retval; | |
2355 | |
2356 if (ERRB_EQ (errb, ERROR_ME)) | |
2357 { | |
2358 (meths->validate_matchspec_method) (matchspec); | |
2359 retval = Qt; | |
2360 } | |
2361 else | |
2362 { | |
2363 Lisp_Object opaque = | |
2364 make_opaque_ptr ((void *) meths->validate_matchspec_method); | |
2365 struct gcpro gcpro1; | |
2366 | |
2367 GCPRO1 (opaque); | |
2368 retval = call_with_suspended_errors | |
2369 ((lisp_fn_t) call_validate_matchspec_method, | |
2370 Qnil, Qspecifier, errb, 2, opaque, matchspec); | |
2371 | |
2372 free_opaque_ptr (opaque); | |
2373 UNGCPRO; | |
2374 } | |
2375 | |
2376 return retval; | |
2377 } | |
2378 else | |
2379 { | |
563 | 2380 maybe_sferror |
428 | 2381 ("Matchspecs not allowed for this specifier type", |
2382 intern (meths->name), Qspecifier, errb); | |
2383 return Qnil; | |
2384 } | |
2385 } | |
2386 | |
442 | 2387 DEFUN ("check-valid-specifier-matchspec", Fcheck_valid_specifier_matchspec, 2, |
2388 2, 0, /* | |
428 | 2389 Signal an error if MATCHSPEC is invalid for SPECIFIER-TYPE. |
2390 See `specifier-matching-instance' for a description of matchspecs. | |
2391 */ | |
2392 (matchspec, specifier_type)) | |
2393 { | |
2394 struct specifier_methods *meths = decode_specifier_type (specifier_type, | |
2395 ERROR_ME); | |
2396 | |
2397 return check_valid_specifier_matchspec (matchspec, meths, ERROR_ME); | |
2398 } | |
2399 | |
2400 DEFUN ("valid-specifier-matchspec-p", Fvalid_specifier_matchspec_p, 2, 2, 0, /* | |
2401 Return non-nil if MATCHSPEC is valid for SPECIFIER-TYPE. | |
2402 See `specifier-matching-instance' for a description of matchspecs. | |
2403 */ | |
2404 (matchspec, specifier_type)) | |
2405 { | |
2406 struct specifier_methods *meths = decode_specifier_type (specifier_type, | |
2407 ERROR_ME); | |
2408 | |
2409 return check_valid_specifier_matchspec (matchspec, meths, ERROR_ME_NOT); | |
2410 } | |
2411 | |
2412 /* This function is purposely not callable from Lisp. If a Lisp | |
2413 caller wants to set a fallback, they should just set the | |
2414 global value. */ | |
2415 | |
2416 void | |
2417 set_specifier_fallback (Lisp_Object specifier, Lisp_Object fallback) | |
2418 { | |
440 | 2419 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 2420 assert (SPECIFIERP (fallback) || |
2421 !NILP (Fvalid_inst_list_p (fallback, Fspecifier_type (specifier)))); | |
2422 if (SPECIFIERP (fallback)) | |
2423 assert (EQ (Fspecifier_type (specifier), Fspecifier_type (fallback))); | |
2424 if (BODILY_SPECIFIER_P (sp)) | |
2425 GHOST_SPECIFIER(sp)->fallback = fallback; | |
2426 else | |
2427 sp->fallback = fallback; | |
2428 /* call the after-change method */ | |
2429 MAYBE_SPECMETH (sp, after_change, | |
2430 (bodily_specifier (specifier), Qfallback)); | |
2431 recompute_cached_specifier_everywhere (specifier); | |
2432 } | |
2433 | |
2434 DEFUN ("specifier-fallback", Fspecifier_fallback, 1, 1, 0, /* | |
2435 Return the fallback value for SPECIFIER. | |
2436 Fallback values are provided by the C code for certain built-in | |
2953 | 2437 specifiers to make sure that instantiation won't fail even if all |
428 | 2438 specs are removed from the specifier, or to implement simple |
2439 inheritance behavior (e.g. this method is used to ensure that | |
2953 | 2440 faces other than `default' inherit their attributes from `default'). |
428 | 2441 By design, you cannot change the fallback value, and specifiers |
2442 created with `make-specifier' will never have a fallback (although | |
2443 a similar, Lisp-accessible capability may be provided in the future | |
2444 to allow for inheritance). | |
2445 | |
2953 | 2446 The fallback value will be an inst-list that is instantiated like |
428 | 2447 any other inst-list, a specifier of the same type as SPECIFIER |
2448 \(results in inheritance), or nil for no fallback. | |
2449 | |
2953 | 2450 When you instantiate a specifier, you can explicitly request that the |
428 | 2451 fallback not be consulted. (The C code does this, for example, when |
2452 merging faces.) See `specifier-instance'. | |
2453 */ | |
2454 (specifier)) | |
2455 { | |
2456 CHECK_SPECIFIER (specifier); | |
2457 return Fcopy_tree (XSPECIFIER (specifier)->fallback, Qt); | |
2458 } | |
2459 | |
2460 static Lisp_Object | |
2461 specifier_instance_from_inst_list (Lisp_Object specifier, | |
2462 Lisp_Object matchspec, | |
2463 Lisp_Object domain, | |
2464 Lisp_Object inst_list, | |
578 | 2465 Error_Behavior errb, int no_quit, |
2953 | 2466 Lisp_Object depth, |
2467 Lisp_Object *instantiator) | |
428 | 2468 { |
2469 /* This function can GC */ | |
440 | 2470 Lisp_Specifier *sp; |
428 | 2471 Lisp_Object device; |
2472 Lisp_Object rest; | |
2473 int count = specpdl_depth (); | |
2474 struct gcpro gcpro1, gcpro2; | |
2475 | |
2476 GCPRO2 (specifier, inst_list); | |
2477 | |
2478 sp = XSPECIFIER (specifier); | |
442 | 2479 device = DOMAIN_DEVICE (domain); |
428 | 2480 |
2481 if (no_quit) | |
2482 /* The instantiate method is allowed to call eval. Since it | |
2483 is quite common for this function to get called from somewhere in | |
2484 redisplay we need to make sure that quits are ignored. Otherwise | |
2485 Fsignal will abort. */ | |
2486 specbind (Qinhibit_quit, Qt); | |
2487 | |
2488 LIST_LOOP (rest, inst_list) | |
2489 { | |
2490 Lisp_Object tagged_inst = XCAR (rest); | |
2491 Lisp_Object tag_set = XCAR (tagged_inst); | |
2492 | |
2493 if (device_matches_specifier_tag_set_p (device, tag_set)) | |
2494 { | |
2495 Lisp_Object val = XCDR (tagged_inst); | |
2953 | 2496 Lisp_Object the_instantiator = val; |
2497 | |
428 | 2498 |
2499 if (HAS_SPECMETH_P (sp, instantiate)) | |
2500 val = call_with_suspended_errors | |
2501 ((lisp_fn_t) RAW_SPECMETH (sp, instantiate), | |
2502 Qunbound, Qspecifier, errb, 5, specifier, | |
2503 matchspec, domain, val, depth); | |
2504 | |
2505 if (!UNBOUNDP (val)) | |
2506 { | |
771 | 2507 unbind_to (count); |
428 | 2508 UNGCPRO; |
2953 | 2509 if (instantiator) |
2510 *instantiator = the_instantiator; | |
428 | 2511 return val; |
2512 } | |
2513 } | |
2514 } | |
2515 | |
771 | 2516 unbind_to (count); |
428 | 2517 UNGCPRO; |
2518 return Qunbound; | |
2519 } | |
2520 | |
2521 /* Given a SPECIFIER and a DOMAIN, return a specific instance for that | |
2522 specifier. Try to find one by checking the specifier types from most | |
2523 specific (buffer) to most general (global). If we find an instance, | |
2524 return it. Otherwise return Qunbound. */ | |
2525 | |
2526 #define CHECK_INSTANCE_ENTRY(key, matchspec, type) do { \ | |
2527 Lisp_Object *CIE_inst_list = \ | |
2528 specifier_get_inst_list (specifier, key, type); \ | |
2529 if (CIE_inst_list) \ | |
2530 { \ | |
2531 Lisp_Object CIE_val = \ | |
2532 specifier_instance_from_inst_list (specifier, matchspec, \ | |
2533 domain, *CIE_inst_list, \ | |
2953 | 2534 errb, no_quit, depth, \ |
2535 instantiator); \ | |
428 | 2536 if (!UNBOUNDP (CIE_val)) \ |
2537 return CIE_val; \ | |
2538 } \ | |
2539 } while (0) | |
2540 | |
2541 /* We accept any window, frame or device domain and do our checking | |
2542 starting from as specific a locale type as we can determine from the | |
2543 domain we are passed and going on up through as many other locale types | |
2544 as we can determine. In practice, when called from redisplay the | |
2545 arg will usually be a window and occasionally a frame. If | |
2546 triggered by a user call, who knows what it will usually be. */ | |
2953 | 2547 |
2548 static Lisp_Object | |
2549 specifier_instance_1 (Lisp_Object specifier, Lisp_Object matchspec, | |
2550 Lisp_Object domain, Error_Behavior errb, int no_quit, | |
2551 int no_fallback, Lisp_Object depth, | |
2552 Lisp_Object *instantiator) | |
428 | 2553 { |
2554 Lisp_Object buffer = Qnil; | |
2555 Lisp_Object window = Qnil; | |
2556 Lisp_Object frame = Qnil; | |
2557 Lisp_Object device = Qnil; | |
444 | 2558 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 2559 |
2953 | 2560 if (instantiator) |
2561 *instantiator = Qunbound; | |
2562 | |
428 | 2563 /* Attempt to determine buffer, window, frame, and device from the |
2564 domain. */ | |
442 | 2565 /* #### get image instances out of domains! */ |
2566 if (IMAGE_INSTANCEP (domain)) | |
2567 window = DOMAIN_WINDOW (domain); | |
2568 else if (WINDOWP (domain)) | |
428 | 2569 window = domain; |
2570 else if (FRAMEP (domain)) | |
2571 frame = domain; | |
2572 else if (DEVICEP (domain)) | |
2573 device = domain; | |
2574 else | |
442 | 2575 /* dmoore writes: [dammit, this should just signal an error or something |
2576 shouldn't it?] | |
2577 | |
2578 No. Errors are handled in Lisp primitives implementation. | |
428 | 2579 Invalid domain is a design error here - kkm. */ |
2500 | 2580 ABORT (); |
428 | 2581 |
2582 if (NILP (buffer) && !NILP (window)) | |
444 | 2583 buffer = WINDOW_BUFFER (XWINDOW (window)); |
428 | 2584 if (NILP (frame) && !NILP (window)) |
2585 frame = XWINDOW (window)->frame; | |
2586 if (NILP (device)) | |
2587 /* frame had better exist; if device is undeterminable, something | |
2588 really went wrong. */ | |
444 | 2589 device = FRAME_DEVICE (XFRAME (frame)); |
428 | 2590 |
2591 /* device had better be determined by now; abort if not. */ | |
2286 | 2592 (void) DEVICE_CLASS (XDEVICE (device)); |
428 | 2593 |
2594 depth = make_int (1 + XINT (depth)); | |
2595 if (XINT (depth) > 20) | |
2596 { | |
563 | 2597 maybe_signal_error (Qstack_overflow, |
2598 "Apparent loop in specifier inheritance", | |
2599 Qunbound, Qspecifier, errb); | |
428 | 2600 /* The specification is fucked; at least try the fallback |
2601 (which better not be fucked, because it's not changeable | |
2602 from Lisp). */ | |
2603 depth = Qzero; | |
2604 goto do_fallback; | |
2605 } | |
2606 | |
434 | 2607 retry: |
428 | 2608 /* First see if we can generate one from the window specifiers. */ |
2609 if (!NILP (window)) | |
2610 CHECK_INSTANCE_ENTRY (window, matchspec, LOCALE_WINDOW); | |
2611 | |
2612 /* Next see if we can generate one from the buffer specifiers. */ | |
2613 if (!NILP (buffer)) | |
2614 CHECK_INSTANCE_ENTRY (buffer, matchspec, LOCALE_BUFFER); | |
2615 | |
2616 /* Next see if we can generate one from the frame specifiers. */ | |
2617 if (!NILP (frame)) | |
2618 CHECK_INSTANCE_ENTRY (frame, matchspec, LOCALE_FRAME); | |
2619 | |
2620 /* If we still haven't succeeded try with the device specifiers. */ | |
2621 CHECK_INSTANCE_ENTRY (device, matchspec, LOCALE_DEVICE); | |
2622 | |
2623 /* Last and least try the global specifiers. */ | |
2624 CHECK_INSTANCE_ENTRY (Qglobal, matchspec, LOCALE_GLOBAL); | |
2625 | |
434 | 2626 do_fallback: |
428 | 2627 /* We're out of specifiers and we still haven't generated an |
2628 instance. At least try the fallback ... If this fails, | |
2629 then we just return Qunbound. */ | |
2630 | |
2631 if (no_fallback || NILP (sp->fallback)) | |
2632 /* I said, I don't want the fallbacks. */ | |
2633 return Qunbound; | |
2634 | |
2635 if (SPECIFIERP (sp->fallback)) | |
2636 { | |
2637 /* If you introduced loops in the default specifier chain, | |
2638 then you're fucked, so you better not do this. */ | |
2639 specifier = sp->fallback; | |
2640 sp = XSPECIFIER (specifier); | |
2641 goto retry; | |
2642 } | |
2643 | |
2644 assert (CONSP (sp->fallback)); | |
2645 return specifier_instance_from_inst_list (specifier, matchspec, domain, | |
2646 sp->fallback, errb, no_quit, | |
2953 | 2647 depth, instantiator); |
428 | 2648 } |
2649 #undef CHECK_INSTANCE_ENTRY | |
2650 | |
2651 Lisp_Object | |
2953 | 2652 specifier_instance (Lisp_Object specifier, Lisp_Object matchspec, |
2653 Lisp_Object domain, Error_Behavior errb, int no_quit, | |
2654 int no_fallback, Lisp_Object depth) | |
2655 { | |
2656 return specifier_instance_1 (specifier, matchspec, domain, errb, | |
2657 no_quit, no_fallback, depth, NULL); | |
2658 } | |
2659 | |
2660 Lisp_Object | |
428 | 2661 specifier_instance_no_quit (Lisp_Object specifier, Lisp_Object matchspec, |
578 | 2662 Lisp_Object domain, Error_Behavior errb, |
428 | 2663 int no_fallback, Lisp_Object depth) |
2664 { | |
2953 | 2665 return specifier_instance_1 (specifier, matchspec, domain, errb, |
2666 1, no_fallback, depth, NULL); | |
2667 } | |
2668 | |
2669 static Lisp_Object | |
2670 specifier_matching_foo (Lisp_Object specifier, | |
2671 Lisp_Object matchspec, | |
2672 Lisp_Object domain, | |
2673 Lisp_Object default_, | |
2674 Lisp_Object no_fallback, | |
2675 int want_instantiator) | |
2676 { | |
2677 Lisp_Object instance, instantiator; | |
2678 | |
2679 CHECK_SPECIFIER (specifier); | |
2680 if (!UNBOUNDP (matchspec)) | |
2681 check_valid_specifier_matchspec (matchspec, | |
2682 XSPECIFIER (specifier)->methods, | |
2683 ERROR_ME); | |
2684 domain = decode_domain (domain); | |
2685 | |
2686 instance = specifier_instance_1 (specifier, matchspec, domain, ERROR_ME, | |
2687 0, !NILP (no_fallback), Qzero, | |
2688 &instantiator); | |
2689 return UNBOUNDP (instance) ? default_ : want_instantiator ? instantiator : | |
2690 instance; | |
428 | 2691 } |
2692 | |
2693 DEFUN ("specifier-instance", Fspecifier_instance, 1, 4, 0, /* | |
2694 Instantiate SPECIFIER (return its value) in DOMAIN. | |
2695 If no instance can be generated for this domain, return DEFAULT. | |
2696 | |
2953 | 2697 DOMAIN is nearly always a window (defaulting to the selected window if |
2698 omitted), but can be a window, frame, or device. Other values that are legal | |
428 | 2699 as a locale (e.g. a buffer) are not valid as a domain because they do not |
2700 provide enough information to identify a particular device (see | |
2953 | 2701 `valid-specifier-domain-p'). Window domains are used internally in nearly |
2702 all circumstances when computing specifier instances of display properties. | |
2703 Frame domains are used in a few circumstances (such as when computing the | |
2704 geometry of a frame based on properties such as the toolbar widths), and | |
2705 device domains are rarely if ever used internally. | |
2706 | |
2707 This function looks through the specifications in SPECIFIER that correspond | |
2708 to DOMAIN, from most specific (specifications for DOMAIN itself) to most | |
2709 general (global specifications), for matching instantiators, and attempts | |
2710 to compute an instance value for each instantiator found. The first | |
2711 successfully computed value is returned. The corresponding instantiator | |
2712 can be returned using `specifier-instantiator'. | |
2713 | |
2714 A specifier is a generalized object for controlling the value of a property -- | |
2715 typically, but not necessarily, a display-related property -- that can vary | |
2716 over particular buffers, frames, device types, etc. | |
2717 | |
2718 A fundamental distinction must be made between the specification of a | |
2719 property's value, and the resulting value itself. This distinction is | |
2720 clearest in the case of an image -- the specification describes the source | |
2721 of the image (for example, a file of JPEG data), and the resulting value | |
2722 encapsulates a window-system object describing the image as displayed on a | |
2723 particular device (for example, a particular X display). The specification | |
2724 might also be an instruction of the form "use the background pixmap of the | |
2725 `modeline' face". A similar mapping exists between color strings and | |
2726 color-instance objects, and font strings and font-instance objects. In | |
2727 some cases, the specification and the resulting value are of the same type, | |
2728 but the distinction is still logically made. | |
2729 | |
2730 The specification of a value is called an instantiator, and the resulting | |
2731 value the instance. | |
428 | 2732 |
2733 "Instantiating" a specifier in a particular domain means determining | |
2734 the specifier's "value" in that domain. This is accomplished by | |
2735 searching through the specifications in the specifier that correspond | |
2736 to all locales that can be derived from the given domain, from specific | |
2737 to general. In most cases, the domain is an Emacs window. In that case | |
2738 specifications are searched for as follows: | |
2739 | |
2740 1. A specification whose locale is the window itself; | |
2741 2. A specification whose locale is the window's buffer; | |
2742 3. A specification whose locale is the window's frame; | |
2743 4. A specification whose locale is the window's frame's device; | |
2953 | 2744 5. A specification whose locale is `global'. |
428 | 2745 |
2746 If all of those fail, then the C-code-provided fallback value for | |
2747 this specifier is consulted (see `specifier-fallback'). If it is | |
2748 an inst-list, then this function attempts to instantiate that list | |
2749 just as when a specification is located in the first five steps above. | |
2750 If the fallback is a specifier, `specifier-instance' is called | |
2751 recursively on this specifier and the return value used. Note, | |
2752 however, that if the optional argument NO-FALLBACK is non-nil, | |
2753 the fallback value will not be consulted. | |
2754 | |
2755 Note that there may be more than one specification matching a particular | |
2756 locale; all such specifications are considered before looking for any | |
2757 specifications for more general locales. Any particular specification | |
2758 that is found may be rejected because its tag set does not match the | |
2759 device being instantiated over, or because the specification is not | |
2760 valid for the device of the given domain (e.g. the font or color name | |
2761 does not exist for this particular X server). | |
2762 | |
793 | 2763 NOTE: When errors occur in the process of trying a particular instantiator, |
2764 and the instantiator is thus skipped, warnings will be issued at level | |
2765 `debug'. Normally, such warnings are ignored entirely, but you can change | |
2766 this by setting `log-warning-minimum-level'. This is useful if you're | |
2767 trying to debug why particular instantiators are not being processed. | |
2768 | |
428 | 2769 The returned value is dependent on the type of specifier. For example, |
2770 for a font specifier (as returned by the `face-font' function), the returned | |
2771 value will be a font-instance object. For glyphs, the returned value | |
2953 | 2772 will be an image-instance object. |
428 | 2773 |
2774 See also `specifier-matching-instance'. | |
2775 */ | |
2776 (specifier, domain, default_, no_fallback)) | |
2777 { | |
2953 | 2778 return specifier_matching_foo (specifier, Qunbound, domain, default_, |
2779 no_fallback, 0); | |
2780 } | |
2781 | |
2782 DEFUN ("specifier-instantiator", Fspecifier_instantiator, 1, 4, 0, /* | |
2783 Return instantiator that would be used to instantiate SPECIFIER in DOMAIN. | |
2784 If no instance can be generated for this domain, return DEFAULT. | |
2785 | |
2786 DOMAIN should be a window, frame, or device. Other values that are legal | |
2787 as a locale (e.g. a buffer) are not valid as a domain because they do not | |
2788 provide enough information to identify a particular device (see | |
2789 `valid-specifier-domain-p'). DOMAIN defaults to the selected window | |
2790 if omitted. | |
2791 | |
2792 See `specifier-instance' for more information about the instantiation process. | |
2793 */ | |
2794 (specifier, domain, default_, no_fallback)) | |
2795 { | |
2796 return specifier_matching_foo (specifier, Qunbound, domain, default_, | |
2797 no_fallback, 1); | |
428 | 2798 } |
2799 | |
2800 DEFUN ("specifier-matching-instance", Fspecifier_matching_instance, 2, 5, 0, /* | |
2801 Return an instance for SPECIFIER in DOMAIN that matches MATCHSPEC. | |
2802 If no instance can be generated for this domain, return DEFAULT. | |
2803 | |
2804 This function is identical to `specifier-instance' except that a | |
2805 specification will only be considered if it matches MATCHSPEC. | |
2806 The definition of "match", and allowed values for MATCHSPEC, are | |
2807 dependent on the particular type of specifier. Here are some examples: | |
2808 | |
2809 -- For chartable (e.g. display table) specifiers, MATCHSPEC should be a | |
2810 character, and the specification (a chartable) must give a value for | |
2811 that character in order to be considered. This allows you to specify, | |
2812 e.g., a buffer-local display table that only gives values for particular | |
2813 characters. All other characters are handled as if the buffer-local | |
2814 display table is not there. (Chartable specifiers are not yet | |
2815 implemented.) | |
2816 | |
872 | 2817 -- For font specifiers, MATCHSPEC should be a list (CHARSET . SECOND-STAGE-P), |
2818 and the specification (a font string) must have a registry that matches | |
2819 the charset's registry. (This only makes sense with Mule support.) This | |
2820 makes it easy to choose a font that can display a particular | |
2821 character. (This is what redisplay does, in fact.) SECOND-STAGE-P means | |
2822 to ignore the font's registry and instead look at the characters in the | |
2823 font to see if the font can support the charset. This currently only makes | |
2824 sense under MS Windows. | |
428 | 2825 */ |
2826 (specifier, matchspec, domain, default_, no_fallback)) | |
2827 { | |
2953 | 2828 return specifier_matching_foo (specifier, matchspec, domain, default_, |
2829 no_fallback, 0); | |
2830 } | |
2831 | |
2832 DEFUN ("specifier-matching-instantiator", Fspecifier_matching_instantiator, | |
2833 2, 5, 0, /* | |
2834 Return instantiator for instance of SPECIFIER in DOMAIN that matches MATCHSPEC. | |
2835 If no instance can be generated for this domain, return DEFAULT. | |
2836 | |
2837 This function is identical to `specifier-matching-instance' but returns | |
2838 the instantiator used to generate the instance, rather than the actual | |
2839 instance. | |
2840 */ | |
2841 (specifier, matchspec, domain, default_, no_fallback)) | |
2842 { | |
2843 return specifier_matching_foo (specifier, matchspec, domain, default_, | |
2844 no_fallback, 1); | |
2845 } | |
2846 | |
2847 static Lisp_Object | |
2848 specifier_matching_foo_from_inst_list (Lisp_Object specifier, | |
2849 Lisp_Object matchspec, | |
2850 Lisp_Object domain, | |
2851 Lisp_Object inst_list, | |
2852 Lisp_Object default_, | |
2853 int want_instantiator) | |
2854 { | |
2855 Lisp_Object val = Qunbound; | |
2856 Lisp_Specifier *sp = XSPECIFIER (specifier); | |
2857 struct gcpro gcpro1; | |
2858 Lisp_Object built_up_list = Qnil; | |
2859 Lisp_Object instantiator; | |
428 | 2860 |
2861 CHECK_SPECIFIER (specifier); | |
2953 | 2862 if (!UNBOUNDP (matchspec)) |
2863 check_valid_specifier_matchspec (matchspec, | |
2864 XSPECIFIER (specifier)->methods, | |
2865 ERROR_ME); | |
2866 check_valid_domain (domain); | |
2867 check_valid_inst_list (inst_list, sp->methods, ERROR_ME); | |
2868 GCPRO1 (built_up_list); | |
2869 built_up_list = build_up_processed_list (specifier, domain, inst_list); | |
2870 if (!NILP (built_up_list)) | |
2871 val = specifier_instance_from_inst_list (specifier, matchspec, domain, | |
2872 built_up_list, ERROR_ME, | |
2873 0, Qzero, &instantiator); | |
2874 UNGCPRO; | |
2875 return UNBOUNDP (val) ? default_ : want_instantiator ? instantiator : val; | |
2876 | |
428 | 2877 } |
2878 | |
2879 DEFUN ("specifier-instance-from-inst-list", Fspecifier_instance_from_inst_list, | |
2880 3, 4, 0, /* | |
2881 Attempt to convert a particular inst-list into an instance. | |
2882 This attempts to instantiate INST-LIST in the given DOMAIN, | |
2883 as if INST-LIST existed in a specification in SPECIFIER. If | |
2884 the instantiation fails, DEFAULT is returned. In most circumstances, | |
2885 you should not use this function; use `specifier-instance' instead. | |
2886 */ | |
2887 (specifier, domain, inst_list, default_)) | |
2888 { | |
2953 | 2889 return specifier_matching_foo_from_inst_list (specifier, Qunbound, |
2890 domain, inst_list, default_, | |
2891 0); | |
2892 } | |
2893 | |
2894 DEFUN ("specifier-instantiator-from-inst-list", Fspecifier_instantiator_from_inst_list, | |
2895 3, 4, 0, /* | |
2896 Attempt to convert an inst-list into an instance; return instantiator. | |
2897 This is identical to `specifier-instance-from-inst-list' but returns | |
2898 the instantiator used to generate the instance, rather than the instance | |
2899 itself. | |
2900 */ | |
2901 (specifier, domain, inst_list, default_)) | |
2902 { | |
2903 return specifier_matching_foo_from_inst_list (specifier, Qunbound, | |
2904 domain, inst_list, default_, | |
2905 1); | |
428 | 2906 } |
2907 | |
442 | 2908 DEFUN ("specifier-matching-instance-from-inst-list", |
2909 Fspecifier_matching_instance_from_inst_list, | |
428 | 2910 4, 5, 0, /* |
2911 Attempt to convert a particular inst-list into an instance. | |
2912 This attempts to instantiate INST-LIST in the given DOMAIN | |
2913 \(as if INST-LIST existed in a specification in SPECIFIER), | |
2914 matching the specifications against MATCHSPEC. | |
2915 | |
2916 This function is analogous to `specifier-instance-from-inst-list' | |
2917 but allows for specification-matching as in `specifier-matching-instance'. | |
2918 See that function for a description of exactly how the matching process | |
2919 works. | |
2920 */ | |
2921 (specifier, matchspec, domain, inst_list, default_)) | |
2922 { | |
2953 | 2923 return specifier_matching_foo_from_inst_list (specifier, matchspec, |
2924 domain, inst_list, default_, | |
2925 0); | |
2926 } | |
2927 | |
2928 DEFUN ("specifier-matching-instantiator-from-inst-list", | |
2929 Fspecifier_matching_instantiator_from_inst_list, | |
2930 4, 5, 0, /* | |
2931 Attempt to convert an inst-list into an instance; return instantiator. | |
2932 This is identical to `specifier-matching-instance-from-inst-list' but returns | |
2933 the instantiator used to generate the instance, rather than the instance | |
2934 itself. | |
2935 */ | |
2936 (specifier, matchspec, domain, inst_list, default_)) | |
2937 { | |
2938 return specifier_matching_foo_from_inst_list (specifier, matchspec, | |
2939 domain, inst_list, default_, | |
2940 1); | |
428 | 2941 } |
2942 | |
2943 | |
2944 /************************************************************************/ | |
2945 /* Caching in the struct window or frame */ | |
2946 /************************************************************************/ | |
2947 | |
853 | 2948 /* Cause the current value of SPECIFIER in the domain of each frame and/or |
2949 window to be cached in the struct frame at STRUCT_FRAME_OFFSET and the | |
2950 struct window at STRUCT_WINDOW_OFFSET. When the value changes in a | |
2951 particular window, VALUE_CHANGED_IN_WINDOW is called. When the value | |
2952 changes in a particular frame, VALUE_CHANGED_IN_FRAME is called. | |
2953 | |
2954 Either STRUCT_WINDOW_OFFSET or STRUCT_FRAME_OFFSET can be 0 to indicate | |
2955 no caching in that sort of object. However, if they're not 0, you | |
2956 must supply a corresponding value-changed function. (This is the case | |
2957 so that you are forced to consider the ramifications of a value change. | |
2958 You nearly always need to do something, e.g. set a dirty flag.) | |
2959 | |
2960 If you create a built-in specifier, you should do the following: | |
2961 | |
2962 - Make sure the file you create the specifier in has a | |
2963 specifier_vars_of_foo() function. If not, create it, declare it in | |
2964 symsinit.h, and make sure it's called in the appropriate place in | |
2965 emacs.c. | |
2966 - In specifier_vars_of_foo(), do a DEFVAR_SPECIFIER(), followed by | |
2967 initializing the specifier using Fmake_specifier(), followed by | |
2968 set_specifier_fallback(), followed (optionally) by | |
2969 set_specifier_caching(). | |
2970 - If you used set_specifier_caching(), make sure to create the | |
2971 appropriate value-changed functions. Also make sure to add the | |
2972 appropriate slots where the values are cached to frameslots.h and | |
2973 winslots.h. | |
2974 | |
2975 Do a grep for menubar_visible_p for an example. | |
2976 */ | |
428 | 2977 |
2978 /* #### It would be nice if the specifier caching automatically knew | |
2979 about specifier fallbacks, so we didn't have to do it ourselves. */ | |
2980 | |
2981 void | |
2982 set_specifier_caching (Lisp_Object specifier, int struct_window_offset, | |
2983 void (*value_changed_in_window) | |
2984 (Lisp_Object specifier, struct window *w, | |
2985 Lisp_Object oldval), | |
2986 int struct_frame_offset, | |
2987 void (*value_changed_in_frame) | |
2988 (Lisp_Object specifier, struct frame *f, | |
444 | 2989 Lisp_Object oldval), |
2990 int always_recompute) | |
428 | 2991 { |
440 | 2992 Lisp_Specifier *sp = XSPECIFIER (specifier); |
428 | 2993 assert (!GHOST_SPECIFIER_P (sp)); |
2994 | |
2995 if (!sp->caching) | |
2996 sp->caching = xnew_and_zero (struct specifier_caching); | |
2997 sp->caching->offset_into_struct_window = struct_window_offset; | |
2998 sp->caching->value_changed_in_window = value_changed_in_window; | |
2999 sp->caching->offset_into_struct_frame = struct_frame_offset; | |
3000 sp->caching->value_changed_in_frame = value_changed_in_frame; | |
853 | 3001 if (struct_window_offset) |
3002 assert (value_changed_in_window); | |
3003 if (struct_frame_offset) | |
3004 assert (value_changed_in_frame); | |
444 | 3005 sp->caching->always_recompute = always_recompute; |
428 | 3006 Vcached_specifiers = Fcons (specifier, Vcached_specifiers); |
3007 if (BODILY_SPECIFIER_P (sp)) | |
3008 GHOST_SPECIFIER(sp)->caching = sp->caching; | |
3009 recompute_cached_specifier_everywhere (specifier); | |
3010 } | |
3011 | |
3012 static void | |
3013 recompute_one_cached_specifier_in_window (Lisp_Object specifier, | |
3014 struct window *w) | |
3015 { | |
3016 Lisp_Object window; | |
444 | 3017 Lisp_Object newval, *location, oldval; |
428 | 3018 |
3019 assert (!GHOST_SPECIFIER_P (XSPECIFIER (specifier))); | |
3020 | |
793 | 3021 window = wrap_window (w); |
428 | 3022 |
3023 newval = specifier_instance (specifier, Qunbound, window, ERROR_ME_WARN, | |
3024 0, 0, Qzero); | |
3025 /* If newval ended up Qunbound, then the calling functions | |
3026 better be able to deal. If not, set a default so this | |
3027 never happens or correct it in the value_changed_in_window | |
3028 method. */ | |
3029 location = (Lisp_Object *) | |
3030 ((char *) w + XSPECIFIER (specifier)->caching->offset_into_struct_window); | |
442 | 3031 /* #### What's the point of this check, other than to optimize image |
3032 instance instantiation? Unless you specify a caching instantiate | |
3033 method the instantiation that specifier_instance will do will | |
3034 always create a new copy. Thus EQ will always fail. Unfortunately | |
3035 calling equal is no good either as this doesn't take into account | |
3036 things attached to the specifier - for instance strings on | |
3037 extents. --andyp */ | |
444 | 3038 if (!EQ (newval, *location) || XSPECIFIER (specifier)->caching->always_recompute) |
428 | 3039 { |
444 | 3040 oldval = *location; |
428 | 3041 *location = newval; |
3042 (XSPECIFIER (specifier)->caching->value_changed_in_window) | |
3043 (specifier, w, oldval); | |
3044 } | |
3045 } | |
3046 | |
3047 static void | |
3048 recompute_one_cached_specifier_in_frame (Lisp_Object specifier, | |
3049 struct frame *f) | |
3050 { | |
3051 Lisp_Object frame; | |
444 | 3052 Lisp_Object newval, *location, oldval; |
428 | 3053 |
3054 assert (!GHOST_SPECIFIER_P (XSPECIFIER (specifier))); | |
3055 | |
793 | 3056 frame = wrap_frame (f); |
428 | 3057 |
3058 newval = specifier_instance (specifier, Qunbound, frame, ERROR_ME_WARN, | |
3059 0, 0, Qzero); | |
3060 /* If newval ended up Qunbound, then the calling functions | |
3061 better be able to deal. If not, set a default so this | |
3062 never happens or correct it in the value_changed_in_frame | |
3063 method. */ | |
3064 location = (Lisp_Object *) | |
3065 ((char *) f + XSPECIFIER (specifier)->caching->offset_into_struct_frame); | |
444 | 3066 if (!EQ (newval, *location) || XSPECIFIER (specifier)->caching->always_recompute) |
428 | 3067 { |
444 | 3068 oldval = *location; |
428 | 3069 *location = newval; |
3070 (XSPECIFIER (specifier)->caching->value_changed_in_frame) | |
3071 (specifier, f, oldval); | |
3072 } | |
3073 } | |
3074 | |
3075 void | |
3076 recompute_all_cached_specifiers_in_window (struct window *w) | |
3077 { | |
3078 Lisp_Object rest; | |
3079 | |
3080 LIST_LOOP (rest, Vcached_specifiers) | |
3081 { | |
3082 Lisp_Object specifier = XCAR (rest); | |
3083 if (XSPECIFIER (specifier)->caching->offset_into_struct_window) | |
3084 recompute_one_cached_specifier_in_window (specifier, w); | |
3085 } | |
3086 } | |
3087 | |
3088 void | |
3089 recompute_all_cached_specifiers_in_frame (struct frame *f) | |
3090 { | |
3091 Lisp_Object rest; | |
3092 | |
3093 LIST_LOOP (rest, Vcached_specifiers) | |
3094 { | |
3095 Lisp_Object specifier = XCAR (rest); | |
3096 if (XSPECIFIER (specifier)->caching->offset_into_struct_frame) | |
3097 recompute_one_cached_specifier_in_frame (specifier, f); | |
3098 } | |
3099 } | |
3100 | |
3101 static int | |
3102 recompute_cached_specifier_everywhere_mapfun (struct window *w, | |
3103 void *closure) | |
3104 { | |
3105 Lisp_Object specifier = Qnil; | |
3106 | |
826 | 3107 specifier = VOID_TO_LISP (closure); |
428 | 3108 recompute_one_cached_specifier_in_window (specifier, w); |
3109 return 0; | |
3110 } | |
3111 | |
3112 static void | |
3113 recompute_cached_specifier_everywhere (Lisp_Object specifier) | |
3114 { | |
3115 Lisp_Object frmcons, devcons, concons; | |
3116 | |
3117 specifier = bodily_specifier (specifier); | |
3118 | |
3119 if (!XSPECIFIER (specifier)->caching) | |
3120 return; | |
3121 | |
3122 if (XSPECIFIER (specifier)->caching->offset_into_struct_window) | |
3123 { | |
3124 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
3125 map_windows (XFRAME (XCAR (frmcons)), | |
3126 recompute_cached_specifier_everywhere_mapfun, | |
3127 LISP_TO_VOID (specifier)); | |
3128 } | |
3129 | |
3130 if (XSPECIFIER (specifier)->caching->offset_into_struct_frame) | |
3131 { | |
3132 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
3133 recompute_one_cached_specifier_in_frame (specifier, | |
3134 XFRAME (XCAR (frmcons))); | |
3135 } | |
3136 } | |
3137 | |
3138 DEFUN ("set-specifier-dirty-flag", Fset_specifier_dirty_flag, 1, 1, 0, /* | |
3139 Force recomputation of any caches associated with SPECIFIER. | |
3140 Note that this automatically happens whenever you change a specification | |
3141 in SPECIFIER; you do not have to call this function then. | |
3142 One example of where this function is useful is when you have a | |
3143 toolbar button whose `active-p' field is an expression to be | |
3144 evaluated. Calling `set-specifier-dirty-flag' on the | |
3145 toolbar specifier will force the `active-p' fields to be | |
3146 recomputed. | |
3147 */ | |
3148 (specifier)) | |
3149 { | |
3150 CHECK_SPECIFIER (specifier); | |
3151 recompute_cached_specifier_everywhere (specifier); | |
3152 return Qnil; | |
3153 } | |
3154 | |
3155 | |
3156 /************************************************************************/ | |
3157 /* Generic specifier type */ | |
3158 /************************************************************************/ | |
3159 | |
3160 DEFINE_SPECIFIER_TYPE (generic); | |
3161 | |
3162 #if 0 | |
3163 | |
3164 /* This is the string that used to be in `generic-specifier-p'. | |
3165 The idea is good, but it doesn't quite work in the form it's | |
3166 in. (One major problem is that validating an instantiator | |
3167 is supposed to require only that the specifier type is passed, | |
3168 while with this approach the actual specifier is needed.) | |
3169 | |
3170 What really needs to be done is to write a function | |
3171 `make-specifier-type' that creates new specifier types. | |
442 | 3172 |
3173 #### [I'll look into this for 19.14.] Well, sometime. (Currently | |
3174 May 2000, 21.2 is in development. 19.14 was released in June 1996.) */ | |
428 | 3175 |
3176 "A generic specifier is a generalized kind of specifier with user-defined\n" | |
3177 "semantics. The instantiator can be any kind of Lisp object, and the\n" | |
3178 "instance computed from it is likewise any kind of Lisp object. The\n" | |
3179 "SPECIFIER-DATA should be an alist of methods governing how the specifier\n" | |
3180 "works. All methods are optional, and reasonable default methods will be\n" | |
2953 | 3181 "provided. Currently there are two defined methods: `instantiate' and\n" |
3182 "`validate'.\n" | |
428 | 3183 "\n" |
2953 | 3184 "`instantiate' specifies how to do the instantiation; if omitted, the\n" |
428 | 3185 "instantiator itself is simply returned as the instance. The method\n" |
3186 "should be a function that accepts three parameters (a specifier, the\n" | |
3187 "instantiator that matched the domain being instantiated over, and that\n" | |
3188 "domain), and should return a one-element list containing the instance,\n" | |
3189 "or nil if no instance exists. Note that the domain passed to this function\n" | |
3190 "is the domain being instantiated over, which may not be the same as the\n" | |
3191 "locale contained in the specification corresponding to the instantiator\n" | |
3192 "(for example, the domain being instantiated over could be a window, but\n" | |
3193 "the locale corresponding to the passed instantiator could be the window's\n" | |
3194 "buffer or frame).\n" | |
3195 "\n" | |
2953 | 3196 "`validate' specifies whether a given instantiator is valid; if omitted,\n" |
428 | 3197 "all instantiators are considered valid. It should be a function of\n" |
3198 "two arguments: an instantiator and a flag CAN-SIGNAL-ERROR. If this\n" | |
3199 "flag is false, the function must simply return t or nil indicating\n" | |
3200 "whether the instantiator is valid. If this flag is true, the function\n" | |
3201 "is free to signal an error if it encounters an invalid instantiator\n" | |
3202 "(this can be useful for issuing a specific error about exactly why the\n" | |
3203 "instantiator is valid). It can also return nil to indicate an invalid\n" | |
3204 "instantiator; in this case, a general error will be signalled." | |
3205 | |
3206 #endif /* 0 */ | |
3207 | |
3208 DEFUN ("generic-specifier-p", Fgeneric_specifier_p, 1, 1, 0, /* | |
3209 Return non-nil if OBJECT is a generic specifier. | |
3210 | |
442 | 3211 See `make-generic-specifier' for a description of possible generic |
3212 instantiators. | |
428 | 3213 */ |
3214 (object)) | |
3215 { | |
3216 return GENERIC_SPECIFIERP (object) ? Qt : Qnil; | |
3217 } | |
3218 | |
3219 | |
3220 /************************************************************************/ | |
3221 /* Integer specifier type */ | |
3222 /************************************************************************/ | |
3223 | |
3224 DEFINE_SPECIFIER_TYPE (integer); | |
3225 | |
3226 static void | |
3227 integer_validate (Lisp_Object instantiator) | |
3228 { | |
3229 CHECK_INT (instantiator); | |
3230 } | |
3231 | |
3232 DEFUN ("integer-specifier-p", Finteger_specifier_p, 1, 1, 0, /* | |
3233 Return non-nil if OBJECT is an integer specifier. | |
442 | 3234 |
3235 See `make-integer-specifier' for a description of possible integer | |
3236 instantiators. | |
428 | 3237 */ |
3238 (object)) | |
3239 { | |
3240 return INTEGER_SPECIFIERP (object) ? Qt : Qnil; | |
3241 } | |
3242 | |
3243 /************************************************************************/ | |
3244 /* Non-negative-integer specifier type */ | |
3245 /************************************************************************/ | |
3246 | |
3247 DEFINE_SPECIFIER_TYPE (natnum); | |
3248 | |
3249 static void | |
3250 natnum_validate (Lisp_Object instantiator) | |
3251 { | |
3252 CHECK_NATNUM (instantiator); | |
3253 } | |
3254 | |
3255 DEFUN ("natnum-specifier-p", Fnatnum_specifier_p, 1, 1, 0, /* | |
3256 Return non-nil if OBJECT is a natnum (non-negative-integer) specifier. | |
442 | 3257 |
3258 See `make-natnum-specifier' for a description of possible natnum | |
3259 instantiators. | |
428 | 3260 */ |
3261 (object)) | |
3262 { | |
3263 return NATNUM_SPECIFIERP (object) ? Qt : Qnil; | |
3264 } | |
3265 | |
3266 /************************************************************************/ | |
3267 /* Boolean specifier type */ | |
3268 /************************************************************************/ | |
3269 | |
3270 DEFINE_SPECIFIER_TYPE (boolean); | |
3271 | |
3272 static void | |
3273 boolean_validate (Lisp_Object instantiator) | |
3274 { | |
3275 if (!EQ (instantiator, Qt) && !EQ (instantiator, Qnil)) | |
563 | 3276 invalid_constant ("Must be t or nil", instantiator); |
428 | 3277 } |
3278 | |
3279 DEFUN ("boolean-specifier-p", Fboolean_specifier_p, 1, 1, 0, /* | |
3280 Return non-nil if OBJECT is a boolean specifier. | |
442 | 3281 |
3282 See `make-boolean-specifier' for a description of possible boolean | |
3283 instantiators. | |
428 | 3284 */ |
3285 (object)) | |
3286 { | |
3287 return BOOLEAN_SPECIFIERP (object) ? Qt : Qnil; | |
3288 } | |
3289 | |
3290 /************************************************************************/ | |
3291 /* Display table specifier type */ | |
3292 /************************************************************************/ | |
3293 | |
3294 DEFINE_SPECIFIER_TYPE (display_table); | |
3295 | |
442 | 3296 #define VALID_SINGLE_DISPTABLE_INSTANTIATOR_P(instantiator) \ |
3297 (VECTORP (instantiator) \ | |
3298 || (CHAR_TABLEP (instantiator) \ | |
3299 && (XCHAR_TABLE_TYPE (instantiator) == CHAR_TABLE_TYPE_CHAR \ | |
3300 || XCHAR_TABLE_TYPE (instantiator) == CHAR_TABLE_TYPE_GENERIC)) \ | |
428 | 3301 || RANGE_TABLEP (instantiator)) |
3302 | |
3303 static void | |
3304 display_table_validate (Lisp_Object instantiator) | |
3305 { | |
3306 if (NILP (instantiator)) | |
3307 /* OK */ | |
3308 ; | |
3309 else if (CONSP (instantiator)) | |
3310 { | |
2367 | 3311 EXTERNAL_LIST_LOOP_2 (car, instantiator) |
428 | 3312 { |
3313 if (!VALID_SINGLE_DISPTABLE_INSTANTIATOR_P (car)) | |
3314 goto lose; | |
3315 } | |
3316 } | |
3317 else | |
3318 { | |
3319 if (!VALID_SINGLE_DISPTABLE_INSTANTIATOR_P (instantiator)) | |
3320 { | |
3321 lose: | |
442 | 3322 dead_wrong_type_argument |
3323 (display_table_specifier_methods->predicate_symbol, | |
428 | 3324 instantiator); |
3325 } | |
3326 } | |
3327 } | |
3328 | |
3329 DEFUN ("display-table-specifier-p", Fdisplay_table_specifier_p, 1, 1, 0, /* | |
3330 Return non-nil if OBJECT is a display-table specifier. | |
442 | 3331 |
3332 See `current-display-table' for a description of possible display-table | |
3333 instantiators. | |
428 | 3334 */ |
3335 (object)) | |
3336 { | |
3337 return DISPLAYTABLE_SPECIFIERP (object) ? Qt : Qnil; | |
3338 } | |
3339 | |
3340 | |
3341 /************************************************************************/ | |
3342 /* Initialization */ | |
3343 /************************************************************************/ | |
3344 | |
3345 void | |
3346 syms_of_specifier (void) | |
3347 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
3348 INIT_LISP_OBJECT (specifier); |
442 | 3349 |
3350 DEFSYMBOL (Qspecifierp); | |
3351 | |
3352 DEFSYMBOL (Qconsole_type); | |
3353 DEFSYMBOL (Qdevice_class); | |
3354 | |
3355 /* specifier types defined in general.c. */ | |
428 | 3356 |
3357 DEFSUBR (Fvalid_specifier_type_p); | |
3358 DEFSUBR (Fspecifier_type_list); | |
3359 DEFSUBR (Fmake_specifier); | |
3360 DEFSUBR (Fspecifierp); | |
3361 DEFSUBR (Fspecifier_type); | |
3362 | |
3363 DEFSUBR (Fvalid_specifier_locale_p); | |
3364 DEFSUBR (Fvalid_specifier_domain_p); | |
3365 DEFSUBR (Fvalid_specifier_locale_type_p); | |
3366 DEFSUBR (Fspecifier_locale_type_from_locale); | |
3367 | |
3368 DEFSUBR (Fvalid_specifier_tag_p); | |
3369 DEFSUBR (Fvalid_specifier_tag_set_p); | |
3370 DEFSUBR (Fcanonicalize_tag_set); | |
3371 DEFSUBR (Fdevice_matches_specifier_tag_set_p); | |
3372 DEFSUBR (Fdefine_specifier_tag); | |
3373 DEFSUBR (Fdevice_matching_specifier_tag_list); | |
3374 DEFSUBR (Fspecifier_tag_list); | |
3375 DEFSUBR (Fspecifier_tag_predicate); | |
3376 | |
3377 DEFSUBR (Fcheck_valid_instantiator); | |
3378 DEFSUBR (Fvalid_instantiator_p); | |
3379 DEFSUBR (Fcheck_valid_inst_list); | |
3380 DEFSUBR (Fvalid_inst_list_p); | |
3381 DEFSUBR (Fcheck_valid_spec_list); | |
3382 DEFSUBR (Fvalid_spec_list_p); | |
3383 DEFSUBR (Fadd_spec_to_specifier); | |
3384 DEFSUBR (Fadd_spec_list_to_specifier); | |
3385 DEFSUBR (Fspecifier_spec_list); | |
3386 DEFSUBR (Fspecifier_specs); | |
3387 DEFSUBR (Fremove_specifier); | |
3388 DEFSUBR (Fcopy_specifier); | |
3389 | |
3390 DEFSUBR (Fcheck_valid_specifier_matchspec); | |
3391 DEFSUBR (Fvalid_specifier_matchspec_p); | |
3392 DEFSUBR (Fspecifier_fallback); | |
3393 DEFSUBR (Fspecifier_instance); | |
2953 | 3394 DEFSUBR (Fspecifier_instantiator); |
428 | 3395 DEFSUBR (Fspecifier_matching_instance); |
2953 | 3396 DEFSUBR (Fspecifier_matching_instantiator); |
428 | 3397 DEFSUBR (Fspecifier_instance_from_inst_list); |
2953 | 3398 DEFSUBR (Fspecifier_instantiator_from_inst_list); |
428 | 3399 DEFSUBR (Fspecifier_matching_instance_from_inst_list); |
2953 | 3400 DEFSUBR (Fspecifier_matching_instantiator_from_inst_list); |
428 | 3401 DEFSUBR (Fset_specifier_dirty_flag); |
3402 | |
3403 DEFSUBR (Fgeneric_specifier_p); | |
3404 DEFSUBR (Finteger_specifier_p); | |
3405 DEFSUBR (Fnatnum_specifier_p); | |
3406 DEFSUBR (Fboolean_specifier_p); | |
3407 DEFSUBR (Fdisplay_table_specifier_p); | |
3408 | |
3409 /* Symbols pertaining to specifier creation. Specifiers are created | |
3410 in the syms_of() functions. */ | |
3411 | |
3412 /* locales are defined in general.c. */ | |
3413 | |
442 | 3414 /* some how-to-add flags in general.c. */ |
3415 DEFSYMBOL (Qremove_tag_set_prepend); | |
3416 DEFSYMBOL (Qremove_tag_set_append); | |
3417 DEFSYMBOL (Qremove_locale); | |
3418 DEFSYMBOL (Qremove_locale_type); | |
428 | 3419 } |
3420 | |
3421 void | |
3422 specifier_type_create (void) | |
3423 { | |
3424 the_specifier_type_entry_dynarr = Dynarr_new (specifier_type_entry); | |
2367 | 3425 dump_add_root_block_ptr (&the_specifier_type_entry_dynarr, &sted_description); |
428 | 3426 |
3427 Vspecifier_type_list = Qnil; | |
3428 staticpro (&Vspecifier_type_list); | |
3429 | |
3430 INITIALIZE_SPECIFIER_TYPE (generic, "generic", "generic-specifier-p"); | |
3431 | |
3432 INITIALIZE_SPECIFIER_TYPE (integer, "integer", "integer-specifier-p"); | |
3433 | |
3434 SPECIFIER_HAS_METHOD (integer, validate); | |
3435 | |
3436 INITIALIZE_SPECIFIER_TYPE (natnum, "natnum", "natnum-specifier-p"); | |
3437 | |
3438 SPECIFIER_HAS_METHOD (natnum, validate); | |
3439 | |
3440 INITIALIZE_SPECIFIER_TYPE (boolean, "boolean", "boolean-specifier-p"); | |
3441 | |
3442 SPECIFIER_HAS_METHOD (boolean, validate); | |
3443 | |
442 | 3444 INITIALIZE_SPECIFIER_TYPE (display_table, "display-table", |
3445 "display-table-p"); | |
428 | 3446 |
3447 SPECIFIER_HAS_METHOD (display_table, validate); | |
3448 } | |
3449 | |
3450 void | |
3451 reinit_specifier_type_create (void) | |
3452 { | |
3453 REINITIALIZE_SPECIFIER_TYPE (generic); | |
3454 REINITIALIZE_SPECIFIER_TYPE (integer); | |
3455 REINITIALIZE_SPECIFIER_TYPE (natnum); | |
3456 REINITIALIZE_SPECIFIER_TYPE (boolean); | |
3457 REINITIALIZE_SPECIFIER_TYPE (display_table); | |
3458 } | |
3459 | |
3460 void | |
3461 vars_of_specifier (void) | |
3462 { | |
3463 Vcached_specifiers = Qnil; | |
3464 staticpro (&Vcached_specifiers); | |
3465 | |
3466 /* Do NOT mark through this, or specifiers will never be GC'd. | |
3467 This is the same deal as for weak hash tables. */ | |
3468 Vall_specifiers = Qnil; | |
452 | 3469 dump_add_weak_object_chain (&Vall_specifiers); |
428 | 3470 |
3471 Vuser_defined_tags = Qnil; | |
3472 staticpro (&Vuser_defined_tags); | |
3473 | |
3474 Vunlock_ghost_specifiers = Qnil; | |
3475 staticpro (&Vunlock_ghost_specifiers); | |
3476 } |