© Harley Hahn 2016

Harley Hahn, Harley Hahn's Emacs Field Guide, 10.1007/978-1-4842-1703-0_4

4. The Emacs Keyboard

Harley Hahn

(1)Santa Barbara, California, USA

4.1 Section 4.1: A Strategy for Learning Emacs

In the first three chapters of this book, we discussed:

  • What is Emacs, and where did it come from?

  • Basic Unix skills and how they relate to Emacs.

  • Installing Emacs on your own computer.

At this point, you are now ready to begin learning how to use Emacs.

With most text editors, the way to start is to learn some of the basic keystrokes — how to move the cursor, how to page up and down, how to search for a pattern, and so on — and then practice, practice, practice.

With Emacs you need a different strategy. As we discussed in Section 1.3, Emacs is wonderful in that it is a full-fledged working environment. However, it is this very same exhaustive complexity that makes Emacs difficult to learn. So, here then, are three helpful guidelines. First, what not to do:

  • 1. Do not jump in and start by learning the basic keystrokes. Keystrokes are easy to learn. To really understand Emacs, you must first have the proper background (Chapters 1 and 2 of this book).

  • 2. As you will see in Section 12.4, Emacs comes with a built-in tutorial. Do not begin by starting Emacs and firing up the tutorial. All that will happen is you will become confused and discouraged. (At least, that’s what happened to me.)

So what should you do?

  • 3. After you have read Chapters 1 and 2, continue by reading each section of this chapter in order. I will start by teaching you all the basic concepts (and there are a lot of them). At the proper time, I will show you how to use the fundamental keystrokes, and then you can practice, practice, practice. When you get to Section 12.4, I will explain how to run the Emacs tutorial, and you can use it as a post-graduate course.

4.2 Section 4.2: The Ctrl Key

Emacs has a lot of key combinations, referred to as "key sequences". (We’ll talk about key sequences Section 6.1, at which time I will give you a technical definition.) There are far more key sequences than you will ever memorize. In Section 4.5, I will explain why there are so many. First, though, you need to understand how Emacs uses the keyboard.

Like all text editors, Emacs uses all the regular keys (letters of the alphabet, numbers, punctuation, and so on). However, Emacs also uses two special keys: Ctrl and Meta.

The Ctrl key is used in the usual way. You hold down <Ctrl> as you press another key. For example, the command <Ctrl-H> starts the built-in Help facility: hold down the Ctrl key and press the letter h. No surprise here.

What will be new to you is that many Emacs commands consist of more than one Ctrl combination in a row, or a Ctrl combination followed by a single letter. Here are two examples:

  • To quit Emacs, you use <Ctrl-X> <Ctrl-C>. That is, press <Ctrl-X> and then press <Ctrl-C> .

  • To start the built-in tutorial, you use <Ctrl-H> t. That is, you press <Ctrl-H> and then press the letter t.

In order to make the description of such key sequences readable, Emacs uses its own notation. As you may know, the Unix convention for describing the Ctrl key sequences is to use a ^ (circumflex) character to represent <Ctrl>. For example, in the Unix world, ^X means <Ctrl-X>. Another part of this convention is that when we describe a Ctrl key sequence, we write the letter of the alphabet in uppercase. For instance, we write ^X, not ^x. We do this because it is easier to read. (You don’t actually press the Shift key when you type the x.)

In Emacs, the Ctrl key is represented by C- (the uppercase letter "C" followed by a hyphen), and the letters are written in lowercase. For example, instead of writing <Ctrl-X> or ^X, we write C-x. Similarly, the combination <Ctrl-X> <Ctrl-C> is written as C-x C-c; and <Ctrl-H> followed by the letter t is written as C-h t. It is important that you recognize this notation because that is what you will see when you read about Emacs. To help you get used to these conventions, I will use them consistently throughout the rest of the book.

4.3 Section 4.3: The Meta (Alt) Key

In addition to the Ctrl key, Emacs uses the Alt key which, for historical reasons, is referred to as the META KEY, written as <Meta>, so whenever you see a reference to the Meta key, just press <Alt>. (With a Macintosh keyboard, the Meta key is the Option key.)

