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