Commit | Line | Data |
---|---|---|
6bf7aab6 | 1 | @c This is part of the Emacs manual. |
73b0cd50 GM |
2 | @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2011 |
3 | @c Free Software Foundation, Inc. | |
6bf7aab6 DL |
4 | @c See file emacs.texi for copying conditions. |
5 | @iftex | |
6 | @chapter Characters, Keys and Commands | |
7 | ||
8 | This chapter explains the character sets used by Emacs for input | |
9bb75d26 CY |
9 | commands, and the fundamental concepts of @dfn{keys} and |
10 | @dfn{commands}, whereby Emacs interprets your keyboard and mouse | |
11 | input. | |
6bf7aab6 DL |
12 | @end iftex |
13 | ||
6cca5de0 LT |
14 | @ifnottex |
15 | @raisesections | |
16 | @end ifnottex | |
17 | ||
6bf7aab6 DL |
18 | @node User Input, Keys, Screen, Top |
19 | @section Kinds of User Input | |
20 | @cindex input with the keyboard | |
21 | @cindex keyboard input | |
22 | @cindex character set (keyboard) | |
76dd3692 | 23 | @cindex @acronym{ASCII} |
6bf7aab6 DL |
24 | @cindex C- |
25 | @cindex Control | |
6bf7aab6 | 26 | |
9bb75d26 CY |
27 | GNU Emacs is primarily designed for use with the keyboard. While it |
28 | is possible to use the mouse to issue editing commands through the | |
29 | menu bar and tool bar, that is not as efficient as using the keyboard. | |
30 | Therefore, this manual mainly documents how to edit with the keyboard. | |
31 | ||
de0bde62 | 32 | @cindex control character |
9bb75d26 | 33 | Keyboard input into Emacs is based on a heavily-extended version of |
de0bde62 CY |
34 | @acronym{ASCII}. Simple characters, like @samp{a}, @samp{B}, |
35 | @samp{3}, @samp{=}, and the space character (denoted as @key{SPC}), | |
36 | are entered by typing the corresponding key. @dfn{Control | |
37 | characters}, such as @key{RET}, @key{TAB}, @key{DEL}, @key{ESC}, | |
38 | @key{F1}, @key{Home}, and @key{left}, are also entered this way, as | |
39 | are certain characters found on non-English keyboards | |
40 | (@pxref{International}). | |
9bb75d26 CY |
41 | |
42 | @cindex modifier keys | |
43 | @cindex Control | |
44 | @cindex C- | |
6bf7aab6 DL |
45 | @cindex Meta |
46 | @cindex M- | |
9bb75d26 CY |
47 | Emacs also recognizes control characters that are entered using |
48 | @dfn{modifier keys}. Two commonly-used modifier keys are | |
de0bde62 CY |
49 | @key{Control} (usually labelled @key{Ctrl}), and @key{Meta} (usually |
50 | labeled @key{Alt})@footnote{We refer to @key{Alt} as @key{Meta} for | |
51 | historical reasons.}. For example, @kbd{Control-a} is entered by | |
52 | holding down the @key{Ctrl} key while pressing @kbd{a}; we will refer | |
53 | to this as @kbd{C-a} for short. Similarly @kbd{Meta-a}, or @kbd{M-a} | |
54 | for short, is entered by holding down the @key{Alt} key and pressing | |
55 | @kbd{a}. Modifier keys can also be applied to non-alphanumerical | |
56 | characters, e.g. @kbd{C-@key{F1}} or @kbd{M-@key{left}}. | |
9bb75d26 CY |
57 | |
58 | @cindex @key{ESC} replacing @key{Meta} key | |
59 | You can also type Meta characters using two-character sequences | |
60 | starting with @key{ESC}. Thus, you can enter @kbd{M-a} by typing | |
61 | @kbd{@key{ESC} a}. You can enter @kbd{C-M-a} by typing @kbd{@key{ESC} | |
62 | C-a}. Unlike @key{Meta}, @key{ESC} is entered as a separate | |
63 | character. You don't hold down @key{ESC} while typing the next | |
64 | character; instead, press @key{ESC} and release it, then enter the | |
65 | next character. This feature is useful on certain text-only terminals | |
66 | where the @key{Meta} key does not function reliably. | |
67 | ||
596258f4 RS |
68 | @cindex keys stolen by window manager |
69 | @cindex window manager, keys stolen by | |
de0bde62 CY |
70 | On graphical displays, the window manager might block some keyboard |
71 | inputs, including @kbd{M-@key{TAB}}, @kbd{M-@key{SPC}}, @kbd{C-M-d} | |
72 | and @kbd{C-M-l}. If you have this problem, you can either customize | |
73 | your window manager to not block those keys, or ``rebind'' the | |
74 | affected Emacs commands (@pxref{Customization}). | |
75 | ||
76 | @cindex input event | |
77 | Simple characters and control characters, as well as certain | |
78 | non-keyboard inputs such as mouse clicks, are collectively referred to | |
79 | as @dfn{input events}. For details about how Emacs internally handles | |
80 | input events, see @ref{Input Events,,, elisp, The Emacs Lisp Reference | |
81 | Manual}. | |
596258f4 | 82 | |
6bf7aab6 DL |
83 | @node Keys, Commands, User Input, Top |
84 | @section Keys | |
85 | ||
9bb75d26 | 86 | Some Emacs commands are invoked by just one input event; for |
de0bde62 CY |
87 | example, @kbd{C-f} moves forward one character in the buffer. Other |
88 | commands take two or more input events to invoke, such as @kbd{C-x | |
89 | C-f} and @kbd{C-x 4 C-f}. | |
6bf7aab6 | 90 | |
9bb75d26 CY |
91 | @cindex key |
92 | @cindex key sequence | |
6bf7aab6 DL |
93 | @cindex complete key |
94 | @cindex prefix key | |
9bb75d26 CY |
95 | A @dfn{key sequence}, or @dfn{key} for short, is a sequence of one |
96 | or more input events that is meaningful as a unit. If a key sequence | |
97 | invokes a command, we call it a @dfn{complete key}; for example, | |
98 | @kbd{C-f}, @kbd{C-x C-f} and @kbd{C-x 4 C-f} are all complete keys. | |
99 | If a key sequence isn't long enough to invoke a command, we call it a | |
100 | @dfn{prefix key}; from the preceding example, we see that @kbd{C-x} | |
de0bde62 CY |
101 | and @kbd{C-x 4} are prefix keys. Every key sequence is either a |
102 | complete key or a prefix key. | |
9bb75d26 CY |
103 | |
104 | A prefix key combines with the following input event to make a | |
de0bde62 CY |
105 | longer key sequence. For example, @kbd{C-x} is a prefix key, so |
106 | typing @kbd{C-x} alone does not invoke a command; instead, Emacs waits | |
107 | for further input (if you pause for longer than a second, it echoes | |
108 | the @kbd{C-x} key to prompt for that input; @pxref{Echo Area}). | |
109 | @kbd{C-x} combines with the next input event to make a two-event key | |
110 | sequence, which could itself be a prefix key (such as @kbd{C-x 4}), or | |
111 | a complete key (such as @kbd{C-x C-f}). There is no limit to the | |
112 | length of key sequences, but in practice they are seldom longer than | |
113 | three or four input events. | |
114 | ||
115 | You can't add input events onto a complete key. For example, | |
116 | because @kbd{C-f} is a complete key, the two-event sequence @kbd{C-f | |
117 | C-k} is two key sequences, not one. | |
6bf7aab6 | 118 | |
9bb75d26 | 119 | By default, the prefix keys in Emacs are @kbd{C-c}, @kbd{C-h}, |
35ea7c7c | 120 | @kbd{C-x}, @kbd{C-x @key{RET}}, @kbd{C-x @@}, @kbd{C-x a}, @kbd{C-x |
9bb75d26 CY |
121 | n}, @kbd{C-x r}, @kbd{C-x v}, @kbd{C-x 4}, @kbd{C-x 5}, @kbd{C-x 6}, |
122 | @key{ESC}, @kbd{M-g}, and @kbd{M-o}. (@key{F1} and @key{F2} are | |
123 | aliases for @kbd{C-h} and @kbd{C-x 6}.) This list is not cast in | |
124 | stone; if you customize Emacs, you can make new prefix keys. You | |
125 | could even eliminate some of the standard ones, though this is not | |
126 | recommended for most users; for example, if you remove the prefix | |
de0bde62 CY |
127 | definition of @kbd{C-x 4}, then @kbd{C-x 4 C-f} becomes an invalid key |
128 | sequence. @xref{Key Bindings}. | |
6bf7aab6 | 129 | |
a85cdd1f | 130 | Typing the help character (@kbd{C-h} or @key{F1}) after a prefix key |
9bb75d26 | 131 | displays a list of the commands starting with that prefix. The sole |
9229fe87 | 132 | exception to this rule is @key{ESC}: @kbd{@key{ESC} C-h} is equivalent |
9bb75d26 | 133 | to @kbd{C-M-h}, which does something else entirely. You can, however, |
de0bde62 | 134 | use @key{F1} to display a list of commands starting with @key{ESC}. |
177c0ea7 | 135 | |
9bb75d26 | 136 | @node Commands, Entering Emacs, Keys, Top |
6bf7aab6 DL |
137 | @section Keys and Commands |
138 | ||
139 | @cindex binding | |
6bf7aab6 | 140 | @cindex command |
6bf7aab6 DL |
141 | This manual is full of passages that tell you what particular keys |
142 | do. But Emacs does not assign meanings to keys directly. Instead, | |
143 | Emacs assigns meanings to named @dfn{commands}, and then gives keys | |
144 | their meanings by @dfn{binding} them to commands. | |
145 | ||
a1864eeb RS |
146 | Every command has a name chosen by a programmer. The name is |
147 | usually made of a few English words separated by dashes; for example, | |
de0bde62 CY |
148 | @code{next-line} or @code{forward-word}. Internally, each command is |
149 | a special type of Lisp @dfn{function}, and the actions associated with | |
150 | the command are performed by running the function. @xref{What Is a | |
9bb75d26 CY |
151 | Function,, What Is a Function, elisp, The Emacs Lisp Reference |
152 | Manual}. | |
6bf7aab6 | 153 | |
a1864eeb RS |
154 | The bindings between keys and commands are recorded in tables called |
155 | @dfn{keymaps}. @xref{Keymaps}. | |
6bf7aab6 DL |
156 | |
157 | When we say that ``@kbd{C-n} moves down vertically one line'' we are | |
a1864eeb RS |
158 | glossing over a subtle distinction that is irrelevant in ordinary use, |
159 | but vital for Emacs customization. The command @code{next-line} does | |
160 | a vertical move downward. @kbd{C-n} has this effect @emph{because} it | |
161 | is bound to @code{next-line}. If you rebind @kbd{C-n} to the command | |
162 | @code{forward-word}, @kbd{C-n} will move forward one word instead. | |
6bf7aab6 | 163 | |
9bb75d26 | 164 | In this manual, we will often speak of keys like @kbd{C-n} as |
a1864eeb RS |
165 | commands, even though strictly speaking the key is bound to a command. |
166 | Usually we state the name of the command which really does the work in | |
167 | parentheses after mentioning the key that runs it. For example, we | |
168 | will say that ``The command @kbd{C-n} (@code{next-line}) moves point | |
169 | vertically down,'' meaning that the command @code{next-line} moves | |
170 | vertically down, and the key @kbd{C-n} is normally bound to it. | |
171 | ||
172 | Since we are discussing customization, we should tell you about | |
173 | @dfn{variables}. Often the description of a command will say, ``To | |
174 | change this, set the variable @code{mumble-foo}.'' A variable is a | |
175 | name used to store a value. Most of the variables documented in this | |
176 | manual are meant for customization: some command or other part of | |
177 | Emacs examines the variable and behaves differently according to the | |
178 | value that you set. You can ignore the information about variables | |
179 | until you are interested in customizing them. Then read the basic | |
180 | information on variables (@pxref{Variables}) and the information about | |
181 | specific variables will make sense. | |
6bf7aab6 | 182 | |
6cca5de0 LT |
183 | @ifnottex |
184 | @lowersections | |
185 | @end ifnottex |