annotate lisp/mail/rmailedit.el @ 21940:f7e788ea680b

new version
author Michael Kifer <kifer@cs.stonybrook.edu>
date Mon, 04 May 1998 22:42:59 +0000
parents ed912554aac6
children 225596bc6090
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 368
diff changeset
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 368
diff changeset
2
7300
cc7cd83ccf3f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6726
diff changeset
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
5 ;; Maintainer: FSF
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
6 ;; Keywords: mail
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
7
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11573
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11573
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11573
diff changeset
23 ;; Boston, MA 02111-1307, USA.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
25 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 (require 'rmail)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
29 (defvar rmail-old-text)
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
30
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 (defvar rmail-edit-map nil)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 (if rmail-edit-map
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33 nil
4179
dfc4e9e14d24 (rmail-edit-map): Inherit properly from text-mode-map;
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
34 ;; Make a keymap that inherits text-mode-map.
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
35 (setq rmail-edit-map (make-sparse-keymap))
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
36 (set-keymap-parent rmail-edit-map text-mode-map)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 ;; Rmail Edit mode is suitable only for specially formatted data.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 (put 'rmail-edit-mode 'mode-class 'special)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 (defun rmail-edit-mode ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 "Major mode for editing the contents of an RMAIL message.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 The editing commands are the same as in Text mode, together with two commands
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 to return to regular RMAIL:
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 * rmail-abort-edit cancels the changes
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 you have made and returns to RMAIL
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 * rmail-cease-edit makes them permanent.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 \\{rmail-edit-map}"
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
51 (text-mode)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 (use-local-map rmail-edit-map)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 (setq major-mode 'rmail-edit-mode)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (setq mode-name "RMAIL Edit")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (if (boundp 'mode-line-modified)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 (setq mode-line-modified (default-value 'mode-line-modified))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 (setq mode-line-format (default-value 'mode-line-format)))
6723
6ff74185a672 (rmail-edit-mode, rmail-cease-edit): Disable summary during edit.
Karl Heuer <kwzh@gnu.org>
parents: 5851
diff changeset
58 (if (rmail-summary-exists)
6726
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
59 (save-excursion
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
60 (set-buffer rmail-summary-buffer)
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
61 (rmail-summary-disable)))
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
62 (run-hooks 'rmail-edit-mode-hook))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63
16347
d710d3502336 (rmail-edit-current-message): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents: 14326
diff changeset
64 ;;;###autoload
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (defun rmail-edit-current-message ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 "Edit the contents of this message."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (rmail-edit-mode)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (make-local-variable 'rmail-old-text)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (setq rmail-old-text (buffer-substring (point-min) (point-max)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 (setq buffer-read-only nil)
11573
4ad650d4a65b (rmail-edit-current-message): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents: 8498
diff changeset
72 (force-mode-line-update)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
14326
e5799768c51b (rmail-edit-current-message): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
76 (message "%s" (substitute-command-keys
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (defun rmail-cease-edit ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 "Finish editing message; switch back to Rmail proper."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 (interactive)
6723
6ff74185a672 (rmail-edit-mode, rmail-cease-edit): Disable summary during edit.
Karl Heuer <kwzh@gnu.org>
parents: 5851
diff changeset
82 (if (rmail-summary-exists)
6726
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
83 (save-excursion
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
84 (set-buffer rmail-summary-buffer)
d6bc6057d197 Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents: 6723
diff changeset
85 (rmail-summary-enable)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 ;; Make sure buffer ends with a newline.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 (goto-char (point-max))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (if (/= (preceding-char) ?\n)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (insert "\n"))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 ;; Adjust the marker that points to the end of this message.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (let ((old rmail-old-text))
11573
4ad650d4a65b (rmail-edit-current-message): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents: 8498
diff changeset
95 (force-mode-line-update)
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
96 (kill-all-local-variables)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (rmail-mode-1)
21436
779c7dcd4c04 (rmail-cease-edit): Call kill-all-local-variables.
Karl Heuer <kwzh@gnu.org>
parents: 16347
diff changeset
98 (rmail-variables)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (if (and (= (length old) (- (point-max) (point-min)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (string= old (buffer-substring (point-min) (point-max))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (setq old nil)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (rmail-set-attribute "edited" t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (if (boundp 'rmail-summary-vector)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (aset rmail-summary-vector (1- rmail-current-message) nil)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (rmail-widen-to-current-msgbeg
21877
ed912554aac6 (rmail-cease-edit): Call rmail-show-message even if message text is unchanged.
Richard M. Stallman <rms@gnu.org>
parents: 21436
diff changeset
109 (function (lambda ()
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 (forward-line 2)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 (if (looking-at "Summary-line: ")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (let ((buffer-read-only nil))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 (delete-region (point)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 (progn (forward-line 1)
21877
ed912554aac6 (rmail-cease-edit): Call rmail-show-message even if message text is unchanged.
Richard M. Stallman <rms@gnu.org>
parents: 21436
diff changeset
115 (point))))))))))))
ed912554aac6 (rmail-cease-edit): Call rmail-show-message even if message text is unchanged.
Richard M. Stallman <rms@gnu.org>
parents: 21436
diff changeset
116 (save-excursion
ed912554aac6 (rmail-cease-edit): Call rmail-show-message even if message text is unchanged.
Richard M. Stallman <rms@gnu.org>
parents: 21436
diff changeset
117 (rmail-show-message)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (setq buffer-read-only t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120 (defun rmail-abort-edit ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 "Abort edit of current message; restore original contents."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 (delete-region (point-min) (point-max))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 (insert rmail-old-text)
8498
ba1acb3cf835 (rmail-abort-edit): Call `rmail-highlight-headers'.
Richard M. Stallman <rms@gnu.org>
parents: 7562
diff changeset
125 (rmail-cease-edit)
ba1acb3cf835 (rmail-abort-edit): Call `rmail-highlight-headers'.
Richard M. Stallman <rms@gnu.org>
parents: 7562
diff changeset
126 (rmail-highlight-headers))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 368
diff changeset
128 ;;; rmailedit.el ends here