annotate lisp/mail/rmailedit.el @ 105095:4adac4895f0f

Update comment for HAVE_NS code in font_find_for_lface().
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Fri, 18 Sep 2009 21:16:28 +0000
parents 6a35503cf20b
children b9bdbb16b3fa
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))
102165
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
171 ;; If they changed the message's encoding, rewrite the charset=
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
172 ;; header for them, so that subsequent rmail-show-message
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
173 ;; decodes it correctly.
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
174 (let ((buffer-read-only nil)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
175 (new-coding (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
176 old-coding mime-charset mime-beg mime-end)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
177 (when (re-search-forward rmail-mime-charset-pattern
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
178 (1- (save-excursion (search-forward "\n\n")))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
179 'move)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
180 (setq mime-beg (match-beginning 1)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
181 mime-end (match-end 1)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
182 old-coding (coding-system-from-name (match-string 1))))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
183 (setq mime-charset
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
184 (symbol-name
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
185 (or (coding-system-get new-coding :mime-charset)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
186 (if (coding-system-equal new-coding 'undecided)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
187 'us-ascii
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
188 new-coding))))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
189 (cond
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
190 ((null old-coding)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
191 ;; If there was no charset= spec, insert one.
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
192 (insert "Content-type: text/plain; charset=" mime-charset "\n"))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
193 ((not (coding-system-equal (coding-system-base old-coding)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
194 new-coding))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
195 (delete-region mime-beg mime-end)
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
196 (insert mime-charset))))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
197 (goto-char (point-min))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
198 (search-forward "\n\n")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
199 (setq headers-end (point))
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
200 (setq new-headers (rmail-edit-headers-alist t))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
201 (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
202 (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
203 (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
204 (save-restriction
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
205 (setq limit
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
206 (save-excursion
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
207 (goto-char (point-min))
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
208 (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
209 ;; 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
210 ;; 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
211 (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
212 (setq character-coding
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
213 (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
214 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
215 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
216 (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
217 (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
218 'undecided)))
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
219 edited-coding
f93f5035af02 (rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents: 102046
diff changeset
220 (rmail-get-coding-system))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
221 (if character-coding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
222 (setq character-coding (downcase character-coding)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
223
101871
cf870c811594 (rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents: 101867
diff changeset
224 (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
225 (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
226 (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
227 (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
228 (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
229 (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
230 data-buffer))
07f6502ced98 (rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents: 101724
diff changeset
231 (delete-region end (point-max)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
233 ;; 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
234 ;; 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
235 (rmail-edit-update-headers (rmail-edit-diff-headers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
236 rmail-old-headers new-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
237
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
238 ;; 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
239 (cond
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
240 ((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
241 (mail-quote-printable-region (point) (point-max)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
242 ((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
243 (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
244 ((and (eq character-coding 'uuencode) is-text-message)
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
245 (error "uuencoded messages are not supported"))))
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
246 (rmail-set-attribute rmail-edited-attr-index t))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
247 ;;??? BROKEN perhaps.
101917
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
248 ;;; (if (boundp 'rmail-summary-vector)
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
249 ;;; (aset rmail-summary-vector (1- rmail-current-message) nil))
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
250 (save-excursion
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
251 (rmail-show-message)
4b1bce6e82a6 Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101871
diff changeset
252 (rmail-toggle-header (if pruned 1 0))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
253 (run-hooks 'rmail-mode-hook))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
254
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
255 (defun rmail-abort-edit ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
256 "Abort edit of current message; restore original contents."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
257 (interactive)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
258 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
259 (delete-region (point-min) (point-max))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
260 (insert rmail-old-text)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
261 (rmail-cease-edit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
262 (rmail-highlight-headers))
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
263
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
264 (defun rmail-edit-headers-alist (&optional widen markers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
265 "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
266 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
267 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
268 and has a final newline.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
269 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
270 is an integer and we use consecutive integers.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
271
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
272 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
273
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
274 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
275 \(HEADER-NAME ENTIRE-STRING BEG-MARKER END-MARKER)."
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
276 (let (header-alist (no-good-header-count 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
277 (save-excursion
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
278 (save-restriction
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
279 (if widen (widen))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
280 (goto-char (point-min))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
281 (search-forward "\n\n")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
282 (narrow-to-region (point-min) (1- (point)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
283 (goto-char (point-min))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
284 (while (not (eobp))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
285 (let ((start (point))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
286 name header)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
287 ;; Match the name.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
288 (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
289 (setq name (match-string-no-properties 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
290 (setq name no-good-header-count
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
291 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
292 (forward-line 1)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
293 (while (looking-at "[ \t]")
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
294 (forward-line 1))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
295 (setq header (buffer-substring-no-properties start (point)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
296 (if markers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
297 (push (list header (copy-marker start) (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
298 header-alist)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
299 (push (cons name header) header-alist))))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
300 (nreverse header-alist)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
301
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
302
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
303 (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
304 "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
305 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
306
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
307 INSERTED's elements describe inserted header fields
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
308 and each looks like (AFTER-WHAT INSERT-WHAT)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
309 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
310 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
311 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
312
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
313 DELETED's elements are elements of OLD-HEADERS.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
314 CHANGED's elements have the form (OLD . NEW)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
315 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
316
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
317 (let ((reverse-new (reverse new-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
318 inserted deleted changed)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
319 (dolist (old old-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
320 (let ((new (assoc (car old) new-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
321 ;; 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
322 ;; it is a deletion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
323 (if (null new)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
324 (push old deleted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
325 ;; 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
326 (unless (equal (cdr old) (cdr new))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
327 (push (cons old new) changed))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
328 ;; 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
329 (setq new-headers (remq new new-headers)))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
330 ;; 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
331 (dolist (new new-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
332 (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
333 ;; 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
334 ;; 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
335 (push (list prev new) inserted)))
102023
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
336 ;; 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
337 ;; 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
338 ;; after a new field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
339 (list (nreverse inserted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
340 (nreverse deleted)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
341 (nreverse changed))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
342
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
343 (defun rmail-edit-update-headers (header-diff)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
344 "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
345 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
346 (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
347 ;; Change all the fields scheduled for being changed.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
348 (dolist (chg (nth 2 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
349 (let* ((match (assoc (cdar chg) buf-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
350 (end (marker-position (nth 2 match))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
351 (goto-char end)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
352 ;; Insert the new, then delete the old.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
353 ;; That avoids collapsing markers.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
354 (insert-before-markers (cddr chg))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
355 (delete-region (nth 1 match) end)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
356 ;; Remove the old field from BUF-HEADERS.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
357 (setq buf-headers (delq match buf-headers))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
358 ;; Update BUF-HEADERS to show the changed field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
359 (push (list (cddr chg) (point-marker)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
360 (copy-marker (- (point) (length (cddr chg))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
361 (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
362 buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
363 ;; Delete all the fields scheduled for deletion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
364 ;; We do deletion after changes
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
365 ;; 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
366 ;; the first of them is considered changed
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
367 ;; and the second is considered deleted.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
368 (dolist (del (nth 1 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
369 (let ((match (assoc (cdr del) buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
370 (delete-region (nth 1 match) (nth 2 match))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
371 ;; Insert all the fields scheduled for insertion.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
372 (dolist (ins (nth 0 header-diff))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
373 (let* ((new (cadr ins))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
374 (after (car ins))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
375 (match (assoc (cdr after) buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
376 (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
377 (insert (cdr new))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
378 ;; Update BUF-HEADERS to show the inserted field.
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
379 (push (list (cdr new)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
380 (copy-marker (- (point) (length (cdr new))))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
381 (point-marker))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
382 buf-headers)))
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
383 ;; Disconnect the markers
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
384 (dolist (hdr buf-headers)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
385 (set-marker (nth 1 hdr) nil)
a92cde59fabc Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents: 101917
diff changeset
386 (set-marker (nth 2 hdr) nil))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
387
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
388 (provide 'rmailedit)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
389
104907
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
390 ;; Local Variables:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
391 ;; generated-autoload-file: "rmail.el"
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
392 ;; End:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 104016
diff changeset
393
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
394 ;; arch-tag: 9524f335-12cc-4e95-9e9b-3208dc30550b
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
395 ;;; rmailedit.el ends here