Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 15: Getting an Overview of a File |  | Previous HourNext Hour
Sections in this Hour: |  |

## Hour 15
Getting an Overview of a File

In this hour you will learn several different methods with which you can focus on part of your document:

- First you'll see how to make Emacs act as if you have only part of your document. This is especially useful if you need to do a search-and-replace on only part of a file, for example.

- Next you'll see two different ways to get an outline of your buffer. You might, for example, show only titles in a document.

## Focusing on Only Part of a Buffer

Emacs has a very useful feature that enables you to narrow your view of a buffer to only part of it. Narrowing to only part of a buffer makes the part appear as if it were the whole buffer, both to you and to many of the functions that operate on a buffer, such as search-and-replace. In other words, it is nearly equivalent to copying the part to another buffer and working on it there.

When you save a buffer that is narrowed, text that is invisible to you will still be saved. Likewise the invisible text will still be backed up.

In Figure 15.1 you can see a buffer that is being narrowed. If you look carefully at the mode-line, you'll see that Emacs acts as if this were all the buffer. For example, it shows the text All to indicate that you're looking at all the buffer (even though the buffer, in its entirety, is several hundred lines long).

Figure 15.1
A narrowed buffer.

To narrow to part of a buffer, mark a region and press C-x n n (narrow-to-region). To show the whole buffer again, press C-x n w (widen).

Well that is it! That is the whole truth about narrowing. Simple, but very useful. Unfortunately it is so simple that most people have a tendency to overlook its power, so here comes an example that I hope will make you remember its power.

When you are writing a large report, you might have two conflicting interests:

- You might want all of the report (or at least the chapter) in one file, so that it is easy for you to search for text in it and to get an overview (using, for example, outline mode described in the next section).

- You might want each section (or even each subsection) to be located in a file for itself, so that it is easy to focus on the current part, and easy to search backward in the current section, without getting too far back in case your search doesn't match anything in the current section.

Narrowing can help you fulfill both wishes. Place the whole chapter in one file, and then narrow to a given section when you work on it. This way searching applies only to the given section, and you can still work with the whole chapter in one file for larger searches.

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 15: Getting an Overview of a File |  | Previous HourNext Hour
Sections in this Hour: |  |

© Copyright Macmillan USA. All rights reserved.