That is precisely the purpose of library Narrow Indirect (narrow-indirect.el
).
It gives you narrowing commands that create an indirect buffer that is a clone of the current buffer and that is narrowed to a particular portion of it. You can narrow to the current defun, active region, or current page.
Suggested key bindings:
(define-key ctl-x-4-map "nd" 'ni-narrow-to-defun-other-window)
(define-key ctl-x-4-map "nn" 'ni-narrow-to-region-other-window)
(define-key ctl-x-4-map "np" 'ni-narrow-to-page-other-window)
It offers two ways to distinguish indirect buffers from non-indirect buffers, for the indirect buffers it creates:
The buffer name of an indirect narrowed buffer starts with a prefix that you can set using option ni-buf-name-prefix
. The default value is I-
.
The name of an indirect narrowed buffer is highlighted in the mode line using face ni-mode-line-buffer-id
instead of face mode-line-buffer-id
. (To turn this off, just customize the former to be the same as the latter.)
Such an indirect buffer gives you a different view of a portion of the buffer, or even of the whole buffer (use C-x h C-x 4 n n
). It always has the same text and text properties, but otherwise it is pretty independent.
In particular, you can kill an indirect buffer without affecting its base buffer. You will likely want to kill indirect narrowed buffers rather than widening them.
See the Emacs manual, node Indirect Buffers.