A variable is a Lisp symbol which has a value. The symbol’s name is also called the variable name. A variable name can contain any characters that can appear in a file, but most variable names consist of ordinary words separated by hyphens.
The name of the variable serves as a compact description of its role. Most variables also have a documentation string, which describes what the variable’s purpose is, what kind of value it should have, and how the value will be used. You can view this documentation using the help command
C-h v (
describe-variable). See Examining.
Emacs uses many Lisp variables for internal record keeping, but the most interesting variables for a non-programmer user are those meant for users to change—these are called customizable variables or user options (see Easy Customization). In the following sections, we will describe other aspects of Emacs variables, such as how to set them outside Customize.
Emacs Lisp allows any variable (with a few exceptions) to have any kind of value. However, many variables are meaningful only if assigned values of a certain type. For example, only numbers are meaningful values for
kill-ring-max, which specifies the maximum length of the kill ring (see Earlier Kills); if you give
kill-ring-max a string value, commands such as
yank) will signal an error. On the other hand, some variables don’t care about type; for instance, if a variable has one effect for
nil values and another effect for non-
nil values, then any value that is not the symbol
nil induces the second effect, regardless of its type (by convention, we usually use the value
t—a symbol which stands for “true"—to specify a non-
nil value). If you set a variable using the customization buffer, you need not worry about giving it an invalid type: the customization buffer usually only allows you to enter meaningful values. When in doubt, use
C-h v (
describe-variable) to check the variable’s documentation string to see what kind of value it expects (see Examining).
|• Examining||Examining or setting one variable’s value.|
|• Hooks||Hook variables let you specify programs for parts of Emacs to run on particular occasions.|
|• Locals||Per-buffer values of variables.|
|• File Variables||How files can specify variable values.|
|• Directory Variables||How variable values can be specified by directory.|
|• Connection Variables||Variables which are valid for buffers with a remote default directory.|