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