Another go at fixing 131
[sxemacs] / lisp / specifier.el
1 ;;; specifier.el --- Lisp interface to specifiers
2
3 ;; Copyright (C) 1997, 2004 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 2000, 2002 Ben Wing.
5
6 ;; Author: Ben Wing <ben@xemacs.org>
7 ;; Keywords: internal, dumped
8
9 ;;; Synched up with: Not in FSF.
10
11 ;; This file is part of SXEmacs.
12
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This file is dumped with SXEmacs.
29
30 ;;; Code:
31
32 (defun make-specifier-and-init (type spec-list &optional dont-canonicalize)
33   "Create and initialize a specifier of type TYPE with spec(s) SPEC-LIST.
34
35 A convenience API combining `make-specifier' and `set-specifier', allowing you
36 to create a specifier and add specs to it at the same time.
37 TYPE specifies the specifier type.  See `make-specifier' for known types.
38 SPEC-LIST supplies the specification(s) to be added to the specifier, in any
39   form acceptable to `canonicalize-spec-list'.
40 Optional DONT-CANONICALIZE, if non-nil, inhibits the conversion, and the
41   SPEC-LIST must already be in full form."
42   (let ((sp (make-specifier type)))
43     (if (not dont-canonicalize)
44         (setq spec-list (canonicalize-spec-list spec-list type)))
45     (add-spec-list-to-specifier sp spec-list)
46     sp))
47
48 ;; God damn, do I hate dynamic scoping.
49
50 (defun map-specifier (ms-specifier ms-func &optional ms-locale ms-maparg)
51   "Apply MS-FUNC to the specification(s) for MS-LOCALE in MS-SPECIFIER.
52
53 If optional MS-LOCALE is a locale, MS-FUNC will be called for that locale.
54 If MS-LOCALE is a locale type, MS-FUNC will be mapped over all locales of that
55 type.  If MS-LOCALE is 'all or nil, MS-FUNC will be mapped over all locales in
56 MS-SPECIFIER.
57
58 Optional MS-MAPARG will be passed to MS-FUNC.
59
60 MS-FUNC is called with four arguments: the MS-SPECIFIER, the locale
61 being mapped over, the inst-list for that locale, and the
62 optional MS-MAPARG.  If any invocation of MS-FUNC returns non-nil,
63 the mapping will stop and the returned value becomes the
64 value returned from `map-specifier'.  Otherwise, `map-specifier'
65 returns nil."
66   (let ((ms-specs (specifier-spec-list ms-specifier ms-locale))
67         ms-result)
68     (while (and ms-specs (not ms-result))
69       (let ((ms-this-spec (car ms-specs)))
70         (setq ms-result (funcall ms-func ms-specifier (car ms-this-spec)
71                               (cdr ms-this-spec) ms-maparg))
72         (setq ms-specs (cdr ms-specs))))
73     ms-result))
74
75 (defun canonicalize-inst-pair (inst-pair specifier-type &optional noerror)
76   "Canonicalize the given INST-PAIR.
77
78 SPECIFIER-TYPE specifies the type of specifier that this INST-PAIR
79 will be used for.
80
81 Canonicalizing means converting to the full form for an inst-pair, i.e.
82 `(TAG-SET . INSTANTIATOR)'.  A single, untagged instantiator is given
83 a tag set of nil (the empty set), and a single tag is converted into
84 a tag set consisting only of that tag.
85
86 If NOERROR is non-nil, signal an error if the inst-pair is invalid;
87 otherwise return t."
88   ;; OK, the possibilities are:
89   ;;
90   ;; a) a single instantiator
91   ;; b) a cons of a tag and an instantiator
92   ;; c) a cons of a tag set and an instantiator
93   (cond ((valid-instantiator-p inst-pair specifier-type)
94          ;; case (a)
95          (cons nil inst-pair))
96
97         ((not (consp inst-pair))
98          ;; not an inst-pair
99          (if noerror t
100            ;; this will signal an appropriate error.
101            (check-valid-instantiator inst-pair specifier-type)))
102
103         ((and (valid-specifier-tag-p (car inst-pair))
104               (valid-instantiator-p (cdr inst-pair) specifier-type))
105          ;; case (b)
106          (cons (list (car inst-pair)) (cdr inst-pair)))
107
108         ((and (valid-specifier-tag-set-p (car inst-pair))
109               (valid-instantiator-p (cdr inst-pair) specifier-type))
110          ;; case (c)
111          inst-pair)
112          
113         (t
114          (if noerror t
115            (signal 'error (list "Invalid specifier tag set"
116                                 (car inst-pair)))))))
117
118 (defun canonicalize-inst-list (inst-list specifier-type &optional noerror)
119   "Canonicalize the given INST-LIST (a list of inst-pairs).
120
121 SPECIFIER-TYPE specifies the type of specifier that this INST-LIST
122 will be used for.
123
124 Canonicalizing means converting to the full form for an inst-list, i.e.
125 `((TAG-SET . INSTANTIATOR) ...)'.  This function accepts a single
126 inst-pair or any abbreviation thereof or a list of (possibly
127 abbreviated) inst-pairs. (See `canonicalize-inst-pair'.)
128
129 If NOERROR is non-nil, signal an error if the inst-list is invalid;
130 otherwise return t."
131
132   ;; OK, the possibilities are:
133   ;;
134   ;; a) an inst-pair or various abbreviations thereof
135   ;; b) a list of (a)
136   (let ((result (canonicalize-inst-pair inst-list specifier-type t)))
137     (if (not (eq result t))
138         ;; case (a)
139         (list result)
140
141       (if (not (consp inst-list))
142           ;; not an inst-list.
143           (if noerror t
144            ;; this will signal an appropriate error.
145             (check-valid-instantiator inst-list specifier-type))
146
147         ;; case (b)
148         (catch 'cann-inst-list
149           ;; don't use mapcar here; we need to catch the case of
150           ;; an invalid list.
151           (let ((rest inst-list)
152                 (result nil))
153             (while rest
154               (if (not (consp rest))
155                   (if noerror (throw 'cann-inst-list t)
156                     (signal 'error (list "Invalid list format" inst-list)))
157                 (let ((res2 (canonicalize-inst-pair (car rest) specifier-type
158                                                     noerror)))
159                   (if (eq res2 t)
160                       ;; at this point, we know we're noerror because
161                       ;; otherwise canonicalize-inst-pair would have
162                       ;; signalled an error.
163                       (throw 'cann-inst-list t)
164                     (setq result (cons res2 result)))))
165               (setq rest (cdr rest)))
166             (nreverse result)))))))
167
168 (defun canonicalize-spec (spec specifier-type &optional noerror)
169   "Canonicalize the given SPEC (a specification).
170
171 SPECIFIER-TYPE is the type of specifier that this SPEC will be used for.
172
173 Canonicalizing means converting to the full form for a spec, i.e.
174 `(LOCALE (TAG-SET . INSTANTIATOR) ...)'.  This function accepts a
175 possibly abbreviated inst-list or a cons of a locale and a possibly
176 abbreviated inst-list. (See `canonicalize-inst-list'.)
177
178 If NOERROR is nil, signal an error if the specification is invalid;
179 otherwise return t."
180   ;; OK, the possibilities are:
181   ;;
182   ;; a) an inst-list or some abbreviation thereof
183   ;; b) a cons of a locale and an inst-list
184   (let ((result (canonicalize-inst-list spec specifier-type t)))
185     (if (not (eq result t))
186         ;; case (a)
187         (cons 'global result)
188
189       (if (not (consp spec))
190           ;; not a spec.
191           (if noerror t
192             ;; this will signal an appropriate error.
193             (check-valid-instantiator spec specifier-type))
194
195         (if (not (valid-specifier-locale-p (car spec)))
196             ;; invalid locale.
197             (if noerror t
198               (signal 'error (list "Invalid specifier locale" (car spec))))
199
200           ;; case (b)
201           (let ((result (canonicalize-inst-list (cdr spec) specifier-type
202                                                 noerror)))
203             (if (eq result t)
204                 ;; at this point, we know we're noerror because
205                 ;; otherwise canonicalize-inst-list would have
206                 ;; signalled an error.
207                 t
208               (cons (car spec) result))))))))
209
210 (defun canonicalize-spec-list (spec-list specifier-type &optional noerror)
211   "Canonicalize the given SPEC-LIST (a list of specifications).
212
213 SPECIFIER-TYPE specifies the type of specifier that this SPEC-LIST
214 will be used for.
215
216 Canonicalizing means converting to the full form for a spec-list, i.e.
217 `((LOCALE (TAG-SET . INSTANTIATOR) ...) ...)'.  This function accepts
218 a possibly abbreviated specification or a list of such things. (See
219 `canonicalize-spec'.) This is the function used to convert spec-lists
220 accepted by `set-specifier' and such into a form suitable for
221 `add-spec-list-to-specifier'.
222
223 The canonicalization algorithm is as follows:
224
225 1. Attempt to parse SPEC-LIST as a single, possibly abbreviated, specification.
226 2. If (1) fails, attempt to parse SPEC-LIST as a list of (abbreviated)
227    specifications.
228 3. If (2) fails, SPEC-LIST is invalid.
229
230 A possibly abbreviated specification SPEC is parsed by
231
232 1. Attempt to parse SPEC as a possibly abbreviated inst-list.
233 2. If (1) fails, attempt to parse SPEC as a cons of a locale and an
234    (abbreviated) inst-list.
235 3. If (2) fails, SPEC is invalid.
236
237 A possibly abbreviated inst-list INST-LIST is parsed by
238
239 1. Attempt to parse INST-LIST as a possibly abbreviated inst-pair.
240 2. If (1) fails, attempt to parse INST-LIST as a list of (abbreviated)
241    inst-pairs.
242 3. If (2) fails, INST-LIST is invalid.
243
244 A possibly abbreviated inst-pair INST-PAIR is parsed by
245
246 1. Check if INST-PAIR is `valid-instantiator-p'.
247 2. If not, check if INST-PAIR is a cons of something that is a tag, ie,
248    `valid-specifier-tag-p', and something that is `valid-instantiator-p'.
249 3. If not, check if INST-PAIR is a cons of a list of tags and something that
250    is `valid-instantiator-p'.
251
252 In summary, this function generally prefers more abbreviated forms.
253
254 This function tries extremely hard to resolve any ambiguities, and the
255 built-in specifier types (font, image, toolbar, etc.) are designed so that
256 there won't be any ambiguities.  (#### Unfortunately there are bugs in the
257 treatment of toolbar spec-lists and generic spec-lists; avoid depending on
258 canonicalization for these types.)
259
260 If NOERROR is nil, signal an error if the spec-list is invalid;
261 otherwise return t."
262   ;; OK, the possibilities are:
263   ;;
264   ;; a) a spec or various abbreviations thereof
265   ;; b) a list of (a)
266   (let ((result (canonicalize-spec spec-list specifier-type t)))
267     (if (not (eq result t))
268         ;; case (a)
269         (list result)
270
271       (if (not (consp spec-list))
272           ;; not a spec-list.
273           (if noerror t
274            ;; this will signal an appropriate error.
275             (check-valid-instantiator spec-list specifier-type))
276
277         ;; case (b)
278         (catch 'cann-spec-list
279           ;; don't use mapcar here; we need to catch the case of
280           ;; an invalid list.
281           (let ((rest spec-list)
282                 (result nil))
283             (while rest
284               (if (not (consp rest))
285                   (if noerror (throw 'cann-spec-list t)
286                     (signal 'error (list "Invalid list format" spec-list)))
287                 (let ((res2 (canonicalize-spec (car rest) specifier-type
288                                                noerror)))
289                   (if (eq res2 t)
290                       ;; at this point, we know we're noerror because
291                       ;; otherwise canonicalize-spec would have
292                       ;; signalled an error.
293                       (throw 'cann-spec-list t)
294                     (setq result (cons res2 result)))))
295               (setq rest (cdr rest)))
296             (nreverse result)))))))
297
298 (defun set-specifier (specifier value &optional locale tag-set how-to-add)
299   "Add the specification(s) given by VALUE to SPECIFIER in LOCALE.
300
301 VALUE may be any of the values accepted by `canonicalize-spec-list', including
302
303 -- an instantiator (either a Lisp object which will be returned when the
304    specifier is instanced, or a Lisp object that can be instantiated to
305    produce an opaque value: eg, a font name (string) can be used for a font
306    specifier, but an instance will be a font object)
307 -- a list of instantiators
308 -- a cons of a locale and an instantiator, or of a locale and a list of
309    instantiators
310 -- a cons of a tag or tag-set and an instantiator (or list of instantiators)
311 -- a cons of a locale and the previous type of item
312 -- a list of one or more of any of the previous types of items
313 -- a canonical spec-list.
314
315 See `canonicalize-spec-list' for details.  If you need to know the details,
316 though, strongly consider using the unambiguous APIs `add-spec-to-specifier'
317 and `add-spec-list-to-specifier' instead.
318
319 Finally, VALUE can itself be a specifier (of the same type as
320 SPECIFIER), if you want to copy specifications from one specifier
321 to another; this is equivalent to calling `copy-specifier', and
322 LOCALE, TAG-SET, and HOW-TO-ADD have the same semantics as with
323 that function.
324
325 Note that a VALUE of `nil' is either illegal or will be treated as a value of
326 `nil'; it does not remove existing specifications.  Use `remove-specifier' for
327 that.  N.B. `remove-specifier' defaults to removing all specifications, not
328 just the 'global one!
329
330 Warning: this function is inherently heuristic, and should not be relied on to
331 properly resolve ambiguities, when specifier instantiators can be lists
332 \(currently, for toolbar specifiers and generic specifiers).  In those cases
333 use either `add-spec-to-specifier' or `add-spec-list-to-specifier'.
334
335 LOCALE indicates where this specification is active, and should be
336 a buffer, a window, a frame, a device, or the symbol `global' to
337 indicate that it applies everywhere.  LOCALE defaults to
338 `global' if omitted, and is overridden by locales provided by VALUE (in the
339 cases where value is a full specification or a spec-list).
340
341 Optional argument TAG-SET is a tag or a list of tags, to be associated
342 with the VALUE.  Tags are symbols (usually naming device types, such
343 as `x' and `tty', or device classes, such as `color', `mono', and
344 `grayscale'); specifying a TAG-SET restricts the scope of VALUE to
345 devices that match all specified tags. (You can also create your
346 own tags using `define-specifier-tag', and use them to identify
347 specifications added by you, so you can remove them later.)
348
349 Optional argument HOW-TO-ADD should be either nil or one of the
350 symbols `prepend', `append', `remove-tag-set-prepend',
351 `remove-tag-set-append', `remove-locale', `remove-locale-type',
352 or `remove-all'.  This specifies what to do with existing
353 specifications in LOCALE (and possibly elsewhere in the specifier).
354 Most of the time, you do not need to worry about this argument;
355 the default behavior of `remove-tag-set-prepend' is usually fine.
356 See `copy-specifier' and `add-spec-to-specifier' for a full
357 description of what each of these means.
358
359 Note that `set-specifier' is exactly complementary to `specifier-specs'
360 except in the case where SPECIFIER has no specs at all in it but nil
361 is a valid instantiator (in that case, `specifier-specs' will return
362 nil (meaning no specs) and `set-specifier' will interpret the `nil'
363 as meaning \"I'm adding a global instantiator and its value is `nil'\"),
364 or in strange cases where there is an ambiguity between a spec-list
365 and an inst-list, etc. (The built-in specifier types are designed
366 in such a way as to avoid any such ambiguities.)"
367
368   ;; backward compatibility: the old function had HOW-TO-ADD as the
369   ;; third argument and no arguments after that.
370   ;; #### this should disappear at some point.
371   (if (and (null how-to-add)
372            (memq locale '(prepend append remove-tag-set-prepend
373                                   remove-tag-set-append remove-locale
374                                   remove-locale-type remove-all)))
375       (progn
376         (setq how-to-add locale)
377         (setq locale nil)))
378
379   ;; proper beginning of the function.
380   (let ((is-valid (valid-instantiator-p value (specifier-type specifier)))
381         (nval value))
382     (cond ((and (not is-valid) (specifierp nval))
383            (copy-specifier nval specifier locale tag-set nil how-to-add))
384           (t
385            (if tag-set
386                (progn
387                  (if (not (listp tag-set))
388                      (setq tag-set (list tag-set)))
389                  ;; You tend to get more accurate errors
390                  ;; for a variety of cases if you call
391                  ;; canonicalize-tag-set here.
392                  (setq tag-set (canonicalize-tag-set tag-set))
393                  (if (and (not is-valid) (consp nval))
394                      (setq nval
395                            (mapcar #'(lambda (x)
396                                        (check-valid-instantiator
397                                         x (specifier-type specifier))
398                                        (cons tag-set x))
399                                    nval))
400                    (setq nval (cons tag-set nval)))))
401            (if locale
402                (setq nval (cons locale nval)))
403            (add-spec-list-to-specifier
404             specifier
405             (canonicalize-spec-list nval (specifier-type specifier))
406             how-to-add))))
407   value)
408
409 (defun modify-specifier-instances (specifier func &optional args force default
410                                    locale tag-set)
411   "Modify all specifications that match LOCALE and TAG-SET by FUNC.
412
413 For each specification that exists for SPECIFIER, in locale LOCALE
414 that matches TAG-SET, call the function FUNC with the instance as its
415 first argument and with optional arguments ARGS.  The result is then
416 used as the new value of the instantiator.
417
418 If there is no specification in the domain LOCALE matching TAG-SET and
419 FORCE is non-nil, an explicit one is created from the matching
420 specifier instance if that exists or DEFAULT otherwise. If LOCALE is
421 not a domain (i.e. a buffer), DEFAULT is always used. FUNC is then
422 applied like above and the resulting specification is added."
423
424   (let ((spec-list (specifier-spec-list specifier locale tag-set)))
425     (cond
426      (spec-list
427       ;; Destructively edit the spec-list
428       (mapc #'(lambda (spec)
429                 (mapc #'(lambda (inst-pair)
430                           (setcdr inst-pair
431                                   (apply func (cdr inst-pair) args)))
432                       (cdr spec)))
433             spec-list)
434       (add-spec-list-to-specifier specifier spec-list))
435      (force
436       (set-specifier specifier
437                      (apply func
438                             (or (and (valid-specifier-domain-p locale)
439                                      (specifier-instance specifier))
440                                 default) args)
441                      locale tag-set)))))
442
443 (defmacro let-specifier (specifier-list &rest body)
444   "Add specifier specs, evaluate forms in BODY and restore the specifiers.
445 \(let-specifier SPECIFIER-LIST BODY...)
446
447 Each element of SPECIFIER-LIST should look like this:
448 \(SPECIFIER VALUE &optional LOCALE TAG-SET HOW-TO-ADD).
449
450 SPECIFIER is the specifier to be temporarily modified.  VALUE is the
451 instantiator to be temporarily added to SPECIFIER in LOCALE.  LOCALE,
452 TAG-SET and HOW-TO-ADD have the same meaning as in
453 `add-spec-to-specifier'.
454
455 The code resulting from macro expansion will add specifications to
456 specifiers using `add-spec-to-specifier'.  After BODY is finished, the
457 temporary specifications are removed and old spec-lists are restored.
458
459 LOCALE, TAG-SET and HOW-TO-ADD may be omitted, and default to nil.
460 The value of the last form in BODY is returned.
461
462 NOTE: If you want the specifier's instance to change in all
463 circumstances, use (selected-window) as the LOCALE.  If LOCALE is nil
464 or omitted, it defaults to `global'.
465
466 Example:
467     (let-specifier ((modeline-shadow-thickness 0 (selected-window)))
468       (sit-for 1))"
469   (check-argument-type 'listp specifier-list)
470   (flet ((gensym-frob (x name)
471            (if (or (atom x) (eq (car x) 'quote))
472                (list x)
473              (list (gensym name) x))))
474     ;; VARLIST is a list of
475     ;; ((SPECIFIERSYM SPECIFIER) (VALUE) (LOCALESYM LOCALE)
476     ;;  (TAG-SET) (HOW-TO-ADD))
477     ;; If any of these is an atom, then a separate symbol is
478     ;; unnecessary, the CAR will contain the atom and CDR will be nil.
479     (let* ((varlist (mapcar #'(lambda (listel)
480                                 (or (and (consp listel)
481                                          (<= (length listel) 5)
482                                          (> (length listel) 1))
483                                     (signal 'error
484                                             (list
485                                              "should be a list of 2-5 elements"
486                                              listel)))
487                                 ;; VALUE, TAG-SET and HOW-TO-ADD are
488                                 ;; referenced only once, so we needn't
489                                 ;; frob them with gensym.
490                                 (list (gensym-frob (nth 0 listel) "specifier-")
491                                       (list (nth 1 listel))
492                                       (gensym-frob (nth 2 listel) "locale-")
493                                       (list (nth 3 listel))
494                                       (list (nth 4 listel))))
495                             specifier-list))
496            ;; OLDVALLIST is a list of (OLDVALSYM OLDVALFORM)
497            (oldvallist (mapcar #'(lambda (varel)
498                                    (list (gensym "old-")
499                                          `(specifier-spec-list
500                                            ,(car (nth 0 varel))
501                                            ,(car (nth 2 varel)))))
502                                varlist)))
503       ;; Bind the appropriate variables.
504       `(let* (,@(mapcan #'(lambda (varel)
505                             (delq nil (mapcar
506                                        #'(lambda (varcons)
507                                            (and (cdr varcons) varcons))
508                                        varel)))
509                         varlist)
510                 ,@oldvallist)
511          (unwind-protect
512              (progn
513                ,@(mapcar #'(lambda (varel)
514                              `(add-spec-to-specifier
515                                ,(car (nth 0 varel)) ,(car (nth 1 varel))
516                                ,(car (nth 2 varel)) ,(car (nth 3 varel))
517                                ,(car (nth 4 varel))))
518                          varlist)
519                ,@body)
520            ;; Reverse the unwinding order, so that using the same
521            ;; specifier multiple times works.
522            ,@(apply #'nconc (nreverse (mapcar*
523                                        #'(lambda (oldval varel)
524                                            `((remove-specifier
525                                               ,(car (nth 0 varel))
526                                               ,(car (nth 2 varel)))
527                                              (add-spec-list-to-specifier
528                                               ,(car (nth 0 varel))
529                                               ,(car oldval))))
530                                        oldvallist varlist))))))))
531
532 (defun make-integer-specifier (spec-list)
533   "Return a new `integer' specifier object with the given specification list.
534 SPEC-LIST can be a list of specifications (each of which is a cons of a
535 locale and a list of instantiators), a single instantiator, or a list
536 of instantiators.  See `make-specifier' for more information about
537 specifiers.
538
539 Valid instantiators for integer specifiers are integers."
540   (make-specifier-and-init 'integer spec-list))
541
542 (defun make-boolean-specifier (spec-list)
543   "Return a new `boolean' specifier object with the given specification list.
544 SPEC-LIST can be a list of specifications (each of which is a cons of a
545 locale and a list of instantiators), a single instantiator, or a list
546 of instantiators.  See `make-specifier' for more information about
547 specifiers.
548
549 Valid instantiators for boolean specifiers are t and nil."
550   (make-specifier-and-init 'boolean spec-list))
551
552 (defun make-natnum-specifier (spec-list)
553   "Return a new `natnum' specifier object with the given specification list.
554 SPEC-LIST can be a list of specifications (each of which is a cons of a
555 locale and a list of instantiators), a single instantiator, or a list
556 of instantiators.  See `make-specifier' for more information about
557 specifiers.
558
559 Valid instantiators for natnum specifiers are non-negative integers."
560   (make-specifier-and-init 'natnum spec-list))
561
562 (defun make-generic-specifier (spec-list)
563   "Return a new `generic' specifier object with the given specification list.
564 SPEC-LIST can be a list of specifications (each of which is a cons of a
565 locale and a list of instantiators), a single instantiator, or a list
566 of instantiators.  See `make-specifier' for more information about
567 specifiers.
568
569 Valid instantiators for generic specifiers are all Lisp values.
570 They are returned back unchanged when a specifier is instantiated."
571   (make-specifier-and-init 'generic spec-list))
572
573 (defun make-display-table-specifier (spec-list)
574   "Return a new `display-table' specifier object with the given spec list.
575 SPEC-LIST can be a list of specifications (each of which is a cons of a
576 locale and a list of instantiators), a single instantiator, or a list
577 of instantiators.  See `make-specifier' for more information about
578 specifiers.
579
580 Valid instantiators for display-table specifiers are described in
581 detail in the doc string for `current-display-table'."
582   (make-specifier-and-init 'display-table spec-list))
583
584 ;; Evaluate this for testing:
585 ; (cl-prettyexpand '(let-specifier ((modeline-shadow-thickness 0 (selected-window) 'x) (fubar (value) baz)) (sit-for 1)))
586 \f
587 (define-specifier-tag 'win 'device-on-window-system-p)
588
589 ;; Add tags for device types that don't have support compiled
590 ;; into the binary that we're about to dump.  This will prevent
591 ;; code like
592 ;;
593 ;; (set-face-foreground 'default "black" nil '(x color))
594 ;;
595 ;; from producing an error if no X support was compiled in.
596
597 (or (valid-specifier-tag-p 'x)
598     (define-specifier-tag 'x (lambda (dev) (eq (device-type dev) 'x))))
599 (or (valid-specifier-tag-p 'tty)
600     (define-specifier-tag 'tty (lambda (dev) (eq (device-type dev) 'tty))))
601 (or (valid-specifier-tag-p 'mswindows)
602     (define-specifier-tag 'mswindows (lambda (dev) 
603                                        (eq (device-type dev) 'mswindows))))
604
605 ;; Add special tag for use by initialization code.  Code that
606 ;; sets up default specs should use this tag.  Code that needs to
607 ;; override default specs (e.g. the X resource initialization
608 ;; code) can safely clear specs with this tag without worrying
609 ;; about clobbering user settings.
610
611 (define-specifier-tag 'default)
612
613 ;;; specifier.el ends here