(rmail-cease-edit): Call rmail-show-message even if message text is unchanged.
[emacs.git] / lisp / mail / rmailedit.el
blob8f5a65a9b59852145841ef9eb9ff74586f89397d
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message.
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: mail
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
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.
25 ;;; Code:
27 (require 'rmail)
29 (defvar rmail-old-text)
31 (defvar rmail-edit-map nil)
32 (if rmail-edit-map
33 nil
34 ;; Make a keymap that inherits text-mode-map.
35 (setq rmail-edit-map (make-sparse-keymap))
36 (set-keymap-parent rmail-edit-map text-mode-map)
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))
40 ;; Rmail Edit mode is suitable only for specially formatted data.
41 (put 'rmail-edit-mode 'mode-class 'special)
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}"
51 (text-mode)
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)))
58 (if (rmail-summary-exists)
59 (save-excursion
60 (set-buffer rmail-summary-buffer)
61 (rmail-summary-disable)))
62 (run-hooks 'rmail-edit-mode-hook))
64 ;;;###autoload
65 (defun rmail-edit-current-message ()
66 "Edit the contents of this message."
67 (interactive)
68 (rmail-edit-mode)
69 (make-local-variable 'rmail-old-text)
70 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
71 (setq buffer-read-only nil)
72 (force-mode-line-update)
73 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
74 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
75 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
76 (message "%s" (substitute-command-keys
77 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
79 (defun rmail-cease-edit ()
80 "Finish editing message; switch back to Rmail proper."
81 (interactive)
82 (if (rmail-summary-exists)
83 (save-excursion
84 (set-buffer rmail-summary-buffer)
85 (rmail-summary-enable)))
86 ;; Make sure buffer ends with a newline.
87 (save-excursion
88 (goto-char (point-max))
89 (if (/= (preceding-char) ?\n)
90 (insert "\n"))
91 ;; Adjust the marker that points to the end of this message.
92 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
93 (point)))
94 (let ((old rmail-old-text))
95 (force-mode-line-update)
96 (kill-all-local-variables)
97 (rmail-mode-1)
98 (rmail-variables)
99 (if (and (= (length old) (- (point-max) (point-min)))
100 (string= old (buffer-substring (point-min) (point-max))))
102 (setq old nil)
103 (rmail-set-attribute "edited" t)
104 (if (boundp 'rmail-summary-vector)
105 (progn
106 (aset rmail-summary-vector (1- rmail-current-message) nil)
107 (save-excursion
108 (rmail-widen-to-current-msgbeg
109 (function (lambda ()
110 (forward-line 2)
111 (if (looking-at "Summary-line: ")
112 (let ((buffer-read-only nil))
113 (delete-region (point)
114 (progn (forward-line 1)
115 (point))))))))))))
116 (save-excursion
117 (rmail-show-message)))
118 (setq buffer-read-only t))
120 (defun rmail-abort-edit ()
121 "Abort edit of current message; restore original contents."
122 (interactive)
123 (delete-region (point-min) (point-max))
124 (insert rmail-old-text)
125 (rmail-cease-edit)
126 (rmail-highlight-headers))
128 ;;; rmailedit.el ends here