Merge changes made in No Gnus
[bpt/emacs.git] / doc / lispref / customize.texi
CommitLineData
b8d4c8d0
GM
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
ddff3351 3@c Copyright (C) 1997-2012 Free Software Foundation, Inc.
b8d4c8d0 4@c See the file elisp.texi for copying conditions.
6336d8c3 5@setfilename ../../info/customize
b8d4c8d0 6@node Customization, Loading, Macros, Top
81927dd2 7@chapter Customization Settings
b8d4c8d0 8
81927dd2
CY
9@cindex customization item
10 This chapter describes how to declare customizable variables and
11customization groups for classifying them. We use the term
12@dfn{customization item} to include customizable variables,
13customization groups, as well as faces.
14
15 @xref{Defining Faces}, for the @code{defface} macro, which is used
16for declaring customizable faces.
b8d4c8d0
GM
17
18@menu
81927dd2
CY
19* Common Keywords:: Common keyword arguments for all kinds of
20 customization declarations.
21* Group Definitions:: Writing customization group definitions.
22* Variable Definitions:: Declaring user options.
23* Customization Types:: Specifying the type of a user option.
24* Applying Customizations:: Functions to apply customization settings.
25* Custom Themes:: Writing Custom themes.
b8d4c8d0
GM
26@end menu
27
28@node Common Keywords
29@section Common Item Keywords
30
31@cindex customization keywords
03988c98
CY
32 The customization declarations that we will describe in the next few
33sections (@code{defcustom}, @code{defgroup}, etc.) all accept keyword
34arguments for specifying various information. This section describes
35keywords that apply to all types of customization declarations.
b8d4c8d0
GM
36
37 All of these keywords, except @code{:tag}, can be used more than once
38in a given item. Each use of the keyword has an independent effect.
39The keyword @code{:tag} is an exception because any given item can only
40display one name.
41
42@table @code
43@item :tag @var{label}
44@kindex tag@r{, customization keyword}
45Use @var{label}, a string, instead of the item's name, to label the
46item in customization menus and buffers. @strong{Don't use a tag
47which is substantially different from the item's real name; that would
0f631634 48cause confusion.}
b8d4c8d0
GM
49
50@kindex group@r{, customization keyword}
51@item :group @var{group}
52Put this customization item in group @var{group}. When you use
53@code{:group} in a @code{defgroup}, it makes the new group a subgroup of
54@var{group}.
55
56If you use this keyword more than once, you can put a single item into
57more than one group. Displaying any of those groups will show this
58item. Please don't overdo this, since the result would be annoying.
59
60@item :link @var{link-data}
61@kindex link@r{, customization keyword}
62Include an external link after the documentation string for this item.
63This is a sentence containing an active field which references some
64other documentation.
65
66There are several alternatives you can use for @var{link-data}:
67
68@table @code
69@item (custom-manual @var{info-node})
70Link to an Info node; @var{info-node} is a string which specifies the
71node name, as in @code{"(emacs)Top"}. The link appears as
72@samp{[Manual]} in the customization buffer and enters the built-in
73Info reader on @var{info-node}.
74
75@item (info-link @var{info-node})
76Like @code{custom-manual} except that the link appears
77in the customization buffer with the Info node name.
78
79@item (url-link @var{url})
80Link to a web page; @var{url} is a string which specifies the
81@acronym{URL}. The link appears in the customization buffer as
82@var{url} and invokes the WWW browser specified by
83@code{browse-url-browser-function}.
84
85@item (emacs-commentary-link @var{library})
86Link to the commentary section of a library; @var{library} is a string
87which specifies the library name.
88
89@item (emacs-library-link @var{library})
90Link to an Emacs Lisp library file; @var{library} is a string which
91specifies the library name.
92
93@item (file-link @var{file})
94Link to a file; @var{file} is a string which specifies the name of the
95file to visit with @code{find-file} when the user invokes this link.
96
97@item (function-link @var{function})
98Link to the documentation of a function; @var{function} is a string
99which specifies the name of the function to describe with
100@code{describe-function} when the user invokes this link.
101
102@item (variable-link @var{variable})
103Link to the documentation of a variable; @var{variable} is a string
104which specifies the name of the variable to describe with
105@code{describe-variable} when the user invokes this link.
106
107@item (custom-group-link @var{group})
108Link to another customization group. Invoking it creates a new
109customization buffer for @var{group}.
110@end table
111
112You can specify the text to use in the customization buffer by adding
113@code{:tag @var{name}} after the first element of the @var{link-data};
114for example, @code{(info-link :tag "foo" "(emacs)Top")} makes a link to
115the Emacs manual which appears in the buffer as @samp{foo}.
116
03988c98 117You can use this keyword more than once, to add multiple links.
b8d4c8d0
GM
118
119@item :load @var{file}
120@kindex load@r{, customization keyword}
121Load file @var{file} (a string) before displaying this customization
f6de8a37
CY
122item (@pxref{Loading}). Loading is done with @code{load}, and only if
123the file is not already loaded.
b8d4c8d0
GM
124
125@item :require @var{feature}
126@kindex require@r{, customization keyword}
127Execute @code{(require '@var{feature})} when your saved customizations
128set the value of this item. @var{feature} should be a symbol.
129
130The most common reason to use @code{:require} is when a variable enables
131a feature such as a minor mode, and just setting the variable won't have
132any effect unless the code which implements the mode is loaded.
133
134@item :version @var{version}
135@kindex version@r{, customization keyword}
136This keyword specifies that the item was first introduced in Emacs
137version @var{version}, or that its default value was changed in that
138version. The value @var{version} must be a string.
139
140@item :package-version '(@var{package} . @var{version})
141@kindex package-version@r{, customization keyword}
142This keyword specifies that the item was first introduced in
143@var{package} version @var{version}, or that its meaning or default
03988c98
CY
144value was changed in that version. This keyword takes priority over
145@code{:version}.
b8d4c8d0 146
03988c98
CY
147@var{package} should be the official name of the package, as a symbol
148(e.g.@: @code{MH-E}). @var{version} should be a string. If the
149package @var{package} is released as part of Emacs, @var{package} and
150@var{version} should appear in the value of
b8d4c8d0
GM
151@code{customize-package-emacs-version-alist}.
152@end table
153
154Packages distributed as part of Emacs that use the
155@code{:package-version} keyword must also update the
156@code{customize-package-emacs-version-alist} variable.
157
158@defvar customize-package-emacs-version-alist
159This alist provides a mapping for the versions of Emacs that are
160associated with versions of a package listed in the
ddff3351 161@code{:package-version} keyword. Its elements are:
b8d4c8d0
GM
162
163@example
164(@var{package} (@var{pversion} . @var{eversion})@dots{})
165@end example
166
167For each @var{package}, which is a symbol, there are one or more
168elements that contain a package version @var{pversion} with an
169associated Emacs version @var{eversion}. These versions are strings.
170For example, the MH-E package updates this alist with the following:
171
ddff3351
GM
172@c Must be small else too wide.
173@c FIXME obviously this is out of date (in the code).
b8d4c8d0
GM
174@smallexample
175(add-to-list 'customize-package-emacs-version-alist
176 '(MH-E ("6.0" . "22.1") ("6.1" . "22.1") ("7.0" . "22.1")
177 ("7.1" . "22.1") ("7.2" . "22.1") ("7.3" . "22.1")
178 ("7.4" . "22.1") ("8.0" . "22.1")))
179@end smallexample
180
181The value of @var{package} needs to be unique and it needs to match
182the @var{package} value appearing in the @code{:package-version}
35a30759 183keyword. Since the user might see the value in an error message, a good
b8d4c8d0
GM
184choice is the official name of the package, such as MH-E or Gnus.
185@end defvar
186
187@node Group Definitions
188@section Defining Customization Groups
189@cindex define customization group
190@cindex customization groups, defining
191
192 Each Emacs Lisp package should have one main customization group which
193contains all the options, faces and other groups in the package. If the
194package has a small number of options and faces, use just one group and
195put everything in it. When there are more than twelve or so options and
196faces, then you should structure them into subgroups, and put the
197subgroups under the package's main customization group. It is OK to
198put some of the options and faces in the package's main group alongside
199the subgroups.
200
201 The package's main or only group should be a member of one or more of
202the standard customization groups. (To display the full list of them,
203use @kbd{M-x customize}.) Choose one or more of them (but not too
204many), and add your group to each of them using the @code{:group}
205keyword.
206
207 The way to declare new customization groups is with @code{defgroup}.
208
209@defmac defgroup group members doc [keyword value]@dots{}
210Declare @var{group} as a customization group containing @var{members}.
211Do not quote the symbol @var{group}. The argument @var{doc} specifies
212the documentation string for the group.
213
214The argument @var{members} is a list specifying an initial set of
215customization items to be members of the group. However, most often
216@var{members} is @code{nil}, and you specify the group's members by
217using the @code{:group} keyword when defining those members.
218
219If you want to specify group members through @var{members}, each element
220should have the form @code{(@var{name} @var{widget})}. Here @var{name}
221is a symbol, and @var{widget} is a widget type for editing that symbol.
222Useful widgets are @code{custom-variable} for a variable,
223@code{custom-face} for a face, and @code{custom-group} for a group.
224
225When you introduce a new group into Emacs, use the @code{:version}
226keyword in the @code{defgroup}; then you need not use it for
227the individual members of the group.
228
229In addition to the common keywords (@pxref{Common Keywords}), you can
230also use this keyword in @code{defgroup}:
231
232@table @code
233@item :prefix @var{prefix}
234@kindex prefix@r{, @code{defgroup} keyword}
03988c98
CY
235If the name of an item in the group starts with @var{prefix}, and the
236customizable variable @code{custom-unlispify-remove-prefixes} is
237non-@code{nil}, the item's tag will omit @var{prefix}. A group can
238have any number of prefixes.
b8d4c8d0
GM
239@end table
240@end defmac
241
03988c98
CY
242@defopt custom-unlispify-remove-prefixes
243If this variable is non-@code{nil}, the prefixes specified by a
244group's @code{:prefix} keyword are omitted from tag names, whenever
245the user customizes the group.
b8d4c8d0 246
03988c98
CY
247The default value is @code{nil}, i.e.@: the prefix-discarding feature
248is disabled. This is because discarding prefixes often leads to
249confusing names for options and faces.
250@end defopt
b8d4c8d0
GM
251
252@node Variable Definitions
253@section Defining Customization Variables
254@cindex define customization options
255@cindex customization variables, how to define
256
b8d4c8d0 257@defmac defcustom option standard doc [keyword value]@dots{}
03988c98
CY
258This macro declares @var{option} as a user option (i.e.@: a
259customizable variable). You should not quote @var{option}.
0f631634 260
b8d4c8d0
GM
261The argument @var{standard} is an expression that specifies the
262standard value for @var{option}. Evaluating the @code{defcustom} form
263evaluates @var{standard}, but does not necessarily install the
264standard value. If @var{option} already has a default value,
265@code{defcustom} does not change it. If the user has saved a
266customization for @var{option}, @code{defcustom} installs the user's
267customized value as @var{option}'s default value. If neither of those
268cases applies, @code{defcustom} installs the result of evaluating
269@var{standard} as the default value.
270
271The expression @var{standard} can be evaluated at various other times,
272too---whenever the customization facility needs to know @var{option}'s
273standard value. So be sure to use an expression which is harmless to
03988c98 274evaluate at any time.
b8d4c8d0 275
1021c761
CY
276The argument @var{doc} specifies the documentation string for the
277variable.
278
b8d4c8d0
GM
279Every @code{defcustom} should specify @code{:group} at least once.
280
b8d4c8d0
GM
281When you evaluate a @code{defcustom} form with @kbd{C-M-x} in Emacs Lisp
282mode (@code{eval-defun}), a special feature of @code{eval-defun}
283arranges to set the variable unconditionally, without testing whether
284its value is void. (The same feature applies to @code{defvar}.)
285@xref{Defining Variables}.
437706cd 286
03988c98
CY
287If you put a @code{defcustom} in a pre-loaded Emacs Lisp file
288(@pxref{Building Emacs}), the standard value installed at dump time
289might be incorrect, e.g.@: because another variable that it depends on
290has not been assigned the right value yet. In that case, use
437706cd 291@code{custom-reevaluate-setting}, described below, to re-evaluate the
03988c98 292standard value after Emacs starts up.
b8d4c8d0
GM
293@end defmac
294
295 @code{defcustom} accepts the following additional keywords:
296
297@table @code
298@item :type @var{type}
299Use @var{type} as the data type for this option. It specifies which
300values are legitimate, and how to display the value.
301@xref{Customization Types}, for more information.
302
303@item :options @var{value-list}
304@kindex options@r{, @code{defcustom} keyword}
305Specify the list of reasonable values for use in this
306option. The user is not restricted to using only these values, but they
307are offered as convenient alternatives.
308
309This is meaningful only for certain types, currently including
310@code{hook}, @code{plist} and @code{alist}. See the definition of the
311individual types for a description of how to use @code{:options}.
312
313@item :set @var{setfunction}
314@kindex set@r{, @code{defcustom} keyword}
315Specify @var{setfunction} as the way to change the value of this
81927dd2 316option when using the Customize interface. The function
8a20ca4c
LMI
317@var{setfunction} should take two arguments, a symbol (the option
318name) and the new value, and should do whatever is necessary to update
319the value properly for this option (which may not mean simply setting
320the option as a Lisp variable). The default for @var{setfunction} is
321@code{set-default}.
b8d4c8d0 322
03988c98
CY
323If you specify this keyword, the variable's documentation string
324should describe how to do the same job in hand-written Lisp code.
325
b8d4c8d0
GM
326@item :get @var{getfunction}
327@kindex get@r{, @code{defcustom} keyword}
328Specify @var{getfunction} as the way to extract the value of this
329option. The function @var{getfunction} should take one argument, a
330symbol, and should return whatever customize should use as the
331``current value'' for that symbol (which need not be the symbol's Lisp
332value). The default is @code{default-value}.
333
334You have to really understand the workings of Custom to use
335@code{:get} correctly. It is meant for values that are treated in
336Custom as variables but are not actually stored in Lisp variables. It
03988c98 337is almost surely a mistake to specify @var{getfunction} for a value
b8d4c8d0
GM
338that really is stored in a Lisp variable.
339
340@item :initialize @var{function}
341@kindex initialize@r{, @code{defcustom} keyword}
342@var{function} should be a function used to initialize the variable
343when the @code{defcustom} is evaluated. It should take two arguments,
344the option name (a symbol) and the value. Here are some predefined
345functions meant for use in this way:
346
347@table @code
348@item custom-initialize-set
349Use the variable's @code{:set} function to initialize the variable, but
350do not reinitialize it if it is already non-void.
351
352@item custom-initialize-default
353Like @code{custom-initialize-set}, but use the function
354@code{set-default} to set the variable, instead of the variable's
355@code{:set} function. This is the usual choice for a variable whose
356@code{:set} function enables or disables a minor mode; with this choice,
357defining the variable will not call the minor mode function, but
358customizing the variable will do so.
359
360@item custom-initialize-reset
361Always use the @code{:set} function to initialize the variable. If
362the variable is already non-void, reset it by calling the @code{:set}
363function using the current value (returned by the @code{:get} method).
364This is the default @code{:initialize} function.
365
366@item custom-initialize-changed
367Use the @code{:set} function to initialize the variable, if it is
368already set or has been customized; otherwise, just use
369@code{set-default}.
370
371@item custom-initialize-safe-set
372@itemx custom-initialize-safe-default
373These functions behave like @code{custom-initialize-set}
374(@code{custom-initialize-default}, respectively), but catch errors.
375If an error occurs during initialization, they set the variable to
03988c98
CY
376@code{nil} using @code{set-default}, and signal no error.
377
378These functions are meant for options defined in pre-loaded files,
379where the @var{standard} expression may signal an error because some
380required variable or function is not yet defined. The value normally
381gets updated in @file{startup.el}, ignoring the value computed by
382@code{defcustom}. After startup, if one unsets the value and
383reevaluates the @code{defcustom}, the @var{standard} expression can be
384evaluated without error.
b8d4c8d0
GM
385@end table
386
db21122c
GM
387@item :risky @var{value}
388@kindex risky@r{, @code{defcustom} keyword}
95ddd36f 389Set the variable's @code{risky-local-variable} property to
0f631634 390@var{value} (@pxref{File Local Variables}).
db21122c
GM
391
392@item :safe @var{function}
393@kindex safe@r{, @code{defcustom} keyword}
95ddd36f 394Set the variable's @code{safe-local-variable} property to
0f631634 395@var{function} (@pxref{File Local Variables}).
db21122c 396
b8d4c8d0
GM
397@item :set-after @var{variables}
398@kindex set-after@r{, @code{defcustom} keyword}
399When setting variables according to saved customizations, make sure to
ddff3351 400set the variables @var{variables} before this one; i.e., delay
b8d4c8d0
GM
401setting this variable until after those others have been handled. Use
402@code{:set-after} if setting this variable won't work properly unless
403those other variables already have their intended values.
404@end table
405
0f631634
CY
406 It is useful to specify the @code{:require} keyword for an option
407that ``turns on'' a certain feature. This causes Emacs to load the
408feature, if it is not already loaded, whenever the option is set.
409@xref{Common Keywords}. Here is an example, from the library
410@file{saveplace.el}:
b8d4c8d0
GM
411
412@example
413(defcustom save-place nil
414 "Non-nil means automatically save place in each file..."
415 :type 'boolean
416 :require 'saveplace
417 :group 'save-place)
418@end example
419
420If a customization item has a type such as @code{hook} or
421@code{alist}, which supports @code{:options}, you can add additional
422values to the list from outside the @code{defcustom} declaration by
423calling @code{custom-add-frequent-value}. For example, if you define a
424function @code{my-lisp-mode-initialization} intended to be called from
425@code{emacs-lisp-mode-hook}, you might want to add that to the list of
426reasonable values for @code{emacs-lisp-mode-hook}, but not by editing
427its definition. You can do it thus:
428
429@example
430(custom-add-frequent-value 'emacs-lisp-mode-hook
431 'my-lisp-mode-initialization)
432@end example
433
434@defun custom-add-frequent-value symbol value
435For the customization option @var{symbol}, add @var{value} to the
436list of reasonable values.
437
438The precise effect of adding a value depends on the customization type
439of @var{symbol}.
440@end defun
441
442Internally, @code{defcustom} uses the symbol property
443@code{standard-value} to record the expression for the standard value,
0f631634
CY
444@code{saved-value} to record the value saved by the user with the
445customization buffer, and @code{customized-value} to record the value
446set by the user with the customization buffer, but not saved.
447@xref{Property Lists}. These properties are lists, the car of which
448is an expression that evaluates to the value.
b8d4c8d0 449
437706cd 450@defun custom-reevaluate-setting symbol
0f631634 451This function re-evaluates the standard value of @var{symbol}, which
03988c98 452should be a user option declared via @code{defcustom}. If the
0f631634 453variable was customized, this function re-evaluates the saved value
03988c98
CY
454instead. Then it sets the user option to that value (using the
455option's @code{:set} property if that is defined).
456
457This is useful for customizable options that are defined before their
458value could be computed correctly. For example, during startup Emacs
459calls this function for some user options that were defined in
460pre-loaded Emacs Lisp files, but whose initial values depend on
461information available only at run-time.
437706cd
EZ
462@end defun
463
1021c761
CY
464@defun custom-variable-p arg
465This function returns non-@code{nil} if @var{arg} is a customizable
466variable. A customizable variable is either a variable that has a
467@code{standard-value} or @code{custom-autoload} property (usually
468meaning it was declared with @code{defcustom}), or an alias for
469another customizable variable.
470@end defun
471
472@defun user-variable-p arg
473This function is like @code{custom-variable-p}, except it also returns
474@code{t} if the first character of the variable's documentation string
475is the character @samp{*}. That is an obsolete way of indicating a
476user option, so for most purposes you may consider
477@code{user-variable-p} as equivalent to @code{custom-variable-p}.
478@end defun
479
b8d4c8d0
GM
480@node Customization Types
481@section Customization Types
482
483@cindex customization types
484 When you define a user option with @code{defcustom}, you must specify
485its @dfn{customization type}. That is a Lisp object which describes (1)
486which values are legitimate and (2) how to display the value in the
487customization buffer for editing.
488
489@kindex type@r{, @code{defcustom} keyword}
490 You specify the customization type in @code{defcustom} with the
491@code{:type} keyword. The argument of @code{:type} is evaluated, but
492only once when the @code{defcustom} is executed, so it isn't useful
493for the value to vary. Normally we use a quoted constant. For
494example:
495
496@example
497(defcustom diff-command "diff"
498 "The command to use to run diff."
499 :type '(string)
500 :group 'diff)
501@end example
502
503 In general, a customization type is a list whose first element is a
504symbol, one of the customization type names defined in the following
505sections. After this symbol come a number of arguments, depending on
506the symbol. Between the type symbol and its arguments, you can
507optionally write keyword-value pairs (@pxref{Type Keywords}).
508
0f631634 509 Some type symbols do not use any arguments; those are called
b8d4c8d0
GM
510@dfn{simple types}. For a simple type, if you do not use any
511keyword-value pairs, you can omit the parentheses around the type
512symbol. For example just @code{string} as a customization type is
513equivalent to @code{(string)}.
514
0f631634
CY
515 All customization types are implemented as widgets; see @ref{Top, ,
516Introduction, widget, The Emacs Widget Library}, for details.
517
b8d4c8d0 518@menu
3deead93 519* Simple Types:: Simple customization types: sexp, integer, etc.
51d9979c
GM
520* Composite Types:: Build new types from other types or data.
521* Splicing into Lists:: Splice elements into list with @code{:inline}.
522* Type Keywords:: Keyword-argument pairs in a customization type.
523* Defining New Types:: Give your type a name.
b8d4c8d0
GM
524@end menu
525
b8d4c8d0
GM
526@node Simple Types
527@subsection Simple Types
528
e1161b06
CY
529 This section describes all the simple customization types. For
530several of these customization types, the customization widget
531provides inline completion with @kbd{C-M-i} or @kbd{M-@key{TAB}}.
b8d4c8d0
GM
532
533@table @code
534@item sexp
e1161b06
CY
535The value may be any Lisp object that can be printed and read back.
536You can use @code{sexp} as a fall-back for any option, if you don't
537want to take the time to work out a more specific type to use.
b8d4c8d0
GM
538
539@item integer
e1161b06 540The value must be an integer.
b8d4c8d0
GM
541
542@item number
e1161b06 543The value must be a number (floating point or integer).
b8d4c8d0
GM
544
545@item float
e1161b06 546The value must be a floating point number.
b8d4c8d0
GM
547
548@item string
e1161b06
CY
549The value must be a string. The customization buffer shows the string
550without delimiting @samp{"} characters or @samp{\} quotes.
b8d4c8d0
GM
551
552@item regexp
553Like @code{string} except that the string must be a valid regular
554expression.
555
556@item character
557The value must be a character code. A character code is actually an
558integer, but this type shows the value by inserting the character in the
559buffer, rather than by showing the number.
560
561@item file
e1161b06 562The value must be a file name. The widget provides completion.
b8d4c8d0
GM
563
564@item (file :must-match t)
e1161b06
CY
565The value must be a file name for an existing file. The widget
566provides completion.
b8d4c8d0
GM
567
568@item directory
e1161b06 569The value must be a directory name. The widget provides completion.
b8d4c8d0
GM
570
571@item hook
e1161b06
CY
572The value must be a list of functions. This customization type is
573used for hook variables. You can use the @code{:options} keyword in a
574hook variable's @code{defcustom} to specify a list of functions
575recommended for use in the hook; @xref{Variable Definitions}.
b8d4c8d0 576
3deead93
CY
577@item symbol
578The value must be a symbol. It appears in the customization buffer as
e1161b06 579the symbol name. The widget provides completion.
b8d4c8d0 580
3deead93 581@item function
e1161b06
CY
582The value must be either a lambda expression or a function name. The
583widget provides completion for function names.
b8d4c8d0 584
3deead93 585@item variable
e1161b06 586The value must be a variable name. The widget provides completion.
3deead93
CY
587
588@item face
e1161b06
CY
589The value must be a symbol which is a face name. The widget provides
590completion.
3deead93
CY
591
592@item boolean
593The value is boolean---either @code{nil} or @code{t}. Note that by
594using @code{choice} and @code{const} together (see the next section),
595you can specify that the value must be @code{nil} or @code{t}, but also
596specify the text to describe each value in a way that fits the specific
597meaning of the alternative.
598
599@item coding-system
600The value must be a coding-system name, and you can do completion with
601@kbd{M-@key{TAB}}.
602
603@item color
e1161b06
CY
604The value must be a valid color name. The widget provides completion
605for color names, as well as a sample and a button for selecting a
2bb0eca1 606color name from a list of color names shown in a @file{*Colors*}
e1161b06 607buffer.
3deead93
CY
608@end table
609
610@node Composite Types
611@subsection Composite Types
612@cindex composite types (customization)
613
614 When none of the simple types is appropriate, you can use composite
615types, which build new types from other types or from specified data.
616The specified types or data are called the @dfn{arguments} of the
617composite type. The composite type normally looks like this:
618
619@example
620(@var{constructor} @var{arguments}@dots{})
621@end example
b8d4c8d0
GM
622
623@noindent
3deead93
CY
624but you can also add keyword-value pairs before the arguments, like
625this:
626
627@example
628(@var{constructor} @r{@{}@var{keyword} @var{value}@r{@}}@dots{} @var{arguments}@dots{})
629@end example
630
631 Here is a table of constructors and how to use them to write
632composite types:
633
634@table @code
635@item (cons @var{car-type} @var{cdr-type})
636The value must be a cons cell, its @sc{car} must fit @var{car-type}, and
637its @sc{cdr} must fit @var{cdr-type}. For example, @code{(cons string
638symbol)} is a customization type which matches values such as
639@code{("foo" . foo)}.
640
e1161b06
CY
641In the customization buffer, the @sc{car} and @sc{cdr} are displayed
642and edited separately, each according to their specified type.
3deead93
CY
643
644@item (list @var{element-types}@dots{})
645The value must be a list with exactly as many elements as the
646@var{element-types} given; and each element must fit the
647corresponding @var{element-type}.
648
649For example, @code{(list integer string function)} describes a list of
650three elements; the first element must be an integer, the second a
651string, and the third a function.
652
653In the customization buffer, each element is displayed and edited
654separately, according to the type specified for it.
655
656@item (group @var{element-types}@dots{})
657This works like @code{list} except for the formatting
658of text in the Custom buffer. @code{list} labels each
659element value with its tag; @code{group} does not.
660
661@item (vector @var{element-types}@dots{})
662Like @code{list} except that the value must be a vector instead of a
663list. The elements work the same as in @code{list}.
664
665@item (alist :key-type @var{key-type} :value-type @var{value-type})
666The value must be a list of cons-cells, the @sc{car} of each cell
667representing a key of customization type @var{key-type}, and the
668@sc{cdr} of the same cell representing a value of customization type
669@var{value-type}. The user can add and delete key/value pairs, and
670edit both the key and the value of each pair.
671
672If omitted, @var{key-type} and @var{value-type} default to
673@code{sexp}.
b8d4c8d0
GM
674
675The user can add any key matching the specified key type, but you can
676give some keys a preferential treatment by specifying them with the
677@code{:options} (see @ref{Variable Definitions}). The specified keys
678will always be shown in the customize buffer (together with a suitable
679value), with a checkbox to include or exclude or disable the key/value
680pair from the alist. The user will not be able to edit the keys
681specified by the @code{:options} keyword argument.
682
683The argument to the @code{:options} keywords should be a list of
684specifications for reasonable keys in the alist. Ordinarily, they are
e1161b06 685simply atoms, which stand for themselves. For example:
b8d4c8d0 686
ddff3351 687@example
b8d4c8d0 688:options '("foo" "bar" "baz")
ddff3351 689@end example
b8d4c8d0
GM
690
691@noindent
692specifies that there are three ``known'' keys, namely @code{"foo"},
693@code{"bar"} and @code{"baz"}, which will always be shown first.
694
695You may want to restrict the value type for specific keys, for
696example, the value associated with the @code{"bar"} key can only be an
697integer. You can specify this by using a list instead of an atom in
698the list. The first element will specify the key, like before, while
699the second element will specify the value type. For example:
700
ddff3351 701@example
b8d4c8d0 702:options '("foo" ("bar" integer) "baz")
ddff3351 703@end example
b8d4c8d0
GM
704
705Finally, you may want to change how the key is presented. By default,
706the key is simply shown as a @code{const}, since the user cannot change
707the special keys specified with the @code{:options} keyword. However,
708you may want to use a more specialized type for presenting the key, like
709@code{function-item} if you know it is a symbol with a function binding.
710This is done by using a customization type specification instead of a
711symbol for the key.
712
ddff3351 713@example
b8d4c8d0
GM
714:options '("foo" ((function-item some-function) integer)
715 "baz")
ddff3351 716@end example
b8d4c8d0
GM
717
718Many alists use lists with two elements, instead of cons cells. For
719example,
720
ddff3351 721@example
b8d4c8d0
GM
722(defcustom list-alist '(("foo" 1) ("bar" 2) ("baz" 3))
723 "Each element is a list of the form (KEY VALUE).")
ddff3351 724@end example
b8d4c8d0
GM
725
726@noindent
727instead of
728
ddff3351 729@example
b8d4c8d0
GM
730(defcustom cons-alist '(("foo" . 1) ("bar" . 2) ("baz" . 3))
731 "Each element is a cons-cell (KEY . VALUE).")
ddff3351 732@end example
b8d4c8d0
GM
733
734Because of the way lists are implemented on top of cons cells, you can
735treat @code{list-alist} in the example above as a cons cell alist, where
736the value type is a list with a single element containing the real
737value.
738
ddff3351 739@example
b8d4c8d0
GM
740(defcustom list-alist '(("foo" 1) ("bar" 2) ("baz" 3))
741 "Each element is a list of the form (KEY VALUE)."
742 :type '(alist :value-type (group integer)))
ddff3351 743@end example
b8d4c8d0
GM
744
745The @code{group} widget is used here instead of @code{list} only because
746the formatting is better suited for the purpose.
747
748Similarly, you can have alists with more values associated with each
749key, using variations of this trick:
750
ddff3351 751@example
b8d4c8d0
GM
752(defcustom person-data '(("brian" 50 t)
753 ("dorith" 55 nil)
754 ("ken" 52 t))
755 "Alist of basic info about people.
756Each element has the form (NAME AGE MALE-FLAG)."
757 :type '(alist :value-type (group integer boolean)))
ddff3351 758@end example
b8d4c8d0 759
3deead93
CY
760@item (plist :key-type @var{key-type} :value-type @var{value-type})
761This customization type is similar to @code{alist} (see above), except
762that (i) the information is stored as a property list,
763(@pxref{Property Lists}), and (ii) @var{key-type}, if omitted,
764defaults to @code{symbol} rather than @code{sexp}.
b8d4c8d0
GM
765
766@item (choice @var{alternative-types}@dots{})
e1161b06
CY
767The value must fit one of @var{alternative-types}. For example,
768@code{(choice integer string)} allows either an integer or a string.
b8d4c8d0
GM
769
770In the customization buffer, the user selects an alternative
771using a menu, and can then edit the value in the usual way for that
772alternative.
773
774Normally the strings in this menu are determined automatically from the
775choices; however, you can specify different strings for the menu by
776including the @code{:tag} keyword in the alternatives. For example, if
777an integer stands for a number of spaces, while a string is text to use
778verbatim, you might write the customization type this way,
779
780@example
781(choice (integer :tag "Number of spaces")
782 (string :tag "Literal text"))
783@end example
784
785@noindent
786so that the menu offers @samp{Number of spaces} and @samp{Literal text}.
787
788In any alternative for which @code{nil} is not a valid value, other than
789a @code{const}, you should specify a valid default for that alternative
790using the @code{:value} keyword. @xref{Type Keywords}.
791
792If some values are covered by more than one of the alternatives,
793customize will choose the first alternative that the value fits. This
794means you should always list the most specific types first, and the
795most general last. Here's an example of proper usage:
796
797@example
798(choice (const :tag "Off" nil)
799 symbol (sexp :tag "Other"))
800@end example
801
802@noindent
803This way, the special value @code{nil} is not treated like other
804symbols, and symbols are not treated like other Lisp expressions.
805
806@item (radio @var{element-types}@dots{})
807This is similar to @code{choice}, except that the choices are displayed
808using `radio buttons' rather than a menu. This has the advantage of
809displaying documentation for the choices when applicable and so is often
810a good choice for a choice between constant functions
811(@code{function-item} customization types).
812
813@item (const @var{value})
814The value must be @var{value}---nothing else is allowed.
815
816The main use of @code{const} is inside of @code{choice}. For example,
817@code{(choice integer (const nil))} allows either an integer or
818@code{nil}.
819
820@code{:tag} is often used with @code{const}, inside of @code{choice}.
821For example,
822
823@example
824(choice (const :tag "Yes" t)
825 (const :tag "No" nil)
826 (const :tag "Ask" foo))
827@end example
828
829@noindent
830describes a variable for which @code{t} means yes, @code{nil} means no,
16152b76 831and @code{foo} means ``ask''.
b8d4c8d0
GM
832
833@item (other @var{value})
834This alternative can match any Lisp value, but if the user chooses this
835alternative, that selects the value @var{value}.
836
837The main use of @code{other} is as the last element of @code{choice}.
838For example,
839
840@example
841(choice (const :tag "Yes" t)
842 (const :tag "No" nil)
843 (other :tag "Ask" foo))
844@end example
845
846@noindent
847describes a variable for which @code{t} means yes, @code{nil} means no,
16152b76 848and anything else means ``ask''. If the user chooses @samp{Ask} from
b8d4c8d0
GM
849the menu of alternatives, that specifies the value @code{foo}; but any
850other value (not @code{t}, @code{nil} or @code{foo}) displays as
851@samp{Ask}, just like @code{foo}.
852
853@item (function-item @var{function})
854Like @code{const}, but used for values which are functions. This
855displays the documentation string as well as the function name.
856The documentation string is either the one you specify with
857@code{:doc}, or @var{function}'s own documentation string.
858
859@item (variable-item @var{variable})
860Like @code{const}, but used for values which are variable names. This
861displays the documentation string as well as the variable name. The
862documentation string is either the one you specify with @code{:doc}, or
863@var{variable}'s own documentation string.
864
865@item (set @var{types}@dots{})
866The value must be a list, and each element of the list must match one of
867the @var{types} specified.
868
869This appears in the customization buffer as a checklist, so that each of
870@var{types} may have either one corresponding element or none. It is
871not possible to specify two different elements that match the same one
872of @var{types}. For example, @code{(set integer symbol)} allows one
873integer and/or one symbol in the list; it does not allow multiple
874integers or multiple symbols. As a result, it is rare to use
875nonspecific types such as @code{integer} in a @code{set}.
876
877Most often, the @var{types} in a @code{set} are @code{const} types, as
878shown here:
879
880@example
881(set (const :bold) (const :italic))
882@end example
883
884Sometimes they describe possible elements in an alist:
885
886@example
887(set (cons :tag "Height" (const height) integer)
888 (cons :tag "Width" (const width) integer))
889@end example
890
891@noindent
892That lets the user specify a height value optionally
893and a width value optionally.
894
895@item (repeat @var{element-type})
896The value must be a list and each element of the list must fit the type
897@var{element-type}. This appears in the customization buffer as a
898list of elements, with @samp{[INS]} and @samp{[DEL]} buttons for adding
899more elements or removing elements.
900
901@item (restricted-sexp :match-alternatives @var{criteria})
902This is the most general composite type construct. The value may be
903any Lisp object that satisfies one of @var{criteria}. @var{criteria}
904should be a list, and each element should be one of these
905possibilities:
906
907@itemize @bullet
908@item
909A predicate---that is, a function of one argument that has no side
910effects, and returns either @code{nil} or non-@code{nil} according to
911the argument. Using a predicate in the list says that objects for which
912the predicate returns non-@code{nil} are acceptable.
913
914@item
915A quoted constant---that is, @code{'@var{object}}. This sort of element
916in the list says that @var{object} itself is an acceptable value.
917@end itemize
918
919For example,
920
921@example
922(restricted-sexp :match-alternatives
923 (integerp 't 'nil))
924@end example
925
926@noindent
927allows integers, @code{t} and @code{nil} as legitimate values.
928
929The customization buffer shows all legitimate values using their read
930syntax, and the user edits them textually.
931@end table
932
933 Here is a table of the keywords you can use in keyword-value pairs
934in a composite type:
935
936@table @code
937@item :tag @var{tag}
938Use @var{tag} as the name of this alternative, for user communication
939purposes. This is useful for a type that appears inside of a
940@code{choice}.
941
942@item :match-alternatives @var{criteria}
943@kindex match-alternatives@r{, customization keyword}
944Use @var{criteria} to match possible values. This is used only in
945@code{restricted-sexp}.
946
947@item :args @var{argument-list}
948@kindex args@r{, customization keyword}
949Use the elements of @var{argument-list} as the arguments of the type
950construct. For instance, @code{(const :args (foo))} is equivalent to
951@code{(const foo)}. You rarely need to write @code{:args} explicitly,
952because normally the arguments are recognized automatically as
953whatever follows the last keyword-value pair.
954@end table
955
956@node Splicing into Lists
957@subsection Splicing into Lists
958
959 The @code{:inline} feature lets you splice a variable number of
e1161b06
CY
960elements into the middle of a @code{list} or @code{vector}
961customization type. You use it by adding @code{:inline t} to a type
962specification which is contained in a @code{list} or @code{vector}
963specification.
964
965 Normally, each entry in a @code{list} or @code{vector} type
966specification describes a single element type. But when an entry
967contains @code{:inline t}, the value it matches is merged directly
968into the containing sequence. For example, if the entry matches a
969list with three elements, those become three elements of the overall
970sequence. This is analogous to @samp{,@@} in a backquote construct
971(@pxref{Backquote}).
b8d4c8d0
GM
972
973 For example, to specify a list whose first element must be @code{baz}
974and whose remaining arguments should be zero or more of @code{foo} and
975@code{bar}, use this customization type:
976
977@example
978(list (const baz) (set :inline t (const foo) (const bar)))
979@end example
980
981@noindent
982This matches values such as @code{(baz)}, @code{(baz foo)}, @code{(baz bar)}
983and @code{(baz foo bar)}.
984
985 When the element-type is a @code{choice}, you use @code{:inline} not
986in the @code{choice} itself, but in (some of) the alternatives of the
987@code{choice}. For example, to match a list which must start with a
988file name, followed either by the symbol @code{t} or two strings, use
989this customization type:
990
991@example
992(list file
993 (choice (const t)
994 (list :inline t string string)))
995@end example
996
997@noindent
998If the user chooses the first alternative in the choice, then the
999overall list has two elements and the second element is @code{t}. If
1000the user chooses the second alternative, then the overall list has three
1001elements and the second and third must be strings.
1002
1003@node Type Keywords
1004@subsection Type Keywords
1005
1006You can specify keyword-argument pairs in a customization type after the
1007type name symbol. Here are the keywords you can use, and their
1008meanings:
1009
1010@table @code
1011@item :value @var{default}
0ec389b9
LMI
1012Provide a default value.
1013
1014If @code{nil} is not a valid value for the alternative, then it is
1015essential to specify a valid default with @code{:value}.
1016
1017If you use this for a type that appears as an alternative inside of
b8d4c8d0
GM
1018@code{choice}; it specifies the default value to use, at first, if and
1019when the user selects this alternative with the menu in the
1020customization buffer.
1021
1022Of course, if the actual value of the option fits this alternative, it
1023will appear showing the actual value, not @var{default}.
1024
b8d4c8d0
GM
1025@item :format @var{format-string}
1026@kindex format@r{, customization keyword}
1027This string will be inserted in the buffer to represent the value
1028corresponding to the type. The following @samp{%} escapes are available
1029for use in @var{format-string}:
1030
1031@table @samp
1032@item %[@var{button}%]
1033Display the text @var{button} marked as a button. The @code{:action}
1034attribute specifies what the button will do if the user invokes it;
1035its value is a function which takes two arguments---the widget which
1036the button appears in, and the event.
1037
1038There is no way to specify two different buttons with different
1039actions.
1040
1041@item %@{@var{sample}%@}
1042Show @var{sample} in a special face specified by @code{:sample-face}.
1043
1044@item %v
1045Substitute the item's value. How the value is represented depends on
1046the kind of item, and (for variables) on the customization type.
1047
1048@item %d
1049Substitute the item's documentation string.
1050
1051@item %h
1052Like @samp{%d}, but if the documentation string is more than one line,
1053add an active field to control whether to show all of it or just the
1054first line.
1055
1056@item %t
1057Substitute the tag here. You specify the tag with the @code{:tag}
1058keyword.
1059
1060@item %%
1061Display a literal @samp{%}.
1062@end table
1063
1064@item :action @var{action}
1065@kindex action@r{, customization keyword}
1066Perform @var{action} if the user clicks on a button.
1067
1068@item :button-face @var{face}
1069@kindex button-face@r{, customization keyword}
1070Use the face @var{face} (a face name or a list of face names) for button
1071text displayed with @samp{%[@dots{}%]}.
1072
1073@item :button-prefix @var{prefix}
1074@itemx :button-suffix @var{suffix}
1075@kindex button-prefix@r{, customization keyword}
1076@kindex button-suffix@r{, customization keyword}
1077These specify the text to display before and after a button.
1078Each can be:
1079
1080@table @asis
1081@item @code{nil}
1082No text is inserted.
1083
1084@item a string
1085The string is inserted literally.
1086
1087@item a symbol
1088The symbol's value is used.
1089@end table
1090
1091@item :tag @var{tag}
1092Use @var{tag} (a string) as the tag for the value (or part of the value)
1093that corresponds to this type.
1094
1095@item :doc @var{doc}
1096@kindex doc@r{, customization keyword}
1097Use @var{doc} as the documentation string for this value (or part of the
1098value) that corresponds to this type. In order for this to work, you
1099must specify a value for @code{:format}, and use @samp{%d} or @samp{%h}
1100in that value.
1101
1102The usual reason to specify a documentation string for a type is to
1103provide more information about the meanings of alternatives inside a
1104@code{:choice} type or the parts of some other composite type.
1105
1106@item :help-echo @var{motion-doc}
1107@kindex help-echo@r{, customization keyword}
1108When you move to this item with @code{widget-forward} or
1109@code{widget-backward}, it will display the string @var{motion-doc} in
1110the echo area. In addition, @var{motion-doc} is used as the mouse
1111@code{help-echo} string and may actually be a function or form evaluated
1112to yield a help string. If it is a function, it is called with one
1113argument, the widget.
1114
1115@item :match @var{function}
1116@kindex match@r{, customization keyword}
1117Specify how to decide whether a value matches the type. The
1118corresponding value, @var{function}, should be a function that accepts
1119two arguments, a widget and a value; it should return non-@code{nil} if
1120the value is acceptable.
1121
72b7e664
RS
1122@item :validate @var{function}
1123Specify a validation function for input. @var{function} takes a
1124widget as an argument, and should return @code{nil} if the widget's
1125current value is valid for the widget. Otherwise, it should return
1126the widget containing the invalid data, and set that widget's
1127@code{:error} property to a string explaining the error.
1128
b8d4c8d0
GM
1129@ignore
1130@item :indent @var{columns}
1131Indent this item by @var{columns} columns. The indentation is used for
1132@samp{%n}, and automatically for group names, for checklists and radio
1133buttons, and for editable lists. It affects the whole of the
1134item except for the first line.
1135
72b7e664
RS
1136@item :offset @var{extra}
1137Indent the subitems of this item @var{extra} columns more than this
1138item itself. By default, subitems are indented the same as their
1139parent.
b8d4c8d0 1140
72b7e664
RS
1141@item :extra-offset @var{n}
1142Add @var{n} extra spaces to this item's indentation, compared to its
1143parent's indentation.
b8d4c8d0 1144
72b7e664
RS
1145@item :notify @var{function}
1146Call @var{function} each time the item or a subitem is changed. The
1147function gets two or three arguments. The first argument is the item
1148itself, the second argument is the item that was changed, and the
1149third argument is the event leading to the change, if any.
b8d4c8d0 1150
72b7e664
RS
1151@item :menu-tag @var{tag-string}
1152Use @var{tag-string} in the menu when the widget is used as an option
1153in a @code{menu-choice} widget.
b8d4c8d0
GM
1154
1155@item :menu-tag-get
1156A function used for finding the tag when the widget is used as an option
1157in a @code{menu-choice} widget. By default, the tag used will be either the
1158@code{:menu-tag} or @code{:tag} property if present, or the @code{princ}
1159representation of the @code{:value} property if not.
1160
b8d4c8d0
GM
1161@item :tab-order
1162Specify the order in which widgets are traversed with
1163@code{widget-forward} or @code{widget-backward}. This is only partially
1164implemented.
1165
1166@enumerate a
1167@item
1168Widgets with tabbing order @code{-1} are ignored.
1169
1170@item
1171(Unimplemented) When on a widget with tabbing order @var{n}, go to the
1172next widget in the buffer with tabbing order @var{n+1} or @code{nil},
1173whichever comes first.
1174
1175@item
1176When on a widget with no tabbing order specified, go to the next widget
1177in the buffer with a positive tabbing order, or @code{nil}
1178@end enumerate
1179
1180@item :parent
1181The parent of a nested widget (e.g., a @code{menu-choice} item or an
1182element of a @code{editable-list} widget).
1183
1184@item :sibling-args
1185This keyword is only used for members of a @code{radio-button-choice} or
1186@code{checklist}. The value should be a list of extra keyword
1187arguments, which will be used when creating the @code{radio-button} or
1188@code{checkbox} associated with this item.
1189@end ignore
1190@end table
1191
1192@node Defining New Types
1193@subsection Defining New Types
1194
1195In the previous sections we have described how to construct elaborate
1196type specifications for @code{defcustom}. In some cases you may want
1197to give such a type specification a name. The obvious case is when
1198you are using the same type for many user options: rather than repeat
1199the specification for each option, you can give the type specification
1200a name, and use that name each @code{defcustom}. The other case is
1201when a user option's value is a recursive data structure. To make it
1202possible for a datatype to refer to itself, it needs to have a name.
1203
1204Since custom types are implemented as widgets, the way to define a new
1205customize type is to define a new widget. We are not going to describe
1206the widget interface here in details, see @ref{Top, , Introduction,
1207widget, The Emacs Widget Library}, for that. Instead we are going to
1208demonstrate the minimal functionality needed for defining new customize
1209types by a simple example.
1210
1211@example
1212(define-widget 'binary-tree-of-string 'lazy
1213 "A binary tree made of cons-cells and strings."
1214 :offset 4
1215 :tag "Node"
1216 :type '(choice (string :tag "Leaf" :value "")
1217 (cons :tag "Interior"
1218 :value ("" . "")
1219 binary-tree-of-string
1220 binary-tree-of-string)))
1221
1222(defcustom foo-bar ""
1223 "Sample variable holding a binary tree of strings."
1224 :type 'binary-tree-of-string)
1225@end example
1226
1227The function to define a new widget is called @code{define-widget}. The
1228first argument is the symbol we want to make a new widget type. The
1229second argument is a symbol representing an existing widget, the new
1230widget is going to be defined in terms of difference from the existing
1231widget. For the purpose of defining new customization types, the
1232@code{lazy} widget is perfect, because it accepts a @code{:type} keyword
1233argument with the same syntax as the keyword argument to
1234@code{defcustom} with the same name. The third argument is a
1235documentation string for the new widget. You will be able to see that
1236string with the @kbd{M-x widget-browse @key{RET} binary-tree-of-string
1237@key{RET}} command.
1238
1239After these mandatory arguments follow the keyword arguments. The most
1240important is @code{:type}, which describes the data type we want to match
1241with this widget. Here a @code{binary-tree-of-string} is described as
1242being either a string, or a cons-cell whose car and cdr are themselves
1243both @code{binary-tree-of-string}. Note the reference to the widget
1244type we are currently in the process of defining. The @code{:tag}
1245attribute is a string to name the widget in the user interface, and the
1246@code{:offset} argument is there to ensure that child nodes are
1247indented four spaces relative to the parent node, making the tree
1248structure apparent in the customization buffer.
1249
1250The @code{defcustom} shows how the new widget can be used as an ordinary
1251customization type.
1252
1253The reason for the name @code{lazy} is that the other composite
1254widgets convert their inferior widgets to internal form when the
1255widget is instantiated in a buffer. This conversion is recursive, so
1256the inferior widgets will convert @emph{their} inferior widgets. If
1257the data structure is itself recursive, this conversion is an infinite
1258recursion. The @code{lazy} widget prevents the recursion: it convert
1259its @code{:type} argument only when needed.
81927dd2
CY
1260
1261@node Applying Customizations
1262@section Applying Customizations
1263
1264The following functions are responsible for installing the user's
1265customization settings for variables and faces, respectively. When
1266the user invokes @samp{Save for future sessions} in the Customize
1267interface, that takes effect by writing a @code{custom-set-variables}
1268and/or a @code{custom-set-faces} form into the custom file, to be
ddff3351 1269evaluated the next time Emacs starts.
81927dd2
CY
1270
1271@defun custom-set-variables &rest args
1272This function installs the variable customizations specified by
1273@var{args}. Each argument in @var{args} should have the form
1274
1275@example
1276(@var{var} @var{expression} [@var{now} [@var{request} [@var{comment}]]])
1277@end example
1278
1279@noindent
1280@var{var} is a variable name (a symbol), and @var{expression} is an
1281expression which evaluates to the desired customized value.
1282
1283If the @code{defcustom} form for @var{var} has been evaluated prior to
1284this @code{custom-set-variables} call, @var{expression} is immediately
1285evaluated, and the variable's value is set to the result. Otherwise,
1286@var{expression} is stored into the variable's @code{saved-value}
1287property, to be evaluated when the relevant @code{defcustom} is called
1288(usually when the library defining that variable is loaded into
1289Emacs).
1290
1291The @var{now}, @var{request}, and @var{comment} entries are for
1292internal use only, and may be omitted. @var{now}, if non-@code{nil},
1293means to set the variable's value now, even if the variable's
1294@code{defcustom} form has not been evaluated. @var{request} is a list
1295of features to be loaded immediately (@pxref{Named Features}).
1296@var{comment} is a string describing the customization.
1297@end defun
1298
1299@defun custom-set-faces &rest args
1300This function installs the face customizations specified by
1301@var{args}. Each argument in @var{args} should have the form
1302
1303@example
1304(@var{face} @var{spec} [@var{now} [@var{comment}]])
1305@end example
1306
1307@noindent
1308@var{face} is a face name (a symbol), and @var{spec} is the customized
1309face specification for that face (@pxref{Defining Faces}).
1310
1311The @var{now} and @var{comment} entries are for internal use only, and
1312may be omitted. @var{now}, if non-@code{nil}, means to install the
1313face specification now, even if the @code{defface} form has not been
1314evaluated. @var{comment} is a string describing the customization.
1315@end defun
1316
1317@node Custom Themes
1318@section Custom Themes
1319
1320 @dfn{Custom themes} are collections of settings that can be enabled
1321or disabled as a unit. @xref{Custom Themes,,, emacs, The GNU Emacs
1322Manual}. Each Custom theme is defined by an Emacs Lisp source file,
1323which should follow the conventions described in this section.
1324(Instead of writing a Custom theme by hand, you can also create one
1325using a Customize-like interface; @pxref{Creating Custom Themes,,,
1326emacs, The GNU Emacs Manual}.)
1327
1328 A Custom theme file should be named @file{@var{foo}-theme.el}, where
1329@var{foo} is the theme name. The first Lisp form in the file should
1330be a call to @code{deftheme}, and the last form should be a call to
1331@code{provide-theme}.
1332
1333@defmac deftheme theme &optional doc
1334This macro declares @var{theme} (a symbol) as the name of a Custom
03ed9e82 1335theme. The optional argument @var{doc} should be a string describing
81927dd2 1336the theme; this is the description shown when the user invokes the
03ed9e82
CY
1337@code{describe-theme} command or types @kbd{?} in the @samp{*Custom
1338Themes*} buffer.
81927dd2 1339
ddff3351
GM
1340Two special theme names are disallowed (using them causes an error):
1341@code{user} is a ``dummy'' theme that stores the user's direct
1342customization settings, and @code{changed} is a ``dummy'' theme that
1343stores changes made outside of the Customize system.
81927dd2
CY
1344@end defmac
1345
1346@defmac provide-theme theme
1347This macro declares that the theme named @var{theme} has been fully
1348specified.
1349@end defmac
1350
03ed9e82
CY
1351 In between @code{deftheme} and @code{provide-theme} are Lisp forms
1352specifying the theme settings: usually a call to
81927dd2 1353@code{custom-theme-set-variables} and/or a call to
03ed9e82 1354@code{custom-theme-set-faces}.
81927dd2
CY
1355
1356@defun custom-theme-set-variables theme &rest args
03ed9e82
CY
1357This function specifies the Custom theme @var{theme}'s variable
1358settings. @var{theme} should be a symbol. Each argument in
1359@var{args} should be a list of the form
81927dd2
CY
1360
1361@example
1362(@var{var} @var{expression} [@var{now} [@var{request} [@var{comment}]]])
1363@end example
1364
1365@noindent
1366where the list entries have the same meanings as in
1367@code{custom-set-variables}. @xref{Applying Customizations}.
1368@end defun
1369
1370@defun custom-theme-set-faces theme &rest args
03ed9e82
CY
1371This function specifies the Custom theme @var{theme}'s face settings.
1372@var{theme} should be a symbol. Each argument in @var{args} should be
1373a list of the form
81927dd2
CY
1374
1375@example
1376(@var{face} @var{spec} [@var{now} [@var{comment}]])
1377@end example
1378
1379@noindent
1380where the list entries have the same meanings as in
1381@code{custom-set-faces}. @xref{Applying Customizations}.
1382@end defun
1383
03ed9e82
CY
1384 In theory, a theme file can also contain other Lisp forms, which
1385would be evaluated when loading the theme, but that is ``bad form''.
1386To protect against loading themes containing malicious code, Emacs
1387displays the source file and asks for confirmation from the user
1388before loading any non-built-in theme for the first time.
1389
1390 The following functions are useful for programmatically enabling and
ddff3351 1391disabling themes:
03ed9e82
CY
1392
1393@defun custom-theme-p theme
1394This function return a non-@code{nil} value if @var{theme} (a symbol)
1395is the name of a Custom theme (i.e.@: a Custom theme which has been
1396loaded into Emacs, whether or not the theme is enabled). Otherwise,
1397it returns @code{nil}.
1398@end defun
1399
1400@deffn Command load-theme theme &optional no-confirm no-enable
1401This function loads the Custom theme named @var{theme} from its source
1402file, looking for the source file in the directories specified by the
1403variable @code{custom-theme-load-path}. @xref{Custom Themes,,, emacs,
ddff3351
GM
1404The GNU Emacs Manual}. It also @dfn{enables} the theme (unless the
1405optional argument @var{no-enable} is non-@code{nil}), causing its
1406variable and face settings to take effect. It prompts the user for
1407confirmation before loading the theme, unless the optional argument
1408@var{no-confirm} is non-@code{nil}.
03ed9e82
CY
1409@end deffn
1410
1411@deffn Command enable-theme theme
1412This function enables the Custom theme named @var{theme}. It signals
1413an error if no such theme has been loaded.
1414@end deffn
1415
1416@deffn Command disable-theme theme
1417This function disables the Custom theme named @var{theme}. The theme
1418remains loaded, so that a subsequent call to @code{enable-theme} will
1419re-enable it.
1420@end deffn