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