annotate lisp/energize/write-file.el @ 71:bae944334fa4

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