The Meta key is used in the same way you use the Ctrl and Shift keys. That is, you hold it down while you press another key. For example, to type an uppercase "A", you hold down the Shift key and press the letter a. To type <Ctrl-A>, you hold down <Ctrl> and press a. And, to use <Meta-A>, you hold down <Alt> and press a. (Or, with a Macintosh keyboard, you hold down <Option> and press a.)

The Emacs notation used to indicate a Meta key sequence is similar to what we use with the Ctrl key, except that we use M- instead of C-. For instance, to indicate the combination <Meta-A>, we write M-a. Here is an example:

  • When you are editing a file, the command to move down one screenful is C-v. The command to move up one screenful is M-v.

This means, to move down one screenful, you press <Ctrl-V>. To move up one screenful, you press <Meta-V> (that is, <Alt-V>).

As an alternative, you can also use the Escape key (<Esc>) as a Meta key. However, when you use <Esc>, you do not hold it down. You press it, let go, and then press the second key. For example, if you want use the M-v command I mentioned above, you can either press <Meta-V> or type the two keys <Esc> v. (This alternative way of using <Meta> was created because, at one time, there were keyboards that didn’t have a Meta key or an Alt key.)

You will occasionally see key sequences that use both the Meta key and the Ctrl key. For example, M-C-s. To type this command, you have two choices. You can either hold down <Ctrl> and <Meta> and press s, or you type the two keys <Esc> <Ctrl-S> .

Thus, there are four possible ways to use each letter of the alphabet. For instance, the letter "a" can be used as a:

  • Lowercase letter (a)

  • Uppercase letter (A)

  • Ctrl combination (C-a)

  • Meta combination (M-a)

  • Meta-Ctrl combination (M-C-a)

When you have a Meta-Ctrl combination, you hold down both keys at the same time. For example, the following two combinations are equivalent, and you will see it written both ways.

M-C-a                
C-M-a

I know this all may sound confusing when you read it, but in practice it is easy.

4.4 Section 4.4: Special Key Names

When you read about Emacs, you will see special names used to represent specific keys. These names are shown in Figure 4-1. It is important that you memorize them, as you will see these names when you read Emacs documentation, especially reference information about commands and Lisp functions.

A385558_1_En_4_Fig1_HTML.gif
Figure 4-1. Emacs names for special keys. When you read about Emacs, you will sometimes see abbreviated names used for special keys. These names are derived from the technology of the 1970s, and they are important enough that it is a good idea to memorize them.

What you see in Figure 4-1 comes from very old technology of the 1970s, when Unix and Emacs were originally developed. Except for the Meta key (which we’ll talk about in a moment) and the Tab key, all the keys in Figure 4-1 can be traced back to the earliest Unix terminal, the Teletype Model 33 ASR we discussed in Section 2.4.

We have already met the Ctrl key and Meta key . To summarize:

  • C- stands for "hold down the Ctrl key"

  • M- stands for "hold down the Meta key"

  • M-C- stands for "hold down both the Meta key and the Ctrl key"

  • As an alternative to the Meta key, you can press <Esc> .

For example, M-x means you can use either <Meta-X> or <Esc> x. M-C-x means you can use either <Meta-Ctrl-X> or <Esc> <Ctrl-X> .

You will see the Meta-Ctrl double-key sequences written in three different ways, but they all mean the same thing. For example, the three commands below are equivalent. They mean either "hold down the Meta and Ctrl keys and press s, or "press the Esc key, let it go, and then press <Ctrl-S> .

C-M-s                
M-C-s
ESC C-s

Here is another, more complex example. While I was researching this chapter, I found a reference that contained a long list of Emacs commands. It the middle of the list was a line that said:

ESC-!                                                                            Enter a shell command.                

In other words, while you are working within Emacs, you can enter a shell command by typing ESC ! (followed by the shell command). The moment I saw this, my mind changed ESC-! to <Meta-!>. (This is the type of thinking I want you to train you mind to do automatically.)

But there is more. Look at your keyboard and notice that the ! (exclamation mark) character is actually an "uppercase" 1 (the number 1). Thus, the sequence ESC ! is actually ESC <Shift-1>, which is the same as <Meta-Shift-1>, which is actually <Alt-Shift-1> on my keyboard.

