aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/emacs/custom.texi540
1 files changed, 229 insertions, 311 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index e01dbd1309b..57f656eb1fe 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -70,11 +70,11 @@ mode command. Because not all minor modes work this way, we recommend
70that you avoid changing the mode variables directly; use the mode 70that you avoid changing the mode variables directly; use the mode
71commands instead. 71commands instead.
72 72
73 Some minor modes are buffer-local; they apply only to the current 73 Some minor modes are @dfn{buffer-local}: they apply only to the
74buffer, so you can enable the mode in certain buffers and not others. 74current buffer, so you can enable the mode in certain buffers and not
75Other minor modes are global: while enabled, they affect everything 75others. Other minor modes are @dfn{global}: while enabled, they
76you do in the Emacs session, in all buffers. Some global minor modes 76affect everything you do in the Emacs session, in all buffers. Some
77are enabled by default. 77global minor modes are enabled by default.
78 78
79 The following is a list of some buffer-local minor modes: 79 The following is a list of some buffer-local minor modes:
80 80
@@ -190,29 +190,23 @@ by default. @xref{Mark}.
190@section Easy Customization Interface 190@section Easy Customization Interface
191 191
192@cindex settings 192@cindex settings
193 Emacs has many @dfn{settings} which have values that you can specify 193 Emacs has many @dfn{settings} which have values that you can change.
194in order to customize various commands. Many are documented in this 194Many are documented in this manual. Most settings are @dfn{user
195manual. Most settings are @dfn{user options}---that is to say, Lisp 195options}---that is to say, Lisp variables (@pxref{Variables})---and
196variables (@pxref{Variables})---so their names appear in the Variable 196their names appear in the Variable Index (@pxref{Variable Index}).
197Index (@pxref{Variable Index}). The other settings are faces and 197The other settings are faces and their attributes (@pxref{Faces}).
198their attributes (@pxref{Faces}).
199 198
200@findex customize 199@findex customize
201@cindex customization buffer 200@cindex customization buffer
202 You can browse interactively through settings and change them using 201 You can browse settings and change them using @kbd{M-x customize}.
203@kbd{M-x customize}. This command creates a @dfn{customization 202This creates a @dfn{customization buffer}, which lets you navigate
204buffer}, which offers commands to navigate through a logically 203through a logically organized list of settings, edit and set their
205organized structure of the Emacs settings; you can also use it to edit 204values, and save them permanently in your initialization file
206and set their values, and to save settings permanently in your 205(@pxref{Init File}).
207@file{~/.emacs} file (@pxref{Init File}).
208
209 The appearance of the example buffers in this section is typically
210different under a graphical display, since faces are then used to indicate
211buttons, links and editable fields.
212 206
213@menu 207@menu
214* Groups: Customization Groups. How settings are classified in a structure. 208* Customization Groups:: How settings are classified in a structure.
215* Browsing: Browsing Custom. Browsing and searching for settings. 209* Browsing Custom:: Browsing and searching for settings.
216* Changing a Variable:: How to edit an option's value and set the option. 210* Changing a Variable:: How to edit an option's value and set the option.
217* Saving Customizations:: Specifying the file for saving customizations. 211* Saving Customizations:: Specifying the file for saving customizations.
218* Face Customization:: How to edit the attributes of a face. 212* Face Customization:: How to edit the attributes of a face.
@@ -239,16 +233,14 @@ under it. It looks like this, in part:
239@page 233@page
240@smallexample 234@smallexample
241@group 235@group
242/- Emacs group: ---------------------------------------------------\ 236/- Emacs group: Customization of the One True Editor. -------------\
243 [State]: visible group members are all at standard values. 237 [State]: visible group members are all at standard values.
244 Customization of the One True Editor. 238
245 See also [Manual]. 239 See also [Manual].
246 240
247Editing group: [Go to Group] 241[Editing] : Basic text editing facilities.
248Basic text editing facilities.
249 242
250External group: [Go to Group] 243[External] : Interfacing to external utilities.
251Interfacing to external utilities.
252 244
253@var{more second-level groups} 245@var{more second-level groups}
254 246
@@ -273,19 +265,18 @@ There are also @dfn{buttons} and @dfn{links}, which do something when
273you @dfn{invoke} them. To invoke a button or a link, either click on 265you @dfn{invoke} them. To invoke a button or a link, either click on
274it with @kbd{Mouse-1}, or move point to it and type @key{RET}. 266it with @kbd{Mouse-1}, or move point to it and type @key{RET}.
275 267
276 For example, the phrase @samp{[State]} that appears in 268 For example, the phrase @samp{[State]} that appears in a
277a second-level group is a button. It operates on the same 269second-level group is a button. It operates on the same customization
278customization buffer. The phrase @samp{[Go to Group]} is a kind 270buffer. Each group name, such as @samp{[Editing]}, is a hypertext
279of hypertext link to another group. Invoking it creates a new 271link to that group; invoking it creates a new customization buffer,
280customization buffer, which shows that group and its contents. 272showing the group and its contents.
281 273
282 The @code{Emacs} group includes a few settings, but mainly it 274 The @code{Emacs} group only contains other groups. These groups, in
283contains other groups, which contain more groups, which contain the 275turn, can contain settings or still more groups. By browsing the
284settings. By browsing the hierarchy of groups, you will eventually 276hierarchy of groups, you will eventually find the feature you are
285find the feature you are interested in customizing. Then you can use 277interested in customizing. Then you can use the customization buffer
286the customization buffer to set that feature's settings. You can also 278to set that feature's settings. You can also go straight to a
287go straight to a particular group by name, using the command @kbd{M-x 279particular group by name, using the command @kbd{M-x customize-group}.
288customize-group}.
289 280
290@node Browsing Custom 281@node Browsing Custom
291@subsection Browsing and Searching for Options and Faces 282@subsection Browsing and Searching for Options and Faces
@@ -442,9 +433,9 @@ field; @kbd{S-@key{TAB}} (@code{widget-backward}) moves backward to
442the previous button or editable field. 433the previous button or editable field.
443 434
444 Typing @key{RET} on an editable field also moves forward, just like 435 Typing @key{RET} on an editable field also moves forward, just like
445@key{TAB}. We set it up this way because people often type @key{RET} 436@key{TAB}. You can thus type @key{RET} when you are finished editing
446when they are finished editing a field. To insert a newline within an 437a field, to move on to the next button or field. To insert a newline
447editable field, use @kbd{C-o} or @kbd{C-q C-j}. 438within an editable field, use @kbd{C-o} or @kbd{C-q C-j}.
448 439
449@cindex saving a setting 440@cindex saving a setting
450@cindex settings, how to save 441@cindex settings, how to save
@@ -511,16 +502,17 @@ are hidden, nor on subgroups which are hidden or not visible in the buffer.
511@node Saving Customizations 502@node Saving Customizations
512@subsection Saving Customizations 503@subsection Saving Customizations
513 504
505@vindex custom-file
514 Saving customizations from the customization buffer works by writing 506 Saving customizations from the customization buffer works by writing
515code that future sessions will read, code to set up those 507code to a file. By reading this code, future sessions can set up the
516customizations again. 508customizations again. Normally, the code is saved in your
509initialization file (@pxref{Init File}).
517 510
518@vindex custom-file 511 You can choose to save your customizations in a file other than your
519 Normally this saves customizations in your init file, 512initialization file. To make this work, you must add a couple of
520@file{~/.emacs}. If you wish, you can save customizations in another 513lines of code to your initialization file, to set the variable
521file instead. To make this work, your @file{~/.emacs} should set 514@code{custom-file} to the name of the desired file, and to load that
522@code{custom-file} to the name of that file. Then you should load the 515file. For example:
523file by calling @code{load}. For example:
524 516
525@example 517@example
526(setq custom-file "~/.emacs-custom.el") 518(setq custom-file "~/.emacs-custom.el")
@@ -531,27 +523,24 @@ file by calling @code{load}. For example:
531files for different Emacs versions, like this: 523files for different Emacs versions, like this:
532 524
533@example 525@example
534(cond ((< emacs-major-version 21) 526(cond ((< emacs-major-version 22)
535 ;; @r{Emacs 20 customization.} 527 ;; @r{Emacs 21 customization.}
536 (setq custom-file "~/.custom-20.el"))
537 ((and (= emacs-major-version 21) (< emacs-minor-version 4))
538 ;; @r{Emacs 21 customization, before version 21.4.}
539 (setq custom-file "~/.custom-21.el")) 528 (setq custom-file "~/.custom-21.el"))
540 ((< emacs-major-version 22) 529 ((and (= emacs-major-version 22) (< emacs-minor-version 3))
541 ;; @r{Emacs version 21.4 or later.} 530 ;; @r{Emacs 22 customization, before version 22.3.}
542 (setq custom-file "~/.custom-21.4.el")) 531 (setq custom-file "~/.custom-22.el"))
543 (t 532 (t
544 ;; @r{Emacs version 22.1 or later.} 533 ;; @r{Emacs version 22.3 or later.}
545 (setq custom-file "~/.custom-22.el"))) 534 (setq custom-file "~/.emacs-custom.el")))
546 535
547(load custom-file) 536(load custom-file)
548@end example 537@end example
549 538
550 If Emacs was invoked with the @option{-q} or @option{--no-init-file} 539 If Emacs was invoked with the @option{-q} or @option{--no-init-file}
551options (@pxref{Initial Options}), it will not let you save your 540options (@pxref{Initial Options}), it will not let you save your
552customizations in your @file{~/.emacs} init file. This is because 541customizations in your initialization file. This is because saving
553saving customizations from such a session would wipe out all the other 542customizations from such a session would wipe out all the other
554customizations you might have on your init file. 543customizations you might have on your initialization file.
555 544
556@node Face Customization 545@node Face Customization
557@subsection Customizing Faces 546@subsection Customizing Faces
@@ -766,32 +755,42 @@ enables the theme.)
766@cindex user option 755@cindex user option
767 756
768 A @dfn{variable} is a Lisp symbol which has a value. The symbol's 757 A @dfn{variable} is a Lisp symbol which has a value. The symbol's
769name is also called the name of the variable. A variable name can 758name is also called the @dfn{variable name}. A variable name can
770contain any characters that can appear in a file, but conventionally 759contain any characters that can appear in a file, but most variable
771variable names consist of words separated by hyphens. A variable can 760names consist of ordinary words separated by hyphens.
772have a documentation string which describes what kind of value it should
773have and how the value will be used.
774 761
775 Emacs Lisp allows any variable (with a few exceptions) to have any 762 The name of the variable serves as a compact description of its
776kind of value, but most variables that Emacs uses expect a value of a 763role. Most variables also have a @dfn{documentation string}, which
777certain type. Often the value should always be a string, or should 764describes what the variable's purpose is, what kind of value it should
778always be a number. Sometimes we say that a certain feature is turned 765have, and how the value will be used. You can view this documentation
779on if a variable is ``non-@code{nil},'' meaning that if the variable's 766using the help command @kbd{C-h v} (@code{describe-variable}).
780value is @code{nil}, the feature is off, but the feature is on for 767@xref{Examining}.
781@emph{any} other value. The conventional value to use to turn on the
782feature---since you have to pick one particular value when you set the
783variable---is @code{t}.
784 768
785 Emacs uses many Lisp variables for internal record keeping, but the 769 Emacs uses many Lisp variables for internal record keeping, but the
786most interesting variables for a non-programmer user are those meant 770most interesting variables for a non-programmer user are those meant
787for users to change---these are called @dfn{user options}. 771for users to change---these are called @dfn{user options}. @xref{Easy
772Customization}, for information about using the Customize facility to
773set user options. In the following sections, we describe will other
774aspects of Emacs variables, such as how to set them outside Customize.
788 775
789 Each user option that you can set with the customization buffer is 776 Emacs Lisp allows any variable (with a few exceptions) to have any
790in fact a Lisp variable. Emacs does not (usually) change the values 777kind of value. However, many variables are meaningful only if
791of these variables on its own; instead, you set the values in order to 778assigned values of a certain type. For example, only numbers are
792control the behavior of certain Emacs commands. Use of the 779meaningful values for @code{kill-ring-max}, which specifies the
793customization buffer is explained above (@pxref{Easy Customization}); 780maximum length of the kill ring (@pxref{Earlier Kills}); if you give
794here we describe other aspects of Emacs variables. 781@code{kill-ring-max} a string value, commands such as @kbd{C-y}
782(@code{yank}) will signal an error. On the other hand, some variables
783don't care about type; for instance, if a variable has one effect for
784@code{nil} values and another effect for ``non-@code{nil}'' values,
785then any value that is not the symbol @code{nil} induces the second
786effect, regardless of its type (by convention, we usually use the
787value @code{t}---a symbol which stands for ``true''---to specify a
788non-@code{nil} value). If you set a variable using the customization
789buffer, you need not worry about giving it an invalid type: the
790customization buffer usually only allows you to enter meaningful
791values. When in doubt, use @kbd{C-h v} (@code{describe-variable}) to
792check the variable's documentation string to see kind of value it
793expects (@pxref{Examining}).
795 794
796@menu 795@menu
797* Examining:: Examining or setting one variable's value. 796* Examining:: Examining or setting one variable's value.
@@ -832,8 +831,9 @@ fill-column's value is 70
832Local in buffer custom.texi; global value is 70 831Local in buffer custom.texi; global value is 70
833Automatically becomes buffer-local when set in any fashion. 832Automatically becomes buffer-local when set in any fashion.
834 833
835This variable is safe to use as a file local variable only if its value 834 Automatically becomes buffer-local when set in any fashion.
836satisfies the predicate `integerp'. 835 This variable is safe as a file local variable if its value
836 satisfies the predicate `integerp'.
837 837
838Documentation: 838Documentation:
839*Column beyond which automatic line-wrapping should happen. 839*Column beyond which automatic line-wrapping should happen.
@@ -843,14 +843,13 @@ You can customize this variable.
843@end smallexample 843@end smallexample
844 844
845@noindent 845@noindent
846The line that says you can customize the variable indicates that this 846The line that says ``You can customize the variable'' indicates that
847variable is a user option. (The star also indicates this, but it is 847this variable is a user option. @kbd{C-h v} is not restricted to user
848an obsolete indicator that may eventually disappear.) @kbd{C-h v} is 848options; it allows any variable name.
849not restricted to user options; it allows any variable name.
850 849
851@findex set-variable 850@findex set-variable
852The most convenient way to set a specific user option variable is with 851 The most convenient way to set a specific user option variable is
853@kbd{M-x set-variable}. This reads the variable name with the 852with @kbd{M-x set-variable}. This reads the variable name with the
854minibuffer (with completion), and then reads a Lisp expression for the 853minibuffer (with completion), and then reads a Lisp expression for the
855new value using the minibuffer a second time (you can insert the old 854new value using the minibuffer a second time (you can insert the old
856value into the minibuffer for editing via @kbd{M-n}). For example, 855value into the minibuffer for editing via @kbd{M-n}). For example,
@@ -877,27 +876,28 @@ Interaction}.
877 Setting variables, like all means of customizing Emacs except where 876 Setting variables, like all means of customizing Emacs except where
878otherwise stated, affects only the current Emacs session. The only 877otherwise stated, affects only the current Emacs session. The only
879way to alter the variable in future sessions is to put something in 878way to alter the variable in future sessions is to put something in
880the @file{~/.emacs} file to set it those sessions (@pxref{Init File}). 879your initialization file to set it those sessions (@pxref{Init File}).
881 880
882@node Hooks 881@node Hooks
883@subsection Hooks 882@subsection Hooks
884@cindex hook 883@cindex hook
885@cindex running a hook 884@cindex running a hook
886 885
887 @dfn{Hooks} are an important mechanism for customization of Emacs. A 886 @dfn{Hooks} are an important mechanism for customizing Emacs. A
888hook is a Lisp variable which holds a list of functions, to be called on 887hook is a Lisp variable which holds a list of functions, to be called
889some well-defined occasion. (This is called @dfn{running the hook}.) 888on some well-defined occasion. (This is called @dfn{running the
890The individual functions in the list are called the @dfn{hook functions} 889hook}.) The individual functions in the list are called the @dfn{hook
891of the hook. With rare exceptions, hooks in Emacs are empty when Emacs 890functions} of the hook. With rare exceptions, hooks in Emacs are
892starts up, so the only hook functions in any given hook are the ones you 891empty when Emacs starts up, so the only hook functions in any given
893explicitly put there as customization. 892hook are the ones you explicitly put there as customization.
894 893
895 Most major modes run one or more @dfn{mode hooks} as the last step of 894 Most major modes run one or more @dfn{mode hooks} as the last step
896initialization. This makes it easy for you to customize the behavior of 895of initialization. This makes it easy for you to customize the
897the mode, by setting up a hook function to override the local variable 896behavior of the mode, by setting up a hook function to override the
898assignments already made by the mode. But hooks are also used in other 897local variable assignments already made by the mode. But hooks are
899contexts. For example, the hook @code{suspend-hook} runs just before 898also used in other contexts. For example, the hook
900Emacs suspends itself (@pxref{Exiting}). 899@code{kill-emacs-hook} runs just before quitting the Emacs job
900(@pxref{Exiting}).
901 901
902@cindex normal hook 902@cindex normal hook
903 Most Emacs hooks are @dfn{normal hooks}. This means that running the 903 Most Emacs hooks are @dfn{normal hooks}. This means that running the
@@ -1112,41 +1112,37 @@ The same is true for man pages which start with the magic string
1112@samp{'\"} to specify a list of troff preprocessors (not all do, 1112@samp{'\"} to specify a list of troff preprocessors (not all do,
1113however). 1113however).
1114 1114
1115 A @dfn{local variables list} goes near the end of the file, in the 1115 A @dfn{local variables list} goes near the end of the file. It
1116last page. (It is often best to put it on a page by itself.) The local 1116starts with a line containing the string @samp{Local Variables:}, and
1117variables list starts with a line containing the string @samp{Local 1117ends with a line containing the string @samp{End:}. In between come
1118Variables:}, and ends with a line containing the string @samp{End:}. In 1118the variable names and values, one set per line, as
1119between come the variable names and values, one set per line, as
1120@samp{@var{variable}:@: @var{value}}. The @var{value}s are not 1119@samp{@var{variable}:@: @var{value}}. The @var{value}s are not
1121evaluated; they are used literally. If a file has both a local 1120evaluated; they are used literally. If a file has both a local
1122variables list and a @samp{-*-} line, Emacs processes @emph{everything} 1121variables list and a @samp{-*-} line, Emacs processes
1123in the @samp{-*-} line first, and @emph{everything} in the local 1122@emph{everything} in the @samp{-*-} line first, and @emph{everything}
1124variables list afterward. 1123in the local variables list afterward.
1125 1124
1126 Here is an example of a local variables list: 1125 Here is an example of a local variables list:
1127 1126
1128@example 1127@example
1129;; Local Variables: ** 1128/* Local Variables: */
1130;; mode:lisp ** 1129/* mode:c */
1131;; comment-column:0 ** 1130/* comment-column:0 */
1132;; comment-start: ";; " ** 1131/* End: */
1133;; comment-end:"**" **
1134;; End: **
1135@end example 1132@end example
1136 1133
1137 Each line starts with the prefix @samp{;; } and each line ends with 1134 In this example, each line starts with the prefix @samp{/*} and each
1138the suffix @samp{ **}. Emacs recognizes these as the prefix and 1135line ends with the suffix @samp{*/}. Emacs recognizes these as the
1139suffix based on the first line of the list, by finding them 1136prefix and suffix by finding them surrounding the magic string
1140surrounding the magic string @samp{Local Variables:}; then it 1137@samp{Local Variables:}, on the first line of the list; it then
1141automatically discards them from the other lines of the list. 1138automatically discards them from the other lines of the list.
1142 1139
1143 The usual reason for using a prefix and/or suffix is to embed the 1140 The usual reason for using a prefix and/or suffix is to embed the
1144local variables list in a comment, so it won't confuse other programs 1141local variables list in a comment, so it won't confuse other programs
1145that the file is intended as input for. The example above is for a 1142that the file is intended as input for. The example above is for the
1146language where comment lines start with @samp{;; } and end with 1143C programming language, where comment lines start with @samp{/*} and
1147@samp{**}; the local values for @code{comment-start} and 1144end with @samp{*/}. Don't use a prefix (or a suffix) if you don't
1148@code{comment-end} customize the rest of Emacs for this unusual 1145need one.
1149syntax. Don't use a prefix (or a suffix) if you don't need one.
1150 1146
1151 If you write a multi-line string value, you should put the prefix 1147 If you write a multi-line string value, you should put the prefix
1152and suffix on each line, even lines that start or end within the 1148and suffix on each line, even lines that start or end within the
@@ -1192,12 +1188,10 @@ alone (@pxref{Init File}). Don't use a local variable list to impose
1192your taste on everyone. 1188your taste on everyone.
1193 1189
1194 The start of the local variables list must be no more than 3000 1190 The start of the local variables list must be no more than 3000
1195characters from the end of the file, and must be in the last page if the 1191characters from the end of the file, and must be in the last page if
1196file is divided into pages. Otherwise, Emacs will not notice it is 1192the file is divided into pages. Otherwise, Emacs will not notice it
1197there. The purpose of this rule is so that a stray @samp{Local 1193is there. The purpose of this rule is so that Emacs need not take the
1198Variables:}@: not in the last page does not confuse Emacs, and so that 1194time to search the whole file.
1199visiting a long file that is all one page and has no local variables
1200list need not take the time to search the whole file.
1201 1195
1202 Use the command @code{normal-mode} to reset the local variables and 1196 Use the command @code{normal-mode} to reset the local variables and
1203major mode of a buffer according to the file name and contents, 1197major mode of a buffer according to the file name and contents,
@@ -1361,12 +1355,12 @@ name, which usually consists of lower-case letters and hyphens.
1361in data structures called @dfn{keymaps}. Emacs has many of these, each 1355in data structures called @dfn{keymaps}. Emacs has many of these, each
1362used on particular occasions. 1356used on particular occasions.
1363 1357
1364 Recall that a @dfn{key sequence} (@dfn{key}, for short) is a sequence 1358 A @dfn{key sequence} (@dfn{key}, for short) is a sequence of
1365of @dfn{input events} that have a meaning as a unit. Input events 1359@dfn{input events} that have a meaning as a unit. Input events
1366include characters, function keys and mouse buttons---all the inputs 1360include characters, function keys and mouse buttons---all the inputs
1367that you can send to the computer with your terminal. A key sequence 1361that you can send to the computer with your terminal. A key sequence
1368gets its meaning from its @dfn{binding}, which says what command it 1362gets its meaning from its @dfn{binding}, which says what command it
1369runs. The function of keymaps is to record these bindings. 1363runs. The role of keymaps is to record these bindings.
1370 1364
1371@cindex global keymap 1365@cindex global keymap
1372 The @dfn{global} keymap is the most important keymap because it is 1366 The @dfn{global} keymap is the most important keymap because it is
@@ -1383,48 +1377,26 @@ Commands to rebind keys, such as @kbd{M-x global-set-key}, actually work
1383by storing the new binding in the proper place in the global map. 1377by storing the new binding in the proper place in the global map.
1384@xref{Rebinding}. 1378@xref{Rebinding}.
1385 1379
1386 Meta characters work differently; Emacs translates each Meta
1387character into a pair of characters starting with @key{ESC}. When you
1388type the character @kbd{M-a} in a key sequence, Emacs replaces it with
1389@kbd{@key{ESC} a}. A meta key comes in as a single input event, but
1390becomes two events for purposes of key bindings. The reason for this is
1391historical, and we might change it someday.
1392
1393@cindex function key 1380@cindex function key
1394 Most modern keyboards have function keys as well as character keys. 1381 Most modern keyboards have function keys as well as character keys.
1395Function keys send input events just as character keys do, and keymaps 1382Function keys send input events just as character keys do, and keymaps
1396can have bindings for them. 1383can have bindings for them. On text terminals, typing a function key
1397 1384actually sends the computer a sequence of characters; the precise
1398 On text terminals, typing a function key actually sends the computer a 1385details of the sequence depends on which function key and on the model
1399sequence of characters; the precise details of the sequence depends on 1386of terminal you are using. (Often the sequence starts with
1400which function key and on the model of terminal you are using. (Often 1387@kbd{@key{ESC} [}.) If Emacs understands your terminal type properly,
1401the sequence starts with @kbd{@key{ESC} [}.) If Emacs understands your 1388it recognizes the character sequences forming function keys wherever
1402terminal type properly, it recognizes the character sequences forming 1389they occur in a key sequence. Thus, for most purposes, you can
1403function keys wherever they occur in a key sequence (not just at the 1390pretend the function keys reach Emacs directly and ignore their
1404beginning). Thus, for most purposes, you can pretend the function keys 1391encoding as character sequences.
1405reach Emacs directly and ignore their encoding as character sequences. 1392
1406 1393 Key sequences can mix function keys and characters. For example, if
1407@cindex mouse 1394your keyboard has a @key{Home} function key, Emacs also recognizes key
1408 Mouse buttons also produce input events. These events come with other 1395sequences like @kbd{C-x @key{Home}}. You can even mix mouse events
1409data---the window and position where you pressed or released the button, 1396with keyboard events, but we recommend against it, because such key
1410and a time stamp. But only the choice of button matters for key 1397sequences are inconvenient to use.
1411bindings; the other data matters only if a command looks at it. 1398
1412(Commands designed for mouse invocation usually do look at the other 1399 As a user, you can redefine any key, but it is usually best to stick
1413data.)
1414
1415 A keymap records definitions for single events. Interpreting a key
1416sequence of multiple events involves a chain of keymaps. The first
1417keymap gives a definition for the first event; this definition is
1418another keymap, which is used to look up the second event in the
1419sequence, and so on.
1420
1421 Key sequences can mix function keys and characters. For example,
1422@kbd{C-x @key{SELECT}} is meaningful. If you make @key{SELECT} a prefix
1423key, then @kbd{@key{SELECT} C-n} makes sense. You can even mix mouse
1424events with keyboard events, but we recommend against it, because such
1425key sequences are inconvenient to use.
1426
1427 As a user, you can redefine any key; but it is usually best to stick
1428to key sequences that consist of @kbd{C-c} followed by a letter (upper 1400to key sequences that consist of @kbd{C-c} followed by a letter (upper
1429or lower case). These keys are ``reserved for users,'' so they won't 1401or lower case). These keys are ``reserved for users,'' so they won't
1430conflict with any properly designed Emacs extension. The function 1402conflict with any properly designed Emacs extension. The function
@@ -1435,9 +1407,13 @@ extensions or major modes which redefine the same key.
1435@node Prefix Keymaps 1407@node Prefix Keymaps
1436@subsection Prefix Keymaps 1408@subsection Prefix Keymaps
1437 1409
1438 A prefix key such as @kbd{C-x} or @key{ESC} has its own keymap, 1410 Internally, Emacs records only single events in each keymap.
1439which holds the definition for the event that immediately follows 1411Interpreting a key sequence of multiple events involves a chain of
1440that prefix. 1412keymaps: the first keymap gives a definition for the first event,
1413which is another keymap, which is used to look up the second event in
1414the sequence, and so on. Thus, a prefix key such as @kbd{C-x} or
1415@key{ESC} has its own keymap, which holds the definition for the event
1416that immediately follows that prefix.
1441 1417
1442 The definition of a prefix key is usually the keymap to use for 1418 The definition of a prefix key is usually the keymap to use for
1443looking up the following event. The definition can also be a Lisp 1419looking up the following event. The definition can also be a Lisp
@@ -1631,11 +1607,6 @@ M-x global-set-key @key{RET} C-x 4 $ spell-other-window @key{RET}
1631redefines @kbd{C-x 4 $} to run the (fictitious) command 1607redefines @kbd{C-x 4 $} to run the (fictitious) command
1632@code{spell-other-window}. 1608@code{spell-other-window}.
1633 1609
1634 The two-character keys consisting of @kbd{C-c} followed by a letter
1635are reserved for user customizations. Lisp programs are not supposed to
1636define these keys, so the bindings you make for them will be available
1637in all major modes and will never get in the way of anything.
1638
1639 You can remove the global definition of a key with 1610 You can remove the global definition of a key with
1640@code{global-unset-key}. This makes the key @dfn{undefined}; if you 1611@code{global-unset-key}. This makes the key @dfn{undefined}; if you
1641type it, Emacs will just beep. Similarly, @code{local-unset-key} makes 1612type it, Emacs will just beep. Similarly, @code{local-unset-key} makes
@@ -1660,67 +1631,68 @@ command is less work to invoke when you really want to.
1660@c it, the tutorial needs to be adjusted. (TUTORIAL.de) 1631@c it, the tutorial needs to be adjusted. (TUTORIAL.de)
1661 1632
1662 If you have a set of key bindings that you like to use all the time, 1633 If you have a set of key bindings that you like to use all the time,
1663you can specify them in your @file{.emacs} file by using their Lisp 1634you can specify them in your initialization file by writing Lisp code
1664syntax. (@xref{Init File}.) 1635(@pxref{Init File}).
1665 1636
1666 The simplest method for doing this works for @acronym{ASCII} characters and 1637@findex kbd
1667Meta-modified @acronym{ASCII} characters only. This method uses a string to 1638 There are several ways to write a key binding using Lisp. The
1668represent the key sequence you want to rebind. For example, here's how 1639simplest is to use the @code{kbd} macro, which converts a textual
1669to bind @kbd{C-z} to @code{shell}: 1640representation of a key sequence---similar to how we have written key
1641sequences in this manual---into a form that can be passed as an
1642argument to @code{global-set-key}. For example, here's how to bind
1643@kbd{C-z} to @code{shell} (@pxref{Interactive Shell}):
1670 1644
1671@example 1645@example
1672(global-set-key "\C-z" 'shell) 1646(global-set-key (kbd "C-z") 'shell)
1673@end example 1647@end example
1674 1648
1675@noindent 1649@noindent
1676This example uses a string constant containing one character, 1650The single-quote before the command name, @code{shell}, marks it as a
1677@kbd{C-z}. (@samp{\C-} is string syntax for a control character.) The
1678single-quote before the command name, @code{shell}, marks it as a
1679constant symbol rather than a variable. If you omit the quote, Emacs 1651constant symbol rather than a variable. If you omit the quote, Emacs
1680would try to evaluate @code{shell} immediately as a variable. This 1652would try to evaluate @code{shell} as a variable. This probably
1681probably causes an error; it certainly isn't what you want. 1653causes an error; it certainly isn't what you want.
1682 1654
1683 Here is another example that binds the key sequence @kbd{C-x M-l}: 1655 Here are some additional examples, including binding function keys
1656and mouse events:
1684 1657
1685@example 1658@example
1686(global-set-key "\C-x\M-l" 'make-symbolic-link) 1659(global-set-key (kbd "C-c y") 'clipboard-yank)
1660(global-set-key (kbd "C-M-q") 'query-replace)
1661(global-set-key (kbd "<f5>") 'flyspell-mode)
1662(global-set-key (kbd "C-<f5>") 'linum-mode)
1663(global-set-key (kbd "C-<right>") 'forward-sentence)
1664(global-set-key (kbd "<mouse-2>") 'mouse-save-then-kill)
1665(global-set-key (kbd "C-<down-mouse-3>") 'mouse-yank-at-click)
1687@end example 1666@end example
1688 1667
1689 To put @key{TAB}, @key{RET}, @key{ESC}, or @key{DEL} in the 1668 Instead of using the @code{kbd} macro, you can use a Lisp string or
1690string, you can use the Emacs Lisp escape sequences, @samp{\t}, 1669vector to specify the key sequence. Using a string is simpler, but
1691@samp{\r}, @samp{\e}, and @samp{\d}. Here is an example which binds 1670only works for @acronym{ASCII} characters and Meta-modified
1692@kbd{C-x @key{TAB}}: 1671@acronym{ASCII} characters. For example, here's how to bind @kbd{C-x
1672M-l} to @code{make-symbolic-link} (@pxref{Misc File Ops}):
1693 1673
1694@example 1674@example
1695(global-set-key "\C-x\t" 'indent-rigidly) 1675(global-set-key "\C-x\M-l" 'make-symbolic-link)
1696@end example 1676@end example
1697 1677
1698 These examples show how to write some other special @acronym{ASCII} characters 1678 To put @key{TAB}, @key{RET}, @key{ESC}, or @key{DEL} in the string,
1699in strings for key bindings: 1679use the Emacs Lisp escape sequences @samp{\t}, @samp{\r}, @samp{\e},
1680and @samp{\d} respectively. Here is an example which binds @kbd{C-x
1681@key{TAB}} to @code{indent-rigidly} (@pxref{Indentation}):
1700 1682
1701@example 1683@example
1702(global-set-key "\r" 'newline) ;; @key{RET} 1684(global-set-key "\C-x\t" 'indent-rigidly)
1703(global-set-key "\d" 'delete-backward-char) ;; @key{DEL}
1704(global-set-key "\C-x\e\e" 'repeat-complex-command) ;; @key{ESC}
1705@end example 1685@end example
1706 1686
1707 When the key sequence includes function keys or mouse button events, 1687 When the key sequence includes function keys or mouse button events,
1708or non-@acronym{ASCII} characters such as @code{C-=} or @code{H-a}, you must use 1688or non-@acronym{ASCII} characters such as @code{C-=} or @code{H-a},
1709the more general method of rebinding, which uses a vector to specify the 1689you must use a vector to specify the key sequence. Each element in
1710key sequence. 1690the vector stands for an input event; the elements are separated by
1711 1691spaces and surrounded by a pair of square brackets. If an element is
1712 The way to write a vector in Emacs Lisp is with square brackets around 1692a symbol, simply write the symbol's name---no other delimiters or
1713the vector elements. Use spaces to separate the elements. If an 1693punctuation are needed. If a vector element is a character, write it
1714element is a symbol, simply write the symbol's name---no other 1694as a Lisp character constant: @samp{?} followed by the character as it
1715delimiters or punctuation are needed. If a vector element is a 1695would appear in a string. Here are some examples:
1716character, write it as a Lisp character constant: @samp{?} followed by
1717the character as it would appear in a string.
1718
1719 Here are examples of using vectors to rebind @kbd{C-=} (a control
1720character not in @acronym{ASCII}), @kbd{C-M-=} (not in @acronym{ASCII} because @kbd{C-=}
1721is not), @kbd{H-a} (a Hyper character; @acronym{ASCII} doesn't have Hyper at
1722all), @key{F7} (a function key), and @kbd{C-Mouse-1} (a
1723keyboard-modified mouse button):
1724 1696
1725@example 1697@example
1726(global-set-key [?\C-=] 'make-symbolic-link) 1698(global-set-key [?\C-=] 'make-symbolic-link)
@@ -1730,25 +1702,15 @@ keyboard-modified mouse button):
1730(global-set-key [C-mouse-1] 'make-symbolic-link) 1702(global-set-key [C-mouse-1] 'make-symbolic-link)
1731@end example 1703@end example
1732 1704
1733 You can use a vector for the simple cases too. Here's how to 1705@noindent
1734rewrite the first six examples above to use vectors: 1706You can use a vector for the simple cases too:
1735 1707
1736@example 1708@example
1737(global-set-key [?\C-z] 'shell) 1709(global-set-key [?\C-z ?\M-l] 'make-symbolic-link)
1738(global-set-key [?\C-x ?l] 'make-symbolic-link)
1739(global-set-key [?\C-x ?\t] 'indent-rigidly)
1740(global-set-key [?\r] 'newline)
1741(global-set-key [?\d] 'delete-backward-char)
1742(global-set-key [?\C-x ?\e ?\e] 'repeat-complex-command)
1743@end example 1710@end example
1744 1711
1745@noindent 1712 Language and coding systems may cause problems with key bindings for
1746As you see, you represent a multi-character key sequence with a vector 1713non-@acronym{ASCII} characters. @xref{Init Non-ASCII}.
1747by listing all of the characters, in order, within the square brackets
1748that delimit the vector.
1749
1750 Language and coding systems can cause problems with key bindings
1751for non-@acronym{ASCII} characters. @xref{Init Non-ASCII}.
1752 1714
1753@node Modifier Keys 1715@node Modifier Keys
1754@subsection Modifier Keys 1716@subsection Modifier Keys
@@ -1762,8 +1724,8 @@ and does not apply to ``shifted'' versions of other keys; for
1762instance, @kbd{C-@@} is not the same as @kbd{C-2}. 1724instance, @kbd{C-@@} is not the same as @kbd{C-2}.
1763 1725
1764 When you customize Emacs, you can make modified alphabetical 1726 When you customize Emacs, you can make modified alphabetical
1765characters case-sensitive way. For instance, you could make @kbd{M-a} 1727characters case-sensitive. For instance, you could make @kbd{M-a} and
1766and @kbd{M-A} run different commands. 1728@kbd{M-A} run different commands.
1767 1729
1768 As a special exception, a @key{Control}-modified alphabetical 1730 As a special exception, a @key{Control}-modified alphabetical
1769character is always case-insensitive, for historical reasons: Emacs 1731character is always case-insensitive, for historical reasons: Emacs
@@ -1830,52 +1792,7 @@ X) may use different names. To make certain what symbol is used for a
1830given function key on your terminal, type @kbd{C-h c} followed by that 1792given function key on your terminal, type @kbd{C-h c} followed by that
1831key. 1793key.
1832 1794
1833 A key sequence which contains function key symbols (or anything but 1795 @xref{Init Rebinding}, for examples of binding function keys.
1834@acronym{ASCII} characters) must be a vector rather than a string.
1835Thus, to bind function key @samp{f1} to the command @code{rmail},
1836write the following:
1837
1838@example
1839(global-set-key [f1] 'rmail)
1840@end example
1841
1842@noindent
1843To bind the right-arrow key to the command @code{forward-char}, you can
1844use this expression:
1845
1846@example
1847(global-set-key [right] 'forward-char)
1848@end example
1849
1850@noindent
1851This uses the Lisp syntax for a vector containing the symbol
1852@code{right}. (This binding is present in Emacs by default.)
1853
1854 @xref{Init Rebinding}, for more information about using vectors for
1855rebinding.
1856
1857 You can mix function keys and characters in a key sequence. This
1858example binds @kbd{C-x @key{NEXT}} to the command @code{forward-page}.
1859
1860@example
1861(global-set-key [?\C-x next] 'forward-page)
1862@end example
1863
1864@noindent
1865where @code{?\C-x} is the Lisp character constant for the character
1866@kbd{C-x}. The vector element @code{next} is a symbol and therefore
1867does not take a question mark.
1868
1869 You can use the modifier keys @key{Control}, @key{Meta},
1870@key{Hyper}, @key{Super}, @key{Alt} and @key{Shift} with function
1871keys. To represent these modifiers, add the strings @samp{C-},
1872@samp{M-}, @samp{H-}, @samp{s-}, @samp{A-} and @samp{S-} at the front
1873of the symbol name. Thus, here is how to make
1874@kbd{Hyper-Meta-@key{RIGHT}} move forward a word:
1875
1876@example
1877(global-set-key [H-M-right] 'forward-word)
1878@end example
1879 1796
1880@cindex keypad 1797@cindex keypad
1881 Many keyboards have a ``numeric keypad'' on the right hand side. 1798 Many keyboards have a ``numeric keypad'' on the right hand side.
@@ -1910,8 +1827,8 @@ used so often that they have special keys of their own. For instance,
1910@key{TAB} was another name for @kbd{C-i}. Later, users found it 1827@key{TAB} was another name for @kbd{C-i}. Later, users found it
1911convenient to distinguish in Emacs between these keys and the ``same'' 1828convenient to distinguish in Emacs between these keys and the ``same''
1912control characters typed with the @key{CTRL} key. Therefore, on most 1829control characters typed with the @key{CTRL} key. Therefore, on most
1913modern terminals, they are no longer the same, and @key{TAB} is 1830modern terminals, they are no longer the same: @key{TAB} is different
1914distinguishable from @kbd{C-i}. 1831from @kbd{C-i}.
1915 1832
1916 Emacs can distinguish these two kinds of input if the keyboard does. 1833 Emacs can distinguish these two kinds of input if the keyboard does.
1917It treats the ``special'' keys as function keys named @code{tab}, 1834It treats the ``special'' keys as function keys named @code{tab},
@@ -2152,16 +2069,17 @@ Reference Manual}.
2152@cindex rebinding keys, permanently 2069@cindex rebinding keys, permanently
2153@cindex startup (init file) 2070@cindex startup (init file)
2154 2071
2155 When Emacs is started, it normally loads a Lisp program from the file 2072 When Emacs is started, it normally tries to load a Lisp program from
2156@file{.emacs} or @file{.emacs.el} in your home directory (@pxref{Find Init}). 2073an @dfn{initialization file}, or @dfn{init file} for short. This
2157We call this file your @dfn{init file} because it specifies how to 2074file, if it exists, specifies how to initialize Emacs for you. Emacs
2158initialize Emacs for you. You can use the command line switch 2075looks for your init file using the filenames @file{~/.emacs},
2159@samp{-q} to prevent loading your init file, and @samp{-u} (or 2076@file{~/.emacs.el}, or @file{~/.emacs.d/init.el}; you can choose to
2160@samp{--user}) to specify a different user's init file (@pxref{Initial 2077use any one of these three names (@pxref{Find Init}). Here, @file{~/}
2161Options}). 2078stands for your home directory.
2162 2079
2163 You can also use @file{~/.emacs.d/init.el} as the init file. Emacs 2080 You can use the command line switch @samp{-q} to prevent loading
2164tries this if it cannot find @file{~/.emacs} or @file{~/.emacs.el}. 2081your init file, and @samp{-u} (or @samp{--user}) to specify a
2082different user's init file (@pxref{Initial Options}).
2165 2083
2166@cindex @file{default.el}, the default init file 2084@cindex @file{default.el}, the default init file
2167 There can also be a @dfn{default init file}, which is the library 2085 There can also be a @dfn{default init file}, which is the library
@@ -2192,14 +2110,14 @@ Many sites put these files in the @file{site-lisp} subdirectory of the
2192Emacs installation directory, typically 2110Emacs installation directory, typically
2193@file{/usr/local/share/emacs/site-lisp}. 2111@file{/usr/local/share/emacs/site-lisp}.
2194 2112
2195 Byte-compiling your @file{.emacs} is not recommended (@pxref{Byte 2113 Byte-compiling your init file is not recommended (@pxref{Byte
2196Compilation,, Byte Compilation, elisp, the Emacs Lisp Reference 2114Compilation,, Byte Compilation, elisp, the Emacs Lisp Reference
2197Manual}). It generally does not speed up startup very much, and often 2115Manual}). It generally does not speed up startup very much, and often
2198leads to problems when you forget to recompile the file. A better 2116leads to problems when you forget to recompile the file. A better
2199solution is to use the Emacs server to reduce the number of times you 2117solution is to use the Emacs server to reduce the number of times you
2200have to start Emacs (@pxref{Emacs Server}). If your @file{.emacs} 2118have to start Emacs (@pxref{Emacs Server}). If your init file defines
2201defines many functions, consider moving them to a separate 2119many functions, consider moving them to a separate (byte-compiled)
2202(byte-compiled) file that you load in your @file{.emacs}. 2120file that you load in your init file.
2203 2121
2204 If you are going to write actual Emacs Lisp programs that go beyond 2122 If you are going to write actual Emacs Lisp programs that go beyond
2205minor customization, you should read the @cite{Emacs Lisp Reference Manual}. 2123minor customization, you should read the @cite{Emacs Lisp Reference Manual}.
@@ -2219,11 +2137,11 @@ Manual}.
2219@node Init Syntax 2137@node Init Syntax
2220@subsection Init File Syntax 2138@subsection Init File Syntax
2221 2139
2222 The @file{.emacs} file contains one or more Lisp function call 2140 The init file contains one or more Lisp expressions. Each of these
2223expressions. Each of these consists of a function name followed by 2141consists of a function name followed by arguments, all surrounded by
2224arguments, all surrounded by parentheses. For example, @code{(setq 2142parentheses. For example, @code{(setq fill-column 60)} calls the
2225fill-column 60)} calls the function @code{setq} to set the variable 2143function @code{setq} to set the variable @code{fill-column}
2226@code{fill-column} (@pxref{Filling}) to 60. 2144(@pxref{Filling}) to 60.
2227 2145
2228 You can set any Lisp variable with @code{setq}, but with certain 2146 You can set any Lisp variable with @code{setq}, but with certain
2229variables @code{setq} won't do what you probably want in the 2147variables @code{setq} won't do what you probably want in the