10

I am editing some file, abc.org, and call org-narrow-to-block to narrow to a code block that I want to edit. For the editing process I have to access another part of abc.org and just want to show it in another window. So I do "C-x 2" and find that the window shows the abc.org, but also narrowed. Is it possible to have two "views" on the file? One narrowed and one not?

I have checked the seven questions tagged with narrowing and did not find a similar question.

13

I think you're looking for clone-indirect-buffer-other-window (bound to C-x 4 c by default).

Note that this makes a linked clone of the buffer so you'll need to remember to kill the cloned buffer as well as the window to avoid accumulating more and more buffers with the same content.

4

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.

2

Have you tried C-x C-c b (org-tree-to-indirect-buffer)? It creates an indirect (new) buffer and narrows it to current subtree, leaving the rest of the document as is.

  • Note that by default only one indirect buffer is maintained at any time. This however can be changed by setting org-indirect-buffer-display to new-frame. – Christoph Jun 9 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.