Next: , Previous: , Up: Customization   [Contents][Index]


19.3 Defining Customization Variables

Use defcustom to declare user-editable variables.

Macro: defcustom option default doc [keyword value]...

Declare option as a customizable user option variable. Do not quote option. The argument doc specifies the documentation string for the variable.

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.

The following additional keywords are defined:

:type type

Use type as the data type for this option. It specifies which values are legitimate, and how to display the value. See Customization Types, for more information.

:options list

Specify list as the list of reasonable values for use in this option.

Currently this is meaningful only when the type is 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

This option specifies that the variable was first introduced, or its default value was changed, in Emacs version version. The value version must be a string. For example,

(defcustom foo-max 34
  "*Maximum number of foo's allowed."
  :type 'integer
  :group 'foo
  :version "20.3")
:set setfunction

Specify setfunction as the way to change the value of this option. The function setfunction should take two arguments, a symbol and the new value, and should do whatever is necessary to update the value properly for this option (which may not mean simply setting the option as a Lisp variable). The default for setfunction is set-default.

:get getfunction

Specify getfunction as the way to extract the value of this option. The function getfunction should take one argument, a symbol, and should return the “current value” for that symbol (which need not be the symbol’s Lisp value). The default is default-value.

:initialize function

function should be a function used to initialize the variable when the 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

Use the variable’s :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

Like 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

Always use the :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

Use the :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 Common Keywords. Here is an example, from the library paren.el:

(defcustom show-paren-mode nil
  "Toggle Show Paren mode..."
  :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.


Next: , Previous: , Up: Customization   [Contents][Index]