[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use defcustom
to declare user-editable variables.
set-variable
; examples of the
former are global minor mode options such as
global-font-lock-mode
and examples of the latter are hooks.
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. You should normally avoid using backquotes in
default because they are not expanded when editing the value,
causing list values to appear to have the wrong structure.
When you evaluate a defcustom
form with C-M-x in Emacs Lisp
mode (eval-defun
), a special feature of eval-defun
arranges to set the variable unconditionally, without testing whether
its value is void. (The same feature applies to defvar
.)
See section 11.5 Defining Global Variables.
defcustom
accepts the following additional keywords:
:type type
:options list
This is meaningful only for certain types, currently including
hook
, plist
and alist
. See the definition of the
individual types for a description of how to use :options
.
: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
.
:set-after variables
:set-after
if setting this variable won't work properly unless
those other variables already have their intended values.
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 14.1 Common Item 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) |
If a customization item has a type such as hook
or alist
,
which supports :options
, you can add additional options to the
item, outside the defcustom
declaration, by calling
custom-add-option
. For example, if you define a function
my-lisp-mode-initialization
intended to be called from
emacs-lisp-mode-hook
, you might want to add that to the list of
options for emacs-lisp-mode-hook
, but not by editing its
definition. You can do it thus:
(custom-add-option 'emacs-lisp-mode-hook 'my-lisp-mode-initialization) |
The precise effect of adding option depends on the customization type of symbol.
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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |