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