Associate one buffer with two files

Associate one buffer with two files

Post by Troy Daniel » Thu, 19 Dec 1996 04:00:00



Is it possible to associate one buffer with two files?  All I really
want is to do is have the save functions write the buffer to both
files.  (E.g., I don't care about loading the file, or resolving
differences if the versions on disk are different.)  I thought about
using after-save-hook, but decided to see if someone had already done
the work before I worried about infinite loops.

Thanks,
Troy Daniels

 
 
 

Associate one buffer with two files

Post by Faried Nawa » Thu, 19 Dec 1996 04:00:00


make a link.

M-x make-symbolic-link RET

 
 
 

Associate one buffer with two files

Post by Vegard Vesterhei » Fri, 20 Dec 1996 04:00:00



> Is it possible to associate one buffer with two files?  All I really
> want is to do is have the save functions write the buffer to both
> files.  (E.g., I don't care about loading the file, or resolving
> differences if the versions on disk are different.)  I thought about
> using after-save-hook, but decided to see if someone had already done
> the work before I worried about infinite loops.

> Thanks,
> Troy Daniels


Here is a small elisp package named carbon-buffer.el which does what
you want.

----- snip - snip -------------------------------------------------

;;;To use, just M-x carbon-buffer-to-file to the remote file name when
;;;you find the local one (or vice versa).
;;;(I had to chamge it for distribution; hope it still works)

;;;You can also put the call in the file's Local Variables section with
;;;an eval, or just set buffer-carbon-file-names there.

(defvar buffer-carbon-file-names nil
  "List of files to carbon-copy this buffer into.")
(make-variable-buffer-local 'buffer-carbon-file-names)

(defun carbon-buffer-to-file (file)
  "Make FILE be a carbon-copy of the file visited by this buffer.
Any time you save the buffer, changes will go both to the buffer's own file
and to FILE.  Yes, you can carbon to many files at once; the list of files
being carbonned to is in the variable buffer-carbon-file-names."
  (interactive "FCarbon to file: ")
  (setq buffer-carbon-file-names (cons file buffer-carbon-file-names)))

(defun write-carbon-files ()
  "A write-file-hook.  See \\[carbon-buffer-to-file]."
  (save-restriction
    (widen)
    (mapcar
     (function (lambda (file)
       (write-region (point-min) (point-max) file)))
     buffer-carbon-file-names))
  nil) ; hook must return nil

(add-hook 'write-file-hooks 'write-carbon-files)
----- snip - snip -------------------------------------------------
--
Vegard Vesterheim               : Phone: +47 73593002
SINTEF Drift, IT-avdelingen     : Fax:   +47 73591700

 
 
 

1. Linked scrolling of one buffer in two frames..?

A couple of weeks ago, I accidentally ran across a function/mode that
permitted one buffer displayed in two windows/frames to scroll in
unison.  E.g. paging down in one frame causes a page down in the other
frame.

At the time it wasn't what I was looking for, and though a novelty,
was quickly forgotten.  I thought it was called something like
"viewport-mode" or "overview-mode" or the like, but after grepping
through info, apropos, etc, etc., this mode still eludes me.

Does anyone know what the heck I'm talking about and know how to
invoke this mode?  8-)

TIA,
John Whitley

2. Mode Z & 3D Books

3. How two get next buffer in list instead of current one after splitting windows?

4. WTB: Amiga 3000T

5. Emerge - merge two files or buffers, code (part 2 of 2)

6. Optus@Home in Australia?

7. Emerge - merge two files or buffers, documentation (part 1 of 2)

8. sendmail and non-authoritative answer

9. Automatically exiting the shell when killing the associated buffer

10. circulating between buffers, loading many files in one time, server-edit

11. delete all buffers associated to a frame?

12. multiple files in one buffer

13. fill-paragraph by first & second line