Commit | Line | Data |
---|---|---|
c88ab9ce ER |
1 | ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message. |
2 | ||
8f1204db | 3 | ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc. |
9750e079 | 4 | |
e5167999 | 5 | ;; Maintainer: FSF |
d7b4d18f | 6 | ;; Keywords: mail |
e5167999 | 7 | |
a2535589 JA |
8 | ;; This file is part of GNU Emacs. |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
a2535589 JA |
13 | ;; any later version. |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
a2535589 | 24 | |
e5167999 | 25 | ;;; Code: |
a2535589 JA |
26 | |
27 | (require 'rmail) | |
28 | ||
c241bb9c KH |
29 | (defvar rmail-old-text) |
30 | ||
a2535589 JA |
31 | (defvar rmail-edit-map nil) |
32 | (if rmail-edit-map | |
33 | nil | |
9a4cc6bd | 34 | ;; Make a keymap that inherits text-mode-map. |
c241bb9c KH |
35 | (setq rmail-edit-map (make-sparse-keymap)) |
36 | (set-keymap-parent rmail-edit-map text-mode-map) | |
a2535589 JA |
37 | (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit) |
38 | (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit)) | |
39 | ||
40 | ;; Rmail Edit mode is suitable only for specially formatted data. | |
41 | (put 'rmail-edit-mode 'mode-class 'special) | |
42 | ||
43 | (defun rmail-edit-mode () | |
44 | "Major mode for editing the contents of an RMAIL message. | |
45 | The editing commands are the same as in Text mode, together with two commands | |
46 | to return to regular RMAIL: | |
47 | * rmail-abort-edit cancels the changes | |
48 | you have made and returns to RMAIL | |
49 | * rmail-cease-edit makes them permanent. | |
50 | \\{rmail-edit-map}" | |
c241bb9c | 51 | (text-mode) |
a2535589 JA |
52 | (use-local-map rmail-edit-map) |
53 | (setq major-mode 'rmail-edit-mode) | |
54 | (setq mode-name "RMAIL Edit") | |
55 | (if (boundp 'mode-line-modified) | |
56 | (setq mode-line-modified (default-value 'mode-line-modified)) | |
57 | (setq mode-line-format (default-value 'mode-line-format))) | |
c35fb216 | 58 | (if (rmail-summary-exists) |
56b25713 KH |
59 | (save-excursion |
60 | (set-buffer rmail-summary-buffer) | |
61 | (rmail-summary-disable))) | |
c241bb9c | 62 | (run-hooks 'rmail-edit-mode-hook)) |
a2535589 | 63 | |
77fb8963 RS |
64 | (defvar rmail-old-pruned nil) |
65 | (put 'rmail-old-pruned 'permanent-local t) | |
66 | ||
7c968ca5 RS |
67 | (defvar rmail-edit-saved-coding-system nil) |
68 | (put 'rmail-edit-saved-coding-system 'permanent-local t) | |
69 | ||
523abd28 | 70 | ;;;###autoload |
a2535589 JA |
71 | (defun rmail-edit-current-message () |
72 | "Edit the contents of this message." | |
73 | (interactive) | |
77fb8963 RS |
74 | (make-local-variable 'rmail-old-pruned) |
75 | (setq rmail-old-pruned (rmail-msg-is-pruned)) | |
7c968ca5 RS |
76 | (make-local-variable 'rmail-edit-saved-coding-system) |
77 | (setq rmail-edit-saved-coding-system save-buffer-coding-system) | |
77fb8963 | 78 | (rmail-toggle-header 0) |
a2535589 | 79 | (rmail-edit-mode) |
7c968ca5 RS |
80 | ;; As the local value of save-buffer-coding-system is deleted by |
81 | ;; rmail-edit-mode, we restore the original value. | |
82 | (make-local-variable 'save-buffer-coding-system) | |
83 | (setq save-buffer-coding-system rmail-edit-saved-coding-system) | |
a2535589 JA |
84 | (make-local-variable 'rmail-old-text) |
85 | (setq rmail-old-text (buffer-substring (point-min) (point-max))) | |
86 | (setq buffer-read-only nil) | |
cde63420 | 87 | (force-mode-line-update) |
a2535589 JA |
88 | (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit) |
89 | (eq (key-binding "\C-c\C-]") 'rmail-abort-edit)) | |
90 | (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort") | |
e26a12ac | 91 | (message "%s" (substitute-command-keys |
77fb8963 | 92 | "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort")))) |
a2535589 JA |
93 | |
94 | (defun rmail-cease-edit () | |
95 | "Finish editing message; switch back to Rmail proper." | |
96 | (interactive) | |
c35fb216 | 97 | (if (rmail-summary-exists) |
56b25713 KH |
98 | (save-excursion |
99 | (set-buffer rmail-summary-buffer) | |
100 | (rmail-summary-enable))) | |
a2535589 JA |
101 | ;; Make sure buffer ends with a newline. |
102 | (save-excursion | |
103 | (goto-char (point-max)) | |
104 | (if (/= (preceding-char) ?\n) | |
105 | (insert "\n")) | |
106 | ;; Adjust the marker that points to the end of this message. | |
107 | (set-marker (aref rmail-message-vector (1+ rmail-current-message)) | |
108 | (point))) | |
109 | (let ((old rmail-old-text)) | |
cde63420 | 110 | (force-mode-line-update) |
c241bb9c | 111 | (kill-all-local-variables) |
a2535589 | 112 | (rmail-mode-1) |
c241bb9c | 113 | (rmail-variables) |
7c968ca5 RS |
114 | ;; As the local value of save-buffer-coding-system is changed by |
115 | ;; rmail-variables, we restore the original value. | |
116 | (setq save-buffer-coding-system rmail-edit-saved-coding-system) | |
a2535589 JA |
117 | (if (and (= (length old) (- (point-max) (point-min))) |
118 | (string= old (buffer-substring (point-min) (point-max)))) | |
119 | () | |
120 | (setq old nil) | |
121 | (rmail-set-attribute "edited" t) | |
122 | (if (boundp 'rmail-summary-vector) | |
123 | (progn | |
124 | (aset rmail-summary-vector (1- rmail-current-message) nil) | |
125 | (save-excursion | |
126 | (rmail-widen-to-current-msgbeg | |
cd95034f | 127 | (function (lambda () |
a2535589 JA |
128 | (forward-line 2) |
129 | (if (looking-at "Summary-line: ") | |
130 | (let ((buffer-read-only nil)) | |
131 | (delete-region (point) | |
132 | (progn (forward-line 1) | |
cd95034f RS |
133 | (point)))))))))))) |
134 | (save-excursion | |
77fb8963 RS |
135 | (rmail-show-message) |
136 | (rmail-toggle-header (if rmail-old-pruned 1 0)))) | |
bd84ce86 | 137 | (run-hooks 'rmail-mode-hook) |
a2535589 JA |
138 | (setq buffer-read-only t)) |
139 | ||
140 | (defun rmail-abort-edit () | |
141 | "Abort edit of current message; restore original contents." | |
142 | (interactive) | |
143 | (delete-region (point-min) (point-max)) | |
144 | (insert rmail-old-text) | |
2ac32b29 RS |
145 | (rmail-cease-edit) |
146 | (rmail-highlight-headers)) | |
a2535589 | 147 | |
c88ab9ce | 148 | ;;; rmailedit.el ends here |