annotate lisp/mail/rmailedit.el @ 105531:ac0c30ffce5c

(report-emacs-bug): Also print `features'.
author Glenn Morris <rgm@gnu.org>
date Fri, 09 Oct 2009 06:29:56 +0000
parents b9bdbb16b3fa
children 6e207d2a8bc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
2
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
3 ;; Copyright (C) 1985, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
4 ;; 2008, 2009 Free Software Foundation, Inc.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
5
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
6 ;; Maintainer: FSF
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
7 ;; Keywords: mail
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
8
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
10
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
14 ;; (at your option) any later version.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
15
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
20
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
23
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
24 ;;; Commentary:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
25
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
26 ;;; Code:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
27
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
28 (require 'rmail)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
29
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
30 (defcustom rmail-edit-mode-hook nil
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
31 "List of functions to call when editing an RMAIL message."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
32 :type 'hook
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
33 :version "21.1"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
34 :group 'rmail-edit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
35
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
36
101724
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
37 (defvar rmail-edit-map
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
38 (let ((map (make-sparse-keymap)))
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
39 ;; Make a keymap that inherits text-mode-map.
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
40 (set-keymap-parent map text-mode-map)
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
41 (define-key map "\C-c\C-c" 'rmail-cease-edit)
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
42 (define-key map "\C-c\C-]" 'rmail-abort-edit)
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
43 map))
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
44
101633
c92166611a26 (rmail-summary-disable): Fix declaration.
Glenn Morris <rgm@gnu.org>
parents: 101629
diff changeset
45 (declare-function rmail-summary-disable "rmailsum" ())
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
46
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
47 (defun rmail-edit-mode ()
102388
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
48 "Major mode for editing the contents of an Rmail message.
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
49 The editing commands are the same as in Text mode, together with
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
50 two commands to return to regular Rmail:
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
51 * \\[rmail-abort-edit] cancels any changes and returns to Rmail
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
52 * \\[rmail-cease-edit] makes them permanent.
102388
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
53 This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
54 \\{rmail-edit-map}"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
55 (if (rmail-summary-exists)
101724
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
56 (with-current-buffer rmail-summary-buffer
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
57 (rmail-summary-disable)))
102388
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
58 ;; Prevent change-major-mode-hook from unswapping the buffers.
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
59 (let ((rmail-buffer-swapped nil))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
60 (delay-mode-hooks (text-mode))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
61 (use-local-map rmail-edit-map)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
62 (setq major-mode 'rmail-edit-mode)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
63 (setq mode-name "RMAIL Edit")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
64 (if (boundp 'mode-line-modified)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
65 (setq mode-line-modified (default-value 'mode-line-modified))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
66 (setq mode-line-format (default-value 'mode-line-format)))
104016
e59e70025fe8 * mail/rmailedit.el (rmail-edit-mode): Use auto-save-include-big-deletions.
Chong Yidong <cyd@stupidchicken.com>
parents: 103239
diff changeset
67 ;; Don't turn off auto-saving based on the size of the buffer
e59e70025fe8 * mail/rmailedit.el (rmail-edit-mode): Use auto-save-include-big-deletions.
Chong Yidong <cyd@stupidchicken.com>
parents: 103239
diff changeset
68 ;; because that code does not understand buffer-swapping.
e59e70025fe8 * mail/rmailedit.el (rmail-edit-mode): Use auto-save-include-big-deletions.
Chong Yidong <cyd@stupidchicken.com>
parents: 103239
diff changeset
69 (make-local-variable 'auto-save-include-big-deletions)
e59e70025fe8 * mail/rmailedit.el (rmail-edit-mode): Use auto-save-include-big-deletions.
Chong Yidong <cyd@stupidchicken.com>
parents: 103239
diff changeset
70 (setq auto-save-include-big-deletions t)
102478
f4571df6b6cc (rmail-edit-mode): Set write-region-annotate-functions. (Bug#2625)
Glenn Morris <rgm@gnu.org>
parents: 102407
diff changeset
71 ;; If someone uses C-x C-s, don't clobber the rmail file (bug#2625).
f4571df6b6cc (rmail-edit-mode): Set write-region-annotate-functions. (Bug#2625)
Glenn Morris <rgm@gnu.org>
parents: 102407
diff changeset
72 (add-hook 'write-region-annotate-functions
f4571df6b6cc (rmail-edit-mode): Set write-region-annotate-functions. (Bug#2625)
Glenn Morris <rgm@gnu.org>
parents: 102407
diff changeset
73 'rmail-write-region-annotate nil t)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
74 (run-mode-hooks 'rmail-edit-mode-hook)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
75
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
76 ;; Rmail Edit mode is suitable only for specially formatted data.
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
77 (put 'rmail-edit-mode 'mode-class 'special)
102388
b5125b379b62 (rmail-edit-mode): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 102165
diff changeset
78
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
79
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
80 (defvar rmail-old-text)
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
81 (defvar rmail-old-pruned nil
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
82 "Non-nil means the message being edited originally had pruned headers.")
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
83 (put 'rmail-old-pruned 'permanent-local t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
84
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
85 (defvar rmail-old-headers nil
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
86 "Holds the headers of this message before editing started.")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
87 (put 'rmail-old-headers 'permanent-local t)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
88
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
89 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
90 (defun rmail-edit-current-message ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
91 "Edit the contents of this message."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
92 (interactive)
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
93 (if (zerop rmail-total-messages)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
94 (error "No messages in this buffer"))
103239
03dd2dfb499f * mail/rmailedit.el (rmail-edit-current-message):
Richard M. Stallman <rms@gnu.org>
parents: 102930
diff changeset
95 (rmail-modify-format)
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
96 (make-local-variable 'rmail-old-pruned)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
97 (setq rmail-old-pruned (rmail-msg-is-pruned))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
98 (rmail-edit-mode)
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
99 (make-local-variable 'rmail-old-text)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
100 (setq rmail-old-text
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
101 (save-restriction
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
102 (widen)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
103 (buffer-substring (point-min) (point-max))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
104 (make-local-variable 'rmail-old-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
105 (setq rmail-old-headers (rmail-edit-headers-alist t))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
106 (setq buffer-read-only nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
107 (setq buffer-undo-list nil)
102479
53f69b319f5d Comment.
Glenn Morris <rgm@gnu.org>
parents: 102478
diff changeset
108 ;; Whether the buffer is initially marked as modified or not
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
109 ;; depends on whether or not the underlying rmail buffer was so marked.
102479
53f69b319f5d Comment.
Glenn Morris <rgm@gnu.org>
parents: 102478
diff changeset
110 ;; Given the way this works, it has to.
53f69b319f5d Comment.
Glenn Morris <rgm@gnu.org>
parents: 102478
diff changeset
111 ;; If you kill the edit buffer, you've killed your rmail buffer.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
112 (force-mode-line-update)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
113 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
114 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
115 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
116 (message "%s" (substitute-command-keys
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
117 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
118
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
119
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
120 (declare-function rmail-summary-enable "rmailsum" ())
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
121
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
122 (defun rmail-cease-edit ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
123 "Finish editing message; switch back to Rmail proper."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
124 (interactive)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
125 (if (rmail-summary-exists)
101724
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
126 (with-current-buffer rmail-summary-buffer
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
127 (rmail-summary-enable)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
128 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
129 ;; Disguise any "From " lines so they don't start a new message.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
130 (save-excursion
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
131 (goto-char (point-min))
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
132 (or rmail-old-pruned (forward-line 1))
101629
caac907da88d (rmail-cease-edit): Add additional quotes to quoted From lines.
Chong Yidong <cyd@stupidchicken.com>
parents: 101369
diff changeset
133 (while (re-search-forward "^>*From " nil t)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
134 (beginning-of-line)
101629
caac907da88d (rmail-cease-edit): Add additional quotes to quoted From lines.
Chong Yidong <cyd@stupidchicken.com>
parents: 101369
diff changeset
135 (insert ">")
caac907da88d (rmail-cease-edit): Add additional quotes to quoted From lines.
Chong Yidong <cyd@stupidchicken.com>
parents: 101369
diff changeset
136 (forward-line)))
102407
4c603ec78d71 (rmail-cease-edit): Use rmail-ensure-blank-line.
Glenn Morris <rgm@gnu.org>
parents: 102388
diff changeset
137 ;; Make sure buffer ends with a blank line so as not to run this
4c603ec78d71 (rmail-cease-edit): Use rmail-ensure-blank-line.
Glenn Morris <rgm@gnu.org>
parents: 102388
diff changeset
138 ;; message together with the following one.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
139 (save-excursion
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
140 (goto-char (point-max))
102407
4c603ec78d71 (rmail-cease-edit): Use rmail-ensure-blank-line.
Glenn Morris <rgm@gnu.org>
parents: 102388
diff changeset
141 (rmail-ensure-blank-line))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
142 (let ((old rmail-old-text)
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
143 (pruned rmail-old-pruned)
102165
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
144 ;; People who know what they are doing might have modified the
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
145 ;; buffer's encoding if editing the message included inserting
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
146 ;; characters that were unencodable by the original message's
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
147 ;; encoding. Make note of the new encoding and use it for
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
148 ;; encoding the edited message.
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
149 (edited-coding buffer-file-coding-system)
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
150 new-headers
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
151 character-coding is-text-message coding-system
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
152 headers-end limit)
102165
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
153 ;; Make sure `edited-coding' can safely encode the edited message.
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
154 (setq edited-coding
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
155 (select-safe-coding-system (point-min) (point-max) edited-coding))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
156 ;; Go back to Rmail mode, but carefully.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
157 (force-mode-line-update)
101724
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
158 (let ((rmail-buffer-swapped nil)) ; Prevent change-major-mode-hook
b87c9a6e8490 (rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101633
diff changeset
159 ; from unswapping the buffers.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
160 (kill-all-local-variables)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
161 (rmail-mode-1)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
162 (if (boundp 'tool-bar-map)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
163 (set (make-local-variable 'tool-bar-map) rmail-tool-bar-map))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
164 (setq buffer-undo-list t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
165 (rmail-variables))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
166 ;; If text has really changed, mark message as edited.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
167 (unless (and (= (length old) (- (point-max) (point-min)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
168 (string= old (buffer-substring (point-min) (point-max))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
169 (setq old nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
170 (goto-char (point-min))
105477
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
171 ;; FIXME the edit may have inadvertently removed this.
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
172 (search-forward "\n\n")
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
173 (setq headers-end (point-marker))
102165
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
174 (goto-char (point-min))
105477
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
175 (save-restriction
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
176 (narrow-to-region (point) headers-end)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
177 ;; If they changed the message's encoding, rewrite the charset=
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
178 ;; header for them, so that subsequent rmail-show-message
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
179 ;; decodes it correctly.
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
180 (let* ((buffer-read-only nil)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
181 (new-coding (coding-system-base edited-coding))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
182 (mime-charset (symbol-name
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
183 (or (coding-system-get new-coding :mime-charset)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
184 (if (coding-system-equal new-coding
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
185 'undecided)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
186 'us-ascii
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
187 new-coding))))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
188 old-coding mime-beg mime-end content-type)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
189 (if (re-search-forward rmail-mime-charset-pattern nil 'move)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
190 (setq mime-beg (match-beginning 1)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
191 mime-end (match-end 1)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
192 old-coding (coding-system-from-name (match-string 1)))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
193 (setq content-type (mail-fetch-field "Content-Type")))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
194 (cond
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
195 ;; No match for rmail-mime-charset-pattern, but there was some
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
196 ;; other Content-Type. We should not insert another. (Bug#4624)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
197 (content-type)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
198 ((null old-coding)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
199 ;; If there was no charset= spec, insert one.
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
200 (backward-char 1)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
201 (insert "Content-type: text/plain; charset=" mime-charset "\n"))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
202 ((not (coding-system-equal (coding-system-base old-coding)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
203 new-coding))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
204 (goto-char mime-end)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
205 (delete-region mime-beg mime-end)
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
206 (insert mime-charset)))))
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
207 (goto-char headers-end)
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
208 (setq new-headers (rmail-edit-headers-alist t))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
209 (rmail-swap-buffers-maybe)
101867
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
210 (narrow-to-region (rmail-msgbeg rmail-current-message)
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
211 (rmail-msgend rmail-current-message))
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
212 (save-restriction
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
213 (setq limit
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
214 (save-excursion
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
215 (goto-char (point-min))
105477
b9bdbb16b3fa (rmail-cease-edit): If there is a Content-Type header we don't
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
216 ;; FIXME this should not be using NOERROR.
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
217 (search-forward "\n\n" nil t)))
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
218 ;; All 3 of the functions we call below assume the buffer was
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
219 ;; narrowed to just the headers of the message.
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
220 (narrow-to-region (rmail-msgbeg rmail-current-message) limit)
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
221 (setq character-coding
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
222 (mail-fetch-field "content-transfer-encoding")
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
223 is-text-message (rmail-is-text-p)
102165
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
224 coding-system (if (and edited-coding
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
225 (not (coding-system-equal
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
226 (coding-system-base edited-coding)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
227 'undecided)))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
228 edited-coding
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
229 (rmail-get-coding-system))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
230 (if character-coding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
231 (setq character-coding (downcase character-coding)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
233 (goto-char limit)
101867
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
234 (let ((inhibit-read-only t))
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
235 (let ((data-buffer (current-buffer))
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
236 (end (copy-marker (point) t)))
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
237 (with-current-buffer rmail-view-buffer
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
238 (encode-coding-region headers-end (point-max) coding-system
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
239 data-buffer))
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
240 (delete-region end (point-max)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
241
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
242 ;; Apply to the mbox buffer any changes in header fields
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
243 ;; that the user made while editing in the view buffer.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
244 (rmail-edit-update-headers (rmail-edit-diff-headers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
245 rmail-old-headers new-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
246
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
247 ;; Re-apply content-transfer-encoding, if any, on the message body.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
248 (cond
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
249 ((string= character-coding "quoted-printable")
101867
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
250 (mail-quote-printable-region (point) (point-max)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
251 ((and (string= character-coding "base64") is-text-message)
101867
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
252 (base64-encode-region (point) (point-max)))
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
253 ((and (eq character-coding 'uuencode) is-text-message)
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
254 (error "uuencoded messages are not supported"))))
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
255 (rmail-set-attribute rmail-edited-attr-index t))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
256 ;;??? BROKEN perhaps.
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
257 ;;; (if (boundp 'rmail-summary-vector)
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
258 ;;; (aset rmail-summary-vector (1- rmail-current-message) nil))
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
259 (save-excursion
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
260 (rmail-show-message)
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
261 (rmail-toggle-header (if pruned 1 0))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
262 (run-hooks 'rmail-mode-hook))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
263
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
264 (defun rmail-abort-edit ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
265 "Abort edit of current message; restore original contents."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
266 (interactive)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
267 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
268 (delete-region (point-min) (point-max))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
269 (insert rmail-old-text)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
270 (rmail-cease-edit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
271 (rmail-highlight-headers))
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
272
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
273 (defun rmail-edit-headers-alist (&optional widen markers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
274 "Return an alist of the headers of the message in the current buffer.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
275 Each element has the form (HEADER-NAME . ENTIRE-STRING).
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
276 ENTIRE-STRING includes the name of the header field (which is HEADER-NAME)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
277 and has a final newline.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
278 If part of the text is not valid as a header field, HEADER-NAME
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
279 is an integer and we use consecutive integers.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
280
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
281 If WIDEN is non-nil, operate on the entire buffer.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
282
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
283 If MARKERS is non-nil, the value looks like
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
284 \(HEADER-NAME ENTIRE-STRING BEG-MARKER END-MARKER)."
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
285 (let (header-alist (no-good-header-count 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
286 (save-excursion
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
287 (save-restriction
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
288 (if widen (widen))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
289 (goto-char (point-min))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
290 (search-forward "\n\n")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
291 (narrow-to-region (point-min) (1- (point)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
292 (goto-char (point-min))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
293 (while (not (eobp))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
294 (let ((start (point))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
295 name header)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
296 ;; Match the name.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
297 (if (looking-at "[ \t]*\\([^:\n \t]\\(\\|[^:\n]*[^:\n \t]\\)\\)[ \t]*:")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
298 (setq name (match-string-no-properties 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
299 (setq name no-good-header-count
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
300 no-good-header-count (1+ no-good-header-count)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
301 (forward-line 1)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
302 (while (looking-at "[ \t]")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
303 (forward-line 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
304 (setq header (buffer-substring-no-properties start (point)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
305 (if markers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
306 (push (list header (copy-marker start) (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
307 header-alist)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
308 (push (cons name header) header-alist))))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
309 (nreverse header-alist)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
310
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
311
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
312 (defun rmail-edit-diff-headers (old-headers new-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
313 "Compare OLD-HEADERS and NEW-HEADERS and return field differences.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
314 The value is a list of three lists, (INSERTED DELETED CHANGED).
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
315
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
316 INSERTED's elements describe inserted header fields
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
317 and each looks like (AFTER-WHAT INSERT-WHAT)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
318 INSERT-WHAT is the header field to insert (a member of NEW-HEADERS).
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
319 AFTER-WHAT is the field to insert it after (a member of NEW-HEADERS)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
320 or else nil to insert it at the beginning.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
321
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
322 DELETED's elements are elements of OLD-HEADERS.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
323 CHANGED's elements have the form (OLD . NEW)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
324 where OLD is a element of OLD-HEADERS and NEW is an element of NEW-HEADERS."
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
325
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
326 (let ((reverse-new (reverse new-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
327 inserted deleted changed)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
328 (dolist (old old-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
329 (let ((new (assoc (car old) new-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
330 ;; If it's in OLD-HEADERS and has no new counterpart,
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
331 ;; it is a deletion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
332 (if (null new)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
333 (push old deleted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
334 ;; If it has a new counterpart, maybe it was changed.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
335 (unless (equal (cdr old) (cdr new))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
336 (push (cons old new) changed))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
337 ;; Remove the new counterpart, since it has been spoken for.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
338 (setq new-headers (remq new new-headers)))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
339 ;; Look at the new headers with no old counterpart.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
340 (dolist (new new-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
341 (let ((prev (cadr (member new reverse-new))))
102046
9b33e73e70e3 (rmail-edit-diff-headers): Delete spurious reference to OLD.
Richard M. Stallman <rms@gnu.org>
parents: 102023
diff changeset
342 ;; Mark each one as an insertion.
9b33e73e70e3 (rmail-edit-diff-headers): Delete spurious reference to OLD.
Richard M. Stallman <rms@gnu.org>
parents: 102023
diff changeset
343 ;; Record the previous new header, to insert it after that.
9b33e73e70e3 (rmail-edit-diff-headers): Delete spurious reference to OLD.
Richard M. Stallman <rms@gnu.org>
parents: 102023
diff changeset
344 (push (list prev new) inserted)))
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
345 ;; It is crucial to return the insertions in buffer order
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
346 ;; so that `rmail-edit-update-headers' can insert a field
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
347 ;; after a new field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
348 (list (nreverse inserted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
349 (nreverse deleted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
350 (nreverse changed))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
351
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
352 (defun rmail-edit-update-headers (header-diff)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
353 "Edit the mail headers in the buffer based on HEADER-DIFF.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
354 HEADER-DIFF should be a return value from `rmail-edit-diff-headers'."
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
355 (let ((buf-headers (rmail-edit-headers-alist nil t)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
356 ;; Change all the fields scheduled for being changed.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
357 (dolist (chg (nth 2 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
358 (let* ((match (assoc (cdar chg) buf-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
359 (end (marker-position (nth 2 match))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
360 (goto-char end)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
361 ;; Insert the new, then delete the old.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
362 ;; That avoids collapsing markers.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
363 (insert-before-markers (cddr chg))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
364 (delete-region (nth 1 match) end)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
365 ;; Remove the old field from BUF-HEADERS.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
366 (setq buf-headers (delq match buf-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
367 ;; Update BUF-HEADERS to show the changed field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
368 (push (list (cddr chg) (point-marker)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
369 (copy-marker (- (point) (length (cddr chg))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
370 (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
371 buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
372 ;; Delete all the fields scheduled for deletion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
373 ;; We do deletion after changes
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
374 ;; because when two fields look alike and get replaced by one,
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
375 ;; the first of them is considered changed
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
376 ;; and the second is considered deleted.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
377 (dolist (del (nth 1 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
378 (let ((match (assoc (cdr del) buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
379 (delete-region (nth 1 match) (nth 2 match))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
380 ;; Insert all the fields scheduled for insertion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
381 (dolist (ins (nth 0 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
382 (let* ((new (cadr ins))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
383 (after (car ins))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
384 (match (assoc (cdr after) buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
385 (goto-char (if match (nth 2 match) (point-min)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
386 (insert (cdr new))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
387 ;; Update BUF-HEADERS to show the inserted field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
388 (push (list (cdr new)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
389 (copy-marker (- (point) (length (cdr new))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
390 (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
391 buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
392 ;; Disconnect the markers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
393 (dolist (hdr buf-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
394 (set-marker (nth 1 hdr) nil)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
395 (set-marker (nth 2 hdr) nil))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
396
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
397 (provide 'rmailedit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
398
104907
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
399 ;; Local Variables:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
400 ;; generated-autoload-file: "rmail.el"
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
401 ;; End:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
402
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
403 ;; arch-tag: 9524f335-12cc-4e95-9e9b-3208dc30550b
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
404 ;;; rmailedit.el ends here