4

For some tasks I prefer single big files over splitting a project (say: a LaTeX report, a medium-sized python script) into separate smaller files, e.g. for easier searching and search-and-replace. However for editing it is often preferable to have separate views of different parts of a project, favoring several small files.

Is the some mode/package for emacs that allows editing parts of files as if they were a separate file, while keeping the buffer synchronized with all other views of the file? I am aware of clone-indirect-buffer, but while it achieves part of the intent, I'd prefer a method that limits the indirect buffer to a specific section of the file. Think e.g. of org-modes C-c ' but implemented with an indirect buffer. Ideally the implementation would support some syntax to define sections.

I think the LEO editor is build around roughly the concept that I want for emacs, though I never tried it (didn't work on my system).

1 Answer 1

3

One library that provides such behavior is Narrow Indirect (narrow-indirect.el). It 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.

You can use indirect buffers for more than you might think. You can use clones taken from portions of Dired buffers, for example, to give you useful (active) views into a directory listing. There are only a few keys/commands (such as g to update the listing) that do not work, because they depend on a view of the whole Dired buffer. Experiment, and you will no doubt find interesting new uses for indirect buffers.

See also the Emacs manual, node Indirect Buffers.

3
  • Seems to to what I asked for mostly. Though in the meantime I have found that the capabilities are mostly builtin already (clone-indirect-buffer and narrow-to-... functions). I guess I'll have to take a look at extending this to autodetecting more general regions myself (forgot to ask for that in my question).
    – kdb
    Nov 7, 2014 at 12:38
  • What do you mean by "autodetecting more general regions"?
    – Drew
    Nov 7, 2014 at 14:47
  • For instance support for a syntax that allows to declare file-sections independent of the content type of the file; E.g. a function "narrow-to-section", where the current section starts with a comment line containing START_SECTION or maybe <SECTION> and ends at a line containing a corresponding closing tag.
    – kdb
    Nov 8, 2014 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .