diff options
| -rw-r--r-- | lisp/mail/pmailedit.el | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/lisp/mail/pmailedit.el b/lisp/mail/pmailedit.el index cc8831732ce..0b8d98fe5d9 100644 --- a/lisp/mail/pmailedit.el +++ b/lisp/mail/pmailedit.el | |||
| @@ -38,13 +38,14 @@ | |||
| 38 | 38 | ||
| 39 | (defvar pmail-old-text) | 39 | (defvar pmail-old-text) |
| 40 | 40 | ||
| 41 | (defvar pmail-edit-map | 41 | (defvar pmail-edit-map nil) |
| 42 | (let ((map (make-sparse-keymap))) | 42 | (if pmail-edit-map |
| 43 | (set-keymap-parent map text-mode-map) | 43 | nil |
| 44 | (define-key map "\C-c\C-c" 'pmail-cease-edit) | 44 | ;; Make a keymap that inherits text-mode-map. |
| 45 | (define-key map "\C-c\C-]" 'pmail-abort-edit) | 45 | (setq pmail-edit-map (make-sparse-keymap)) |
| 46 | map) | 46 | (set-keymap-parent pmail-edit-map text-mode-map) |
| 47 | "Keymap for `pmail-edit-mode'.") | 47 | (define-key pmail-edit-map "\C-c\C-c" 'pmail-cease-edit) |
| 48 | (define-key pmail-edit-map "\C-c\C-]" 'pmail-abort-edit)) | ||
| 48 | 49 | ||
| 49 | ;; Pmail Edit mode is suitable only for specially formatted data. | 50 | ;; Pmail Edit mode is suitable only for specially formatted data. |
| 50 | (put 'pmail-edit-mode 'mode-class 'special) | 51 | (put 'pmail-edit-mode 'mode-class 'special) |
| @@ -87,7 +88,7 @@ This functions runs the normal hook `pmail-edit-mode-hook'. | |||
| 87 | (if (= pmail-total-messages 0) | 88 | (if (= pmail-total-messages 0) |
| 88 | (error "No messages in this file")) | 89 | (error "No messages in this file")) |
| 89 | (make-local-variable 'pmail-old-pruned) | 90 | (make-local-variable 'pmail-old-pruned) |
| 90 | (setq pmail-old-pruned (pmail-msg-is-pruned)) | 91 | (setq pmail-old-pruned (eq pmail-header-style 'normal)) |
| 91 | (make-local-variable 'pmail-edit-saved-coding-system) | 92 | (make-local-variable 'pmail-edit-saved-coding-system) |
| 92 | (setq pmail-edit-saved-coding-system save-buffer-coding-system) | 93 | (setq pmail-edit-saved-coding-system save-buffer-coding-system) |
| 93 | (pmail-header-show-headers) | 94 | (pmail-header-show-headers) |
| @@ -109,18 +110,18 @@ This functions runs the normal hook `pmail-edit-mode-hook'. | |||
| 109 | (defun pmail-cease-edit () | 110 | (defun pmail-cease-edit () |
| 110 | "Finish editing message; switch back to Pmail proper." | 111 | "Finish editing message; switch back to Pmail proper." |
| 111 | (interactive) | 112 | (interactive) |
| 112 | (when (pmail-summary-exists) | 113 | (if (pmail-summary-exists) |
| 113 | (with-current-buffer pmail-summary-buffer | 114 | (save-excursion |
| 114 | (pmail-summary-enable))) | 115 | (set-buffer pmail-summary-buffer) |
| 116 | (pmail-summary-enable))) | ||
| 115 | ;; Make sure buffer ends with a newline. | 117 | ;; Make sure buffer ends with a newline. |
| 116 | (save-excursion | 118 | (save-excursion |
| 117 | (goto-char (point-max)) | 119 | (goto-char (point-max)) |
| 118 | (when (/= (preceding-char) ?\n) | 120 | (if (/= (preceding-char) ?\n) |
| 119 | (insert "\n")) | 121 | (insert "\n")) |
| 120 | ;; Adjust the marker that points to the end of this message, unless | 122 | ;; Adjust the marker that points to the end of this message. |
| 121 | ;; we're at the last message. | 123 | (set-marker (aref pmail-message-vector (1+ pmail-current-message)) |
| 122 | (when (< pmail-current-message (length pmail-desc-vector)) | 124 | (point))) |
| 123 | (pmail-desc-set-start (1+ pmail-current-message) (point)))) | ||
| 124 | (let ((old pmail-old-text)) | 125 | (let ((old pmail-old-text)) |
| 125 | (force-mode-line-update) | 126 | (force-mode-line-update) |
| 126 | (kill-all-local-variables) | 127 | (kill-all-local-variables) |
| @@ -131,16 +132,26 @@ This functions runs the normal hook `pmail-edit-mode-hook'. | |||
| 131 | ;; As the local value of save-buffer-coding-system is changed by | 132 | ;; As the local value of save-buffer-coding-system is changed by |
| 132 | ;; pmail-variables, we restore the original value. | 133 | ;; pmail-variables, we restore the original value. |
| 133 | (setq save-buffer-coding-system pmail-edit-saved-coding-system) | 134 | (setq save-buffer-coding-system pmail-edit-saved-coding-system) |
| 134 | (unless (and (= (length old) (- (point-max) (point-min))) | 135 | (if (and (= (length old) (- (point-max) (point-min))) |
| 135 | (string= old (buffer-substring (point-min) (point-max)))) | 136 | (string= old (buffer-substring (point-min) (point-max)))) |
| 137 | () | ||
| 136 | (setq old nil) | 138 | (setq old nil) |
| 137 | (pmail-set-attribute "edited" t)) | 139 | (pmail-set-attribute "edited" t) |
| 140 | (if (boundp 'pmail-summary-vector) | ||
| 141 | (progn | ||
| 142 | (aset pmail-summary-vector (1- pmail-current-message) nil) | ||
| 143 | (save-excursion | ||
| 144 | (pmail-widen-to-current-msgbeg | ||
| 145 | (function (lambda () | ||
| 146 | (forward-line 2) | ||
| 147 | (if (looking-at "Summary-line: ") | ||
| 148 | (let ((buffer-read-only nil)) | ||
| 149 | (delete-region (point) | ||
| 150 | (progn (forward-line 1) | ||
| 151 | (point)))))))))))) | ||
| 138 | (save-excursion | 152 | (save-excursion |
| 139 | (pmail-show-message) | 153 | (pmail-show-message) |
| 140 | ;; `pmail-show-message' always hides the headers, so we show them | 154 | (pmail-toggle-header (if pmail-old-pruned 1 0)))) |
| 141 | ;; here if they were visible before starting the edit. | ||
| 142 | (when pmail-old-pruned | ||
| 143 | (pmail-header-show-headers)))) | ||
| 144 | (run-hooks 'pmail-mode-hook) | 155 | (run-hooks 'pmail-mode-hook) |
| 145 | (setq buffer-read-only t)) | 156 | (setq buffer-read-only t)) |
| 146 | 157 | ||
| @@ -149,7 +160,8 @@ This functions runs the normal hook `pmail-edit-mode-hook'. | |||
| 149 | (interactive) | 160 | (interactive) |
| 150 | (delete-region (point-min) (point-max)) | 161 | (delete-region (point-min) (point-max)) |
| 151 | (insert pmail-old-text) | 162 | (insert pmail-old-text) |
| 152 | (pmail-cease-edit)) | 163 | (pmail-cease-edit) |
| 164 | (pmail-highlight-headers)) | ||
| 153 | 165 | ||
| 154 | (provide 'pmailedit) | 166 | (provide 'pmailedit) |
| 155 | 167 | ||