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-1 and Figure 4-2 show Emacs frames and Emacs windows. In Figure 4-1, we see our dickens and odyssey buffers in two separate frames. Figure 4-2 shows 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, 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.

4.1.3 More About Buffers

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 Ctrl and 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.



Learning GNU Emacs
Learning GNU Emacs, Third Edition
ISBN: 0596006489
EAN: 2147483647
Year: 2003
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net