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