Update FSF's address.
[bpt/emacs.git] / lisp / mail / rmailedit.el
CommitLineData
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
29(defvar rmail-edit-map nil)
30(if rmail-edit-map
31 nil
9a4cc6bd
RS
32 ;; Make a keymap that inherits text-mode-map.
33 (setq rmail-edit-map (nconc (make-sparse-keymap) text-mode-map))
a2535589
JA
34 (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
35 (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
36
37;; Rmail Edit mode is suitable only for specially formatted data.
38(put 'rmail-edit-mode 'mode-class 'special)
39
40(defun rmail-edit-mode ()
41 "Major mode for editing the contents of an RMAIL message.
42The editing commands are the same as in Text mode, together with two commands
43to return to regular RMAIL:
44 * rmail-abort-edit cancels the changes
45 you have made and returns to RMAIL
46 * rmail-cease-edit makes them permanent.
47\\{rmail-edit-map}"
48 (use-local-map rmail-edit-map)
49 (setq major-mode 'rmail-edit-mode)
50 (setq mode-name "RMAIL Edit")
51 (if (boundp 'mode-line-modified)
52 (setq mode-line-modified (default-value 'mode-line-modified))
53 (setq mode-line-format (default-value 'mode-line-format)))
c35fb216 54 (if (rmail-summary-exists)
56b25713
KH
55 (save-excursion
56 (set-buffer rmail-summary-buffer)
57 (rmail-summary-disable)))
a2535589
JA
58 (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
59
60(defun rmail-edit-current-message ()
61 "Edit the contents of this message."
62 (interactive)
63 (rmail-edit-mode)
64 (make-local-variable 'rmail-old-text)
65 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
66 (setq buffer-read-only nil)
cde63420 67 (force-mode-line-update)
a2535589
JA
68 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
69 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
70 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
71 (message (substitute-command-keys
72 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
73
74(defun rmail-cease-edit ()
75 "Finish editing message; switch back to Rmail proper."
76 (interactive)
c35fb216 77 (if (rmail-summary-exists)
56b25713
KH
78 (save-excursion
79 (set-buffer rmail-summary-buffer)
80 (rmail-summary-enable)))
a2535589
JA
81 ;; Make sure buffer ends with a newline.
82 (save-excursion
83 (goto-char (point-max))
84 (if (/= (preceding-char) ?\n)
85 (insert "\n"))
86 ;; Adjust the marker that points to the end of this message.
87 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
88 (point)))
89 (let ((old rmail-old-text))
cde63420 90 (force-mode-line-update)
a2535589
JA
91 (rmail-mode-1)
92 (if (and (= (length old) (- (point-max) (point-min)))
93 (string= old (buffer-substring (point-min) (point-max))))
94 ()
95 (setq old nil)
96 (rmail-set-attribute "edited" t)
97 (if (boundp 'rmail-summary-vector)
98 (progn
99 (aset rmail-summary-vector (1- rmail-current-message) nil)
100 (save-excursion
101 (rmail-widen-to-current-msgbeg
102 (function (lambda ()
103 (forward-line 2)
104 (if (looking-at "Summary-line: ")
105 (let ((buffer-read-only nil))
106 (delete-region (point)
107 (progn (forward-line 1)
108 (point))))))))
109 (rmail-show-message))))))
110 (setq buffer-read-only t))
111
112(defun rmail-abort-edit ()
113 "Abort edit of current message; restore original contents."
114 (interactive)
115 (delete-region (point-min) (point-max))
116 (insert rmail-old-text)
2ac32b29
RS
117 (rmail-cease-edit)
118 (rmail-highlight-headers))
a2535589 119
c88ab9ce 120;;; rmailedit.el ends here