3

I would like to accomplish the following behaviour in Emacs and was wondering if there's an existing package that already does what I want.

I want my buffer to display only lines 30 to 60 in file myfile.txt, and simply hide the rest of the file from me.

  • When I scroll up to the top, I should be at line 30.
  • When I scroll down to the bottom, I should be at line 60.
  • If I edit this region, these edits should be reflected in the original file.
  • The region should grow/shrink as I insert/delete lines.
  • I should be able to open multiple regions to the same file in different buffers.

This is very close to my ideal workflow. Thanks very much for your help!

Patrick Li
  • 672
  • 4
  • 11
  • 1
    For all but the last requirements, you have [narrowing](https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html). – Juancho Jan 13 '17 at 19:16
  • 1
    For the last requirement, check [indirect buffers](https://www.emacswiki.org/emacs/IndirectBuffers). – Juancho Jan 13 '17 at 19:18

3 Answers3

5

The Narrowing,you can Narrow down to between point and mark with C-x n n,then what you edit will be restricted in this region,after that you just Widen to make the entire buffer accessible again C-x n w.Perhaps this is what you are looking for

ramsay
  • 3,197
  • 2
  • 14
  • 13
2

Try library Narrow Indirect (narrow-indirect.el)

It provides simple commands to create an indirect buffer that is a clone of the current buffer and that is narrowed to a particular portion of it. By default, it helps you distinguish such indirect buffers from non-indirect buffers, by using a buffer-name prefix (default I-) and by using a different face for the buffer name in the mode line.

Drew
  • 29,895
  • 7
  • 74
  • 104
1

To complement the other answers, if you are working on an org file specifically, you also have the following commands :

C-x n s (org-narrow-to-subtree) : Narrow buffer to current subtree.

C-x n w (widen) : Widen buffer to remove narrowing.

And if you are using blocks (‘#+BEGIN’ … ‘#+END) :

C-x n b (org-narrow-to-block) : Narrow buffer to current block.

kotchwane
  • 2,082
  • 1
  • 19
  • 24