Use defcustom
to declare user-editable variables.
If option is void, defcustom
initializes it to
default. default should be an expression to compute the
value; be careful in writing it, because it can be evaluated on more
than one occasion.
defcustom
accepts the following additional keywords:
:type type
:options list
hook
. In that
case, the elements of list should be functions that are useful as
elements of the hook value. The user is not restricted to using only
these functions, but they are offered as convenient alternatives.
:version version
(defcustom foo-max 34 "*Maximum number of foo's allowed." :type 'integer :group 'foo :version "20.3")
:set setfunction
set-default
.
:get getfunction
default-value
.
:initialize function
defcustom
is evaluated. It should take two arguments, the
symbol and value. Here are some predefined functions meant for use in
this way:
custom-initialize-set
:set
function to initialize the variable, but
do not reinitialize it if it is already non-void. This is the default
:initialize
function.
custom-initialize-default
custom-initialize-set
, but use the function
set-default
to set the variable, instead of the variable's
:set
function. This is the usual choice for a variable whose
:set
function enables or disables a minor mode; with this choice,
defining the variable will not call the minor mode function, but
customizing the variable will do so.
custom-initialize-reset
:set
function to initialize the variable. If the
variable is already non-void, reset it by calling the :set
function using the current value (returned by the :get
method).
custom-initialize-changed
:set
function to initialize the variable, if it is
already set or has been customized; otherwise, just use
set-default
.
The :require
option is useful for an option that turns on the
operation of a certain feature. Assuming that the package is coded to
check the value of the option, you still need to arrange for the package
to be loaded. You can do that with :require
. See section Common Keywords for All Kinds of Items. Here is an example, from the library `paren.el':
(defcustom show-paren-mode nil "Toggle Show Paren mode@enddots{}" :set (lambda (symbol value) (show-paren-mode (or value 0))) :initialize 'custom-initialize-default :type 'boolean :group 'paren-showing :require 'paren)
Internally, defcustom
uses the symbol property
standard-value
to record the expression for the default value,
and saved-value
to record the value saved by the user with the
customization buffer. The saved-value
property is actually a
list whose car is an expression which evaluates to the value.
Go to the first, previous, next, last section, table of contents.