So when I read that the way to enter a shell command is by using ESC !, my mind immediately knew to press <Alt-Shift-1>, type the shell command, and then press <Enter>. One day, your mind will do the same and, on that day, you will know you are an Emacs person.

To continue with the discussion of Figure 4-1. The BS, DEL, ESC, RET, SPC, and TAB keys are simple to understand: they represent the following keys: Backspace, Delete, Esc (Escape), Return (Enter), Space, and Tab. (DEL refers to the same Delete key we discussed in Section 2.10.)

Note

On a Macintosh keyboard, BS refers to the Delete key at the top-right corner of the main part of the keyboard. This is the primary Delete key, which corresponds to the Backspace key on a PC keyboard. DEL refers the secondary Delete key, the one to the left of the End key.

The secondary Delete key is available only with a full-sized Macintosh keyboard. If you have a compact keyboard, you won’t have this key. Instead, you can use either <fn-Delete> or <Control-D> .

4.5 Section 4.5: The Meta Key, Bucky Bits, and Much More

As soon as you start to use Emacs, you will find out how important the Meta key is. In fact, the use of the Meta key is one of the defining characteristics of Emacs. And yet, I hear you say, "What Meta key? Ain’t no stinkin’ Meta key on my keyboard." Indeed, modern keyboards don’t have a Meta key, we use <Alt> instead (or <Option> with a Macintosh). So why don’t we just call it the Alt key?

The Meta key is a legacy from the early days of Emacs and Lisp at MIT (see Section 1.4), when there actually were keyboards that had this key. In fact, there were at least two such keyboards that were used with Lisp machines. (Remember, Emacs is tightly integrated with the Lisp programming language.) These keyboards were called the Knight keyboard and the Space Cadet keyboard. I’ll talk more about them in a moment but, first, I want to explain a few technical details.

In Section 1.2 we talked about ASCII (the American Standard Code for Information Interchange). The list of all the ASCII characters and their meanings is called the ASCII CODE . The ASCII code uses 8-bit bytes to store characters, one character per byte. The original, plain vanilla ASCII code used only 7 of the 8 bits and, thus, defined 128 characters from 0 to 127. The original purpose of the Meta key was to turn on the top (8th) bit to allow the use of characters 128 through 255. In other words, using a Meta key effectively doubled the number of different characters from 128 to 256.

The tradition of using a special key to modify the top bits of a character began with the Stanford University SAIL KEYBOARD , developed in 1971 for special-purpose Lisp computers at the Stanford Artificial Intelligence Lab (SAIL). These keyboards had a number of extra keys, including Meta, Control and Alt.

Shortly afterwards, the West Coast SAIL keyboard began to influence the design of keyboards used by the East Coast AI (artificial intelligence) community. First, the so-called KNIGHT KEYBOARD was created by Tom Knight to be used on the legendary MIT Lisp Machines at MIT’s AI Lab, where Emacs was later developed. (A LISP MACHINE was a single-user computer, optimized to run the Lisp programming language.) This keyboard and the Lisp working environment heavily influenced Richard Stallman when he designed Emacs.

Later, Tom Knight enhanced the Knight keyboard to create the more complex SPACE CADET keyboard (see below). Finally, the Space Cadet keyboard was adapted into several versions of a simpler SYMBOLICS KEYBOARD , used on commercial Lisp machines in the early 1980s.

All of these keyboards had a Meta key, which is how it found its way into Emacs. However, there was more. The Knight keyboard had four modifier keys: Top, Shift, Meta, and Ctrl. The Space Cadet keyboard had seven such keys: Top, Greek, Shift, Hyper, Super, Meta, and Ctrl.

Each key on the Space Cadet keyboard had three markings: in the regular place, higher up (top), and on the front of the key. In the regular place were the standard characters: letters, numbers, and punctuation, exactly like a regular keyboard. Above the regular character were special symbols, mostly mathematical. In fact, the "top" keys on the Space Cadet keyboard contained the complete APL character set. (APL is a mathematical programming language created by Ken Iversen in the 1960s.) On the front of the keys were Greek letters. To access the extra keys, you used <Shift>, <Top>, and <Greek> .

