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