| 1 |
@c This is part of the Emacs manual. |
|---|
| 2 |
@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001, |
|---|
| 3 |
@c 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
|---|
| 4 |
@c See file emacs.texi for copying conditions. |
|---|
| 5 |
@node Customization, Quitting, Amusements, Top |
|---|
| 6 |
@chapter Customization |
|---|
| 7 |
@cindex customization |
|---|
| 8 |
|
|---|
| 9 |
This chapter talks about various topics relevant to adapting the |
|---|
| 10 |
behavior of Emacs in ways we have anticipated. |
|---|
| 11 |
@iftex |
|---|
| 12 |
See @cite{The Emacs Lisp Reference Manual} |
|---|
| 13 |
@end iftex |
|---|
| 14 |
@ifnottex |
|---|
| 15 |
@xref{Top, Emacs Lisp, Emacs Lisp, elisp, The Emacs Lisp |
|---|
| 16 |
Reference Manual}, |
|---|
| 17 |
@end ifnottex |
|---|
| 18 |
for how to make more far-reaching and open-ended changes. @xref{X |
|---|
| 19 |
Resources}, for information on using X resources to customize Emacs. |
|---|
| 20 |
|
|---|
| 21 |
Customization that you do within Emacs normally affects only the |
|---|
| 22 |
particular Emacs session that you do it in---it does not persist |
|---|
| 23 |
between sessions unless you save the customization in a file such as |
|---|
| 24 |
your init file (@file{.emacs}) that will affect future sessions. |
|---|
| 25 |
(@xref{Init File}.) When you tell the customization buffer to save |
|---|
| 26 |
customizations for future sessions, this actually works by editing |
|---|
| 27 |
@file{.emacs} for you. |
|---|
| 28 |
|
|---|
| 29 |
Another means of customization is the keyboard macro, which is a |
|---|
| 30 |
sequence of keystrokes to be replayed with a single command. |
|---|
| 31 |
@xref{Keyboard Macros}, for full instruction how to record, manage, and |
|---|
| 32 |
replay sequences of keys. |
|---|
| 33 |
|
|---|
| 34 |
@menu |
|---|
| 35 |
* Minor Modes:: Each minor mode is one feature you can turn on |
|---|
| 36 |
independently of any others. |
|---|
| 37 |
* Easy Customization:: Convenient way to browse and change settings. |
|---|
| 38 |
* Variables:: Many Emacs commands examine Emacs variables |
|---|
| 39 |
to decide what to do; by setting variables, |
|---|
| 40 |
you can control their functioning. |
|---|
| 41 |
* Key Bindings:: The keymaps say what command each key runs. |
|---|
| 42 |
By changing them, you can "redefine keys". |
|---|
| 43 |
* Syntax:: The syntax table controls how words and |
|---|
| 44 |
expressions are parsed. |
|---|
| 45 |
* Init File:: How to write common customizations in the |
|---|
| 46 |
@file{.emacs} file. |
|---|
| 47 |
@end menu |
|---|
| 48 |
|
|---|
| 49 |
@node Minor Modes |
|---|
| 50 |
@section Minor Modes |
|---|
| 51 |
@cindex minor modes |
|---|
| 52 |
@cindex mode, minor |
|---|
| 53 |
|
|---|
| 54 |
Minor modes are optional features which you can turn on or off. For |
|---|
| 55 |
example, Auto Fill mode is a minor mode in which @key{SPC} breaks lines |
|---|
| 56 |
between words as you type. All the minor modes are independent of each |
|---|
| 57 |
other and of the selected major mode. Most minor modes say in the mode |
|---|
| 58 |
line when they are enabled; for example, @samp{Fill} in the mode line means |
|---|
| 59 |
that Auto Fill mode is enabled. |
|---|
| 60 |
|
|---|
| 61 |
You should append @code{-mode} to the name of a minor mode to |
|---|
| 62 |
produce the name of the command that turns the mode on or off. Thus, |
|---|
| 63 |
the command to enable or disable Auto Fill mode is called |
|---|
| 64 |
@code{auto-fill-mode}. These commands are usually invoked with |
|---|
| 65 |
@kbd{M-x}, but you can bind keys to them if you wish. |
|---|
| 66 |
|
|---|
| 67 |
With no argument, the minor mode function turns the mode on if it |
|---|
| 68 |
was off, and off if it was on. This is known as @dfn{toggling}. A |
|---|
| 69 |
positive argument always turns the mode on, and an explicit zero |
|---|
| 70 |
argument or a negative argument always turns it off. |
|---|
| 71 |
|
|---|
| 72 |
Some minor modes are global: while enabled, they affect everything |
|---|
| 73 |
you do in the Emacs session, in all buffers. Other minor modes are |
|---|
| 74 |
buffer-local; they apply only to the current buffer, so you can enable |
|---|
| 75 |
the mode in certain buffers and not others. |
|---|
| 76 |
|
|---|
| 77 |
For most minor modes, the command name is also the name of a |
|---|
| 78 |
variable. The variable's value is non-@code{nil} if the mode is |
|---|
| 79 |
enabled and @code{nil} if it is disabled. Some minor-mode commands |
|---|
| 80 |
work by just setting the variable. For example, the command |
|---|
| 81 |
@code{abbrev-mode} works by setting the value of @code{abbrev-mode} as |
|---|
| 82 |
a variable; it is this variable that directly turns Abbrev mode on and |
|---|
| 83 |
off. You can directly set the variable's value instead of calling the |
|---|
| 84 |
mode function. For other minor modes, you need to either set the |
|---|
| 85 |
variable through the Customize interface or call the mode function to |
|---|
| 86 |
correctly enable or disable the mode. To check which of these two |
|---|
| 87 |
possibilities applies to a given minor mode, use @kbd{C-h v} to ask |
|---|
| 88 |
for documentation on the variable name. |
|---|
| 89 |
|
|---|
| 90 |
For minor mode commands that work by just setting the minor mode |
|---|
| 91 |
variable, that variable provides a good way for Lisp programs to turn |
|---|
| 92 |
minor modes on and off; it is also useful in a file's local variables |
|---|
| 93 |
list (@pxref{File Variables}). But please think twice before setting |
|---|
| 94 |
minor modes with a local variables list, because most minor modes are |
|---|
| 95 |
a matter of user preference---other users editing the same file might |
|---|
| 96 |
not want the same minor modes you prefer. |
|---|
| 97 |
|
|---|
| 98 |
The most useful buffer-local minor modes include Abbrev mode, Auto |
|---|
| 99 |
Fill mode, Auto Save mode, Font-Lock mode, Glasses mode, Outline minor |
|---|
| 100 |
mode, Overwrite mode, and Binary Overwrite mode. |
|---|
| 101 |
|
|---|
| 102 |
Abbrev mode allows you to define abbreviations that automatically expand |
|---|
| 103 |
as you type them. For example, @samp{amd} might expand to @samp{abbrev |
|---|
| 104 |
mode}. @xref{Abbrevs}, for full information. |
|---|
| 105 |
|
|---|
| 106 |
Auto Fill mode allows you to enter filled text without breaking lines |
|---|
| 107 |
explicitly. Emacs inserts newlines as necessary to prevent lines from |
|---|
| 108 |
becoming too long. @xref{Filling}. |
|---|
| 109 |
|
|---|
| 110 |
Auto Save mode saves the buffer contents periodically to reduce the |
|---|
| 111 |
amount of work you can lose in case of a crash. @xref{Auto Save}. |
|---|
| 112 |
|
|---|
| 113 |
Enriched mode enables editing and saving of formatted text. |
|---|
| 114 |
@xref{Formatted Text}. |
|---|
| 115 |
|
|---|
| 116 |
Flyspell mode automatically highlights misspelled words. |
|---|
| 117 |
@xref{Spelling}. |
|---|
| 118 |
|
|---|
| 119 |
Font-Lock mode automatically highlights certain textual units found |
|---|
| 120 |
in programs, such as comments, strings, and function names being |
|---|
| 121 |
defined. This requires a display that can show multiple fonts or |
|---|
| 122 |
colors. @xref{Faces}. |
|---|
| 123 |
|
|---|
| 124 |
@ignore |
|---|
| 125 |
ISO Accents mode makes the characters @samp{`}, @samp{'}, @samp{"}, |
|---|
| 126 |
@samp{^}, @samp{/} and @samp{~} combine with the following letter, to |
|---|
| 127 |
produce an accented letter in the ISO Latin-1 character set. The |
|---|
| 128 |
newer and more general feature of input methods more or less |
|---|
| 129 |
supersedes ISO Accents mode. @xref{Unibyte Mode}. |
|---|
| 130 |
@end ignore |
|---|
| 131 |
|
|---|
| 132 |
Outline minor mode provides the same facilities as the major mode |
|---|
| 133 |
called Outline mode; but since it is a minor mode instead, you can |
|---|
| 134 |
combine it with any major mode. @xref{Outline Mode}. |
|---|
| 135 |
|
|---|
| 136 |
@cindex Overwrite mode |
|---|
| 137 |
@cindex mode, Overwrite |
|---|
| 138 |
Overwrite mode causes ordinary printing characters to replace existing |
|---|
| 139 |
text instead of shoving it to the right. For example, if point is in |
|---|
| 140 |
front of the @samp{B} in @samp{FOOBAR}, then in Overwrite mode typing a |
|---|
| 141 |
@kbd{G} changes it to @samp{FOOGAR}, instead of producing @samp{FOOGBAR} |
|---|
| 142 |
as usual. In Overwrite mode, the command @kbd{C-q} inserts the next |
|---|
| 143 |
character whatever it may be, even if it is a digit---this gives you a |
|---|
| 144 |
way to insert a character instead of replacing an existing character. |
|---|
| 145 |
|
|---|
| 146 |
@findex overwrite-mode |
|---|
| 147 |
@kindex INSERT |
|---|
| 148 |
The command @code{overwrite-mode} is an exception to the rule that |
|---|
| 149 |
commands which toggle minor modes are normally not bound to keys: it is |
|---|
| 150 |
bound to the @key{INSERT} function key. This is because many other |
|---|
| 151 |
programs bind @key{INSERT} to similar functions. |
|---|
| 152 |
|
|---|
| 153 |
@findex binary-overwrite-mode |
|---|
| 154 |
Binary Overwrite mode is a variant of Overwrite mode for editing |
|---|
| 155 |
binary files; it treats newlines and tabs like other characters, so that |
|---|
| 156 |
they overwrite other characters and can be overwritten by them. |
|---|
| 157 |
In Binary Overwrite mode, digits after @kbd{C-q} specify an |
|---|
| 158 |
octal character code, as usual. |
|---|
| 159 |
|
|---|
| 160 |
Here are some useful minor modes that normally apply to all buffers |
|---|
| 161 |
at once. Since Line Number mode and Transient Mark mode can be |
|---|
| 162 |
enabled or disabled just by setting the value of the minor mode |
|---|
| 163 |
variable, you @emph{can} set them differently for particular buffers, |
|---|
| 164 |
by explicitly making the corresponding variable local in those |
|---|
| 165 |
buffers. @xref{Locals}. |
|---|
| 166 |
|
|---|
| 167 |
Icomplete mode displays an indication of available completions when |
|---|
| 168 |
you are in the minibuffer and completion is active. @xref{Completion |
|---|
| 169 |
Options}. |
|---|
| 170 |
|
|---|
| 171 |
Line Number mode enables continuous display in the mode line of the |
|---|
| 172 |
line number of point, and Column Number mode enables display of the |
|---|
| 173 |
column number. @xref{Mode Line}. |
|---|
| 174 |
|
|---|
| 175 |
Scroll Bar mode gives each window a scroll bar (@pxref{Scroll Bars}). |
|---|
| 176 |
Menu Bar mode gives each frame a menu bar (@pxref{Menu Bars}). Both of |
|---|
| 177 |
these modes are enabled by default when you use the X Window System. |
|---|
| 178 |
|
|---|
| 179 |
In Transient Mark mode, every change in the buffer contents |
|---|
| 180 |
``deactivates'' the mark, so that commands that operate on the region |
|---|
| 181 |
will get an error. This means you must either set the mark, or |
|---|
| 182 |
explicitly ``reactivate'' it, before each command that uses the region. |
|---|
| 183 |
The advantage of Transient Mark mode is that Emacs can display the |
|---|
| 184 |
region highlighted. @xref{Mark}. |
|---|
| 185 |
|
|---|
| 186 |
@node Easy Customization |
|---|
| 187 |
@section Easy Customization Interface |
|---|
| 188 |
|
|---|
| 189 |
@cindex settings |
|---|
| 190 |
Emacs has many @dfn{settings} which have values that you can specify |
|---|
| 191 |
in order to customize various commands. Many are documented in this |
|---|
| 192 |
manual. Most settings are @dfn{user options}---that is to say, Lisp |
|---|
| 193 |
variables (@pxref{Variables})---so their names appear in the Variable |
|---|
| 194 |
Index (@pxref{Variable Index}). The other settings are faces and |
|---|
| 195 |
their attributes (@pxref{Faces}). |
|---|
| 196 |
|
|---|
| 197 |
@findex customize |
|---|
| 198 |
@cindex customization buffer |
|---|
| 199 |
You can browse interactively through settings and change them using |
|---|
| 200 |
@kbd{M-x customize}. This command creates a @dfn{customization |
|---|
| 201 |
buffer}, which offers commands to navigate through a logically |
|---|
| 202 |
organized structure of the Emacs settings; you can also use it to edit |
|---|
| 203 |
and set their values, and to save settings permanently in your |
|---|
| 204 |
@file{~/.emacs} file (@pxref{Init File}). |
|---|
| 205 |
|
|---|
| 206 |
The appearance of the example buffers in this section is typically |
|---|
| 207 |
different under a graphical display, since faces are then used to indicate |
|---|
| 208 |
buttons, links and editable fields. |
|---|
| 209 |
|
|---|
| 210 |
@menu |
|---|
| 211 |
* Groups: Customization Groups. How settings are classified in a structure. |
|---|
| 212 |
* Browsing: Browsing Custom. Browsing and searching for settings. |
|---|
| 213 |
* Changing a Variable:: How to edit an option's value and set the option. |
|---|
| 214 |
* Saving Customizations:: Specifying the file for saving customizations. |
|---|
| 215 |
* Face Customization:: How to edit the attributes of a face. |
|---|
| 216 |
* Specific Customization:: Making a customization buffer for specific |
|---|
| 217 |
variables, faces, or groups. |
|---|
| 218 |
* Custom Themes:: How to define collections of customized options |
|---|
| 219 |
that can be loaded and unloaded together. |
|---|
| 220 |
@end menu |
|---|
| 221 |
|
|---|
| 222 |
@node Customization Groups |
|---|
| 223 |
@subsection Customization Groups |
|---|
| 224 |
@cindex customization groups |
|---|
| 225 |
|
|---|
| 226 |
For customization purposes, settings are organized into @dfn{groups} |
|---|
| 227 |
to help you find them. Groups are collected into bigger groups, all |
|---|
| 228 |
the way up to a master group called @code{Emacs}. |
|---|
| 229 |
|
|---|
| 230 |
@kbd{M-x customize} creates a customization buffer that shows the |
|---|
| 231 |
top-level @code{Emacs} group and the second-level groups immediately |
|---|
| 232 |
under it. It looks like this, in part: |
|---|
| 233 |
|
|---|
| 234 |
@c we want the buffer example to all be on one page, but unfortunately |
|---|
| 235 |
@c that's quite a bit of text, so force all space to the bottom. |
|---|
| 236 |
@page |
|---|
| 237 |
@smallexample |
|---|
| 238 |
@group |
|---|
| 239 |
/- Emacs group: ---------------------------------------------------\ |
|---|
| 240 |
[State]: visible group members are all at standard values. |
|---|
| 241 |
Customization of the One True Editor. |
|---|
| 242 |
See also [Manual]. |
|---|
| 243 |
|
|---|
| 244 |
Editing group: [Go to Group] |
|---|
| 245 |
Basic text editing facilities. |
|---|
| 246 |
|
|---|
| 247 |
External group: [Go to Group] |
|---|
| 248 |
Interfacing to external utilities. |
|---|
| 249 |
|
|---|
| 250 |
@var{more second-level groups} |
|---|
| 251 |
|
|---|
| 252 |
\- Emacs group end ------------------------------------------------/ |
|---|
| 253 |
@end group |
|---|
| 254 |
@end smallexample |
|---|
| 255 |
|
|---|
| 256 |
@noindent |
|---|
| 257 |
This says that the buffer displays the contents of the @code{Emacs} |
|---|
| 258 |
group. The other groups are listed because they are its contents. But |
|---|
| 259 |
they are listed differently, without indentation and dashes, because |
|---|
| 260 |
@emph{their} contents are not included. Each group has a single-line |
|---|
| 261 |
documentation string; the @code{Emacs} group also has a @samp{[State]} |
|---|
| 262 |
line. |
|---|
| 263 |
|
|---|
| 264 |
@cindex editable fields (customization buffer) |
|---|
| 265 |
@cindex buttons (customization buffer) |
|---|
| 266 |
@cindex links (customization buffer) |
|---|
| 267 |
Most of the text in the customization buffer is read-only, but it |
|---|
| 268 |
typically includes some @dfn{editable fields} that you can edit. |
|---|
| 269 |
There are also @dfn{buttons} and @dfn{links}, which do something when |
|---|
| 270 |
you @dfn{invoke} them. To invoke a button or a link, either click on |
|---|
| 271 |
it with @kbd{Mouse-1}, or move point to it and type @key{RET}. |
|---|
| 272 |
|
|---|
| 273 |
For example, the phrase @samp{[State]} that appears in |
|---|
| 274 |
a second-level group is a button. It operates on the same |
|---|
| 275 |
customization buffer. The phrase @samp{[Go to Group]} is a kind |
|---|
| 276 |
of hypertext link to another group. Invoking it creates a new |
|---|
| 277 |
customization buffer, which shows that group and its contents. |
|---|
| 278 |
|
|---|
| 279 |
The @code{Emacs} group includes a few settings, but mainly it |
|---|
| 280 |
contains other groups, which contain more groups, which contain the |
|---|
| 281 |
settings. By browsing the hierarchy of groups, you will eventually |
|---|
| 282 |
find the feature you are interested in customizing. Then you can use |
|---|
| 283 |
the customization buffer to set that feature's settings. You can also |
|---|
| 284 |
go straight to a particular group by name, using the command @kbd{M-x |
|---|
| 285 |
customize-group}. |
|---|
| 286 |
|
|---|
| 287 |
@node Browsing Custom |
|---|
| 288 |
@subsection Browsing and Searching for Options and Faces |
|---|
| 289 |
@findex customize-browse |
|---|
| 290 |
|
|---|
| 291 |
@kbd{M-x customize-browse} is another way to browse the available |
|---|
| 292 |
settings. This command creates a special customization buffer which |
|---|
| 293 |
shows only the names of groups and settings, and puts them in a |
|---|
| 294 |
structure. |
|---|
| 295 |
|
|---|
| 296 |
In this buffer, you can show the contents of a group by invoking the |
|---|
| 297 |
@samp{[+]} button. When the group contents are visible, this button |
|---|
| 298 |
changes to @samp{[-]}; invoking that hides the group contents again. |
|---|
| 299 |
|
|---|
| 300 |
Each group or setting in this buffer has a link which says |
|---|
| 301 |
@samp{[Group]}, @samp{[Option]} or @samp{[Face]}. Invoking this link |
|---|
| 302 |
creates an ordinary customization buffer showing just that group and |
|---|
| 303 |
its contents, just that user option, or just that face. This is the |
|---|
| 304 |
way to change settings that you find with @kbd{M-x customize-browse}. |
|---|
| 305 |
|
|---|
| 306 |
If you can guess part of the name of the settings you are interested |
|---|
| 307 |
in, @kbd{M-x customize-apropos} is another way to search for settings. |
|---|
| 308 |
However, unlike @code{customize} and @code{customize-browse}, |
|---|
| 309 |
@code{customize-apropos} can only find groups and settings that are |
|---|
| 310 |
loaded in the current Emacs session. @xref{Specific Customization,, |
|---|
| 311 |
Customizing Specific Items}. |
|---|
| 312 |
|
|---|
| 313 |
@node Changing a Variable |
|---|
| 314 |
@subsection Changing a Variable |
|---|
| 315 |
|
|---|
| 316 |
Here is an example of what a variable (a user option) looks like in |
|---|
| 317 |
the customization buffer: |
|---|
| 318 |
|
|---|
| 319 |
@smallexample |
|---|
| 320 |
Kill Ring Max: [Hide Value] 60 |
|---|
| 321 |
[State]: STANDARD. |
|---|
| 322 |
Maximum length of kill ring before oldest elements are thrown away. |
|---|
| 323 |
@end smallexample |
|---|
| 324 |
|
|---|
| 325 |
The text following @samp{[Hide Value]}, @samp{60} in this case, indicates |
|---|
| 326 |
the current value of the variable. If you see @samp{[Show Value]} instead of |
|---|
| 327 |
@samp{[Hide Value]}, it means that the value is hidden; the customization |
|---|
| 328 |
buffer initially hides values that take up several lines. Invoke |
|---|
| 329 |
@samp{[Show Value]} to show the value. |
|---|
| 330 |
|
|---|
| 331 |
The line after the variable name indicates the @dfn{customization |
|---|
| 332 |
state} of the variable: in the example above, it says you have not |
|---|
| 333 |
changed the option yet. The @samp{[State]} button at the beginning of |
|---|
| 334 |
this line gives you a menu of various operations for customizing the |
|---|
| 335 |
variable. |
|---|
| 336 |
|
|---|
| 337 |
The line after the @samp{[State]} line displays the beginning of the |
|---|
| 338 |
variable's documentation string. If there are more lines of |
|---|
| 339 |
documentation, this line ends with a @samp{[More]} button; invoke that |
|---|
| 340 |
to show the full documentation string. |
|---|
| 341 |
|
|---|
| 342 |
To enter a new value for @samp{Kill Ring Max}, move point to the |
|---|
| 343 |
value and edit it textually. For example, you can type @kbd{M-d}, |
|---|
| 344 |
then insert another number. As you begin to alter the text, you will |
|---|
| 345 |
see the @samp{[State]} line change to say that you have edited the |
|---|
| 346 |
value: |
|---|
| 347 |
|
|---|
| 348 |
@smallexample |
|---|
| 349 |
[State]: EDITED, shown value does not take effect until you set or @r{@dots{}} |
|---|
| 350 |
save it. |
|---|
| 351 |
@end smallexample |
|---|
| 352 |
|
|---|
| 353 |
@cindex user options, how to set |
|---|
| 354 |
@cindex variables, how to set |
|---|
| 355 |
@cindex settings, how to set |
|---|
| 356 |
Editing the value does not actually set the variable. To do that, |
|---|
| 357 |
you must @dfn{set} the variable. To do this, invoke the |
|---|
| 358 |
@samp{[State]} button and choose @samp{Set for Current Session}. |
|---|
| 359 |
|
|---|
| 360 |
The state of the variable changes visibly when you set it: |
|---|
| 361 |
|
|---|
| 362 |
@smallexample |
|---|
| 363 |
[State]: SET for current session only. |
|---|
| 364 |
@end smallexample |
|---|
| 365 |
|
|---|
| 366 |
You don't have to worry about specifying a value that is not valid; |
|---|
| 367 |
the @samp{Set for Current Session} operation checks for validity and |
|---|
| 368 |
will not install an unacceptable value. |
|---|
| 369 |
|
|---|
| 370 |
@kindex M-TAB @r{(customization buffer)} |
|---|
| 371 |
@findex widget-complete |
|---|
| 372 |
While editing a field that is a file name, directory name, |
|---|
| 373 |
command name, or anything else for which completion is defined, you |
|---|
| 374 |
can type @kbd{M-@key{TAB}} (@code{widget-complete}) to do completion. |
|---|
| 375 |
(@kbd{@key{ESC} @key{TAB}} and @kbd{C-M-i} do the same thing.) |
|---|
| 376 |
|
|---|
| 377 |
Some variables have a small fixed set of possible legitimate values. |
|---|
| 378 |
These variables don't let you edit the value textually. Instead, a |
|---|
| 379 |
@samp{[Value Menu]} button appears before the value; invoke this |
|---|
| 380 |
button to change the value. For a boolean ``on or off'' value, the |
|---|
| 381 |
button says @samp{[Toggle]}, and it changes to the other value. |
|---|
| 382 |
@samp{[Value Menu]} and @samp{[Toggle]} simply edit the buffer; the |
|---|
| 383 |
changes take real effect when you use the @samp{Set for Current |
|---|
| 384 |
Session} operation. |
|---|
| 385 |
|
|---|
| 386 |
Some variables have values with complex structure. For example, the |
|---|
| 387 |
value of @code{file-coding-system-alist} is an association list. Here |
|---|
| 388 |
is how it appears in the customization buffer: |
|---|
| 389 |
|
|---|
| 390 |
@smallexample |
|---|
| 391 |
File Coding System Alist: [Hide Value] |
|---|
| 392 |
[INS] [DEL] File regexp: \.elc\' |
|---|
| 393 |
Choice: [Value Menu] Encoding/decoding pair: |
|---|
| 394 |
Decoding: emacs-mule |
|---|
| 395 |
Encoding: emacs-mule |
|---|
| 396 |
[INS] [DEL] File regexp: \(\`\|/\)loaddefs.el\' |
|---|
| 397 |
Choice: [Value Menu] Encoding/decoding pair: |
|---|
| 398 |
Decoding: raw-text |
|---|
| 399 |
Encoding: raw-text-unix |
|---|
| 400 |
[INS] [DEL] File regexp: \.tar\' |
|---|
| 401 |
Choice: [Value Menu] Encoding/decoding pair: |
|---|
| 402 |
Decoding: no-conversion |
|---|
| 403 |
Encoding: no-conversion |
|---|
| 404 |
[INS] [DEL] File regexp: |
|---|
| 405 |
Choice: [Value Menu] Encoding/decoding pair: |
|---|
| 406 |
Decoding: undecided |
|---|
| 407 |
Encoding: nil |
|---|
| 408 |
[INS] |
|---|
| 409 |
[State]: STANDARD. |
|---|
| 410 |
Alist to decide a coding system to use for a file I/O @r{@dots{}} |
|---|
| 411 |
operation. [Hide Rest] |
|---|
| 412 |
The format is ((PATTERN . VAL) ...), |
|---|
| 413 |
where PATTERN is a regular expression matching a file name, |
|---|
| 414 |
@r{[@dots{}more lines of documentation@dots{}]} |
|---|
| 415 |
@end smallexample |
|---|
| 416 |
|
|---|
| 417 |
@noindent |
|---|
| 418 |
Each association in the list appears on four lines, with several |
|---|
| 419 |
editable fields and/or buttons. You can edit the regexps and coding |
|---|
| 420 |
systems using ordinary editing commands. You can also invoke |
|---|
| 421 |
@samp{[Value Menu]} to switch to a different kind of value---for |
|---|
| 422 |
instance, to specify a function instead of a pair of coding systems. |
|---|
| 423 |
|
|---|
| 424 |
To delete an association from the list, invoke the @samp{[DEL]} button |
|---|
| 425 |
for that item. To add an association, invoke @samp{[INS]} at the |
|---|
| 426 |
position where you want to add it. There is an @samp{[INS]} button |
|---|
| 427 |
between each pair of associations, another at the beginning and another |
|---|
| 428 |
at the end, so you can add a new association at any position in the |
|---|
| 429 |
list. |
|---|
| 430 |
|
|---|
| 431 |
@kindex TAB @r{(customization buffer)} |
|---|
| 432 |
@kindex S-TAB @r{(customization buffer)} |
|---|
| 433 |
@findex widget-forward |
|---|
| 434 |
@findex widget-backward |
|---|
| 435 |
Two special commands, @key{TAB} and @kbd{S-@key{TAB}}, are useful |
|---|
| 436 |
for moving through the customization buffer. @key{TAB} |
|---|
| 437 |
(@code{widget-forward}) moves forward to the next button or editable |
|---|
| 438 |
field; @kbd{S-@key{TAB}} (@code{widget-backward}) moves backward to |
|---|
| 439 |
the previous button or editable field. |
|---|
| 440 |
|
|---|
| 441 |
Typing @key{RET} on an editable field also moves forward, just like |
|---|
| 442 |
@key{TAB}. We set it up this way because people often type @key{RET} |
|---|
| 443 |
when they are finished editing a field. To insert a newline within an |
|---|
| 444 |
editable field, use @kbd{C-o} or @kbd{C-q C-j}. |
|---|
| 445 |
|
|---|
| 446 |
@cindex saving a setting |
|---|
| 447 |
@cindex settings, how to save |
|---|
| 448 |
Setting the variable changes its value in the current Emacs session; |
|---|
| 449 |
@dfn{saving} the value changes it for future sessions as well. To |
|---|
| 450 |
save the variable, invoke @samp{[State]} and select the @samp{Save for |
|---|
| 451 |
Future Sessions} operation. This works by writing code so as to set |
|---|
| 452 |
the variable again, each time you start Emacs (@pxref{Saving |
|---|
| 453 |
Customizations}). |
|---|
| 454 |
|
|---|
| 455 |
You can also restore the variable to its standard value by invoking |
|---|
| 456 |
@samp{[State]} and selecting the @samp{Erase Customization} operation. |
|---|
| 457 |
There are actually four reset operations: |
|---|
| 458 |
|
|---|
| 459 |
@table @samp |
|---|
| 460 |
@item Undo Edits |
|---|
| 461 |
If you have made some modifications and not yet set the variable, |
|---|
| 462 |
this restores the text in the customization buffer to match |
|---|
| 463 |
the actual value. |
|---|
| 464 |
|
|---|
| 465 |
@item Reset to Saved |
|---|
| 466 |
This restores the value of the variable to the last saved value, |
|---|
| 467 |
and updates the text accordingly. |
|---|
| 468 |
|
|---|
| 469 |
@item Erase Customization |
|---|
| 470 |
This sets the variable to its standard value, and updates the text |
|---|
| 471 |
accordingly. This also eliminates any saved value for the variable, |
|---|
| 472 |
so that you will get the standard value in future Emacs sessions. |
|---|
| 473 |
|
|---|
| 474 |
@item Set to Backup Value |
|---|
| 475 |
This sets the variable to a previous value that was set in the |
|---|
| 476 |
customization buffer in this session. If you customize a variable |
|---|
| 477 |
and then reset it, which discards the customized value, |
|---|
| 478 |
you can get the discarded value back again with this operation. |
|---|
| 479 |
@end table |
|---|
| 480 |
|
|---|
| 481 |
@cindex comments on customized settings |
|---|
| 482 |
Sometimes it is useful to record a comment about a specific |
|---|
| 483 |
customization. Use the @samp{Add Comment} item from the |
|---|
| 484 |
@samp{[State]} menu to create a field for entering the comment. The |
|---|
| 485 |
comment you enter will be saved, and displayed again if you again view |
|---|
| 486 |
the same variable in a customization buffer, even in another session. |
|---|
| 487 |
|
|---|
| 488 |
The state of a group indicates whether anything in that group has been |
|---|
| 489 |
edited, set or saved. |
|---|
| 490 |
|
|---|
| 491 |
Near the top of the customization buffer there are two lines of buttons: |
|---|
| 492 |
|
|---|
| 493 |
@smallexample |
|---|
| 494 |
[Set for Current Session] [Save for Future Sessions] |
|---|
| 495 |
[Undo Edits] [Reset to Saved] [Erase Customization] [Finish] |
|---|
| 496 |
@end smallexample |
|---|
| 497 |
|
|---|
| 498 |
@vindex custom-buffer-done-function |
|---|
| 499 |
@noindent |
|---|
| 500 |
Invoking @samp{[Finish]} either buries or kills this customization |
|---|
| 501 |
buffer according to the setting of the option |
|---|
| 502 |
@code{custom-buffer-done-kill}; the default is to bury the buffer. |
|---|
| 503 |
Each of the other buttons performs an operation---set, save or |
|---|
| 504 |
reset---on each of the settings in the buffer that could meaningfully |
|---|
| 505 |
be set, saved or reset. They do not operate on settings whose values |
|---|
| 506 |
are hidden, nor on subgroups which are hidden or not visible in the buffer. |
|---|
| 507 |
|
|---|
| 508 |
@node Saving Customizations |
|---|
| 509 |
@subsection Saving Customizations |
|---|
| 510 |
|
|---|
| 511 |
Saving customizations from the customization buffer works by writing |
|---|
| 512 |
code that future sessions will read, code to set up those |
|---|
| 513 |
customizations again. |
|---|
| 514 |
|
|---|
| 515 |
@vindex custom-file |
|---|
| 516 |
Normally this saves customizations in your init file, |
|---|
| 517 |
@file{~/.emacs}. If you wish, you can save customizations in another |
|---|
| 518 |
file instead. To make this work, your @file{~/.emacs} should set |
|---|
| 519 |
@code{custom-file} to the name of that file. Then you should load the |
|---|
| 520 |
file by calling @code{load}. For example: |
|---|
| 521 |
|
|---|
| 522 |
@example |
|---|
| 523 |
(setq custom-file "~/.emacs-custom.el") |
|---|
| 524 |
(load custom-file) |
|---|
| 525 |
@end example |
|---|
| 526 |
|
|---|
| 527 |
You can use @code{custom-file} to specify different customization |
|---|
| 528 |
files for different Emacs versions, like this: |
|---|
| 529 |
|
|---|
| 530 |
@example |
|---|
| 531 |
(cond ((< emacs-major-version 21) |
|---|
| 532 |
;; @r{Emacs 20 customization.} |
|---|
| 533 |
(setq custom-file "~/.custom-20.el")) |
|---|
| 534 |
((and (= emacs-major-version 21) (< emacs-minor-version 4)) |
|---|
| 535 |
;; @r{Emacs 21 customization, before version 21.4.} |
|---|
| 536 |
(setq custom-file "~/.custom-21.el")) |
|---|
| 537 |
((< emacs-major-version 22) |
|---|
| 538 |
;; @r{Emacs version 21.4 or later.} |
|---|
| 539 |
(setq custom-file "~/.custom-21.4.el")) |
|---|
| 540 |
(t |
|---|
| 541 |
;; @r{Emacs version 22.1 or later.} |
|---|
| 542 |
(setq custom-file "~/.custom-22.el"))) |
|---|
| 543 |
|
|---|
| 544 |
(load custom-file) |
|---|
| 545 |
@end example |
|---|
| 546 |
|
|---|
| 547 |
If Emacs was invoked with the @option{-q} or @option{--no-init-file} |
|---|
| 548 |
options (@pxref{Initial Options}), it will not let you save your |
|---|
| 549 |
customizations in your @file{~/.emacs} init file. This is because |
|---|
| 550 |
saving customizations from such a session would wipe out all the other |
|---|
| 551 |
customizations you might have on your init file. |
|---|
| 552 |
|
|---|
| 553 |
@node Face Customization |
|---|
| 554 |
@subsection Customizing Faces |
|---|
| 555 |
@cindex customizing faces |
|---|
| 556 |
@cindex bold font |
|---|
| 557 |
@cindex italic font |
|---|
| 558 |
@cindex fonts and faces |
|---|
| 559 |
|
|---|
| 560 |
In addition to variables, some customization groups also include |
|---|
| 561 |
faces. When you show the contents of a group, both the variables and |
|---|
| 562 |
the faces in the group appear in the customization buffer. Here is an |
|---|
| 563 |
example of how a face looks: |
|---|
| 564 |
|
|---|
| 565 |
@smallexample |
|---|
| 566 |
Custom Changed Face:(sample) [Hide Face] |
|---|
| 567 |
[State]: STANDARD. |
|---|
| 568 |
Face used when the customize item has been changed. |
|---|
| 569 |
Parent groups: [Custom Magic Faces] |
|---|
| 570 |
Attributes: [ ] Font Family: * |
|---|
| 571 |
[ ] Width: * |
|---|
| 572 |
[ ] Height: * |
|---|
| 573 |
[ ] Weight: * |
|---|
| 574 |
[ ] Slant: * |
|---|
| 575 |
[ ] Underline: * |
|---|
| 576 |
[ ] Overline: * |
|---|
| 577 |
[ ] Strike-through: * |
|---|
| 578 |
[ ] Box around text: * |
|---|
| 579 |
[ ] Inverse-video: * |
|---|
| 580 |
[X] Foreground: white (sample) |
|---|
| 581 |
[X] Background: blue (sample) |
|---|
| 582 |
[ ] Stipple: * |
|---|
| 583 |
[ ] Inherit: * |
|---|
| 584 |
@end smallexample |
|---|
| 585 |
|
|---|
| 586 |
Each face attribute has its own line. The @samp{[@var{x}]} button |
|---|
| 587 |
before the attribute name indicates whether the attribute is |
|---|
| 588 |
@dfn{enabled}; @samp{[X]} means that it's enabled, and @samp{[ ]} |
|---|
| 589 |
means that it's disabled. You can enable or disable the attribute by |
|---|
| 590 |
clicking that button. When the attribute is enabled, you can change |
|---|
| 591 |
the attribute value in the usual ways. |
|---|
| 592 |
|
|---|
| 593 |
For the colors, you can specify a color name (use @kbd{M-x |
|---|
| 594 |
list-colors-display} for a list of them) or a hexadecimal color |
|---|
| 595 |
specification of the form @samp{#@var{rr}@var{gg}@var{bb}}. |
|---|
| 596 |
(@samp{#000000} is black, @samp{#ff0000} is red, @samp{#00ff00} is |
|---|
| 597 |
green, @samp{#0000ff} is blue, and @samp{#ffffff} is white.) On a |
|---|
| 598 |
black-and-white display, the colors you can use for the background are |
|---|
| 599 |
@samp{black}, @samp{white}, @samp{gray}, @samp{gray1}, and |
|---|
| 600 |
@samp{gray3}. Emacs supports these shades of gray by using background |
|---|
| 601 |
stipple patterns instead of a color. |
|---|
| 602 |
|
|---|
| 603 |
Setting, saving and resetting a face work like the same operations for |
|---|
| 604 |
variables (@pxref{Changing a Variable}). |
|---|
| 605 |
|
|---|
| 606 |
A face can specify different appearances for different types of |
|---|
| 607 |
display. For example, a face can make text red on a color display, but |
|---|
| 608 |
use a bold font on a monochrome display. To specify multiple |
|---|
| 609 |
appearances for a face, select @samp{For All Kinds of Displays} in the |
|---|
| 610 |
menu you get from invoking @samp{[State]}. |
|---|
| 611 |
|
|---|
| 612 |
@findex modify-face |
|---|
| 613 |
Another more basic way to set the attributes of a specific face is |
|---|
| 614 |
with @kbd{M-x modify-face}. This command reads the name of a face, then |
|---|
| 615 |
reads the attributes one by one. For the color and stipple attributes, |
|---|
| 616 |
the attribute's current value is the default---type just @key{RET} if |
|---|
| 617 |
you don't want to change that attribute. Type @samp{none} if you want |
|---|
| 618 |
to clear out the attribute. |
|---|
| 619 |
|
|---|
| 620 |
@node Specific Customization |
|---|
| 621 |
@subsection Customizing Specific Items |
|---|
| 622 |
|
|---|
| 623 |
Instead of finding the setting you want to change by navigating the |
|---|
| 624 |
structure of groups, here are other ways to specify the settings that |
|---|
| 625 |
you want to customize. |
|---|
| 626 |
|
|---|
| 627 |
@table @kbd |
|---|
| 628 |
@item M-x customize-option @key{RET} @var{option} @key{RET} |
|---|
| 629 |
Set up a customization buffer with just one user option variable, |
|---|
| 630 |
@var{option}. |
|---|
| 631 |
@item M-x customize-face @key{RET} @var{face} @key{RET} |
|---|
| 632 |
Set up a customization buffer with just one face, @var{face}. |
|---|
| 633 |
@item M-x customize-group @key{RET} @var{group} @key{RET} |
|---|
| 634 |
Set up a customization buffer with just one group, @var{group}. |
|---|
| 635 |
@item M-x customize-apropos @key{RET} @var{regexp} @key{RET} |
|---|
| 636 |
Set up a customization buffer with all the settings and groups that |
|---|
| 637 |
match @var{regexp}. |
|---|
| 638 |
@item M-x customize-changed @key{RET} @var{version} @key{RET} |
|---|
| 639 |
Set up a customization buffer with all the settings and groups |
|---|
| 640 |
whose meaning has changed since Emacs version @var{version}. |
|---|
| 641 |
@item M-x customize-saved |
|---|
| 642 |
Set up a customization buffer containing all settings that you |
|---|
| 643 |
have saved with customization buffers. |
|---|
| 644 |
@item M-x customize-unsaved |
|---|
| 645 |
Set up a customization buffer containing all settings that you have |
|---|
| 646 |
set but not saved. |
|---|
| 647 |
@end table |
|---|
| 648 |
|
|---|
| 649 |
@findex customize-option |
|---|
| 650 |
If you want to alter a particular user option with the customization |
|---|
| 651 |
buffer, and you know its name, you can use the command @kbd{M-x |
|---|
| 652 |
customize-option} and specify the user option (variable) name. This |
|---|
| 653 |
sets up the customization buffer with just one user option---the one |
|---|
| 654 |
that you asked for. Editing, setting and saving the value work as |
|---|
| 655 |
described above, but only for the specified user option. Minibuffer |
|---|
| 656 |
completion is handy if you only know part of the name. However, this |
|---|
| 657 |
command can only see options that have been loaded in the current |
|---|
| 658 |
Emacs session. |
|---|
| 659 |
|
|---|
| 660 |
@findex customize-face |
|---|
| 661 |
Likewise, you can modify a specific face, chosen by name, using |
|---|
| 662 |
@kbd{M-x customize-face}. By default it operates on the face used |
|---|
| 663 |
on the character after point. |
|---|
| 664 |
|
|---|
| 665 |
@findex customize-group |
|---|
| 666 |
You can also set up the customization buffer with a specific group, |
|---|
| 667 |
using @kbd{M-x customize-group}. The immediate contents of the chosen |
|---|
| 668 |
group, including settings (user options and faces), and other groups, |
|---|
| 669 |
all appear as well (even if not already loaded). However, the |
|---|
| 670 |
subgroups' own contents are not included. |
|---|
| 671 |
|
|---|
| 672 |
@findex customize-apropos |
|---|
| 673 |
For a more general way of controlling what to customize, you can use |
|---|
| 674 |
@kbd{M-x customize-apropos}. You specify a regular expression as |
|---|
| 675 |
argument; then all @emph{loaded} settings and groups whose names match |
|---|
| 676 |
this regular expression are set up in the customization buffer. If |
|---|
| 677 |
you specify an empty regular expression, this includes @emph{all} |
|---|
| 678 |
loaded groups and settings---which takes a long time to set up. |
|---|
| 679 |
|
|---|
| 680 |
@findex customize-changed |
|---|
| 681 |
When you upgrade to a new Emacs version, you might want to consider |
|---|
| 682 |
customizing new settings, and settings whose meanings or default |
|---|
| 683 |
values have changed. To do this, use @kbd{M-x customize-changed} and |
|---|
| 684 |
specify a previous Emacs version number using the minibuffer. It |
|---|
| 685 |
creates a customization buffer which shows all the settings and groups |
|---|
| 686 |
whose definitions have been changed since the specified version, |
|---|
| 687 |
loading them if necessary. |
|---|
| 688 |
|
|---|
| 689 |
@findex customize-saved |
|---|
| 690 |
@findex customize-unsaved |
|---|
| 691 |
If you change settings and then decide the change was a mistake, you |
|---|
| 692 |
can use two special commands to revisit your previous changes. Use |
|---|
| 693 |
@kbd{M-x customize-saved} to look at the settings that you have saved. |
|---|
| 694 |
Use @kbd{M-x customize-unsaved} to look at the settings that you |
|---|
| 695 |
have set but not saved. |
|---|
| 696 |
|
|---|
| 697 |
@node Custom Themes |
|---|
| 698 |
@subsection Customization Themes |
|---|
| 699 |
@cindex custom themes |
|---|
| 700 |
|
|---|
| 701 |
@dfn{Custom themes} are collections of settings that can be enabled |
|---|
| 702 |
or disabled as a unit. You can use Custom themes to switch quickly |
|---|
| 703 |
and easily between various collections of settings, and to transfer |
|---|
| 704 |
such collections from one computer to another. |
|---|
| 705 |
|
|---|
| 706 |
@findex customize-create-theme |
|---|
| 707 |
To define a Custom theme, use @kbd{M-x customize-create-theme}, |
|---|
| 708 |
which brings up a buffer named @samp{*New Custom Theme*}. At the top |
|---|
| 709 |
of the buffer is an editable field where you can specify the name of |
|---|
| 710 |
the theme. Click on the button labelled @samp{Insert Variable} to add |
|---|
| 711 |
a variable to the theme, and click on @samp{Insert Face} to add a |
|---|
| 712 |
face. You can edit these values in the @samp{*New Custom Theme*} |
|---|
| 713 |
buffer like in an ordinary Customize buffer. To remove an option from |
|---|
| 714 |
the theme, click on its @samp{State} button and select @samp{Delete}. |
|---|
| 715 |
|
|---|
| 716 |
@vindex custom-theme-directory |
|---|
| 717 |
After adding the desired options, click on @samp{Save Theme} to save |
|---|
| 718 |
the Custom theme. This writes the theme definition to a file |
|---|
| 719 |
@file{@var{foo}-theme.el} (where @var{foo} is the theme name you |
|---|
| 720 |
supplied), in the directory @file{~/.emacs.d/}. You can specify the |
|---|
| 721 |
directory by setting @code{custom-theme-directory}. |
|---|
| 722 |
|
|---|
| 723 |
You can view and edit the settings of a previously-defined theme by |
|---|
| 724 |
clicking on @samp{Visit Theme} and specifying the theme name. You can |
|---|
| 725 |
also import the variables and faces that you have set using Customize |
|---|
| 726 |
by visiting the ``special'' theme named @samp{user}. This theme, which |
|---|
| 727 |
records all the options that you set in the ordinary customization |
|---|
| 728 |
buffer, is always enabled, and always takes precedence over all other |
|---|
| 729 |
enabled Custom themes. Additionally, the @samp{user} theme is |
|---|
| 730 |
recorded with code in your @file{.emacs} file, rather than a |
|---|
| 731 |
@file{user-theme.el} file. |
|---|
| 732 |
|
|---|
| 733 |
@vindex custom-enabled-themes |
|---|
| 734 |
Once you have defined a Custom theme, you can use it by customizing |
|---|
| 735 |
the variable @code{custom-enabled-themes}. This is a list of Custom |
|---|
| 736 |
themes that are @dfn{enabled}, or put into effect. If you set |
|---|
| 737 |
@code{custom-enabled-themes} using the Customize interface, the theme |
|---|
| 738 |
definitions are automatically loaded from the theme files, if they |
|---|
| 739 |
aren't already. If you save the value of @code{custom-enabled-themes} |
|---|
| 740 |
for future Emacs sessions, those Custom themes will be enabled |
|---|
| 741 |
whenever Emacs is started up. |
|---|
| 742 |
|
|---|
| 743 |
If two enabled themes specify different values for an option, the |
|---|
| 744 |
theme occurring earlier in @code{custom-enabled-themes} takes effect. |
|---|
| 745 |
|
|---|
| 746 |
@findex load-theme |
|---|
| 747 |
@findex enable-theme |
|---|
| 748 |
@findex disable-theme |
|---|
| 749 |
You can temporarily enable a Custom theme with @kbd{M-x |
|---|
| 750 |
enable-theme}. This prompts for a theme name in the minibuffer, loads |
|---|
| 751 |
the theme from the theme file if necessary, and enables the theme. |
|---|
| 752 |
You can @dfn{disable} any enabled theme with the command @kbd{M-x |
|---|
| 753 |
disable-theme}; this returns the options specified in the theme to |
|---|
| 754 |
their original values. To re-enable the theme, type @kbd{M-x |
|---|
| 755 |
enable-theme} again. If a theme file is changed during your Emacs |
|---|
| 756 |
session, you can reload it by typing @kbd{M-x load-theme}. (This also |
|---|
| 757 |
enables the theme.) |
|---|
| 758 |
|
|---|
| 759 |
@node Variables |
|---|
| 760 |
@section Variables |
|---|
| 761 |
@cindex variable |
|---|
| 762 |
@cindex option, user |
|---|
| 763 |
@cindex user option |
|---|
| 764 |
|
|---|
| 765 |
A @dfn{variable} is a Lisp symbol which has a value. The symbol's |
|---|
| 766 |
name is also called the name of the variable. A variable name can |
|---|
| 767 |
contain any characters that can appear in a file, but conventionally |
|---|
| 768 |
variable names consist of words separated by hyphens. A variable can |
|---|
| 769 |
have a documentation string which describes what kind of value it should |
|---|
| 770 |
have and how the value will be used. |
|---|
| 771 |
|
|---|
| 772 |
Emacs Lisp allows any variable (with a few exceptions) to have any |
|---|
| 773 |
kind of value, but most variables that Emacs uses expect a value of a |
|---|
| 774 |
certain type. Often the value should always be a string, or should |
|---|
| 775 |
always be a number. Sometimes we say that a certain feature is turned |
|---|
| 776 |
on if a variable is ``non-@code{nil},'' meaning that if the variable's |
|---|
| 777 |
value is @code{nil}, the feature is off, but the feature is on for |
|---|
| 778 |
@emph{any} other value. The conventional value to use to turn on the |
|---|
| 779 |
feature---since you have to pick one particular value when you set the |
|---|
| 780 |
variable---is @code{t}. |
|---|
| 781 |
|
|---|
| 782 |
Emacs uses many Lisp variables for internal record keeping, but the |
|---|
| 783 |
most interesting variables for a non-programmer user are those meant |
|---|
| 784 |
for users to change---these are called @dfn{user options}. |
|---|
| 785 |
|
|---|
| 786 |
Each user option that you can set with the customization buffer is |
|---|
| 787 |
in fact a Lisp variable. Emacs does not (usually) change the values |
|---|
| 788 |
of these variables on its own; instead, you set the values in order to |
|---|
| 789 |
control the behavior of certain Emacs commands. Use of the |
|---|
| 790 |
customization buffer is explained above (@pxref{Easy Customization}); |
|---|
| 791 |
here we describe other aspects of Emacs variables. |
|---|
| 792 |
|
|---|
| 793 |
@menu |
|---|
| 794 |
* Examining:: Examining or setting one variable's value. |
|---|
| 795 |
* Hooks:: Hook variables let you specify programs for parts |
|---|
| 796 |
of Emacs to run on particular occasions. |
|---|
| 797 |
* Locals:: Per-buffer values of variables. |
|---|
| 798 |
* File Variables:: How files can specify variable values. |
|---|
| 799 |
@end menu |
|---|
| 800 |
|
|---|
| 801 |
@node Examining |
|---|
| 802 |
@subsection Examining and Setting Variables |
|---|
| 803 |
@cindex setting variables |
|---|
| 804 |
|
|---|
| 805 |
@table @kbd |
|---|
| 806 |
@item C-h v @var{var} @key{RET} |
|---|
| 807 |
Display the value and documentation of variable @var{var} |
|---|
| 808 |
(@code{describe-variable}). |
|---|
| 809 |
@item M-x set-variable @key{RET} @var{var} @key{RET} @var{value} @key{RET} |
|---|
| 810 |
Change the value of variable @var{var} to @var{value}. |
|---|
| 811 |
@end table |
|---|
| 812 |
|
|---|
| 813 |
To examine the value of a single variable, use @kbd{C-h v} |
|---|
| 814 |
(@code{describe-variable}), which reads a variable name using the |
|---|
| 815 |
minibuffer, with completion. It displays both the value and the |
|---|
| 816 |
documentation of the variable. For example, |
|---|
| 817 |
|
|---|
| 818 |
@example |
|---|
| 819 |
C-h v fill-column @key{RET} |
|---|
| 820 |
@end example |
|---|
| 821 |
|
|---|
| 822 |
@noindent |
|---|
| 823 |
displays something like this: |
|---|
| 824 |
|
|---|
| 825 |
@smallexample |
|---|
| 826 |
fill-column is a variable defined in `C source code'. |
|---|
| 827 |
fill-column's value is 70 |
|---|
| 828 |
Local in buffer custom.texi; global value is 70 |
|---|
| 829 |
Automatically becomes buffer-local when set in any fashion. |
|---|
| 830 |
|
|---|
| 831 |
This variable is safe to use as a file local variable only if its value |
|---|
| 832 |
satisfies the predicate `integerp'. |
|---|
| 833 |
|
|---|
| 834 |
Documentation: |
|---|
| 835 |
*Column beyond which automatic line-wrapping should happen. |
|---|
| 836 |
Interactively, you can set the buffer local value using C-x f. |
|---|
| 837 |
|
|---|
| 838 |
You can customize this variable. |
|---|
| 839 |
@end smallexample |
|---|
| 840 |
|
|---|
| 841 |
@noindent |
|---|
| 842 |
The line that says you can customize the variable indicates that this |
|---|
| 843 |
variable is a user option. (The star also indicates this, but it is |
|---|
| 844 |
an obsolete indicator that may eventually disappear.) @kbd{C-h v} is |
|---|
| 845 |
not restricted to user options; it allows any variable name. |
|---|
| 846 |
|
|---|
| 847 |
@findex set-variable |
|---|
| 848 |
The most convenient way to set a specific user option variable is with |
|---|
| 849 |
@kbd{M-x set-variable}. This reads the variable name with the |
|---|
| 850 |
minibuffer (with completion), and then reads a Lisp expression for the |
|---|
| 851 |
new value using the minibuffer a second time (you can insert the old |
|---|
| 852 |
value into the minibuffer for editing via @kbd{M-n}). For example, |
|---|
| 853 |
|
|---|
| 854 |
@example |
|---|
| 855 |
M-x set-variable @key{RET} fill-column @key{RET} 75 @key{RET} |
|---|
| 856 |
@end example |
|---|
| 857 |
|
|---|
| 858 |
@noindent |
|---|
| 859 |
sets @code{fill-column} to 75. |
|---|
| 860 |
|
|---|
| 861 |
@kbd{M-x set-variable} is limited to user option variables, but you can |
|---|
| 862 |
set any variable with a Lisp expression, using the function @code{setq}. |
|---|
| 863 |
Here is a @code{setq} expression to set @code{fill-column}: |
|---|
| 864 |
|
|---|
| 865 |
@example |
|---|
| 866 |
(setq fill-column 75) |
|---|
| 867 |
@end example |
|---|
| 868 |
|
|---|
| 869 |
To execute an expression like this one, go to the @samp{*scratch*} |
|---|
| 870 |
buffer, type in the expression, and then type @kbd{C-j}. @xref{Lisp |
|---|
| 871 |
Interaction}. |
|---|
| 872 |
|
|---|
| 873 |
Setting variables, like all means of customizing Emacs except where |
|---|
| 874 |
otherwise stated, affects only the current Emacs session. The only |
|---|
| 875 |
way to alter the variable in future sessions is to put something in |
|---|
| 876 |
the @file{~/.emacs} file to set it those sessions (@pxref{Init File}). |
|---|
| 877 |
|
|---|
| 878 |
@node Hooks |
|---|
| 879 |
@subsection Hooks |
|---|
| 880 |
@cindex hook |
|---|
| 881 |
@cindex running a hook |
|---|
| 882 |
|
|---|
| 883 |
@dfn{Hooks} are an important mechanism for customization of Emacs. A |
|---|
| 884 |
hook is a Lisp variable which holds a list of functions, to be called on |
|---|
| 885 |
some well-defined occasion. (This is called @dfn{running the hook}.) |
|---|
| 886 |
The individual functions in the list are called the @dfn{hook functions} |
|---|
| 887 |
of the hook. With rare exceptions, hooks in Emacs are empty when Emacs |
|---|
| 888 |
starts up, so the only hook functions in any given hook are the ones you |
|---|
| 889 |
explicitly put there as customization. |
|---|
| 890 |
|
|---|
| 891 |
Most major modes run one or more @dfn{mode hooks} as the last step of |
|---|
| 892 |
initialization. This makes it easy for you to customize the behavior of |
|---|
| 893 |
the mode, by setting up a hook function to override the local variable |
|---|
| 894 |
assignments already made by the mode. But hooks are also used in other |
|---|
| 895 |
contexts. For example, the hook @code{suspend-hook} runs just before |
|---|
| 896 |
Emacs suspends itself (@pxref{Exiting}). |
|---|
| 897 |
|
|---|
| 898 |
@cindex normal hook |
|---|
| 899 |
Most Emacs hooks are @dfn{normal hooks}. This means that running the |
|---|
| 900 |
hook operates by calling all the hook functions, unconditionally, with |
|---|
| 901 |
no arguments. We have made an effort to keep most hooks normal so that |
|---|
| 902 |
you can use them in a uniform way. Every variable in Emacs whose name |
|---|
| 903 |
ends in @samp{-hook} is a normal hook. |
|---|
| 904 |
|
|---|
| 905 |
@cindex abnormal hook |
|---|
| 906 |
There are also a few @dfn{abnormal hooks}. These variables' names end |
|---|
| 907 |
in @samp{-hooks} or @samp{-functions}, instead of @samp{-hook}. What |
|---|
| 908 |
makes these hooks abnormal is that there is something peculiar about the |
|---|
| 909 |
way its functions are called---perhaps they are given arguments, or |
|---|
| 910 |
perhaps the values they return are used in some way. For example, |
|---|
| 911 |
@code{find-file-not-found-functions} (@pxref{Visiting}) is abnormal because |
|---|
| 912 |
as soon as one hook function returns a non-@code{nil} value, the rest |
|---|
| 913 |
are not called at all. The documentation of each abnormal hook variable |
|---|
| 914 |
explains in detail what is peculiar about it. |
|---|
| 915 |
|
|---|
| 916 |
@findex add-hook |
|---|
| 917 |
You can set a hook variable with @code{setq} like any other Lisp |
|---|
| 918 |
variable, but the recommended way to add a hook function to a hook |
|---|
| 919 |
(either normal or abnormal) is by calling @code{add-hook}. |
|---|
| 920 |
@xref{Hooks,,, elisp, The Emacs Lisp Reference Manual}. |
|---|
| 921 |
|
|---|
| 922 |
For example, here's how to set up a hook to turn on Auto Fill mode |
|---|
| 923 |
when entering Text mode and other modes based on Text mode: |
|---|
| 924 |
|
|---|
| 925 |
@example |
|---|
| 926 |
(add-hook 'text-mode-hook 'turn-on-auto-fill) |
|---|
| 927 |
@end example |
|---|
| 928 |
|
|---|
| 929 |
The next example shows how to use a hook to customize the indentation |
|---|
| 930 |
of C code. (People often have strong personal preferences for one |
|---|
| 931 |
format compared to another.) Here the hook function is an anonymous |
|---|
| 932 |
lambda expression. |
|---|
| 933 |
|
|---|
| 934 |
@example |
|---|
| 935 |
@group |
|---|
| 936 |
(setq my-c-style |
|---|
| 937 |
'((c-comment-only-line-offset . 4) |
|---|
| 938 |
@end group |
|---|
| 939 |
@group |
|---|
| 940 |
(c-cleanup-list . (scope-operator |
|---|
| 941 |
empty-defun-braces |
|---|
| 942 |
defun-close-semi)) |
|---|
| 943 |
@end group |
|---|
| 944 |
@group |
|---|
| 945 |
(c-offsets-alist . ((arglist-close . c-lineup-arglist) |
|---|
| 946 |
(substatement-open . 0))))) |
|---|
| 947 |
@end group |
|---|
| 948 |
|
|---|
| 949 |
@group |
|---|
| 950 |
(add-hook 'c-mode-common-hook |
|---|
| 951 |
'(lambda () |
|---|
| 952 |
(c-add-style "my-style" my-c-style t))) |
|---|
| 953 |
@end group |
|---|
| 954 |
@end example |
|---|
| 955 |
|
|---|
| 956 |
It is best to design your hook functions so that the order in which |
|---|
| 957 |
they are executed does not matter. Any dependence on the order is |
|---|
| 958 |
``asking for trouble.'' However, the order is predictable: the most |
|---|
| 959 |
recently added hook functions are executed first. |
|---|
| 960 |
|
|---|
| 961 |
@findex remove-hook |
|---|
| 962 |
If you play with adding various different versions of a hook |
|---|
| 963 |
function by calling @code{add-hook} over and over, remember that all |
|---|
| 964 |
the versions you added will remain in the hook variable together. You |
|---|
| 965 |
can clear out individual functions by calling @code{remove-hook}, or |
|---|
| 966 |
do @code{(setq @var{hook-variable} nil)} to remove everything. |
|---|
| 967 |
|
|---|
| 968 |
@node Locals |
|---|
| 969 |
@subsection Local Variables |
|---|
| 970 |
|
|---|
| 971 |
@table @kbd |
|---|
| 972 |
@item M-x make-local-variable @key{RET} @var{var} @key{RET} |
|---|
| 973 |
Make variable @var{var} have a local value in the current buffer. |
|---|
| 974 |
@item M-x kill-local-variable @key{RET} @var{var} @key{RET} |
|---|
| 975 |
Make variable @var{var} use its global value in the current buffer. |
|---|
| 976 |
@item M-x make-variable-buffer-local @key{RET} @var{var} @key{RET} |
|---|
| 977 |
Mark variable @var{var} so that setting it will make it local to the |
|---|
| 978 |
buffer that is current at that time. |
|---|
| 979 |
@end table |
|---|
| 980 |
|
|---|
| 981 |
@cindex local variables |
|---|
| 982 |
Almost any variable can be made @dfn{local} to a specific Emacs |
|---|
| 983 |
buffer. This means that its value in that buffer is independent of its |
|---|
| 984 |
value in other buffers. A few variables are always local in every |
|---|
| 985 |
buffer. Every other Emacs variable has a @dfn{global} value which is in |
|---|
| 986 |
effect in all buffers that have not made the variable local. |
|---|
| 987 |
|
|---|
| 988 |
@findex make-local-variable |
|---|
| 989 |
@kbd{M-x make-local-variable} reads the name of a variable and makes |
|---|
| 990 |
it local to the current buffer. Changing its value subsequently in |
|---|
| 991 |
this buffer will not affect others, and changes in its global value |
|---|
| 992 |
will not affect this buffer. |
|---|
| 993 |
|
|---|
| 994 |
@findex make-variable-buffer-local |
|---|
| 995 |
@cindex per-buffer variables |
|---|
| 996 |
@kbd{M-x make-variable-buffer-local} marks a variable so it will |
|---|
| 997 |
become local automatically whenever it is set. More precisely, once a |
|---|
| 998 |
variable has been marked in this way, the usual ways of setting the |
|---|
| 999 |
variable automatically do @code{make-local-variable} first. We call |
|---|
| 1000 |
such variables @dfn{per-buffer} variables. Many variables in Emacs |
|---|
| 1001 |
are normally per-buffer; the variable's document string tells you when |
|---|
| 1002 |
this is so. A per-buffer variable's global value is normally never |
|---|
| 1003 |
effective in any buffer, but it still has a meaning: it is the initial |
|---|
| 1004 |
value of the variable for each new buffer. |
|---|
| 1005 |
|
|---|
| 1006 |
Major modes (@pxref{Major Modes}) always make variables local to the |
|---|
| 1007 |
buffer before setting the variables. This is why changing major modes |
|---|
| 1008 |
in one buffer has no effect on other buffers. Minor modes also work |
|---|
| 1009 |
by setting variables---normally, each minor mode has one controlling |
|---|
| 1010 |
variable which is non-@code{nil} when the mode is enabled |
|---|
| 1011 |
(@pxref{Minor Modes}). For many minor modes, the controlling variable |
|---|
| 1012 |
is per buffer, and thus always buffer-local. Otherwise, you can make |
|---|
| 1013 |
it local in a specific buffer like any other variable. |
|---|
| 1014 |
|
|---|
| 1015 |
A few variables cannot be local to a buffer because they are always |
|---|
| 1016 |
local to each display instead (@pxref{Multiple Displays}). If you try to |
|---|
| 1017 |
make one of these variables buffer-local, you'll get an error message. |
|---|
| 1018 |
|
|---|
| 1019 |
@findex kill-local-variable |
|---|
| 1020 |
@kbd{M-x kill-local-variable} makes a specified variable cease to be |
|---|
| 1021 |
local to the current buffer. The global value of the variable |
|---|
| 1022 |
henceforth is in effect in this buffer. Setting the major mode kills |
|---|
| 1023 |
all the local variables of the buffer except for a few variables |
|---|
| 1024 |
specially marked as @dfn{permanent locals}. |
|---|
| 1025 |
|
|---|
| 1026 |
@findex setq-default |
|---|
| 1027 |
To set the global value of a variable, regardless of whether the |
|---|
| 1028 |
variable has a local value in the current buffer, you can use the Lisp |
|---|
| 1029 |
construct @code{setq-default}. This construct is used just like |
|---|
| 1030 |
@code{setq}, but it sets variables' global values instead of their local |
|---|
| 1031 |
values (if any). When the current buffer does have a local value, the |
|---|
| 1032 |
new global value may not be visible until you switch to another buffer. |
|---|
| 1033 |
Here is an example: |
|---|
| 1034 |
|
|---|
| 1035 |
@example |
|---|
| 1036 |
(setq-default fill-column 75) |
|---|
| 1037 |
@end example |
|---|
| 1038 |
|
|---|
| 1039 |
@noindent |
|---|
| 1040 |
@code{setq-default} is the only way to set the global value of a variable |
|---|
| 1041 |
that has been marked with @code{make-variable-buffer-local}. |
|---|
| 1042 |
|
|---|
| 1043 |
@findex default-value |
|---|
| 1044 |
Lisp programs can use @code{default-value} to look at a variable's |
|---|
| 1045 |
default value. This function takes a symbol as argument and returns its |
|---|
| 1046 |
default value. The argument is evaluated; usually you must quote it |
|---|
| 1047 |
explicitly. For example, here's how to obtain the default value of |
|---|
| 1048 |
@code{fill-column}: |
|---|
| 1049 |
|
|---|
| 1050 |
@example |
|---|
| 1051 |
(default-value 'fill-column) |
|---|
| 1052 |
@end example |
|---|
| 1053 |
|
|---|
| 1054 |
@node File Variables |
|---|
| 1055 |
@subsection Local Variables in Files |
|---|
| 1056 |
@cindex local variables in files |
|---|
| 1057 |
@cindex file local variables |
|---|
| 1058 |
|
|---|
| 1059 |
A file can specify local variable values for use when you edit the |
|---|
| 1060 |
file with Emacs. Visiting the file checks for local variable |
|---|
| 1061 |
specifications; it automatically makes these variables local to the |
|---|
| 1062 |
buffer, and sets them to the values specified in the file. |
|---|
| 1063 |
|
|---|
| 1064 |
@menu |
|---|
| 1065 |
* Specifying File Variables:: Specifying file local variables. |
|---|
| 1066 |
* Safe File Variables:: Making sure file local variables are safe. |
|---|
| 1067 |
@end menu |
|---|
| 1068 |
|
|---|
| 1069 |
@node Specifying File Variables |
|---|
| 1070 |
@subsubsection Specifying File Variables |
|---|
| 1071 |
|
|---|
| 1072 |
There are two ways to specify file local variable values: in the first |
|---|
| 1073 |
line, or with a local variables list. Here's how to specify them in the |
|---|
| 1074 |
first line: |
|---|
| 1075 |
|
|---|
| 1076 |
@example |
|---|
| 1077 |
-*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*- |
|---|
| 1078 |
@end example |
|---|
| 1079 |
|
|---|
| 1080 |
@noindent |
|---|
| 1081 |
You can specify any number of variables/value pairs in this way, each |
|---|
| 1082 |
pair with a colon and semicolon as shown above. @code{mode: |
|---|
| 1083 |
@var{modename};} specifies the major mode; this should come first in the |
|---|
| 1084 |
line. The @var{value}s are not evaluated; they are used literally. |
|---|
| 1085 |
Here is an example that specifies Lisp mode and sets two variables with |
|---|
| 1086 |
numeric values: |
|---|
| 1087 |
|
|---|
| 1088 |
@smallexample |
|---|
| 1089 |
;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*- |
|---|
| 1090 |
@end smallexample |
|---|
| 1091 |
|
|---|
| 1092 |
You can also specify the coding system for a file in this way: just |
|---|
| 1093 |
specify a value for the ``variable'' named @code{coding}. The ``value'' |
|---|
| 1094 |
must be a coding system name that Emacs recognizes. @xref{Coding |
|---|
| 1095 |
Systems}. @w{@samp{unibyte: t}} specifies unibyte loading for a |
|---|
| 1096 |
particular Lisp file. @xref{Enabling Multibyte}. |
|---|
| 1097 |
|
|---|
| 1098 |
The @code{eval} pseudo-variable, described below, can be specified in |
|---|
| 1099 |
the first line as well. |
|---|
| 1100 |
|
|---|
| 1101 |
@cindex shell scripts, and local file variables |
|---|
| 1102 |
In shell scripts, the first line is used to identify the script |
|---|
| 1103 |
interpreter, so you cannot put any local variables there. To |
|---|
| 1104 |
accommodate this, Emacs looks for local variable specifications in the |
|---|
| 1105 |
@emph{second} line when the first line specifies an interpreter. |
|---|
| 1106 |
|
|---|
| 1107 |
A @dfn{local variables list} goes near the end of the file, in the |
|---|
| 1108 |
last page. (It is often best to put it on a page by itself.) The local |
|---|
| 1109 |
variables list starts with a line containing the string @samp{Local |
|---|
| 1110 |
Variables:}, and ends with a line containing the string @samp{End:}. In |
|---|
| 1111 |
between come the variable names and values, one set per line, as |
|---|
| 1112 |
@samp{@var{variable}:@: @var{value}}. The @var{value}s are not |
|---|
| 1113 |
evaluated; they are used literally. If a file has both a local |
|---|
| 1114 |
variables list and a @samp{-*-} line, Emacs processes @emph{everything} |
|---|
| 1115 |
in the @samp{-*-} line first, and @emph{everything} in the local |
|---|
| 1116 |
variables list afterward. |
|---|
| 1117 |
|
|---|
| 1118 |
Here is an example of a local variables list: |
|---|
| 1119 |
|
|---|
| 1120 |
@example |
|---|
| 1121 |
;; Local Variables: ** |
|---|
| 1122 |
;; mode:lisp ** |
|---|
| 1123 |
;; comment-column:0 ** |
|---|
| 1124 |
;; comment-start: ";; " ** |
|---|
| 1125 |
;; comment-end:"**" ** |
|---|
| 1126 |
;; End: ** |
|---|
| 1127 |
@end example |
|---|
| 1128 |
|
|---|
| 1129 |
Each line starts with the prefix @samp{;; } and each line ends with |
|---|
| 1130 |
the suffix @samp{ **}. Emacs recognizes these as the prefix and |
|---|
| 1131 |
suffix based on the first line of the list, by finding them |
|---|
| 1132 |
surrounding the magic string @samp{Local Variables:}; then it |
|---|
| 1133 |
automatically discards them from the other lines of the list. |
|---|
| 1134 |
|
|---|
| 1135 |
The usual reason for using a prefix and/or suffix is to embed the |
|---|
| 1136 |
local variables list in a comment, so it won't confuse other programs |
|---|
| 1137 |
that the file is intended as input for. The example above is for a |
|---|
| 1138 |
language where comment lines start with @samp{;; } and end with |
|---|
| 1139 |
@samp{**}; the local values for @code{comment-start} and |
|---|
| 1140 |
@code{comment-end} customize the rest of Emacs for this unusual |
|---|
| 1141 |
syntax. Don't use a prefix (or a suffix) if you don't need one. |
|---|
| 1142 |
|
|---|
| 1143 |
If you write a multi-line string value, you should put the prefix |
|---|
| 1144 |
and suffix on each line, even lines that start or end within the |
|---|
| 1145 |
string. They will be stripped off for processing the list. If you |
|---|
| 1146 |
want to split a long string across multiple lines of the file, you can |
|---|
| 1147 |
use backslash-newline, which is ignored in Lisp string constants. |
|---|
| 1148 |
Here's an example of doing this: |
|---|
| 1149 |
|
|---|
| 1150 |
@example |
|---|
| 115 |
|---|