Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 3: Getting Started with Emacs

Previous HourNext Hour

Sections in this Hour:

 

The Minibuffer


The very last line of the Emacs window is called the minibuffer. It is used by Emacs to ask you questions about files to open, buffers to change to, permission to kill buffers and much more. Furthermore it will be used to give you information about various things, such as which files have been saved, the progress of fontifications, and when automatic backup is done.

Seeing Old Messages from the Minibuffer

The messages shown in the minibuffer are also copied to a special buffer. This is very valuable knowledge if several messages come after each other and you don't finish reading the first one before the next is shown (overwriting the first one).

Seeing the Content of the Message Buffer

Follow these steps to get to the message buffer and to get back to your current buffer:

1. Press C-x (that is, press the Control key, hold it down while you press x, and release the Control key) and press b.

2. Emacs will now ask for a buffer to switch to in the minibuffer:

Press Return.

3. The message buffer now be appears, and you can browse through it with the cursor keys. When you are finished, press C-x b.

4. Again Emacs asks for a buffer to switch to. By default, it suggests the latest buffer you visited, so you can simply press Return.

This might seem terribly cumbersome, but when you get used to Emacs, you will see that it is simple to change to the *Messages* buffer, just as you can change to any other buffer. In GNU Emacs and in XEmacs version 20, you can press the Tab key when you have typed part of the name to ask Emacs to complete it for you. This, unfortunately, doesn't work in XEmacs version 19.

Interaction with the Minibuffer

There are several different kinds of questions that Emacs might ask you in the minibuffer. The simplest kind are questions where you are allowed to answer only yes or no. There are in fact two kinds of yes/no questions:

The latter type are for questions that have a large influence on your situation. An example of this is Buffer modified; kill anyway? (yes or no). The other kind of question is for situations where the wrong action might be irritating but not fatal. An example of this is Quit spell checking? (y or n). If you give Emacs an invalid answer, it tells you the available choices you have and asks you again.

In other situations, Emacs asks you for a filename, a buffer name, or one of its functions. (You will see numerous examples of the latter in which you press M-x and subsequently type a function name.) In these situations, you can press the Tab key to ask Emacs to complete as much as possible of what you already typed. Thus when you open files, it is not necessary to type the whole path for the file, but only what is necessary to make it unique, as the following task shows.

Using Filename Completion when Opening Files

The following steps show how you can let Emacs do typing for you when you want to open a file:

1. Press C-x C-f. Emacs asks you for a file to open. (In Emacs terminology, this is called finding a file .) Emacs inserts the working directory of the buffer you are currently editing (see Figure 3.4).

Figure 3.4
Emacs asks for a filename and suggests your current directory. (In this case this is my home directory.)

2. Now type /et (see Figure 3.5).

Figure 3.5
Typing /et and the Tab key makes Emacs complete the directory name for you.

3. Press the Tab key and watch how Emacs completes the filename for you to /etc/ (see Figure 3.6).

Figure 3.6
Emacs fills in c/ in the word /etc/.

4. Now you can continue typing. Type the letter p and press the Tab key again (see Figure 3.7).

Figure 3.7
Pressing the Tab key when Emacs can't add any unambiguous characters makes it show you a list of possible completions.

5. Because there are several possible completions for /etc/p, Emacs asks you to type a bit more. It does, however, list the possible completions. You can now continue this way until you have typed the whole filename. When you have finished that, press Enter and Emacs opens the file for you to edit.

Using Emacs's filename completion can save you much time. Think of how much you would have to type to open a file such as /usr/share/emacs/20.2/lisp/progmodes/perl-mode.el if you didn't have completions.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 3: Getting Started with Emacs

Previous HourNext Hour

Sections in this Hour: