[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: defvar and defcustom
From: |
Drew Adams |
Subject: |
RE: defvar and defcustom |
Date: |
Wed, 4 Nov 2009 09:55:57 -0800 |
> Whats the diff between defvar and defcustom?
> IOW if defvar defines a non-customise variable how is it different
> from setq?
Read the excellent manual: `C-h i', choose `Elisp', then `i defvar'.
1. setq vs defvar:
* defvar does not change the value of its variable, if it already has a value.
* defvar lets you attach a doc string.
* defvar applies only to the default value of a variable, not to a local value.
In this, it is like setq-default.
2. defcustom vs defvar:
* defcustom is intended for customizable user options, that is, for user
customization using Customize.
* defvar defines a non-Customizable user option if the doc string starts with
`*'. You can set the option value interactively, with `M-x set-variable', but
you cannot use Customize with it.
* defcustom lets you control the type of the variable's value (using keyword
:type).
* defcustom lets you group variables, for modularity (using keyword :group).
* defcustom lets you do lots more to control the variable's value - what happens
regarding its initialization, what happens each time it is set, and so on.
* defcustom variables are saved persistently (in your `custom-file' or in your
init file if you have no `custom-file').
That will get you started, but there is no substitute for exploring the manual
for this (and looking at examples in the Emacs code).