XEmacs 21.2-b1
[chise/xemacs-chise.git.1] / man / lispref / specifiers.texi
1 @c -*-texinfo-*-
2 @c This is part of the XEmacs Lisp Reference Manual.
3 @c Copyright (C) 1995, 1996 Ben Wing.
4 @c See the file lispref.texi for copying conditions.
5 @setfilename ../../info/specifiers.info
6 @node Specifiers, Faces and Window-System Objects, Extents, top
7 @chapter Specifiers
8 @cindex specifier
9
10 A specifier is an object used to keep track of a property whose value
11 may vary depending on the particular situation (e.g. particular buffer
12 displayed in a particular window) that it is used in.  The value of many
13 built-in properties, such as the font, foreground, background, and such
14 properties of a face and variables such as
15 @code{modeline-shadow-thickness} and @code{top-toolbar-height}, is
16 actually a specifier object.  The specifier object, in turn, is
17 ``instanced'' in a particular situation to yield the real value
18 of the property in that situation.
19
20 @defun specifierp object
21 This function returns non-@code{nil} if @var{object} is a specifier.
22 @end defun
23
24 @menu
25 * Introduction to Specifiers::  Specifiers provide a clean way for
26                                 display and other properties to vary
27                                 (under user control) in a wide variety
28                                 of contexts.
29 * Specifiers In-Depth::         Gory details about specifier innards.
30 * Specifier Instancing::        Instancing means obtaining the ``value'' of
31                                 a specifier in a particular context.
32 * Specifier Types::             Specifiers come in different flavors.
33 * Adding Specifications::       Specifications control a specifier's ``value''
34                                 by giving conditions under which a
35                                 particular value is valid.
36 * Retrieving Specifications::   Querying a specifier's specifications.
37 * Specifier Tag Functions::     Working with specifier tags.
38 * Specifier Instancing Functions::
39                                 Functions to instance a specifier.
40 * Specifier Example::           Making all this stuff clearer.
41 * Creating Specifiers::         Creating specifiers for your own use.
42 * Specifier Validation Functions::
43                                 Validating the components of a specifier.
44 * Other Specification Functions::
45                                 Other ways of working with specifications.
46 @end menu
47
48 @node Introduction to Specifiers
49 @section Introduction to Specifiers
50
51 Sometimes you may want the value of a property to vary depending on
52 the context the property is used in.  A simple example of this in XEmacs
53 is buffer-local variables.  For example, the variable
54 @code{modeline-format}, which controls the format of the modeline, can
55 have different values depending on the particular buffer being edited.
56 The variable has a default value which most modes will use, but a
57 specialized package such as Calendar might change the variable so
58 as to tailor the modeline to its own purposes.
59
60 Other properties (such as those that can be changed by the
61 @code{modify-frame-parameters} function, for example the color of the
62 text cursor) can have frame-local values, although it might also make
63 sense for them to have buffer-local values.  In other cases, you might
64 want the property to vary depending on the particular window within the
65 frame that applies (e.g. the top or bottom window in a split frame), the
66 device type that that frame appears on (X or tty), etc.  Perhaps you can
67 envision some more complicated scenario where you want a particular
68 value in a specified buffer, another value in all other buffers
69 displayed on a particular frame, another value in all other buffers
70 displayed in all other frames on any mono (two-color, e.g. black and
71 white only) displays, and a default value in all other circumstances.
72
73 A @dfn{specifier} is a generalization of this, allowing a great deal
74 of flexibility in controlling exactly what value a property has in which
75 circumstances.  It is most commonly used for display properties, such as
76 an image or the foreground color of a face.  As a simple example, you can
77 specify that the foreground of the default face be
78
79 @itemize @bullet
80 @item
81 blue for a particular buffer
82 @item
83 green for all other buffers
84 @end itemize
85
86 As a more complicated example, you could specify that the foreground of
87 the default face be
88
89 @itemize @bullet
90 @item
91 forest green for all buffers displayed in a particular Emacs window, or
92 green if the X server doesn't recognize the color @samp{forest green}
93 @item
94 blue for all buffers displayed in a particular frame
95 @item
96 red for all other buffers displayed on a color device
97 @item
98 white for all other buffers
99 @end itemize
100
101 @node Specifiers In-Depth
102 @section In-Depth Overview of a Specifier
103 @cindex specification (in a specifier)
104 @cindex domain (in a specifier)
105 @cindex locale (in a specifier)
106 @cindex instantiator (in a specifier)
107 @cindex instancing (in a specifier)
108 @cindex instance (in a specifier)
109 @cindex inst-list (in a specifier)
110 @cindex inst-pair (in a specifier)
111 @cindex tag (in a specifier)
112 @cindex tag set (in a specifier)
113 @cindex specifier, specification
114 @cindex specifier, domain
115 @cindex specifier, locale
116 @cindex specifier, instantiator
117 @cindex specifier, instancing
118 @cindex specifier, instance
119 @cindex specifier, inst-list
120 @cindex specifier, inst-pair
121 @cindex specifier, tag
122 @cindex specifier, tag set
123
124 A specifier object encapsulates a set of @dfn{specifications}, each of
125 which says what its value should be if a particular condition applies.
126 For example, one specification might be ``The value should be
127 darkseagreen2 on X devices'' another might be ``The value should be blue
128 in the *Help* buffer''.  In specifier terminology, these conditions are
129 called @dfn{locales} and the values are called @dfn{instantiators}.
130 Given a specifier, a logical question is ``What is its value in a
131 particular situation?'' This involves looking through the specifications
132 to see which ones apply to this particular situation, and perhaps
133 preferring one over another if more than one applies.  In specifier
134 terminology, a ``particular situation'' is called a @dfn{domain}, and
135 determining its value in a particular domain is called @dfn{instancing}.
136 Most of the time, a domain is identified by a particular window.  For
137 example, if the redisplay engine is drawing text in the default face in
138 a particular window, it retrieves the specifier for the foreground color
139 of the default face and @dfn{instances} it in the domain given by that
140 window; in other words, it asks the specifier, ``What is your value in
141 this window?''.
142
143 More specifically, a specifier contains a set of @dfn{specifications},
144 each of which associates a @dfn{locale} (a window object, a buffer
145 object, a frame object, a device object, or the symbol @code{global})
146 with an @dfn{inst-list}, which is a list of one or more
147 @dfn{inst-pairs}. (For each possible locale, there can be at most one
148 specification containing that locale.) Each inst-pair is a cons of a
149 @dfn{tag set} (an unordered list of zero or more symbols, or @dfn{tags})
150 and an @dfn{instantiator} (the allowed form of this varies depending on
151 the type of specifier).  In a given specification, there may be more
152 than one inst-pair with the same tag set; this is unlike for locales.
153
154 The tag set is used to restrict the sorts of devices over which the
155 instantiator is valid and to uniquely identify instantiators added by a
156 particular application, so that different applications can work on the
157 same specifier and not interfere with each other.  Each tag can have a
158 @dfn{predicate} associated with it, which is a function of one argument
159 (a device) that specifies whether the tag matches that particular
160 device. (If a tag does not have a predicate, it matches all devices.)
161 All tags in a tag set must match a device for the associated inst-pair
162 to be instantiable over that device.  (A null tag set is perfectly
163 valid.)
164
165 The valid device types (normally @code{x}, @code{tty}, and
166 @code{stream}) and device classes (normally @code{color},
167 @code{grayscale}, and @code{mono}) can always be used as tags, and match
168 devices of the associated type or class (@pxref{Consoles and Devices}).
169 User-defined tags may be defined, with an optional predicate specified.
170 An application can create its own tag, use it to mark all its
171 instantiators, and be fairly confident that it will not interfere with
172 other applications that modify the same specifier -- Functions that add
173 a specification to a specifier usually only overwrite existing
174 inst-pairs with the same tag set as was given, and a particular tag or
175 tag set can be specified when removing instantiators.
176
177 When a specifier is instanced in a domain, both the locale and the tag
178 set can be viewed as specifying necessary conditions that must apply in
179 that domain for an instantiator to be considered as a possible result of
180 the instancing.  More specific locales always override more general
181 locales (thus, there is no particular ordering of the specifications in
182 a specifier); however, the tag sets are simply considered in the order
183 that the inst-pairs occur in the specification's inst-list.
184
185 Note also that the actual object that results from the instancing
186 (called an @dfn{instance object}) may not be the same as the instantiator
187 from which it was derived.  For some specifier types (such as integer
188 specifiers and boolean specifiers), the instantiator will be returned
189 directly as the instance object.  For other types, however, this
190 is not the case.  For example, for font specifiers, the instantiator
191 is a font-description string and the instance object is a font-instance
192 object, which describes how the font is displayed on a particular device.
193 A font-instance object encapsulates such things as the actual font name
194 used to display the font on that device (a font-description string
195 under X is usually a wildcard specification that may resolve to
196 different font names, with possibly different foundries, widths, etc.,
197 on different devices), the extra properties of that font on that
198 device, etc.  Furthermore, this conversion (called @dfn{instantiation})
199 might fail -- a font or color might not exist on a particular device,
200 for example.
201
202 @node Specifier Instancing
203 @section How a Specifier Is Instanced
204 @cindex fallback (in a specifier)
205 @cindex specifier, fallback
206
207 Instancing of a specifier in a particular window domain proceeds as
208 follows:
209
210 @itemize @bullet
211 @item
212 First, XEmacs searches for a specification whose locale is the same as
213 the window.  If that fails, the search is repeated, looking for a locale
214 that is the same as the window's buffer.  If that fails, the search is
215 repeated using the window's frame, then using the device that frame is
216 on.  Finally, the specification whose locale is the symbol @code{global}
217 (if there is such a specification) is considered.
218 @item
219 The inst-pairs contained in the specification that was found are
220 considered in their order in the inst-list, looking for one whose tag
221 set matches the device that is derived from the window domain.  (The
222 tag set is an unordered list of zero or more tag symbols.  For all
223 tags that have predicates associated with them, the predicate must
224 match the device.)
225 @item
226 If a matching tag set is found, the corresponding instantiator is passed
227 to the specifier's instantiation method, which is specific to the type
228 of the specifier.  If it succeeds, the resulting instance object is
229 returned as the result of the instancing and the instancing is done.
230 Otherwise, the operation continues, looking for another matching
231 inst-pair in the current specification.
232 @item
233 When there are no more inst-pairs to be considered in the current
234 specification, the search starts over, looking for another specification
235 as in the first step above.
236 @item
237 If all specifications are exhausted and no instance object can be
238 derived, the instancing fails. (Actually, this is not completely true.
239 Some specifier objects for built-in properties have a @dfn{fallback}
240 value, which is either an inst-list or another specifier object, that is
241 consulted if the instancing is about to fail.  If it is an inst-list,
242 the searching proceeds using the inst-pairs in that list.  If it is a
243 specifier, the entire instancing starts over using that specifier
244 instead of the given one.  Fallback values are set by the C code and
245 cannot be modified, except perhaps indirectly, using any Lisp functions.
246 The purpose of them is to supply some values to make sure that
247 instancing of built-in properties can't fail and to implement some basic
248 specifier inheritance, such as the fact that faces inherit their
249 properties from the @code{default} face.)
250 @end itemize
251
252 It is also possible to instance a specifier over a frame domain or
253 device domain instead of over a window domain.  The C code, for example,
254 instances the @code{top-toolbar-height} variable over a frame domain in
255 order to determine the height of a frame's top toolbar.  Instancing over
256 a frame or device is similar to instancing over a window except that
257 specifications for locales that cannot be derived from the domain are
258 ignored.  Specifically, instancing over a frame looks first for frame
259 locales, then device locales, then the @code{global} locale.  Instancing
260 over a device domain looks only for device locales and the @code{global}
261 locale.
262
263 @node Specifier Types
264 @section Specifier Types
265
266 There are various different types of specifiers.  The type of a
267 specifier controls what sorts of instantiators are valid, how an
268 instantiator is instantiated, etc.  Here is a list of built-in specifier
269 types:
270
271 @table @code
272 @item boolean
273 The valid instantiators are the symbols @code{t} and @code{nil}.
274 Instance objects are the same as instantiators so no special
275 instantiation function is needed.
276
277 @item integer
278 The valid instantiators are integers.  Instance objects are the same as
279 instantiators so no special instantiation function is needed.
280 @code{modeline-shadow-thickness} is an example of an integer specifier
281 (negative thicknesses indicate that the shadow is drawn recessed instead
282 of raised).
283
284 @item natnum
285 The valid instantiators are natnums (non-negative integers).  Instance
286 objects are the same as instantiators so no special instantiation
287 function is needed.  Natnum specifiers are used for dimension variables
288 such as @code{top-toolbar-height}.
289
290 @item generic
291 All Lisp objects are valid instantiators.  Instance objects are the same
292 as instantiators so no special instantiation function is needed.
293
294 @item font
295 The valid instantiators are strings describing fonts or vectors
296 indicating inheritance from the font of some face.  Instance objects are
297 font-instance objects, which are specific to a particular device.  The
298 instantiation method for font specifiers can fail, unlike for integer,
299 natnum, boolean, and generic specifiers.
300
301 @item color
302 The valid instantiators are strings describing colors or vectors
303 indicating inheritance from the foreground or background of some face.
304 Instance objects are color-instance objects, which are specific to a
305 particular device.  The instantiation method for color specifiers can fail,
306 as for font specifiers.
307
308 @item image
309 Images are perhaps the most complicated type of built-in specifier.  The
310 valid instantiators are strings (a filename, inline data for a pixmap,
311 or text to be displayed in a text glyph) or vectors describing inline
312 data of various sorts or indicating inheritance from the
313 background-pixmap property of some face.  Instance objects are either
314 strings (for text images), image-instance objects (for pixmap images),
315 or subwindow objects (for subwindow images).  The instantiation method
316 for image specifiers can fail, as for font and color specifiers.
317
318 @item face-boolean
319 The valid instantiators are the symbols @code{t} and @code{nil} and
320 vectors indicating inheritance from a boolean property of some face.
321 Specifiers of this sort are used for all of the built-in boolean
322 properties of faces.  Instance objects are either the symbol @code{t}
323 or the symbol @code{nil}.
324
325 @item toolbar
326 The valid instantiators are toolbar descriptors, which are lists
327 of toolbar-button descriptors (each of which is a vector of two
328 or four elements).  @xref{Toolbar} for more information.
329 @end table
330
331 Color and font instance objects can also be used in turn as
332 instantiators for a new color or font instance object.  Since these
333 instance objects are device-specific, the instantiator can be used
334 directly as the new instance object, but only if they are of the same
335 device.  If the devices differ, the base color or font of the
336 instantiating object is effectively used instead as the instantiator.
337
338 @xref{Faces and Window-System Objects} for more information on fonts,
339 colors, and face-boolean specifiers.  @xref{Glyphs} for more information
340 about image specifiers.  @xref{Toolbar} for more information on toolbar
341 specifiers.
342
343 @defun specifier-type specifier
344 This function returns the type of @var{specifier}.  The returned value
345 will be a symbol: one of @code{integer}, @code{boolean}, etc., as
346 listed in the above table.
347 @end defun
348
349 Functions are also provided to query whether an object is a particular
350 kind of specifier:
351
352 @defun boolean-specifier-p object
353 This function returns non-@code{nil} if @var{object} is a boolean
354 specifier.
355 @end defun
356
357 @defun integer-specifier-p object
358 This function returns non-@code{nil} if @var{object} is an integer
359 specifier.
360 @end defun
361
362 @defun natnum-specifier-p object
363 This function returns non-@code{nil} if @var{object} is a natnum
364 specifier.
365 @end defun
366
367 @defun generic-specifier-p object
368 This function returns non-@code{nil} if @var{object} is a generic
369 specifier.
370 @end defun
371
372 @defun face-boolean-specifier-p object
373 This function returns non-@code{nil} if @var{object} is a face-boolean
374 specifier.
375 @end defun
376
377 @defun toolbar-specifier-p object
378 This function returns non-@code{nil} if @var{object} is a toolbar
379 specifier.
380 @end defun
381
382 @defun font-specifier-p object
383 This function returns non-@code{nil} if @var{object} is a font
384 specifier.
385 @end defun
386
387 @defun color-specifier-p object
388 This function returns non-@code{nil} if @var{object} is a color
389 specifier.
390 @end defun
391
392 @defun image-specifier-p object
393 This function returns non-@code{nil} if @var{object} is an image
394 specifier.
395 @end defun
396
397 @node Adding Specifications
398 @section Adding specifications to a Specifier
399
400 @defun add-spec-to-specifier specifier instantiator &optional locale tag-set how-to-add
401 This function adds a specification to @var{specifier}.  The
402 specification maps from @var{locale} (which should be a window, buffer,
403 frame, device, or the symbol @code{global}, and defaults to
404 @code{global}) to @var{instantiator}, whose allowed values depend on the
405 type of the specifier.  Optional argument @var{tag-set} limits the
406 instantiator to apply only to the specified tag set, which should be a
407 list of tags all of which must match the device being instantiated over
408 (tags are a device type, a device class, or tags defined with
409 @code{define-specifier-tag}).  Specifying a single symbol for
410 @var{tag-set} is equivalent to specifying a one-element list containing
411 that symbol.  Optional argument @var{how-to-add} specifies what to do if
412 there are already specifications in the specifier.  It should be one of
413
414 @table @code
415 @item prepend
416 Put at the beginning of the current list of instantiators for @var{locale}.
417 @item append
418 Add to the end of the current list of instantiators for @var{locale}.
419 @item remove-tag-set-prepend
420 This is the default.  Remove any existing instantiators whose tag set is
421 the same as @var{tag-set}; then put the new instantiator at the
422 beginning of the current list.
423 @item remove-tag-set-append
424 Remove any existing instantiators whose tag set is the same as
425 @var{tag-set}; then put the new instantiator at the end of the current
426 list.
427 @item remove-locale
428 Remove all previous instantiators for this locale before adding the new
429 spec.
430 @item remove-locale-type
431 Remove all specifications for all locales of the same type as
432 @var{locale} (this includes @var{locale} itself) before adding the new
433 spec.
434 @item remove-all
435 Remove all specifications from the specifier before adding the new spec.
436 @end table
437
438 @code{remove-tag-set-prepend} is the default.
439
440 You can retrieve the specifications for a particular locale or locale type
441 with the function @code{specifier-spec-list} or @code{specifier-specs}.
442 @end defun
443
444 @defun add-spec-list-to-specifier specifier spec-list &optional how-to-add
445 This function adds a @dfn{spec-list} (a list of specifications) to
446 @var{specifier}.  The format of a spec-list is
447
448 @example
449   @code{((@var{locale} (@var{tag-set} . @var{instantiator}) ...) ...)}
450 @end example
451
452 where
453
454 @itemize @bullet
455 @item
456 @var{locale} := a window, a buffer, a frame, a device, or @code{global}
457 @item
458 @var{tag-set} := an unordered list of zero or more @var{tags}, each of
459 which is a symbol
460 @item
461 @var{tag} := a device class (@pxref{Consoles and Devices}), a device type,
462 or a tag defined with @code{define-specifier-tag}
463 @item
464 @var{instantiator} := format determined by the type of specifier
465 @end itemize
466
467 The pair @code{(@var{tag-set} . @var{instantiator})} is called an
468 @dfn{inst-pair}.  A list of inst-pairs is called an @dfn{inst-list}.
469 The pair @code{(@var{locale} . @var{inst-list})} is called a
470 @dfn{specification}.  A spec-list, then, can be viewed as a list of
471 specifications.
472
473 @var{how-to-add} specifies how to combine the new specifications with
474 the existing ones, and has the same semantics as for
475 @code{add-spec-to-specifier}.
476
477 In many circumstances, the higher-level function @code{set-specifier} is
478 more convenient and should be used instead.
479 @end defun
480
481 @deffn Macro let-specifier specifier-list &rest body
482 This special form temporarily adds specifications to specifiers,
483 evaluates forms in @var{body} and restores the specifiers to their
484 previous states.  The specifiers and their temporary specifications are
485 listed in @var{specifier-list}.
486
487 The format of @var{specifier-list} is
488
489 @example
490 ((@var{specifier} @var{value} &optional @var{locale} @var{tag-set} @var{how-to-add}) ...)
491 @end example
492
493 @var{specifier} is the specifier to be temporarily modified.
494 @var{value} is the instantiator to be temporarily added to specifier in
495 @var{locale}.  @var{locale}, @var{tag-set} and @var{how-to-add} have the
496 same meaning as in @code{add-spec-to-specifier}.
497
498 This special form is implemented as a macro; the code resulting from
499 macro expansion will add specifications to specifiers using
500 @code{add-spec-to-specifier}.  After forms in @var{body} are evaluated,
501 the temporary specifications are removed and old specifier spec-lists
502 are restored.
503
504 @var{locale}, @var{tag-set} and @var{how-to-add} may be omitted, and
505 default to @code{nil}.  The value of the last form in @var{body} is
506 returned.
507
508 NOTE: If you want the specifier's instance to change in all
509 circumstances, use @code{(selected-window)} as the @var{locale}.  If
510 @var{locale} is @code{nil} or omitted, it defaults to @code{global}.
511
512 The following example removes the 3D modeline effect in the currently
513 selected window for the duration of a second:
514
515 @example
516 (let-specifier ((modeline-shadow-thickness 0 (selected-window)))
517   (sit-for 1))
518 @end example
519 @end deffn
520
521 @defun set-specifier specifier value &optional how-to-add
522 This function adds some specifications to @var{specifier}.  @var{value}
523 can be a single instantiator or tagged instantiator (added as a global
524 specification), a list of tagged and/or untagged instantiators (added as
525 a global specification), a cons of a locale and instantiator or locale
526 and instantiator list, a list of such conses, or nearly any other
527 reasonable form.  More specifically, @var{value} can be anything
528 accepted by @code{canonicalize-spec-list}.
529
530 @var{how-to-add} is the same as in @code{add-spec-to-specifier}.
531
532 Note that @code{set-specifier} is exactly complementary to
533 @code{specifier-specs} except in the case where @var{specifier} has no
534 specs at all in it but @code{nil} is a valid instantiator (in that case,
535 @code{specifier-specs} will return @code{nil} (meaning no specs) and
536 @code{set-specifier} will interpret the @code{nil} as meaning ``I'm
537 adding a global instantiator and its value is @code{nil}''), or in
538 strange cases where there is an ambiguity between a spec-list and an
539 inst-list, etc. (The built-in specifier types are designed in such a way
540 as to avoid any such ambiguities.)
541
542 If you want to work with spec-lists, you should probably not use these
543 functions, but should use the lower-level functions
544 @code{specifier-spec-list} and @code{add-spec-list-to-specifier}.  These
545 functions always work with fully-qualified spec-lists; thus, there is no
546 ambiguity.
547 @end defun
548
549 @defun canonicalize-inst-pair inst-pair specifier-type &optional noerror
550 This function canonicalizes the given @var{inst-pair}.
551
552 @var{specifier-type} specifies the type of specifier that this
553 @var{spec-list} will be used for.
554
555 Canonicalizing means converting to the full form for an inst-pair, i.e.
556 @code{(@var{tag-set} . @var{instantiator})}.  A single, untagged
557 instantiator is given a tag set of @code{nil} (the empty set), and a
558 single tag is converted into a tag set consisting only of that tag.
559
560 If @var{noerror} is non-@code{nil}, signal an error if the inst-pair is
561 invalid; otherwise return @code{t}.
562 @end defun
563
564 @defun canonicalize-inst-list inst-list specifier-type &optional noerror
565 This function canonicalizes the given @var{inst-list} (a list of
566 inst-pairs).
567
568 @var{specifier-type} specifies the type of specifier that this @var{inst-list}
569 will be used for.
570
571 Canonicalizing means converting to the full form for an inst-list, i.e.
572 @code{((@var{tag-set} . @var{instantiator}) ...)}.  This function
573 accepts a single inst-pair or any abbreviation thereof or a list of
574 (possibly abbreviated) inst-pairs. (See @code{canonicalize-inst-pair}.)
575
576 If @var{noerror} is non-@code{nil}, signal an error if the inst-list is
577 invalid; otherwise return @code{t}.
578 @end defun
579
580 @defun canonicalize-spec spec specifier-type &optional noerror
581 This function canonicalizes the given @var{spec} (a specification).
582
583 @var{specifier-type} specifies the type of specifier that this
584 @var{spec-list} will be used for.
585
586 Canonicalizing means converting to the full form for a spec, i.e.
587 @code{(@var{locale} (@var{tag-set} . @var{instantiator}) ...)}.  This
588 function accepts a possibly abbreviated inst-list or a cons of a locale
589 and a possibly abbreviated inst-list. (See
590 @code{canonicalize-inst-list}.)
591
592 If @var{noerror} is @code{nil}, signal an error if the specification is
593 invalid; otherwise return @code{t}.
594 @end defun
595
596 @defun canonicalize-spec-list spec-list specifier-type &optional noerror
597 This function canonicalizes the given @var{spec-list} (a list of
598 specifications).
599
600 @var{specifier-type} specifies the type of specifier that this
601 @var{spec-list} will be used for.
602
603 Canonicalizing means converting to the full form for a spec-list, i.e.
604 @code{((@var{locale} (@var{tag-set} . @var{instantiator}) ...) ...)}.
605 This function accepts a possibly abbreviated specification or a list of
606 such things. (See @code{canonicalize-spec}.) This is the function used
607 to convert spec-lists accepted by @code{set-specifier} and such into a
608 form suitable for @code{add-spec-list-to-specifier}.
609
610 This function tries extremely hard to resolve any ambiguities,
611 and the built-in specifier types (font, image, toolbar, etc.) are
612 designed so that there won't be any ambiguities.
613
614 If @var{noerror} is @code{nil}, signal an error if the spec-list is
615 invalid; otherwise return @code{t}.
616 @end defun
617
618 @node Retrieving Specifications
619 @section Retrieving the Specifications from a Specifier
620
621 @defun specifier-spec-list specifier &optional locale tag-set exact-p
622 This function returns the spec-list of specifications for
623 @var{specifier} in @var{locale}.
624
625 If @var{locale} is a particular locale (a window, buffer, frame, device,
626 or the symbol @code{global}), a spec-list consisting of the
627 specification for that locale will be returned.
628
629 If @var{locale} is a locale type (i.e. a symbol @code{window},
630 @code{buffer}, @code{frame}, or @code{device}), a spec-list of the
631 specifications for all locales of that type will be returned.
632
633 If @var{locale} is @code{nil} or the symbol @code{all}, a spec-list of
634 all specifications in @var{specifier} will be returned.
635
636 @var{locale} can also be a list of locales, locale types, and/or
637 @code{all}; the result is as if @code{specifier-spec-list} were called
638 on each element of the list and the results concatenated together.
639
640 Only instantiators where @var{tag-set} (a list of zero or more tags) is
641 a subset of (or possibly equal to) the instantiator's tag set are
642 returned.  (The default value of@code{ nil} is a subset of all tag sets,
643 so in this case no instantiators will be screened out.) If @var{exact-p}
644 is non-@code{nil}, however, @var{tag-set} must be equal to an
645 instantiator's tag set for the instantiator to be returned.
646 @end defun
647
648 @defun specifier-specs specifier &optional locale tag-set exact-p
649 This function returns the specification(s) for @var{specifier} in
650 @var{locale}.
651
652 If @var{locale} is a single locale or is a list of one element
653 containing a single locale, then a ``short form'' of the instantiators
654 for that locale will be returned.  Otherwise, this function is identical
655 to @code{specifier-spec-list}.
656
657 The ``short form'' is designed for readability and not for ease of use
658 in Lisp programs, and is as follows:
659
660 @enumerate
661 @item
662 If there is only one instantiator, then an inst-pair (i.e. cons of tag
663 and instantiator) will be returned; otherwise a list of inst-pairs will
664 be returned.
665 @item
666 For each inst-pair returned, if the instantiator's tag is @code{any},
667 the tag will be removed and the instantiator itself will be returned
668 instead of the inst-pair.
669 @item
670 If there is only one instantiator, its value is @code{nil}, and its tag
671 is @code{any}, a one-element list containing @code{nil} will be returned
672 rather than just @code{nil}, to distinguish this case from there being
673 no instantiators at all.
674 @end enumerate
675
676 @end defun
677
678 @defun specifier-fallback specifier
679 This function returns the fallback value for @var{specifier}.  Fallback
680 values are provided by the C code for certain built-in specifiers to
681 make sure that instancing won't fail even if all specs are removed from
682 the specifier, or to implement simple inheritance behavior (e.g. this
683 method is used to ensure that faces other than @code{default} inherit
684 their attributes from @code{default}).  By design, you cannot change the
685 fallback value, and specifiers created with @code{make-specifier} will
686 never have a fallback (although a similar, Lisp-accessible capability
687 may be provided in the future to allow for inheritance).
688
689 The fallback value will be an inst-list that is instanced like
690 any other inst-list, a specifier of the same type as @var{specifier}
691 (results in inheritance), or @code{nil} for no fallback.
692
693 When you instance a specifier, you can explicitly request that the
694 fallback not be consulted. (The C code does this, for example, when
695 merging faces.) See @code{specifier-instance}.
696 @end defun
697
698 @node Specifier Tag Functions
699 @section Working With Specifier Tags
700
701 A specifier tag set is an entity that is attached to an instantiator
702 and can be used to restrict the scope of that instantiator to a
703 particular device class or device type and/or to mark instantiators
704 added by a particular package so that they can be later removed.
705
706 A specifier tag set consists of a list of zero of more specifier tags,
707 each of which is a symbol that is recognized by XEmacs as a tag.  (The
708 valid device types and device classes are always tags, as are any tags
709 defined by @code{define-specifier-tag}.) It is called a ``tag set'' (as
710 opposed to a list) because the order of the tags or the number of times
711 a particular tag occurs does not matter.
712
713 Each tag has a predicate associated with it, which specifies whether
714 that tag applies to a particular device.  The tags which are device
715 types and classes match devices of that type or class.  User-defined
716 tags can have any predicate, or none (meaning that all devices match).
717 When attempting to instance a specifier, a particular instantiator is
718 only considered if the device of the domain being instanced over matches
719 all tags in the tag set attached to that instantiator.
720
721 Most of the time, a tag set is not specified, and the instantiator gets
722 a null tag set, which matches all devices.
723
724 @defun valid-specifier-tag-p tag
725 This function returns non-@code{nil} if @var{tag} is a valid specifier
726 tag.
727 @end defun
728
729 @defun valid-specifier-tag-set-p tag-set
730 This function returns non-@code{nil} if @var{tag-set} is a valid
731 specifier tag set.
732 @end defun
733
734 @defun canonicalize-tag-set tag-set
735 This function canonicalizes the given tag set.  Two canonicalized tag
736 sets can be compared with @code{equal} to see if they represent the same
737 tag set. (Specifically, canonicalizing involves sorting by symbol name
738 and removing duplicates.)
739 @end defun
740
741 @defun device-matches-specifier-tag-set-p device tag-set
742 This function returns non-@code{nil} if @var{device} matches specifier
743 tag set @var{tag-set}.  This means that @var{device} matches each tag in
744 the tag set.
745 @end defun
746
747 @defun define-specifier-tag tag &optional predicate
748 This function defines a new specifier tag.  If @var{predicate} is
749 specified, it should be a function of one argument (a device) that
750 specifies whether the tag matches that particular device.  If
751 @var{predicate} is omitted, the tag matches all devices.
752
753 You can redefine an existing user-defined specifier tag.  However, you
754 cannot redefine the built-in specifier tags (the device types and
755 classes) or the symbols @code{nil}, @code{t}, @code{all}, or
756 @code{global}.
757 @end defun
758
759 @defun device-matching-specifier-tag-list &optional device
760 This function returns a list of all specifier tags matching
761 @var{device}.  @var{device} defaults to the selected device if omitted.
762 @end defun
763
764 @defun specifier-tag-list
765 This function returns a list of all currently-defined specifier tags.
766 This includes the built-in ones (the device types and classes).
767 @end defun
768
769 @defun specifier-tag-predicate tag
770 This function returns the predicate for the given specifier tag.
771 @end defun
772
773 @node Specifier Instancing Functions
774 @section Functions for Instancing a Specifier
775
776 @defun specifier-instance specifier &optional domain default no-fallback
777 This function instantiates @var{specifier} (return its value) in
778 @var{domain}.  If no instance can be generated for this domain, return
779 @var{default}.
780
781 @var{domain} should be a window, frame, or device.  Other values that
782 are legal as a locale (e.g. a buffer) are not valid as a domain because
783 they do not provide enough information to identify a particular device
784 (see @code{valid-specifier-domain-p}).  @var{domain} defaults to the
785 selected window if omitted.
786
787 @dfn{Instantiating} a specifier in a particular domain means determining
788 the specifier's ``value'' in that domain.  This is accomplished by
789 searching through the specifications in the specifier that correspond to
790 all locales that can be derived from the given domain, from specific to
791 general.  In most cases, the domain is an Emacs window.  In that case
792 specifications are searched for as follows:
793
794 @enumerate
795 @item
796 A specification whose locale is the window itself;
797 @item
798 A specification whose locale is the window's buffer;
799 @item
800 A specification whose locale is the window's frame;
801 @item
802 A specification whose locale is the window's frame's device;
803 @item
804 A specification whose locale is the symbol @code{global}.
805 @end enumerate
806
807 If all of those fail, then the C-code-provided fallback value for this
808 specifier is consulted (see @code{specifier-fallback}).  If it is an
809 inst-list, then this function attempts to instantiate that list just as
810 when a specification is located in the first five steps above.  If the
811 fallback is a specifier, @code{specifier-instance} is called recursively
812 on this specifier and the return value used.  Note, however, that if the
813 optional argument @var{no-fallback} is non-@code{nil}, the fallback
814 value will not be consulted.
815
816 Note that there may be more than one specification matching a particular
817 locale; all such specifications are considered before looking for any
818 specifications for more general locales.  Any particular specification
819 that is found may be rejected because it is tagged to a particular
820 device class (e.g. @code{color}) or device type (e.g. @code{x}) or both
821 and the device for the given domain does not match this, or because the
822 specification is not valid for the device of the given domain (e.g.  the
823 font or color name does not exist for this particular X server).
824
825 The returned value is dependent on the type of specifier.  For example,
826 for a font specifier (as returned by the @code{face-font} function), the
827 returned value will be a font-instance object.  For images, the returned
828 value will be a string, pixmap, or subwindow.
829 @end defun
830
831 @defun specifier-instance-from-inst-list specifier domain inst-list &optional default
832 This function attempts to convert a particular inst-list into an
833 instance.  This attempts to instantiate @var{inst-list} in the given
834 @var{domain}, as if @var{inst-list} existed in a specification in
835 @var{specifier}.  If the instantiation fails, @var{default} is returned.
836 In most circumstances, you should not use this function; use
837 @code{specifier-instance} instead.
838 @end defun
839
840 @node Specifier Example
841 @section Example of Specifier Usage
842
843 Now let us present an example to clarify the theoretical discussions we
844 have been through.  In this example, we will use the general specifier
845 functions for clarity.  Keep in mind that many types of specifiers, and
846 some other types of objects that are associated with specifiers
847 (e.g. faces), provide convenience functions making it easier to work
848 with objects of that type.
849
850 Let us consider the background color of the default face.  A specifier
851 is used to specify how that color will appear in different domains.
852 First, let's retrieve the specifier:
853
854 @example
855 (setq sp (face-property 'default 'background))
856     @result{}   #<color-specifier 0x3da>
857 @end example
858
859 @example
860 (specifier-specs sp)
861     @result{}   ((#<buffer "device.c"> (nil . "forest green"))
862                  (#<window on "Makefile" 0x8a2b> (nil . "hot pink"))
863                  (#<x-frame "emacs" 0x4ac> (nil . "puke orange")
864                                            (nil . "moccasin"))
865                  (#<x-frame "VM" 0x4ac> (nil . "magenta"))
866                  (global ((tty) . "cyan") (nil . "white"))
867                 )
868 @end example
869
870 Then, say we want to determine what the background color of the default
871 face is for the window currently displaying the buffer @samp{*scratch*}.
872 We call
873
874 @example
875 (get-buffer-window "*scratch*")
876     @result{} #<window on "*scratch*" 0x4ad>
877 (window-frame (get-buffer-window "*scratch*"))
878     @result{} #<x-frame "emacs" 0x4ac>
879 (specifier-instance sp (get-buffer-window "*scratch*"))
880     @result{} #<color-instance moccasin 47=(FFFF,E4E4,B5B5) 0x6309>
881 @end example
882
883 Note that we passed a window to @code{specifier-instance}, not a buffer.
884 We cannot pass a buffer because a buffer by itself does not provide enough
885 information.  The buffer might not be displayed anywhere at all, or
886 could be displayed in many different frames on different devices.
887
888 The result is arrived at like this:
889
890 @enumerate
891 @item
892 First, we look for a specification matching the buffer displayed in the
893 window, i.e. @samp{*scratch}.  There are none, so we proceed.
894 @item
895 Then, we look for a specification matching the window itself.  Again, there
896 are none.
897 @item
898 Then, we look for a specification matching the window's frame.  The
899 specification @code{(#<x-frame "emacs" 0x4ac> . "puke orange")} is
900 found.  We call the instantiation method for colors, passing it the
901 locale we were searching over (i.e. the window, in this case) and the
902 instantiator (@samp{"puke orange"}).  However, the particular device
903 which this window is on (let's say it's an X connection) doesn't
904 recognize the color @samp{"puke orange"}, so the specification is
905 rejected.
906 @item
907 So we continue looking for a specification matching the window's frame.
908 We find @samp{(#<x-frame "emacs" 0x4ac> . "moccasin")}.  Again, we
909 call the instantiation method for colors.  This time, the X server
910 our window is on recognizes the color @samp{moccasin}, and so the
911 instantiation method succeeds and returns a color instance.
912 @end enumerate
913
914 @node Creating Specifiers
915 @section Creating New Specifier Objects
916
917 @defun make-specifier type
918 This function creates a new specifier.
919
920 A specifier is an object that can be used to keep track of a property
921 whose value can be per-buffer, per-window, per-frame, or per-device,
922 and can further be restricted to a particular device-type or device-class.
923 Specifiers are used, for example, for the various built-in properties of a
924 face; this allows a face to have different values in different frames,
925 buffers, etc.  For more information, see `specifier-instance',
926 `specifier-specs', and `add-spec-to-specifier'; or, for a detailed
927 description of specifiers, including how they are instantiated over a
928 particular domain (i.e. how their value in that domain is determined),
929 see the chapter on specifiers in the XEmacs Lisp Reference Manual.
930
931 @var{type} specifies the particular type of specifier, and should be one
932 of the symbols @code{generic}, @code{integer}, @code{natnum},
933 @code{boolean}, @code{color}, @code{font}, @code{image},
934 @code{face-boolean}, or @code{toolbar}.
935
936 For more information on particular types of specifiers, see the
937 functions @code{generic-specifier-p}, @code{integer-specifier-p},
938 @code{natnum-specifier-p}, @code{boolean-specifier-p},
939 @code{color-specifier-p}, @code{font-specifier-p},
940 @code{image-specifier-p}, @code{face-boolean-specifier-p}, and
941 @code{toolbar-specifier-p}.
942 @end defun
943
944 @defun make-specifier-and-init type spec-list &optional dont-canonicalize
945 This function creates and initialize a new specifier.
946
947 This is a front-end onto @code{make-specifier} that allows you to create
948 a specifier and add specs to it at the same time.  @var{type} specifies
949 the specifier type.  @var{spec-list} supplies the specification(s) to be
950 added to the specifier. Normally, almost any reasonable abbreviation of
951 the full spec-list form is accepted, and is converted to the full form;
952 however, if optional argument @var{dont-canonicalize} is non-@code{nil},
953 this conversion is not performed, and the @var{spec-list} must already
954 be in full form.  See @code{canonicalize-spec-list}.
955 @end defun
956
957 @node Specifier Validation Functions
958 @section Functions for Checking the Validity of Specifier Components
959
960 @defun valid-specifier-domain-p domain
961 This function returns non-@code{nil} if @var{domain} is a valid
962 specifier domain.  A domain is used to instance a specifier
963 (i.e. determine the specifier's value in that domain).  Valid domains
964 are a window, frame, or device.  (@code{nil} is not valid.)
965 @end defun
966
967 @defun valid-specifier-locale-p locale
968 This function returns non-@code{nil} if @var{locale} is a valid
969 specifier locale.  Valid locales are a device, a frame, a window, a
970 buffer, and @code{global}.  (@code{nil} is not valid.)
971 @end defun
972
973 @defun valid-specifier-locale-type-p locale-type
974 Given a specifier @var{locale-type}, this function returns non-nil if it
975 is valid.  Valid locale types are the symbols @code{global},
976 @code{device}, @code{frame}, @code{window}, and @code{buffer}. (Note,
977 however, that in functions that accept either a locale or a locale type,
978 @code{global} is considered an individual locale.)
979 @end defun
980
981 @defun valid-specifier-type-p specifier-type
982 Given a @var{specifier-type}, this function returns non-@code{nil} if it
983 is valid.  Valid types are @code{generic}, @code{integer},
984 @code{boolean}, @code{color}, @code{font}, @code{image},
985 @code{face-boolean}, and @code{toolbar}.
986 @end defun
987
988 @defun valid-specifier-tag-p tag
989 This function returns non-@code{nil} if @var{tag} is a valid specifier
990 tag.
991 @end defun
992
993 @defun valid-instantiator-p instantiator specifier-type
994 This function returns non-@code{nil} if @var{instantiator} is valid for
995 @var{specifier-type}.
996 @end defun
997
998 @defun valid-inst-list-p inst-list type
999 This function returns non-@code{nil} if @var{inst-list} is valid for
1000 specifier type @var{type}.
1001 @end defun
1002
1003 @defun valid-spec-list-p spec-list type
1004 This function returns non-@code{nil} if @var{spec-list} is valid for
1005 specifier type @var{type}.
1006 @end defun
1007
1008 @defun check-valid-instantiator instantiator specifier-type
1009 This function signals an error if @var{instantiator} is invalid for
1010 @var{specifier-type}.
1011 @end defun
1012
1013 @defun check-valid-inst-list inst-list type
1014 This function signals an error if @var{inst-list} is invalid for
1015 specifier type @var{type}.
1016 @end defun
1017
1018 @defun check-valid-spec-list spec-list type
1019 This function signals an error if @var{spec-list} is invalid for
1020 specifier type @var{type}.
1021 @end defun
1022
1023 @node Other Specification Functions
1024 @section Other Functions for Working with Specifications in a Specifier
1025
1026 @defun copy-specifier specifier &optional dest locale tag-set exact-p how-to-add
1027 This function copies @var{specifier} to @var{dest}, or creates a new one
1028 if @var{dest} is @code{nil}.
1029
1030 If @var{dest} is @code{nil} or omitted, a new specifier will be created
1031 and the specifications copied into it.  Otherwise, the specifications
1032 will be copied into the existing specifier in @var{dest}.
1033
1034 If @var{locale} is @code{nil} or the symbol @code{all}, all
1035 specifications will be copied.  If @var{locale} is a particular locale,
1036 the specification for that particular locale will be copied.  If
1037 @var{locale} is a locale type, the specifications for all locales of
1038 that type will be copied.  @var{locale} can also be a list of locales,
1039 locale types, and/or @code{all}; this is equivalent to calling
1040 @code{copy-specifier} for each of the elements of the list.  See
1041 @code{specifier-spec-list} for more information about @var{locale}.
1042
1043 Only instantiators where @var{tag-set} (a list of zero or more tags) is
1044 a subset of (or possibly equal to) the instantiator's tag set are
1045 copied.  (The default value of @code{nil} is a subset of all tag sets,
1046 so in this case no instantiators will be screened out.) If @var{exact-p}
1047 is non-@code{nil}, however, @var{tag-set} must be equal to an
1048 instantiator's tag set for the instantiator to be copied.
1049
1050 Optional argument @var{how-to-add} specifies what to do with existing
1051 specifications in @var{dest}.  If nil, then whichever locales or locale
1052 types are copied will first be completely erased in @var{dest}.
1053 Otherwise, it is the same as in @code{add-spec-to-specifier}.
1054 @end defun
1055
1056 @defun remove-specifier specifier &optional locale tag-set exact-p
1057 This function removes specification(s) for @var{specifier}.
1058
1059 If @var{locale} is a particular locale (a buffer, window, frame, device,
1060 or the symbol @code{global}), the specification for that locale will be
1061 removed.
1062
1063 If instead, @var{locale} is a locale type (i.e. a symbol @code{buffer},
1064 @code{window}, @code{frame}, or @code{device}), the specifications for
1065 all locales of that type will be removed.
1066
1067 If @var{locale} is @code{nil} or the symbol @code{all}, all
1068 specifications will be removed.
1069
1070 @var{locale} can also be a list of locales, locale types, and/or
1071 @code{all}; this is equivalent to calling @code{remove-specifier} for
1072 each of the elements in the list.
1073
1074 Only instantiators where @var{tag-set} (a list of zero or more tags) is
1075 a subset of (or possibly equal to) the instantiator's tag set are
1076 removed.  (The default value of @code{nil} is a subset of all tag sets,
1077 so in this case no instantiators will be screened out.) If @var{exact-p}
1078 is non-@code{nil}, however, @var{tag-set} must be equal to an
1079 instantiator's tag set for the instantiator to be removed.
1080 @end defun
1081
1082 @defun map-specifier specifier func &optional locale maparg
1083 This function applies @var{func} to the specification(s) for
1084 @var{locale} in @var{specifier}.
1085
1086 If @var{locale} is a locale, @var{func} will be called for that locale.
1087 If @var{locale} is a locale type, @var{func} will be mapped over all
1088 locales of that type.  If @var{locale} is @code{nil} or the symbol
1089 @code{all}, @var{func} will be mapped over all locales in
1090 @var{specifier}.
1091
1092 @var{func} is called with four arguments: the @var{specifier}, the
1093 locale being mapped over, the inst-list for that locale, and the
1094 optional @var{maparg}.  If any invocation of @var{func} returns
1095 non-@code{nil}, the mapping will stop and the returned value becomes the
1096 value returned from @code{map-specifier}.  Otherwise,
1097 @code{map-specifier} returns @code{nil}.
1098 @end defun
1099
1100 @defun specifier-locale-type-from-locale locale
1101 Given a specifier @var{locale}, this function returns its type.
1102 @end defun
1103