Search code examples
emacseditorregions

How to view and edit only a small part of a text file in Emacs


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!


Solution

  • 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.