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