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