Next: Convenience Features and Customization of Buffer Handling, Previous: Operating on Several Buffers, Up: Using Multiple Buffers [Contents][Index]
An indirect buffer shares the text of some other buffer, which is called the base buffer of the indirect buffer. In some ways it is a buffer analogue of a symbolic link between files.
Create an indirect buffer named indirect-name with base buffer base-buffer.
Create an indirect buffer that is a twin copy of the current buffer.
Create an indirect buffer that is a twin copy of the current buffer, and
select it in another window (
The text of the indirect buffer is always identical to the text of its base buffer; changes made by editing either one are visible immediately in the other. “Text” here includes both the characters and their text properties. But in all other respects, the indirect buffer and its base buffer are completely separate. They can have different names, different values of point, different narrowing, different markers, different overlays, different major modes, and different local variables.
An indirect buffer cannot visit a file, but its base buffer can. If you try to save the indirect buffer, that actually works by saving the base buffer. Killing the base buffer effectively kills the indirect buffer, but killing an indirect buffer has no effect on its base buffer.
One way to use indirect buffers is to display multiple views of an outline. See Viewing One Outline in Multiple Views.
A quick and handy way to make an indirect buffer is with the command
M-x clone-indirect-buffer. It creates and selects an indirect
buffer whose base buffer is the current buffer. With a numeric
argument, it prompts for the name of the indirect buffer; otherwise it
uses the name of the current buffer, with a ‘<n>’ suffix
added. C-x 4 c (
works like M-x clone-indirect-buffer, but it selects the new
buffer in another window. These functions run the hook
clone-indirect-buffer-hook after creating the indirect buffer.
The more general way to make an indirect buffer is with the command M-x make-indirect-buffer. It creates an indirect buffer named indirect-name from a buffer base-buffer, prompting for both using the minibuffer.
Note: When a modification is made to the text of a buffer, the modification hooks are run only in the base buffer, because most of the functions on those hooks are not prepared to work correctly in indirect buffers. So if you need a modification hook function in an indirect buffer, you need to manually add that function to the hook in the base buffer and then make the function operate in the desired indirect buffer.