aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2008-12-29 19:19:15 +0000
committerRichard M. Stallman2008-12-29 19:19:15 +0000
commit0a458363357ade8be6bbe08418803879e988728e (patch)
treeb785475598bfe2ed5ccc2562cc8cec87621d7888
parente1ebab6e8be57647f26adacb5d9ddac801048d39 (diff)
downloademacs-0a458363357ade8be6bbe08418803879e988728e.tar.gz
emacs-0a458363357ade8be6bbe08418803879e988728e.zip
(pmail-edit-mode): Bind buffer-swwapped-with to nil.
(pmail-edit-current-message): Save all of buffer as old text. Clear undo list. (pmail-cease-edit): Widen first. Operate in the view buffer; copy edited text back to mbox buffer and re-encode what was decoded to display the message. (pmail-abort-edit): Widen first.
-rw-r--r--lisp/mail/pmailedit.el125
1 files changed, 84 insertions, 41 deletions
diff --git a/lisp/mail/pmailedit.el b/lisp/mail/pmailedit.el
index d26a7b681c9..3c48590a893 100644
--- a/lisp/mail/pmailedit.el
+++ b/lisp/mail/pmailedit.el
@@ -61,20 +61,20 @@ to return to regular PMAIL:
61 * \\[pmail-cease-edit] makes them permanent. 61 * \\[pmail-cease-edit] makes them permanent.
62This functions runs the normal hook `pmail-edit-mode-hook'. 62This functions runs the normal hook `pmail-edit-mode-hook'.
63\\{pmail-edit-map}" 63\\{pmail-edit-map}"
64 ;; Changing the major mode unswaps the Pmail buffer
65 ;; via change-major-mode-hook.
66 (delay-mode-hooks (text-mode))
67 (use-local-map pmail-edit-map)
68 (setq major-mode 'pmail-edit-mode)
69 (setq mode-name "PMAIL Edit")
70 (if (boundp 'mode-line-modified)
71 (setq mode-line-modified (default-value 'mode-line-modified))
72 (setq mode-line-format (default-value 'mode-line-format)))
73 (if (pmail-summary-exists) 64 (if (pmail-summary-exists)
74 (save-excursion 65 (save-excursion
75 (set-buffer pmail-summary-buffer) 66 (set-buffer pmail-summary-buffer)
76 (pmail-summary-disable))) 67 (pmail-summary-disable)))
77 (run-mode-hooks 'pmail-edit-mode-hook)) 68 (let (buffer-swapped-with)
69 ;; Prevent change-major-mode-hook from unswapping the buffers.
70 (delay-mode-hooks (text-mode))
71 (use-local-map pmail-edit-map)
72 (setq major-mode 'pmail-edit-mode)
73 (setq mode-name "PMAIL Edit")
74 (if (boundp 'mode-line-modified)
75 (setq mode-line-modified (default-value 'mode-line-modified))
76 (setq mode-line-format (default-value 'mode-line-format)))
77 (run-mode-hooks 'pmail-edit-mode-hook)))
78 78
79(defvar pmail-old-pruned nil) 79(defvar pmail-old-pruned nil)
80(put 'pmail-old-pruned 'permanent-local t) 80(put 'pmail-old-pruned 'permanent-local t)
@@ -87,12 +87,13 @@ This functions runs the normal hook `pmail-edit-mode-hook'.
87 (error "No messages in this buffer")) 87 (error "No messages in this buffer"))
88 (make-local-variable 'pmail-old-pruned) 88 (make-local-variable 'pmail-old-pruned)
89 (setq pmail-old-pruned (eq pmail-header-style 'normal)) 89 (setq pmail-old-pruned (eq pmail-header-style 'normal))
90 ;; Changing the major mode unswaps the Pmail buffer
91 ;; via change-major-mode-hook.
92 (pmail-edit-mode) 90 (pmail-edit-mode)
93 (make-local-variable 'pmail-old-text) 91 (make-local-variable 'pmail-old-text)
94 (setq pmail-old-text (buffer-substring (point-min) (point-max))) 92 (save-restriction
93 (widen)
94 (setq pmail-old-text (buffer-substring (point-min) (point-max))))
95 (setq buffer-read-only nil) 95 (setq buffer-read-only nil)
96 (setq buffer-undo-list nil)
96 (force-mode-line-update) 97 (force-mode-line-update)
97 (if (and (eq (key-binding "\C-c\C-c") 'pmail-cease-edit) 98 (if (and (eq (key-binding "\C-c\C-c") 'pmail-cease-edit)
98 (eq (key-binding "\C-c\C-]") 'pmail-abort-edit)) 99 (eq (key-binding "\C-c\C-]") 'pmail-abort-edit))
@@ -107,6 +108,7 @@ This functions runs the normal hook `pmail-edit-mode-hook'.
107 (save-excursion 108 (save-excursion
108 (set-buffer pmail-summary-buffer) 109 (set-buffer pmail-summary-buffer)
109 (pmail-summary-enable))) 110 (pmail-summary-enable)))
111 (widen)
110 ;; Disguise any "From " lines so they don't start a new message. 112 ;; Disguise any "From " lines so they don't start a new message.
111 (save-excursion 113 (save-excursion
112 (goto-char (point-min)) 114 (goto-char (point-min))
@@ -120,45 +122,86 @@ This functions runs the normal hook `pmail-edit-mode-hook'.
120 (if (/= (preceding-char) ?\n) 122 (if (/= (preceding-char) ?\n)
121 (insert "\n")) 123 (insert "\n"))
122 (unless (looking-back "\n\n") 124 (unless (looking-back "\n\n")
123 (insert "\n")) 125 (insert "\n")))
124 ;; Adjust the marker that points to the end of this message. 126 (let ((old pmail-old-text)
125 (set-marker (aref pmail-message-vector (1+ pmail-current-message)) 127 character-coding is-text-message coding-system
126 (point))) 128 headers-end)
127 (let ((old pmail-old-text))
128 ;; Go back to Pmail mode, but carefully. 129 ;; Go back to Pmail mode, but carefully.
129 (force-mode-line-update) 130 (force-mode-line-update)
130 (kill-all-local-variables) 131 (let (buffer-swapped-with)
131 (pmail-mode-1) 132 (kill-all-local-variables)
132 (if (boundp 'tool-bar-map) 133 (pmail-mode-1)
133 (set (make-local-variable 'tool-bar-map) pmail-tool-bar-map)) 134 (if (boundp 'tool-bar-map)
134 (pmail-variables) 135 (set (make-local-variable 'tool-bar-map) pmail-tool-bar-map))
136 (setq buffer-undo-list t)
137 (pmail-variables))
135 ;; If text has really changed, mark message as edited. 138 ;; If text has really changed, mark message as edited.
136 (unless (and (= (length old) (- (point-max) (point-min))) 139 (unless (and (= (length old) (- (point-max) (point-min)))
137 (string= old (buffer-substring (point-min) (point-max)))) 140 (string= old (buffer-substring (point-min) (point-max))))
138 (setq old nil) 141 (setq old nil)
139 (pmail-set-attribute pmail-edited-attr-index t) 142 (goto-char (point-min))
140 ;;;??? BROKEN perhaps. 143 (search-forward "\n\n")
141 ;; I think that the Summary-Line header may not be kept there any more. 144 (setq headers-end (point))
142 (if (boundp 'pmail-summary-vector) 145
143 (progn 146 (pmail-swap-buffers-maybe)
144 (aset pmail-summary-vector (1- pmail-current-message) nil) 147
145 (save-excursion 148 (setq character-coding (mail-fetch-field "content-transfer-encoding")
146 (pmail-widen-to-current-msgbeg 149 is-text-message (pmail-is-text-p)
147 (function (lambda () 150 coding-system (pmail-get-coding-system))
148 (forward-line 2) 151 (if character-coding
149 (if (looking-at "Summary-line: ") 152 (setq character-coding (downcase character-coding)))
150 (let ((buffer-read-only nil)) 153
151 (delete-region (point) 154 (narrow-to-region (pmail-msgbeg pmail-current-message)
152 (progn (forward-line 1) 155 (pmail-msgend pmail-current-message))
153 (point)))))))))))) 156 (goto-char (point-min))
154 (save-excursion 157 (search-forward "\n\n")
155 (pmail-show-message) 158 (let ((inhibit-read-only t)
156 (pmail-toggle-header (if pmail-old-pruned 1 0)))) 159 (headers-end-1 (point)))
160 (insert-buffer-substring pmail-view-buffer headers-end)
161 (delete-region (point) (point-max))
162
163 ;; Re-encode the message body in whatever
164 ;; way it was decoded.
165 (cond
166 ((string= character-coding "quoted-printable")
167 (mail-quote-printable-region headers-end-1 (point-max)))
168 ((and (string= character-coding "base64") is-text-message)
169 (base64-encode-region headers-end-1 (point-max)))
170 ((eq character-coding 'uuencode)
171 (error "Not supported yet."))
172 (t
173 (if (or (not coding-system) (not (coding-system-p coding-system)))
174 (setq coding-system 'undecided))
175 (encode-coding-region headers-end-1 (point-max) coding-system)))
176 ))
177
178 (pmail-set-attribute pmail-edited-attr-index t)
179
180 ;;??? BROKEN perhaps.
181 ;; I think that the Summary-Line header may not be kept there any more.
182;;; (if (boundp 'pmail-summary-vector)
183;;; (progn
184;;; (aset pmail-summary-vector (1- pmail-current-message) nil)
185;;; (save-excursion
186;;; (pmail-widen-to-current-msgbeg
187;;; (function (lambda ()
188;;; (forward-line 2)
189;;; (if (looking-at "Summary-line: ")
190;;; (let ((buffer-read-only nil))
191;;; (delete-region (point)
192;;; (progn (forward-line 1)
193;;; (point)))))))))))
194 )
195
196 (save-excursion
197 (pmail-show-message)
198 (pmail-toggle-header (if pmail-old-pruned 1 0)))
157 (run-hooks 'pmail-mode-hook)) 199 (run-hooks 'pmail-mode-hook))
158 200
159(defun pmail-abort-edit () 201(defun pmail-abort-edit ()
160 "Abort edit of current message; restore original contents." 202 "Abort edit of current message; restore original contents."
161 (interactive) 203 (interactive)
204 (widen)
162 (delete-region (point-min) (point-max)) 205 (delete-region (point-min) (point-max))
163 (insert pmail-old-text) 206 (insert pmail-old-text)
164 (pmail-cease-edit) 207 (pmail-cease-edit)