Go to the previous, next section.
This chapter explains the character set used by Emacs for input commands and for the contents of files, and also explains the concepts of keys and commands which are necessary for understanding how your keyboard input is understood by Emacs.
GNU Emacs uses the ASCII character set, which defines 128 different character codes. Some of these codes are assigned graphic symbols such as `a' and `='; the rest are control characters, such as Control-a (also called C-a for short). C-a gets its name from the fact that you type it by holding down the CTRL key and then pressing a. There is no distinction between C-a and C-A; they are the same character.
Some control characters have special names, and special keys you can type them with: RET, TAB, LFD, DEL and ESC. The space character is usually referred to below as SPC, even though strictly speaking it is a graphic character whose graphic happens to be blank.
Emacs extends the 7-bit ASCII code to an 8-bit code by adding an extra bit to each character. This makes 256 possible command characters. The additional bit is called Meta. Any ASCII character can be made Meta; examples of Meta characters include Meta-a (M-a, for short), M-A (not the same character as M-a, but those two characters normally have the same meaning in Emacs), M-RET, and M-C-a. For traditional reasons, M-C-a is usually called C-M-a; logically speaking, the order in which the modifier keys CTRL and META are mentioned does not matter.
Some terminals have a META key, and allow you to type Meta characters by holding this key down. Thus, Meta-a is typed by holding down META and pressing a. The META key works much like the SHIFT key. Such a key is not always labeled META, however, as this function is often a special option for a key with some other primary purpose.
If there is no META key, you can still type Meta characters using two-character sequences starting with ESC. Thus, to enter M-a, you could type ESC a. To enter C-M-a, you would type ESC C-a. ESC is allowed on terminals with Meta keys, too, in case you have formed a habit of using it.
Emacs believes the terminal has a META key if the variable
meta-flag is non-nil. Normally this is set automatically
according to the termcap entry for your terminal type. However, sometimes
the termcap entry is wrong, and then it is useful to set this variable
yourself. See section Variables, for how to do this.
Emacs buffers also use an 8-bit character set, because bytes have 8 bits, but only the ASCII characters are considered meaningful. ASCII graphic characters in Emacs buffers are displayed with their graphics. LFD is the same as a newline character; it is displayed by starting a new line. TAB is displayed by moving to the next tab stop column (usually every 8 columns). Other control characters are displayed as a caret (`^') followed by the non-control version of the character; thus, C-a is displayed as `^A'. Non-ASCII characters 128 and up are displayed with octal escape sequences; thus, character code 243 (octal), also called M-# when used as an input character, is displayed as `\243'.
A complete key---where `key' is short for key sequence---is a sequence of keystrokes that are understood by Emacs as a unit, as a single command (possibly undefined). Most single characters constitute complete keys in the standard Emacs command set; there are also some multi-character keys. Examples of complete keys are C-a, X, RET, C-x C-f and C-x 4 C-f.
A prefix key is a sequence of keystrokes that are the beginning of a complete key, but not a whole one. Prefix keys and complete keys are collectively called keys.
A prefix key is the beginning of a series of longer sequences that are valid keys; adding any single character to the end of the prefix gives a valid key, which could be defined as an Emacs command, or could be a prefix itself. For example, C-x is standardly defined as a prefix, so C-x and the next input character combine to make a two-character key. There are 256 different two-character keys starting with C-x, one for each possible second character. Many of these two-character keys starting with C-x are standardly defined as Emacs commands. Notable examples include C-x C-f and C-x s (see section File Handling).
Adding one character to a prefix key does not have to form a complete key. It could make another, longer prefix. For example, C-x 4 is itself a prefix that leads to 256 different three-character keys, including C-x 4 f, C-x 4 b and so on. It would be possible to define one of those three-character sequences as a prefix, creating a series of four-character keys, but we did not define any of them this way.
By contrast, the two-character sequence C-f C-k is not a key, because the C-f is a complete key in itself. It's impossible to give C-f C-k an independent meaning as a command as long as C-f retains its meaning. C-f C-k is two commands.
All told, the prefix keys in Emacs are C-c, C-x, C-h, C-x 4, and ESC. But this is not built in; it is just a matter of Emacs's standard key bindings. In customizing Emacs, you could make new prefix keys, or eliminate these. See section Customizing Key Bindings.
Whether a sequence is a key can be changed by customization. For example, if you redefine C-f as a prefix, C-f C-k automatically becomes a key (complete, unless you define it too as a prefix). Conversely, if you remove the prefix definition of C-x 4, then C-x 4 f (or C-x 4 anything) is no longer a key.
This manual is full of passages that tell you what particular keys do. But Emacs does not assign meanings to keys directly. Instead, Emacs assigns meanings to functions, and then gives keys their meanings by binding them to functions.
A function is a Lisp object that can be executed as a program. Usually
it is a Lisp symbol which has been given a function definition; every
symbol has a name, usually made of a few English words separated by
dashes, such as next-line or forward-word. It also has a
definition which is a Lisp program; this is what makes the
function do what it does. Only some functions can be the bindings of
keys; these are functions whose definitions use interactive to
specify how to call them interactively. Such functions are called
commands, and their names are command names.
See section 'Defining Commands' in The GNU Emacs Lisp Manual, for more information.
The bindings between keys and functions are recorded in various tables called keymaps. See section Keymaps.
When we say that "C-n moves down vertically one line" we are
glossing over a distinction that is irrelevant in ordinary use but is vital
in understanding how to customize Emacs. It is the function
next-line that is programmed to move down vertically. C-n has
this effect because it is bound to that function. If you rebind
C-n to the function forward-word then C-n will move
forward by words instead. Rebinding keys is a common method of
customization.
In the rest of this manual, we usually ignore this subtlety to keep
things simple. To give the customizer the information he needs, we
state the name of the command which really does the work in parentheses
after mentioning the key that runs it. For example, we will say that
"The command C-n (next-line) moves point vertically down,"
meaning that next-line is a command that moves vertically down
and C-n is a key that is standardly bound to it.
While we are on the subject of information for customization only, it's a
good time to tell you about variables. Often the description of a
command will say, "To change this, set the variable mumble-foo."
A variable is a name used to remember a value. Most of the variables
documented in this manual exist just to facilitate customization: some
command or other part of Emacs examines the variable and behaves
differently accordingly. Until you are interested in customizing, you can
ignore the information about variables. When you are ready to be
interested, read the basic information on variables, and then the
information on individual variables will make sense. See section Variables.
Go to the previous, next section.