[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Characters, Keys and Commands

ASCII consists of 128 character codes. Some of these codes are assigned graphic symbols such as `a' and `='; the rest are control characters, such as Control-a (usually written C-a for short). C-a gets its name from the fact that you type it by holding down the CTRL key while pressing a.

Some control characters have special names, and special keys you can type them with: for example, 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.

On ASCII terminals, there are only 32 possible control characters. These are the control variants of letters and `@[]\^_'. In addition, the shift key is meaningless with control characters: C-a and C-A are the same character, and af cannot distinguish them.

One af character set extension is that characters have an additional modifier, called Meta. Every character has a Meta variant; examples include Meta-a (normally written M-a, for short), M-A (not the same character as M-a, but those two characters normally have the same meaning in af), M-RET, and M-C-a. For reasons of tradition, we usually write C-M-a rather than M-C-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 labelled 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. ASCII terminals represent function keys as a special sequence of ASCII characters. Because of this, it is possible, although not simple, to configure af to handle function and arrow keys. (see section 21. Customisation)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 Keys

A key sequence (key, for short) is a sequence of characters that are meaningful as a unit--as "a single command." Some af command sequences are just one character; for example, just C-n is enough to move down one line. But af also has commands that take two or more characters to invoke.

If a sequence of events is enough to invoke a command, it is a complete key. Examples of complete keys include C-n, RET, C-x C-f and C-x 4 C-f. If it isn't long enough to be complete, we call it a prefix key. The above examples show that C-x and C-x 4 are prefix keys. Every key sequence is either a complete key or a prefix key.

Many single characters constitute complete keys in the standard af command bindings. A few of them are prefix keys. A prefix key combines with the following character to make a longer key sequence, which may itself be complete or a prefix. For example, C-x is a prefix key, so C-x and the next character combine to make a two-character key sequence. Most of these key sequences are complete keys, including C-x C-f and C-x b. A few, such as C-x 4 and C-x r, are themselves prefix keys that lead to three-character key sequences. There's no limit to the length of a key sequence, but in practice people rarely use sequences longer than four characters.

By contrast, you can't add more characters onto a complete key. For example, the two-character sequence C-n C-k is not a key, because the C-n is a complete key in itself. It's impossible to give C-n C-k an independent meaning as a command. C-n C-k is two key sequences, not one.

All told, the prefix keys in af are C-h, C-t, C-x C-x 4, and ESC. But this is not cast in concrete; it is just a matter of af standard key bindings. If you customise af, you can make new prefix keys, or eliminate these (see section 21.6 Customising Key Bindings).

If you do make or eliminate prefix keys, that changes the set of possible key sequences. For example, if you redefine C-n as a prefix, C-n 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Keys and Commands

This manual is full of passages that tell you what particular keys do. But af does not assign meanings to keys directly. Instead, af assigns meanings to named commands, and then gives keys their meanings by binding them to commands.

Every command has a name chosen by a programmer. The name is usually made of a few English words separated by dashes; for example, next-line or open-message. The bindings between keys and commands are recorded in various tables called keymaps (see section 21.6 Customising Key Bindings).

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 customise af. It is the command next-line that is programmed to move down vertically. C-n has this effect because it is bound to that command. If you rebind C-n to the command end-of-buffer then C-n will move to the end of the buffer instead. Rebinding keys is a common method of customisation.

In the rest of this manual, we usually ignore this subtlety to keep things simple. To give the information needed for customisation, 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 customisation 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 foobar." A variable is a name used to remember a value. Most of the variables documented in this manual exist just to facilitate customisation: some command or other part of af examines the variable and behaves differently according to the value that you set. Until you are interested in customising, 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 21.4 Variables).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Major Modes

Af has several modes of operation; known as major modes. A major mode is in effect a subset of af, where a command may have a different effect, and different commands may be available (This is probably the most pronounced difference between af and Emacs; Emacs major modes just alter its behaviour in minor ways, such as changing key bindings; while af major modes may have a completely different set of commands and behaviour).

There are three major modes currently available in af. Mail mode is the mode used for buffers displaying mail messages; most af buffers use mail mode. Minibuffer mode is used to support the minibuffer; it has no commands to handle mail messages, but many extra commands to allow editing of text. Typeout mode is the mode used for displaying text to the screen. Again, it has no commands to handle mail messages, it simply allows you to browse text displayed on the screen.

Each major mode allows you to bind keys independently of the other major modes (just like in Emacs), so keys may be bound in only one mode, or even be bound to different things in different modes (just as they can in Emacs). For example, in mail mode SPC just clears the echo area, in minibuffer mode it inserts a space into the text you are editing, and in typeout mode it scrolls the text up to display the next page.

Each af command may be available in all modes, or just in some of them. For example the command open-message is only available in mail mode, since in the other modes you are not dealing with mail messages and the command wouldn't make sense. So you can't run the command open-message in typeout mode even by typing M-x open-message.

A command may also have slightly different behaviour in different modes. For example the command search-forward in mail mode searches through the text of each mail message, looking for some text. In typeout mode it searches through the text you are viewing instead.

This distinction is only really important when customising af; when you are using af it is (hopefully) quite obvious what commands are likely to work. The important thing to remember is that keys may do very different things depending on whether you are browsing a list of messages, entering an argument in the minibuffer, or viewing text.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Minor Modes

A minor mode is a particular feature which can be turned on or off. For example, Read Only mode selects whether you are allowed to modify the contents of a buffer. Unlike the major modes, the minor modes are independent of each other, although they may only be valid in some major modes.

Minor modes are usually specific to a buffer, so they may be turned on in some buffers and off in others. Normally, minor modes are turned on or off automatically in response to some situation. There may also be a command to turn the minor mode off if it is on, or on if it is off; this will be formed from the prefix `toggle-' followed by the name of the mode. So the command to turn Read Only mode on or off is toggle-read-only.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Malc Arnold on August, 22 2002 using texi2html