Emacs: Multiple files in one buffer?

Jason Stephenson jason at sigio.com
Fri Mar 9 21:16:30 EST 2007


aluminumsulfate at earthlink.net wrote:
> 
> 
> ....  What I'd like to do is have
> each function in a C source file appear in different subfiles. But I
> want to be able to perform text operations over the whole bunch of
> them... query-replace, isearch-forward, etc.
> 
> I don't think it would require any extra structure in the document.
> Emacs supports some kind of text attributes which are just slightly
> too mystical for my current understanding. They use these text
> attributes to implement the forms package for fill-out forms (maybe
> that's where I saw it?).  I could see giving a chunk of text in a
> buffer a "source file" attribute containing the name of the file whose
> contents that chunk of text represents.


For C functions it should be relatively straightforward assuming that 
each function gets its own .c file and that the name of the .c file is 
identical to the function name. You could add a c-mode-hook that 
overrides write-file and save-buffer commands to cycle through the 
functions in the buffer, make a region around the function and then 
write the region to a file using write-region. There are other 
possibilities, but this is probably the most efficient.

It would probably be best to implement the above as around advice for 
the functions in question and load the file containing the advice in a 
c-mode-hook. If you don't have it already, I suggest getting the Elisp 
info manual and reading the section on Advising Functions. It explains 
how to write advice functions to override or to extend the built-in 
functions.

Also, if all of the .c files are in the same directory, you could add a 
new command to open all the .c files in a directory into the current 
buffer. Another possibility would be to open the .c files for the 
function signatures in a currently open .h file. With a little extra 
magic, you could have everything in one buffer and then save the .h 
stuff to the .h file and each function implementation to its own .c 
file. For bonus points, you could remove the old .c files of functions 
that were deleted or renamed.


> 
> /me goes poking in the forms package info manual... falls asleep.

The forms package might give you some ideas, but it is probably overkill 
for something like this.


More information about the gnhlug-discuss mailing list