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