annotate lisp/rmail/rmailedit.el @ 7:c153ca296910

Added tag r19-15b4 for changeset 27bc7f280385
author cvs
date Mon, 13 Aug 2007 08:47:16 +0200
parents 376386a54a3c
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (require 'rmail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defvar rmail-edit-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (if rmail-edit-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (setq rmail-edit-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (set-keymap-parent rmail-edit-map text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (set-keymap-name rmail-edit-map 'rmail-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Rmail Edit mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (put 'rmail-edit-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun rmail-edit-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Major mode for editing the contents of an RMAIL message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 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
43 to return to regular RMAIL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 * rmail-abort-edit cancels the changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 you have made and returns to RMAIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * rmail-cease-edit makes them permanent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 \\{rmail-edit-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (use-local-map rmail-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq major-mode 'rmail-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq mode-name "RMAIL Edit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if (boundp 'mode-line-modified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (setq mode-line-modified (default-value 'mode-line-modified))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (setq mode-line-format (default-value 'mode-line-format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar rmail-old-text) ;jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defun rmail-edit-current-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "Edit the contents of this message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (rmail-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (make-local-variable 'rmail-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; Make mode line update.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (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
69 (message (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "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
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun rmail-cease-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Finish editing message; switch back to Rmail proper."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; Make sure buffer ends with a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (if (/= (preceding-char) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Adjust the marker that points to the end of this message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (let ((old rmail-old-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; Update the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (rmail-mode-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (if (and (= (length old) (- (point-max) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (string= old (buffer-substring (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (setq old nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (rmail-set-attribute "edited" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if (boundp 'rmail-summary-vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (aset rmail-summary-vector (1- rmail-current-message) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (rmail-widen-to-current-msgbeg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (forward-line 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (looking-at "Summary-line: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (progn (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (point))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (rmail-show-message))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun rmail-abort-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "Abort edit of current message; restore original contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (insert rmail-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (rmail-cease-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; rmailedit.el ends here