comparison lisp/rmail/rmailedit.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message.
2
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
8 ;; This file is part of XEmacs.
9
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; 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.
14
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Code:
25
26 (require 'rmail)
27
28 (defvar rmail-edit-map nil)
29 (if rmail-edit-map
30 nil
31 (setq rmail-edit-map (make-sparse-keymap))
32 (set-keymap-parent rmail-edit-map text-mode-map)
33 (set-keymap-name rmail-edit-map 'rmail-edit-map)
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.
42 The editing commands are the same as in Text mode, together with two commands
43 to 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)))
54 (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
55
56 (defvar rmail-old-text) ;jwz
57 (defun rmail-edit-current-message ()
58 "Edit the contents of this message."
59 (interactive)
60 (rmail-edit-mode)
61 (make-local-variable 'rmail-old-text)
62 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
63 (setq buffer-read-only nil)
64 (set-buffer-modified-p (buffer-modified-p))
65 ;; Make mode line update.
66 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
67 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
68 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
69 (message (substitute-command-keys
70 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
71
72 (defun rmail-cease-edit ()
73 "Finish editing message; switch back to Rmail proper."
74 (interactive)
75 ;; Make sure buffer ends with a newline.
76 (save-excursion
77 (goto-char (point-max))
78 (if (/= (preceding-char) ?\n)
79 (insert "\n"))
80 ;; Adjust the marker that points to the end of this message.
81 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
82 (point)))
83 (let ((old rmail-old-text))
84 ;; Update the mode line.
85 (set-buffer-modified-p (buffer-modified-p))
86 (rmail-mode-1)
87 (if (and (= (length old) (- (point-max) (point-min)))
88 (string= old (buffer-substring (point-min) (point-max))))
89 ()
90 (setq old nil)
91 (rmail-set-attribute "edited" t)
92 (if (boundp 'rmail-summary-vector)
93 (progn
94 (aset rmail-summary-vector (1- rmail-current-message) nil)
95 (save-excursion
96 (rmail-widen-to-current-msgbeg
97 (function (lambda ()
98 (forward-line 2)
99 (if (looking-at "Summary-line: ")
100 (let ((buffer-read-only nil))
101 (delete-region (point)
102 (progn (forward-line 1)
103 (point))))))))
104 (rmail-show-message))))))
105 (setq buffer-read-only t))
106
107 (defun rmail-abort-edit ()
108 "Abort edit of current message; restore original contents."
109 (interactive)
110 (delete-region (point-min) (point-max))
111 (insert rmail-old-text)
112 (rmail-cease-edit))
113
114 ;;; rmailedit.el ends here