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