Mercurial > hg > xemacs-beta
comparison lisp/energize/write-file.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 ; | |
5 ; The function implements semantic 1. Comment out the lines marked -2 | |
6 ; to get semantic 2 and comment out the lines marked -3 to get semantic 3. | |
7 ; | |
8 ; semantic 1: If it is assumed that C-x C-w _should_ rename the | |
9 ; buffer as well as writing to the _new_ file, | |
10 ; Energize is concerned, this should look as if I had copied the | |
11 ; buffer, reverted the original to the disk image, and killed the | |
12 ; reverted buffer, leaving only the new buffer without | |
13 ; Energize dependencies or attachments. | |
14 ; | |
15 ; semantic 2: ... I would | |
16 ; either want it to simply create the new file, leaving the buffer | |
17 ; alone... | |
18 ; | |
19 ; semantic 3: ... or second best creating the file and a new buffer for it, | |
20 ; so that I had two buffers, one for each named version of the | |
21 ; file. | |
22 | |
23 | |
24 (defun energize-write-file (filename) | |
25 "Write the current buffer into file FILENAME. | |
26 Revert and kill the current buffer and replaces it by a new buffer | |
27 showing FILENAME." | |
28 (interactive | |
29 (list (if buffer-file-name | |
30 (read-file-name "Energize write file: " | |
31 nil nil nil nil) | |
32 (read-file-name "Energize write file: " | |
33 (cdr (assq 'default-directory | |
34 (buffer-local-variables))) | |
35 nil nil (buffer-name))))) | |
36 (if (and (file-exists-p filename) | |
37 (not | |
38 (yes-or-no-p (format "File %s already exists. Overwrite it? " | |
39 filename)))) | |
40 (error "Aborted")) | |
41 (write-region (point-min) (point-max) filename nil nil) | |
42 (if buffer-file-name ; -2 -3 | |
43 (revert-buffer t t)) ; -2 -3 | |
44 (kill-buffer nil) ; -2 -3 | |
45 (set-window-buffer ; -2 | |
46 (selected-window) ; -2 | |
47 (find-file-noselect filename)) ; -2 | |
48 ) | |
49 | |
50 | |
51 ; Pick just one of the following | |
52 ; This uses the new function for all buffers | |
53 (define-key ctl-x-map '(control w) 'energize-write-file) | |
54 ; This preserves old behavior for non-energize buffers | |
55 ; (energize-advise-function 'write-file) | |
56 |