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:

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:

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: