Emacs: Multiple files in one buffer?

Jason Stephenson jason at sigio.com
Thu Mar 8 22:58:15 EST 2007


aluminumsulfate at earthlink.net wrote:
> This message is addressed to all the Emacs gurus on the list...

Dunno if I'm a guru or not, but I've used GNU Emacs for 15 years and 
dabbled with X-Emacs briefly. My .emacs is only about 4K in size, but 
I've created a couple minor and major modes for various special file 
types. I'm also running the latest GNU Emacs (22.0.95) from cvs.

> I have a vague sort-of-almost memory of having read something about a
> major mode which will let you edit multiple files in a single buffer.
> I wondered how that could work, how emacs could know which part of the
> buffer belonged to which file, but I didn't think it was useful
> (indeed, I deemed it dangerous) at the time.

Closest thing to what you describe that I have heard of is 
HtmlModeDeluxe (http://www.emacswiki.org/cgi-bin/emacs/HtmlModeDeluxe). 
It allows you to run multiple major modes at once on different regions 
of a buffer, so that the different PHP, HTML and CSS sections have 
proper highlighting. However, all of those regions in the buffer come 
from one file.

I'm not sure that you could make different regions of a buffer point 
explicitly to different files. My experience with Emacs suggests that 
the notion of a buffer is very tightly integrated with the file system's 
understanding of a file.

That said, you can actually load multiple files into a single buffer, 
but the default save commands will save the entire buffer as a single 
file unless you have severely hacked the file save hooks for your 
current mode and have some clearly defined markers that Emacs could use 
to split the data apart. You'd also need some way to preserve the file 
names so that your mode would know how to save the various sections. 
Essentially, your buffer data would need to have some kind of structure 
to it, and your editing mode would need to enforce that structure in 
some way, most likely through custom navigation commands. Even if you 
were just editing free-form plain text files, your buffer would need 
special lines that would tell the file save hook where a new file begins 
and what that file's name is.

Generally, when I've needed to edit multiple files sort of 
simultaneously I've simply opened the various files and split the window 
however many times are necessary for portions of each buffer to show.


More information about the gnhlug-discuss mailing list