Mercurial > hg > xemacs-beta
comparison lisp/vm/vm-edit.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; Editing VM messages | |
2 ;;; Copyright (C) 1990, 1991, 1993, 1994 Kyle E. Jones | |
3 ;;; | |
4 ;;; This program is free software; you can redistribute it and/or modify | |
5 ;;; it under the terms of the GNU General Public License as published by | |
6 ;;; the Free Software Foundation; either version 1, or (at your option) | |
7 ;;; any later version. | |
8 ;;; | |
9 ;;; This program is distributed in the hope that it will be useful, | |
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ;;; GNU General Public License for more details. | |
13 ;;; | |
14 ;;; You should have received a copy of the GNU General Public License | |
15 ;;; along with this program; if not, write to the Free Software | |
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | |
18 (provide 'vm-edit) | |
19 | |
20 (defun vm-edit-message (&optional prefix-argument) | |
21 "Edit the current message. Prefix arg means mark as unedited instead. | |
22 If editing, the current message is copied into a temporary buffer, and | |
23 this buffer is selected for editing. The major mode of this buffer is | |
24 controlled by the variable vm-edit-message-mode. The hooks specified | |
25 in vm-edit-message-hook are run just prior to returning control to the user | |
26 for editing. | |
27 | |
28 Use C-c ESC when you have finished editing the message. The message | |
29 will be inserted into its folder replacing the old version of the | |
30 message. If you don't want your edited version of the message to | |
31 replace the original, use C-c C-] and the edit will be aborted." | |
32 (interactive "P") | |
33 (vm-follow-summary-cursor) | |
34 (vm-select-folder-buffer) | |
35 (vm-check-for-killed-summary) | |
36 (vm-error-if-folder-read-only) | |
37 (vm-error-if-folder-empty) | |
38 (if (and (vm-virtual-message-p (car vm-message-pointer)) | |
39 (null (vm-virtual-messages-of (car vm-message-pointer)))) | |
40 (error "Can't edit unmirrored virtual messages.")) | |
41 (if prefix-argument | |
42 (if (vm-edited-flag (car vm-message-pointer)) | |
43 (progn | |
44 (vm-set-edited-flag-of (car vm-message-pointer) nil) | |
45 (vm-update-summary-and-mode-line))) | |
46 (let ((mp vm-message-pointer) | |
47 (offset (- (point) (vm-headers-of (car vm-message-pointer)))) | |
48 (edit-buf (vm-edit-buffer-of (car vm-message-pointer))) | |
49 (folder-buffer (current-buffer))) | |
50 (if (not (and edit-buf (buffer-name edit-buf))) | |
51 (progn | |
52 (vm-save-restriction | |
53 (widen) | |
54 (setq edit-buf | |
55 (generate-new-buffer | |
56 (format "edit of %s's note re: %s" | |
57 (vm-su-full-name (car vm-message-pointer)) | |
58 (vm-su-subject (car vm-message-pointer))))) | |
59 (vm-set-edit-buffer-of (car mp) edit-buf) | |
60 (copy-to-buffer edit-buf | |
61 (vm-headers-of (car mp)) | |
62 (vm-text-end-of (car mp)))) | |
63 (set-buffer edit-buf) | |
64 (set-buffer-modified-p nil) | |
65 (goto-char (point-min)) | |
66 (if (< offset 0) | |
67 (search-forward "\n\n" nil t) | |
68 (forward-char offset)) | |
69 (funcall (or vm-edit-message-mode 'text-mode)) | |
70 (use-local-map vm-edit-message-map) | |
71 ;; (list (car mp)) because a different message may | |
72 ;; later be stuffed into a cons linked that is linked | |
73 ;; into the folder's message list. | |
74 (setq vm-message-pointer (list (car mp)) | |
75 vm-mail-buffer folder-buffer | |
76 vm-system-state 'editing) | |
77 (run-hooks 'vm-edit-message-hook) | |
78 (message | |
79 (substitute-command-keys | |
80 "Type \\[vm-edit-message-end] to end edit, \\[vm-edit-message-abort] to abort with no change."))) | |
81 (set-buffer edit-buf)) | |
82 (if (and vm-frame-per-edit (vm-multiple-frames-possible-p)) | |
83 (let ((w (vm-get-buffer-window edit-buf))) | |
84 (if (null w) | |
85 (progn | |
86 (vm-goto-new-frame 'edit) | |
87 (vm-set-hooks-for-frame-deletion)) | |
88 (save-excursion | |
89 (select-window w) | |
90 (and vm-warp-mouse-to-new-frame | |
91 (vm-warp-mouse-to-frame-maybe (vm-window-frame w))))))) | |
92 (vm-display edit-buf t '(vm-edit-message vm-edit-message-other-frame) | |
93 (list this-command 'editing-message))))) | |
94 | |
95 (defun vm-edit-message-other-frame (&optional prefix) | |
96 "Like vm-edit-message, but run in a newly created frame." | |
97 (interactive "P") | |
98 (if (vm-multiple-frames-possible-p) | |
99 (vm-goto-new-frame 'edit)) | |
100 (let ((vm-search-other-frames nil) | |
101 (vm-frame-per-edit nil)) | |
102 (vm-edit-message prefix)) | |
103 (if (vm-multiple-frames-possible-p) | |
104 (vm-set-hooks-for-frame-deletion))) | |
105 | |
106 (defun vm-discard-cached-data (&optional count) | |
107 "Discard cached information about the current message. | |
108 When VM gathers information from the headers of a message, it stores it | |
109 internally for future reference. This command causes VM to forget this | |
110 information, and VM will be forced to search the headers of the message | |
111 again for these data. VM will also have to decide again which headers | |
112 should be displayed and which should not. Therefore this command is | |
113 useful if you change the value of vm-visible-headers or | |
114 vm-invisible-header-regexp in the midst of a VM session. | |
115 | |
116 Numeric prefix argument N means to discard data from the current message | |
117 plus the next N-1 messages. A negative N means discard data from the | |
118 current message and the previous N-1 messages. | |
119 | |
120 When invoked on marked messages (via vm-next-command-uses-marks), | |
121 data is discarded only from the marked messages in the current folder." | |
122 (interactive "p") | |
123 (or count (setq count 1)) | |
124 (vm-follow-summary-cursor) | |
125 (vm-select-folder-buffer) | |
126 (vm-check-for-killed-summary) | |
127 (vm-error-if-folder-empty) | |
128 (let ((mlist (vm-select-marked-or-prefixed-messages count)) m) | |
129 (while mlist | |
130 (setq m (vm-real-message-of (car mlist))) | |
131 (if vm-thread-obarray | |
132 (vm-unthread-message m t)) | |
133 (fillarray (vm-cache-of m) nil) | |
134 (vm-set-vheaders-of m nil) | |
135 (vm-set-vheaders-regexp-of m nil) | |
136 (vm-set-text-of m nil) | |
137 (if vm-thread-obarray | |
138 (vm-build-threads (list m))) | |
139 (if vm-summary-show-threads | |
140 (vm-sort-messages "thread")) | |
141 (let ((v-list (vm-virtual-messages-of m))) | |
142 (save-excursion | |
143 (while v-list | |
144 (set-buffer (vm-buffer-of (car v-list))) | |
145 (if vm-thread-obarray | |
146 (vm-build-threads (list (car v-list)))) | |
147 (if vm-summary-show-threads | |
148 (vm-sort-messages "thread")) | |
149 (setq v-list (cdr v-list))))) | |
150 (vm-mark-for-summary-update m) | |
151 (setq mlist (cdr mlist)))) | |
152 (vm-display nil nil '(vm-discard-cached-data) '(vm-discard-cached-data)) | |
153 (vm-update-summary-and-mode-line)) | |
154 | |
155 (defun vm-edit-message-end () | |
156 "End the edit of a message and copy the result to its folder." | |
157 (interactive) | |
158 (if (null vm-message-pointer) | |
159 (error "This is not a VM message edit buffer.")) | |
160 (if (null (buffer-name (vm-buffer-of (car vm-message-pointer)))) | |
161 (error "The folder buffer for this message has been killed.")) | |
162 ;; make sure the message ends with a newline | |
163 (goto-char (point-max)) | |
164 (and (/= (preceding-char) ?\n) (insert ?\n)) | |
165 ;; munge message separators found in the edited message to | |
166 ;; prevent message from being split into several messages. | |
167 (vm-munge-message-separators (vm-message-type-of (car vm-message-pointer)) | |
168 (point-min) (point-max)) | |
169 ;; for From_-with-Content-Length recompute the Content-Length header | |
170 (if (eq (vm-message-type-of (car vm-message-pointer)) | |
171 'From_-with-Content-Length) | |
172 (let ((buffer-read-only nil) | |
173 length) | |
174 (goto-char (point-min)) | |
175 ;; first delete all copies of Content-Length | |
176 (while (and (re-search-forward vm-content-length-search-regexp nil t) | |
177 (null (match-beginning 1)) | |
178 (progn (goto-char (match-beginning 0)) | |
179 (vm-match-header vm-content-length-header))) | |
180 (delete-region (vm-matched-header-start) (vm-matched-header-end))) | |
181 ;; now compute the message body length | |
182 (goto-char (point-min)) | |
183 (search-forward "\n\n" nil 0) | |
184 (setq length (- (point-max) (point))) | |
185 ;; insert the header | |
186 (goto-char (point-min)) | |
187 (insert vm-content-length-header " " (int-to-string length) "\n"))) | |
188 (let ((edit-buf (current-buffer)) | |
189 (mp vm-message-pointer)) | |
190 (if (buffer-modified-p) | |
191 (progn | |
192 (widen) | |
193 (save-excursion | |
194 (set-buffer (vm-buffer-of (vm-real-message-of (car mp)))) | |
195 (if (not (memq (vm-real-message-of (car mp)) vm-message-list)) | |
196 (error "The original copy of this message has been expunged.")) | |
197 (vm-save-restriction | |
198 (widen) | |
199 (goto-char (vm-headers-of (vm-real-message-of (car mp)))) | |
200 (let ((vm-message-pointer mp) | |
201 opoint | |
202 (buffer-read-only nil)) | |
203 (setq opoint (point)) | |
204 (insert-buffer-substring edit-buf) | |
205 (delete-region | |
206 (point) (vm-text-end-of (vm-real-message-of (car mp)))) | |
207 (vm-discard-cached-data)) | |
208 (vm-set-edited-flag-of (car mp) t) | |
209 (vm-set-edit-buffer-of (car mp) nil)) | |
210 (set-buffer (vm-buffer-of (car mp))) | |
211 (if (eq (vm-real-message-of (car mp)) | |
212 (vm-real-message-of (car vm-message-pointer))) | |
213 (vm-preview-current-message) | |
214 (vm-update-summary-and-mode-line)))) | |
215 (message "No change.")) | |
216 (vm-display edit-buf nil '(vm-edit-message-end) | |
217 '(vm-edit-message-end reading-message startup)) | |
218 (set-buffer-modified-p nil) | |
219 (kill-buffer edit-buf))) | |
220 | |
221 (defun vm-edit-message-abort () | |
222 "Abort the edit of a message, forgetting changes to the message." | |
223 (interactive) | |
224 (if (null vm-message-pointer) | |
225 (error "This is not a VM message edit buffer.")) | |
226 (if (null (buffer-name (vm-buffer-of (vm-real-message-of (car vm-message-pointer))))) | |
227 (error "The folder buffer for this message has been killed.")) | |
228 (vm-set-edit-buffer-of (car vm-message-pointer) nil) | |
229 (vm-display (current-buffer) nil | |
230 '(vm-edit-message-abort) | |
231 '(vm-edit-message-abort reading-message startup)) | |
232 (set-buffer-modified-p nil) | |
233 (kill-buffer (current-buffer)) | |
234 (message "Aborted, no change.")) |