In this way, the Space Cadet keyboard lets you to type four completely different sets of characters. First, you type lowercase characters, numbers and punctuation in the regular way. Second, you hold down the Shift key to type uppercase letters and punctuation, also in the regular way. Third, you hold down the Top key to type the mathematical symbols and the Greek key to type the Greek letters. In other words, the Shift, Top, and Greek keys worked like regular shift keys. (Note: Because the Greek letters are on the front of the keys, you will sometimes see the Greek key referred to as the Front key.)

The other four modifier keys — Ctrl, Meta, Hyper, Super — used extra bits that were tacked on to the actual characters. For example, in the same way that you can type, say, <Ctrl-A> to send a special signal to the computer, you could also type <Meta-A>, <Hyper-A>, and <Super-A>, all of which were different. (In fact, in is actually possible to still use a Hyper key and a super Key with Emacs. All you have to do is use Emacs Lisp commands to make specific keys on your keyboard become the Hyper and Super keys. You can then connect Emacs commands that don’t already have a key sequence — of which there are many — to use whichever Hyper and Super key sequences you want. By the way, if you are using a PC keyboard with Linux, by default, the Windows key is the Super Key.)

To return to the Space Cadet keyboard , in all, you could use it to type more than 8,000 different characters. This phenomenon gave rise to the Emacs (and the general hacker) philosophy that it is worthwhile to memorize the meanings of a very large number of strange, complicated key sequences, if it will reduce typing time.

Note

If you are experienced enough with Unix to have encountered the never-ending debate of Emacs vs. the vi text editor, here is the gist of it in one sentence:

Emacs people believe that it is worthwhile to memorize the meanings of a very large number of strange, complicated key sequences, if it will reduce typing time.

The extra bits used by the Ctrl, Meta, Hyper, and Super keys are known as BUCKY BITS . They are named after Niklaus Worth, the inventor of the Pascal programming language , whose nickname was Bucky. When Worth was at Stanford in 1964-1965, he suggested adding an extra key (called <Edit>) to use the 8th bit within bytes that stored 7-bit ASCII characters. Although this exact suggestion was never implemented, it did inspire the idea to use extra keys (and extra bits) to extend a keyboard’s character set. As the story goes, Worth had prominent front teeth (buck teeth), so behind his back some people called him Bucky. Hence the name bucky bits.

One last point: the Knight keyboard was named after Tom Knight, one of the Lisp Machine’s principal designers. However, the name also has more metaphysical connotations in that it recalls a semi-mythical organization of Lisp hackers called the Knights of the Lambda Calculus. (The lambda calculus is the mathematical theory upon which the Lisp programming language is based.)

4.6 Section 4.6: Meta Key Problems When Using a Terminal Window

When you run Emacs within a terminal window (see Section 2.6 and Section 5.2), you may encounter a problem using the Meta key.

With most keyboards, the Meta key is the Alt key. However, terminal windows are GUI-based programs that use the Alt key to access top-level menus. For example, it is common to access the File menu by pressing <Alt-F>. This can interfere with using the Meta key, because when you type certain key sequences, the terminal window program will grab the <Alt> key, instead of leaving it for Emacs to interpret. Here is a common example.

With Ubuntu Linux, the default terminal window is a Free Software Foundation program called Gnome Terminal . By default, Gnome Terminal uses <Alt> key combinations to let you access menus. For instance, to access the View menu, you type <Alt-V>. This means that the Emacs command M-v (which you will meet in Section 7.1 and Section 8.5) won’t work properly. All that will happen is you will pull-down the View menu for the terminal window program.

In you have this problem, you need to find an option to disable <Alt> as a menu shortcut key. For example, with Gnome Terminal, pull down the View menu and select "Keyboard Shortcuts". You will see the following option:

Enable menu access keys (such as Alt+F to open the File menu)                

Once you turn off this option, Gnome Terminal will ignore the Alt key, and your Emacs Meta key will work properly.

Of course, none of this matters when you run Emacs within a virtual terminal (see Section 2.6).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.173.227