home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / energize / write-file.el < prev    next >
Encoding:
Text File  |  1992-12-19  |  2.1 KB  |  57 lines

  1. ; If you load this in your .emacs, write-file will be redefined to do
  2. ; what is described below.  If you like it please tell us so
  3. ; that we could provide it by default.
  4. ; The function implements semantic 1.  Comment out the lines marked -2
  5. ; to get semantic 2 and comment out the lines marked -3 to get semantic 3.
  6. ; semantic 1: If it is assumed that C-x C-w _should_ rename the
  7. ;             buffer as well as writing to the _new_ file, 
  8. ;             Energize is concerned, this should look as if I had copied the
  9. ;             buffer, reverted the original to the disk image, and killed the
  10. ;             reverted buffer, leaving only the new buffer without
  11. ;             Energize dependencies or attachments.
  12. ; semantic 2: ... I would
  13. ;             either want it to simply create the new file, leaving the buffer
  14. ;             alone...
  15. ; semantic 3: ... or second best creating the file and a new buffer for it,
  16. ;             so that I had two buffers, one for each named version of the
  17. ;             file.
  18.  
  19.  
  20. (defun energize-write-file (filename)
  21.   "Write the current buffer into file FILENAME.
  22. Revert and kill the current buffer and replaces it by a new buffer 
  23. showing FILENAME."
  24.   (interactive
  25.    (list (if buffer-file-name
  26.          (read-file-name "Energize write file: "
  27.                  nil nil nil nil)
  28.        (read-file-name "Energize write file: "
  29.                (cdr (assq 'default-directory
  30.                       (buffer-local-variables)))
  31.                nil nil (buffer-name)))))
  32.   (if (and (file-exists-p filename)
  33.        (not
  34.         (yes-or-no-p (format "File %s already exists.  Overwrite it? "
  35.                  filename))))
  36.       (error "Aborted"))
  37.   (write-region (point-min) (point-max) filename nil nil)
  38.   (if buffer-file-name            ; -2   -3
  39.       (revert-buffer t t))        ; -2   -3
  40.   (kill-buffer nil)            ; -2   -3
  41.   (set-window-buffer            ; -2
  42.    (selected-window)            ; -2 
  43.    (find-file-noselect filename))    ; -2 
  44.   )  
  45.  
  46.  
  47. ; Pick just one of the following
  48. ;   This uses the new function for all buffers
  49. (define-key ctl-x-map '(control w) 'energize-write-file)
  50. ;   This preserves old behavior for non-energize buffers
  51. ; (energize-advise-function 'write-file)
  52.  
  53.