annotate lisp/rmail/rmailedit.el @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents 0293115a14e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'rmail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (defvar rmail-edit-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (if rmail-edit-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (setq rmail-edit-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (set-keymap-parent rmail-edit-map text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (set-keymap-name rmail-edit-map 'rmail-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Rmail Edit mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (put 'rmail-edit-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defun rmail-edit-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "Major mode for editing the contents of an RMAIL message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 The editing commands are the same as in Text mode, together with two commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 to return to regular RMAIL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 * rmail-abort-edit cancels the changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 you have made and returns to RMAIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * rmail-cease-edit makes them permanent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 \\{rmail-edit-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (use-local-map rmail-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq major-mode 'rmail-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq mode-name "RMAIL Edit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (boundp 'mode-line-modified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (setq mode-line-modified (default-value 'mode-line-modified))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq mode-line-format (default-value 'mode-line-format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar rmail-old-text) ;jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun rmail-edit-current-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Edit the contents of this message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (rmail-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (make-local-variable 'rmail-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Make mode line update.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (message (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defun rmail-cease-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "Finish editing message; switch back to Rmail proper."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Make sure buffer ends with a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (/= (preceding-char) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Adjust the marker that points to the end of this message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let ((old rmail-old-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; Update the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (rmail-mode-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (and (= (length old) (- (point-max) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (string= old (buffer-substring (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq old nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (rmail-set-attribute "edited" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (boundp 'rmail-summary-vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (aset rmail-summary-vector (1- rmail-current-message) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (rmail-widen-to-current-msgbeg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (forward-line 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (looking-at "Summary-line: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (progn (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (point))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (rmail-show-message))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun rmail-abort-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Abort edit of current message; restore original contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (insert rmail-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (rmail-cease-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; rmailedit.el ends here