• You search for a string you can see on the screen, and Emacs can't find it. The most probable explanation is that Emacs is taking into account line breaks and punctuation, and you're not including these in the search string. Use word search, which ignores any line breaks or punctuation, to find the string.
• You get a message that says, Searching for program: No such file or directory ispell
. You don't have Ispell installed. Ispell is external to Emacs; see Chapter 13for details on installing Ispell on Mac OS X and Windows.
• You can't see the pop-up menu in Flyspell. You activate this pop-up menu by pointing the mouse at a given word and pressing the middle mouse button. Essentially, you need a three-button mouse to run Flyspell.
Chapter 4. Using Buffers, Windows, and Frames
One of the most universally useful features of Emacs is the ability to edit multiple buffers at once and to display more than one buffer using windows and frames. The commands for doing this are simple; you learn only a few commands and yet experience a tremendous boost in productivity. The more you use multiple buffers, frames, and windows, the more uses you'll think of for them.
In this chapter, we discuss how to use buffers, windows, and frames. First we cover the most commonly used commands, then, in the case of buffers and windows, move on to some more esoteric commands. At the end of the chapter, we discuss bookmarks, a method for marking your place in a file.
4.1 Understanding Buffers, Windows, and Frames
Conceptually, Emacs is different from most applications in two important ways. First, its window terminology is different. Second, Emacs buffers are not tied to windows or frames, unlike most applications.
4.1.1 Windows Versus Frames
Let's get our terms straight first. GUI windows are not Emacs windows. Emacs calls GUI windows frames . In part, this terminology is necessary because Emacs predates GUIs and is still often used on terminals without GUI windows. Emacs windows are split screens. We've seen them already; for example, when you ask for keyboard help, you see it displayed in a *Help*
buffer at the bottom of your screen. Figures Figure 4-1and Figure 4-2show Emacs frames and Emacs windows. In Figure 4-1, we see our dickens
and odyssey
buffers in two separate frames. Figure 4-2shows a single frame displaying two Emacs windows, one on top of the other, showing these two files.
Figure 4-1. Editing dickens and odyssey in Emacs frames
Figure 4-2. Editing dickens and odyssey in Emacs windows
From now on, when we say frame, we mean a separate GUI window. When we say window, we mean a portion of the current Emacs display. And from a practical standpoint, we emphasize that this is not an either-or proposition. Even if you prefer multiple frames, you will still use Emacs-style windows sometimes. Emacs itself will see to that.
4.1.2 Buffers: Independent of Windows and Frames
Now what about buffers? Essentially, both windows and frames are ways to display a buffer, which, as defined in Chapter 1 Chapter 1. Emacs Basics Some of you out there are probably dying to get your hands on the keyboard and start typing. We won't try to stop you; turn to the section called "Starting Emacs" and you can go ahead. But do read the beginning of this chapter later when you're ready for a break. Emacs is much easier to learn if you understand some of the basic concepts involved, which we discuss in the following introduction.
, may contain a copy of a file or not. Buffers may contain files. They may be Emacs-generated buffers, like *Messages*
, *scratch*
, or *Help*
. Or they may be buffers that you create but haven't written to a file.
Most GUI applications tie certain files to certain GUI windows or, in Emacspeak, frames. Emacs's detachment of buffers from their display (whether a split display or a separate frame) is more powerful and flexible. To be honest, most of the time we prefer using a single Emacs frame and switching between buffers using C-x b. It's much easier than mousing between frames or dealing with a split screen, though each has its advantages in some situations.
How do you know how many buffers are active in Emacs and what they are? There are three ways: the buffer list (which appears in a window when you type C-x C-b), the Buffers menu (which lists active buffers and commands for navigating them), and the Buffer pop-up menu (accessed by holding down Ctrland clicking the left mouse button, which lists buffers by mode).
Emacs creates its own specialized buffers. The names for these internal buffers generally have the format * buffer name *
. *Help*
, *scratch*
, and *Buffer List*
are just a few of the buffers that Emacs creates.
When you start Emacs, it generates two buffers:
*Messages*
*scratch*
*Messages*
is a buffer where Emacs accumulates messages from its startup and from the minibuffer. *scratch*
is just what it sounds like: a temporary scratchpad where you can type. It won't be saved unless you explicitly write it to a file using C-x C-w.
Of course, typically you edit files with Emacs. These files are then copied into buffers of the same name. If you ask for help, you'll also have a *Help*
buffer.
The number of buffers you can have really has no limit. Most of the time, only one or two buffers are displayed, but even if you can't see them, all the buffers you create in an Emacs session are still active. You can think of them as a stack of pages, with the one being displayed as the top page. At any time, you can turn to another page (another buffer), or you can create a new page.
Each buffer has an associated major mode that determines much about how Emacs behaves in that buffer. For example, text mode, designed for writing text, behaves differently from Lisp mode, which is designed for writing Lisp programs.
You can display multiple buffers in separate windows or frames or both. The important thing to remember is that all the buffers you create are active even if they are not currently displayed.
4.2 Working with Multiple Buffers
If you want to create a buffer that contains a file, simply type C-x C-fto find the file. Emacs automatically creates a second buffer and moves you there. If you already have a copy of the file in a buffer, C-x C-fjust moves you to the existing buffer. This move is sensible and probably really what you want anyhow; if C-x C-fread the file from disk every time, you could end up with many versions of the same file that were each slightly different. If the filename you give C-x C-fdoesn't exist, Emacs assumes you want to create a new file by that name and moves you to a blank buffer.
C-x C-fis always followed by a filename. The command for moving between buffers, C-x b, is followed by a buffer name. Did you realize that the mode line doesn't display filenames but only buffer names? Some versions of Emacs show both, but GNU Emacs shows only the buffer name. The buffer name and the filename, if any, are the same unless you change them (see the section "Renaming Buffers," later in this chapter).
To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enterif that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name. Now press Enterto move to the buffer.
Читать дальше