Add 2010 to copyright years.
[bpt/emacs.git] / doc / emacs / commands.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
62eda0e2 2@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2001, 2002,
114f9c96 3@c 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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
9commands, and the fundamental concepts of @dfn{keys} and
10@dfn{commands}, whereby Emacs interprets your keyboard and mouse
11input.
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
26@cindex control characters
27
9bb75d26
CY
28 GNU Emacs is primarily designed for use with the keyboard. While it
29is possible to use the mouse to issue editing commands through the
30menu bar and tool bar, that is not as efficient as using the keyboard.
31Therefore, this manual mainly documents how to edit with the keyboard.
32
33 Keyboard input into Emacs is based on a heavily-extended version of
34@acronym{ASCII}. The simplest characters that you can input into
35Emacs correspond to graphic symbols such as @samp{a}, @samp{B},
36@samp{3}, @samp{=}, the space character (conventionally denoted as
37@key{SPC}), and so on. Entering these using the keyboard is
38straightforward. Certain characters found on non-English keyboards
39also fall into this category (@pxref{International}).
40
41 In addition to these simple characters, Emacs recognizes
42@dfn{control characters} such as @key{RET}, @key{TAB}, @key{DEL},
43@key{ESC}, @key{F1}, @key{Home}, @key{left}, etc. Most keyboards have
44special keys for entering these.
45
46@cindex modifier keys
47@cindex Control
48@cindex C-
6bf7aab6
DL
49@cindex Meta
50@cindex M-
9bb75d26
CY
51 Emacs also recognizes control characters that are entered using
52@dfn{modifier keys}. Two commonly-used modifier keys are
53@key{Control} (which is usually labelled as @key{Ctrl}), and
54@key{Meta} (which is usually labeled as @key{Alt})@footnote{We refer
55to @key{Alt} as @key{Meta} for historical reasons.}. For example,
56@kbd{Control-a} is entered by holding down the @key{Ctrl} key while
57pressing @kbd{a}; we will refer to this as @kbd{C-a} for short.
58Similarly @kbd{Meta-a}, or @kbd{M-a} for short, is entered by holding
59down the @key{Alt} key and pressing @kbd{a}.
60
61@cindex @key{ESC} replacing @key{Meta} key
62 You can also type Meta characters using two-character sequences
63starting with @key{ESC}. Thus, you can enter @kbd{M-a} by typing
64@kbd{@key{ESC} a}. You can enter @kbd{C-M-a} by typing @kbd{@key{ESC}
65C-a}. Unlike @key{Meta}, @key{ESC} is entered as a separate
66character. You don't hold down @key{ESC} while typing the next
67character; instead, press @key{ESC} and release it, then enter the
68next character. This feature is useful on certain text-only terminals
69where the @key{Meta} key does not function reliably.
70
71 Modifier keys can apply not only to alphanumerical characters, but
72also to special input characters, such as the arrow keys and mouse
73buttons.
6bf7aab6
DL
74
75@cindex input event
9bb75d26
CY
76 @xref{Input Events,,, elisp, The Emacs Lisp Reference Manual}, for
77the full Lisp-level details about keyboard and mouse input, which are
78collectively referred to as @dfn{input events}. If you are not doing
79Lisp programming, but simply want to redefine the meaning of some
80characters or non-character events, see @ref{Customization}.
6bf7aab6 81
596258f4
RS
82@cindex keys stolen by window manager
83@cindex window manager, keys stolen by
84 On graphical displays, the window manager is likely to block the
9bb75d26
CY
85character @kbd{M-@key{TAB}} before Emacs can see it. It may also
86block @kbd{M-@key{SPC}}, @kbd{C-M-d} and @kbd{C-M-l}. If you have
596258f4
RS
87these problems, we recommend that you customize your window manager to
88turn off those commands, or put them on key combinations that Emacs
89does not use.
90
6bf7aab6
DL
91@node Keys, Commands, User Input, Top
92@section Keys
93
9bb75d26
CY
94 Some Emacs commands are invoked by just one input event; for
95example, @kbd{C-f} moves forward one character in the buffer. But
96Emacs also has commands that take two or more input events to invoke,
97such as @kbd{C-x C-f} and @kbd{C-x 4 C-f}.
6bf7aab6 98
9bb75d26
CY
99@cindex key
100@cindex key sequence
6bf7aab6
DL
101@cindex complete key
102@cindex prefix key
9bb75d26
CY
103 A @dfn{key sequence}, or @dfn{key} for short, is a sequence of one
104or more input events that is meaningful as a unit. If a key sequence
105invokes a command, we call it a @dfn{complete key}; for example,
106@kbd{C-f}, @kbd{C-x C-f} and @kbd{C-x 4 C-f} are all complete keys.
107If a key sequence isn't long enough to invoke a command, we call it a
108@dfn{prefix key}; from the preceding example, we see that @kbd{C-x}
109and @kbd{C-x 4} are prefix keys. Every key is either a complete key
110or a prefix key.
111
112 A prefix key combines with the following input event to make a
113longer key sequence, which may itself be complete or a prefix. For
114example, @kbd{C-x} is a prefix key, so @kbd{C-x} and the next input
115event combine to make a two-event key sequence. This two-event key
116sequence could itself be a prefix key (such as @kbd{C-x 4}), or a
117complete key (such as @kbd{C-x C-f}). There is no limit to the length
118of a key sequence, but in practice people rarely use sequences longer
119than three or four input events.
6bf7aab6 120
a1864eeb
RS
121 You can't add input events onto a complete key. For example, the
122two-event sequence @kbd{C-f C-k} is not a key, because the @kbd{C-f}
9bb75d26 123is a complete key in itself, so @kbd{C-f C-k} cannot have an
a1864eeb
RS
124independent meaning as a command. @kbd{C-f C-k} is two key sequences,
125not one.@refill
6bf7aab6 126
9bb75d26 127 By default, the prefix keys in Emacs are @kbd{C-c}, @kbd{C-h},
35ea7c7c 128@kbd{C-x}, @kbd{C-x @key{RET}}, @kbd{C-x @@}, @kbd{C-x a}, @kbd{C-x
9bb75d26
CY
129n}, @kbd{C-x r}, @kbd{C-x v}, @kbd{C-x 4}, @kbd{C-x 5}, @kbd{C-x 6},
130@key{ESC}, @kbd{M-g}, and @kbd{M-o}. (@key{F1} and @key{F2} are
131aliases for @kbd{C-h} and @kbd{C-x 6}.) This list is not cast in
132stone; if you customize Emacs, you can make new prefix keys. You
133could even eliminate some of the standard ones, though this is not
134recommended for most users; for example, if you remove the prefix
135definition of @kbd{C-x 4}, then @kbd{C-x 4 @var{anything}} would
136become an invalid key sequence. @xref{Key Bindings}.
6bf7aab6 137
a85cdd1f 138 Typing the help character (@kbd{C-h} or @key{F1}) after a prefix key
9bb75d26
CY
139displays a list of the commands starting with that prefix. The sole
140exception to this rule is @key{ESC}: @kbd{@key{ESC}C-h} is equivalent
141to @kbd{C-M-h}, which does something else entirely. You can, however,
142use @key{F1} to displays a list of the commands starting with
143@key{ESC}.
177c0ea7 144
9bb75d26 145@node Commands, Entering Emacs, Keys, Top
6bf7aab6
DL
146@section Keys and Commands
147
148@cindex binding
6bf7aab6
DL
149@cindex command
150@cindex function definition
151 This manual is full of passages that tell you what particular keys
152do. But Emacs does not assign meanings to keys directly. Instead,
153Emacs assigns meanings to named @dfn{commands}, and then gives keys
154their meanings by @dfn{binding} them to commands.
155
a1864eeb
RS
156 Every command has a name chosen by a programmer. The name is
157usually made of a few English words separated by dashes; for example,
6bf7aab6 158@code{next-line} or @code{forward-word}. A command also has a
a1864eeb 159@dfn{function definition} which is a Lisp program; this is how the
9bb75d26
CY
160command does its work. In Emacs Lisp, a command is a Lisp function
161with special properties that make it suitable for interactive use.
162For more information on commands and functions, see @ref{What Is a
163Function,, What Is a Function, elisp, The Emacs Lisp Reference
164Manual}.
6bf7aab6 165
a1864eeb
RS
166 The bindings between keys and commands are recorded in tables called
167@dfn{keymaps}. @xref{Keymaps}.
6bf7aab6
DL
168
169 When we say that ``@kbd{C-n} moves down vertically one line'' we are
a1864eeb
RS
170glossing over a subtle distinction that is irrelevant in ordinary use,
171but vital for Emacs customization. The command @code{next-line} does
172a vertical move downward. @kbd{C-n} has this effect @emph{because} it
173is bound to @code{next-line}. If you rebind @kbd{C-n} to the command
174@code{forward-word}, @kbd{C-n} will move forward one word instead.
6bf7aab6 175
9bb75d26 176 In this manual, we will often speak of keys like @kbd{C-n} as
a1864eeb
RS
177commands, even though strictly speaking the key is bound to a command.
178Usually we state the name of the command which really does the work in
179parentheses after mentioning the key that runs it. For example, we
180will say that ``The command @kbd{C-n} (@code{next-line}) moves point
181vertically down,'' meaning that the command @code{next-line} moves
182vertically down, and the key @kbd{C-n} is normally bound to it.
183
184 Since we are discussing customization, we should tell you about
185@dfn{variables}. Often the description of a command will say, ``To
186change this, set the variable @code{mumble-foo}.'' A variable is a
187name used to store a value. Most of the variables documented in this
188manual are meant for customization: some command or other part of
189Emacs examines the variable and behaves differently according to the
190value that you set. You can ignore the information about variables
191until you are interested in customizing them. Then read the basic
192information on variables (@pxref{Variables}) and the information about
193specific variables will make sense.
6bf7aab6 194
6cca5de0
LT
195@ifnottex
196@lowersections
197@end ifnottex
198
ab5796a9
MB
199@ignore
200 arch-tag: 9be43eef-d1f4-4d03-a916-c741ea713a45
201@end ignore