Remove time-stamp annoyance.
[emacs.git] / lisp / mail / rmailedit.el
blob955786353e9f5ce88ccfe198055a9cd6ff714f93
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message
3 ;; Copyright (C) 1985, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: mail
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (require 'rmail)
32 (defcustom rmail-edit-mode-hook nil
33 "List of functions to call when editing an RMAIL message."
34 :type 'hook
35 :version "21.1"
36 :group 'rmail-edit)
38 (defvar rmail-old-text)
40 (defvar rmail-edit-map nil)
41 (if rmail-edit-map
42 nil
43 ;; Make a keymap that inherits text-mode-map.
44 (setq rmail-edit-map (make-sparse-keymap))
45 (set-keymap-parent rmail-edit-map text-mode-map)
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))
49 ;; Rmail Edit mode is suitable only for specially formatted data.
50 (put 'rmail-edit-mode 'mode-class 'special)
52 (declare-function rmail-summary-disable "" ())
53 (declare-function rmail-summary-enable "rmailsum" ())
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:
59 * \\[rmail-abort-edit] cancels the changes
60 you have made and returns to RMAIL
61 * \\[rmail-cease-edit] makes them permanent.
62 This functions runs the normal hook `rmail-edit-mode-hook'.
63 \\{rmail-edit-map}"
64 (delay-mode-hooks (text-mode))
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)))
71 (if (rmail-summary-exists)
72 (save-excursion
73 (set-buffer rmail-summary-buffer)
74 (rmail-summary-disable)))
75 (run-mode-hooks 'rmail-edit-mode-hook))
77 (defvar rmail-old-pruned nil)
78 (put 'rmail-old-pruned 'permanent-local t)
80 (defvar rmail-edit-saved-coding-system nil)
81 (put 'rmail-edit-saved-coding-system 'permanent-local t)
83 ;;;###autoload
84 (defun rmail-edit-current-message ()
85 "Edit the contents of this message."
86 (interactive)
87 (make-local-variable 'rmail-old-pruned)
88 (setq rmail-old-pruned (rmail-msg-is-pruned))
89 (make-local-variable 'rmail-edit-saved-coding-system)
90 (setq rmail-edit-saved-coding-system save-buffer-coding-system)
91 (rmail-toggle-header 0)
92 (rmail-edit-mode)
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)
97 (make-local-variable 'rmail-old-text)
98 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
99 (setq buffer-read-only nil)
100 (force-mode-line-update)
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")
104 (message "%s" (substitute-command-keys
105 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
107 (defun rmail-cease-edit ()
108 "Finish editing message; switch back to Rmail proper."
109 (interactive)
110 (if (rmail-summary-exists)
111 (save-excursion
112 (set-buffer rmail-summary-buffer)
113 (rmail-summary-enable)))
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))
123 (force-mode-line-update)
124 (kill-all-local-variables)
125 (rmail-mode-1)
126 (set (make-local-variable 'tool-bar-map) rmail-tool-bar-map)
127 (rmail-variables)
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)
131 (if (and (= (length old) (- (point-max) (point-min)))
132 (string= old (buffer-substring (point-min) (point-max))))
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
141 (function (lambda ()
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)
147 (point))))))))))))
148 (save-excursion
149 (rmail-show-message)
150 (rmail-toggle-header (if rmail-old-pruned 1 0))))
151 (run-hooks 'rmail-mode-hook)
152 (setq buffer-read-only t))
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)
159 (rmail-cease-edit)
160 (rmail-highlight-headers))
162 (provide 'rmailedit)
164 ;; arch-tag: 93c22709-a14a-46c1-ab91-52c3f5a0ec12
165 ;;; rmailedit.el ends here