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

## Using Outline or Narrowing in Two Different Views of the Same File

If you try to open the same buffer in two different windows, and afterward try to narrow it in two different ways, or try to create two different outlines, you will see that this is not possible. The reason for this is that both narrowing and the outline functions modify some characteristics of the buffer, which is independent of the fact that the buffer is shown in two different windows. Likewise you will see that it is not possible to mark in a buffer two different regions, which are shown in two different windows. The reason for this is that the mark (which is one end of the region) is shared between the windows.

A solution to these problems is to copy the buffer and use the copy for the outline and so on. Unfortunately this means that if you edit the one, you won't update the other. Emacs contains a nicer solution to this problem called indirect buffers . An indirect buffer is a copy of a buffer that has separate marks and other buffer characteristics but that ensures that an edit in one buffer is transferred to the other immediately.

Caution - Indirect buffers are unfortunately not yet part of XEmacs. This should change in later versions. So if you use XEmacs, you simply have to stick with the method of copying the content of the buffer to another one.

In sams-lib.el the function sams-make-buffer-copy exists. When this function is invoked, a new frame is created with an indirect buffer which is a copy of the current buffer.

If you get a copy of a buffer this way, you can use either outline or narrowing in two different views of the same file. Furthermore you can get two buffers with separate marks, so it is possible to get two different regions of the same file. This makes it possible to invoke ediff-regions-linewise on two regions in the same buffer (or what at least appears to be the same buffer).

Caution - If you are using GNU Emacs 19 then you must use the library noutline instead of outline when you want to use indirect buffers. Simply press M-x load-library RET noutline RET to load the noutline library. The noutline library is an alternative implementation of the outline functions that works with indirect buffers. In GNU Emacs 20, this is no problem, because the noutline library, in fact, is the default for the outline functions.

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.