home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / emacs / help / 3928 < prev    next >
Encoding:
Text File  |  1992-09-01  |  2.6 KB  |  74 lines

  1. Xref: sparky gnu.emacs.help:3928 comp.emacs:2996
  2. Newsgroups: gnu.emacs.help,comp.emacs
  3. Path: sparky!uunet!stanford.edu!CSD-NewsHost.Stanford.EDU!CSD-Newshost!witchel
  4. From: witchel@Xenon.Stanford.EDU (Emmett Jethro Witchel)
  5. Subject: Re: Can 1 buffer visit >1 file? - Solution
  6. In-Reply-To: jym@mica.berkeley.edu's message of 31 Aug 92 09:24:09
  7. Message-ID: <WITCHEL.92Sep1112621@Xenon.Stanford.EDU>
  8. Followup-To: gnu.emacs.help,comp.emacs
  9. Sender: news@CSD-NewsHost.Stanford.EDU
  10. Organization: Computer Science Department, Stanford University.
  11. References: <WITCHEL.92Aug26162918@Xenon.Stanford.EDU>
  12.     <JYM.92Aug31092409@remarque.berkeley.edu>
  13. Date: 1 Sep 92 11:26:21
  14. Lines: 58
  15.  
  16.  
  17.     I thank all repsonses I got.  Everyone mentioned write-file-hooks,
  18. but the most complete solution follows.
  19.  
  20. From Vegard@protek.unit.no
  21.  
  22. You wrote:
  23. >    Is is possible for 1 buffer to be visiting more than one file?
  24.  
  25. Here is what I picked up from the net some time ago, 
  26. I guess it is what you are looking for.
  27.  
  28. ------------------ snip ---- snip ------------------
  29.  
  30. ;;;Authorizing-Users: Ray Nickson <Ray.Nickson@comp.vuw.ac.nz>
  31.  
  32. ;;;To use, just M-x carbon-buffer-to-file to the remote file name when
  33. ;;;you find the local one (or vice versa).
  34. ;;;(I had to chamge it for distribution; hope it still works)
  35.  
  36. ;;;You can also put the call in the file's Local Variables section with
  37. ;;;an eval, or just set buffer-carbon-file-names there.
  38.  
  39. (defvar buffer-carbon-file-names nil
  40.   "List of files to carbon-copy this buffer into.")
  41. (make-variable-buffer-local 'buffer-carbon-file-names)
  42.  
  43. (defun carbon-buffer-to-file (file)
  44.   "Make FILE be a carbon-copy of the file visited by this buffer.
  45. Any time you save the buffer, changes will go both to the buffer's own file
  46. and to FILE.  Yes, you can carbon to many files at once; the list of files
  47. being carbonned to is in the variable buffer-carbon-file-names."
  48.   (interactive "FCarbon to file: ")
  49.   (setq buffer-carbon-file-names (cons file buffer-carbon-file-names)))
  50.  
  51. (defun write-carbon-files ()
  52.   "A write-file-hook.  See \\[carbon-buffer-to-file]."
  53.   (save-restriction
  54.     (widen)
  55.     (mapcar
  56.      (function (lambda (file)
  57.        (write-region (point-min) (point-max) file)))
  58.      buffer-carbon-file-names))
  59.   nil) ; hook must return nil
  60.  
  61. (setq write-file-hooks (cons 'write-carbon-files write-file-hooks))
  62.  
  63.  
  64. ;;; (setq write-file-hooks 'nil)
  65.  
  66.  
  67. ;;; Local Variables: ***
  68. ;;; eval: (carbon-buffer-to-file "/vv@vtsg01:Emacs/carbon-copy.el") ***
  69. ;;; End: ***
  70. ------------------ snip ---- snip ---------------------
  71. Vegard Vesterheim        : Phone: +47 7 593885
  72. Production Engineering, SINTEF    : Fax:   +47 7 597043
  73. N-7034 Trondheim, NORWAY        : Email: vegard@protek.unit.no
  74.