Mercurial > emacs
annotate lisp/mail/rmailedit.el @ 102377:505e79fad612
* makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): Add auth.
($(infodir)/auth, auth.dvi): New targets.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 03 Mar 2009 09:21:31 +0000 |
parents | f93f5035af02 |
children | b5125b379b62 |
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 | 3 ;; Copyright (C) 1985, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
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 | 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 () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
48 "Major mode for editing the contents of an RMAIL message. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
49 The editing commands are the same as in Text mode, together with two commands |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
50 to return to regular RMAIL: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
51 * \\[rmail-abort-edit] cancels the changes |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
52 you have made and returns to RMAIL |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
53 * \\[rmail-cease-edit] makes them permanent. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
54 This functions runs the normal hook `rmail-edit-mode-hook'. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
55 \\{rmail-edit-map}" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
56 (if (rmail-summary-exists) |
101724
b87c9a6e8490
(rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101633
diff
changeset
|
57 (with-current-buffer rmail-summary-buffer |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
58 (rmail-summary-disable))) |
101724
b87c9a6e8490
(rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101633
diff
changeset
|
59 (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
|
60 ; from unswapping the buffers. |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
61 (delay-mode-hooks (text-mode)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
62 (use-local-map rmail-edit-map) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
63 (setq major-mode 'rmail-edit-mode) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
64 (setq mode-name "RMAIL Edit") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
65 (if (boundp 'mode-line-modified) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
66 (setq mode-line-modified (default-value 'mode-line-modified)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
67 (setq mode-line-format (default-value 'mode-line-format))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
68 (run-mode-hooks 'rmail-edit-mode-hook))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
69 |
101917 | 70 ;; Rmail Edit mode is suitable only for specially formatted data. |
71 (put 'rmail-edit-mode 'mode-class 'special) | |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
72 |
101917 | 73 |
74 (defvar rmail-old-text) | |
75 (defvar rmail-old-pruned nil | |
76 "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
|
77 (put 'rmail-old-pruned 'permanent-local t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
78 |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
79 (defvar rmail-old-headers nil |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
80 "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
|
81 (put 'rmail-old-headers 'permanent-local t) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
82 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
83 ;;;###autoload |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
84 (defun rmail-edit-current-message () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
85 "Edit the contents of this message." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
86 (interactive) |
101917 | 87 (if (zerop rmail-total-messages) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
88 (error "No messages in this buffer")) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
89 (make-local-variable 'rmail-old-pruned) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
90 (setq rmail-old-pruned (rmail-msg-is-pruned)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
91 (rmail-edit-mode) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
92 (make-local-variable 'rmail-old-text) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
93 (setq rmail-old-text |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
94 (save-restriction |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
95 (widen) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
96 (buffer-substring (point-min) (point-max)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
97 (make-local-variable 'rmail-old-headers) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
98 (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
|
99 (setq buffer-read-only nil) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
100 (setq buffer-undo-list nil) |
101917 | 101 ;; FIXME whether the buffer is initially marked as modified or not |
102 ;; depends on whether or not the underlying rmail buffer was so marked. | |
103 ;; Seems poor. | |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
104 (force-mode-line-update) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
105 (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
|
106 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
107 (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
|
108 (message "%s" (substitute-command-keys |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
109 "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
|
110 |
101917 | 111 |
112 (declare-function rmail-summary-enable "rmailsum" ()) | |
113 | |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
114 (defun rmail-cease-edit () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
115 "Finish editing message; switch back to Rmail proper." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
116 (interactive) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
117 (if (rmail-summary-exists) |
101724
b87c9a6e8490
(rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101633
diff
changeset
|
118 (with-current-buffer rmail-summary-buffer |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
119 (rmail-summary-enable))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
120 (widen) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
121 ;; 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
|
122 (save-excursion |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
123 (goto-char (point-min)) |
101917 | 124 (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
|
125 (while (re-search-forward "^>*From " nil t) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
126 (beginning-of-line) |
101629
caac907da88d
(rmail-cease-edit): Add additional quotes to quoted From lines.
Chong Yidong <cyd@stupidchicken.com>
parents:
101369
diff
changeset
|
127 (insert ">") |
caac907da88d
(rmail-cease-edit): Add additional quotes to quoted From lines.
Chong Yidong <cyd@stupidchicken.com>
parents:
101369
diff
changeset
|
128 (forward-line))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
129 ;; Make sure buffer ends with a blank line |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
130 ;; so as not to run this message together with the following one. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
131 (save-excursion |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
132 (goto-char (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
133 (if (/= (preceding-char) ?\n) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
134 (insert "\n")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
135 (unless (looking-back "\n\n") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
136 (insert "\n"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
137 (let ((old rmail-old-text) |
101917 | 138 (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
|
139 ;; 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
|
140 ;; 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
|
141 ;; 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
|
142 ;; 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
|
143 ;; 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
|
144 (edited-coding buffer-file-coding-system) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
145 new-headers |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
146 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
|
147 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
|
148 ;; 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
|
149 (setq edited-coding |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
150 (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
|
151 ;; Go back to Rmail mode, but carefully. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
152 (force-mode-line-update) |
101724
b87c9a6e8490
(rmail-edit-map): Move init into declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101633
diff
changeset
|
153 (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
|
154 ; from unswapping the buffers. |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
155 (kill-all-local-variables) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
156 (rmail-mode-1) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
157 (if (boundp 'tool-bar-map) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
158 (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
|
159 (setq buffer-undo-list t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
160 (rmail-variables)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
161 ;; If text has really changed, mark message as edited. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
162 (unless (and (= (length old) (- (point-max) (point-min))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
163 (string= old (buffer-substring (point-min) (point-max)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
164 (setq old nil) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
165 (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
|
166 ;; 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
|
167 ;; 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
|
168 ;; decodes it correctly. |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
169 (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
|
170 (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
|
171 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
|
172 (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
|
173 (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
|
174 'move) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
175 (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
|
176 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
|
177 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
|
178 (setq mime-charset |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
179 (symbol-name |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
180 (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
|
181 (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
|
182 'us-ascii |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
183 new-coding)))) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
184 (cond |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
185 ((null old-coding) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
186 ;; 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
|
187 (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
|
188 ((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
|
189 new-coding)) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
190 (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
|
191 (insert mime-charset)))) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
192 (goto-char (point-min)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
193 (search-forward "\n\n") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
194 (setq headers-end (point)) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
195 (setq new-headers (rmail-edit-headers-alist t)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
196 (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
|
197 (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
|
198 (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
|
199 (save-restriction |
cf870c811594
(rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents:
101867
diff
changeset
|
200 (setq limit |
cf870c811594
(rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents:
101867
diff
changeset
|
201 (save-excursion |
cf870c811594
(rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents:
101867
diff
changeset
|
202 (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
|
203 (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
|
204 ;; 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
|
205 ;; 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
|
206 (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
|
207 (setq character-coding |
cf870c811594
(rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents:
101867
diff
changeset
|
208 (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
|
209 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
|
210 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
|
211 (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
|
212 (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
|
213 'undecided))) |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
214 edited-coding |
f93f5035af02
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Eli Zaretskii <eliz@gnu.org>
parents:
102046
diff
changeset
|
215 (rmail-get-coding-system)))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
216 (if character-coding |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
217 (setq character-coding (downcase character-coding))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
218 |
101871
cf870c811594
(rmail-cease-edit): Look for the message's encoding, and its
Eli Zaretskii <eliz@gnu.org>
parents:
101867
diff
changeset
|
219 (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
|
220 (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
|
221 (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
|
222 (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
|
223 (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
|
224 (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
|
225 data-buffer)) |
07f6502ced98
(rmail-cease-edit): narrow-to-region before extracting mail message headers.
Eli Zaretskii <eliz@gnu.org>
parents:
101724
diff
changeset
|
226 (delete-region end (point-max))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
227 |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
228 ;; 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
|
229 ;; 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
|
230 (rmail-edit-update-headers (rmail-edit-diff-headers |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
231 rmail-old-headers new-headers)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
232 |
101917 | 233 ;; 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
|
234 (cond |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
235 ((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
|
236 (mail-quote-printable-region (point) (point-max))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
237 ((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
|
238 (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
|
239 ((and (eq character-coding 'uuencode) is-text-message) |
101917 | 240 (error "uuencoded messages are not supported")))) |
241 (rmail-set-attribute rmail-edited-attr-index t)) | |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
242 ;;??? BROKEN perhaps. |
101917 | 243 ;;; (if (boundp 'rmail-summary-vector) |
244 ;;; (aset rmail-summary-vector (1- rmail-current-message) nil)) | |
245 (save-excursion | |
246 (rmail-show-message) | |
247 (rmail-toggle-header (if pruned 1 0)))) | |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
248 (run-hooks 'rmail-mode-hook)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
249 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
250 (defun rmail-abort-edit () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
251 "Abort edit of current message; restore original contents." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
252 (interactive) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
253 (widen) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
254 (delete-region (point-min) (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
255 (insert rmail-old-text) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
256 (rmail-cease-edit) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
257 (rmail-highlight-headers)) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
258 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
259 (defun rmail-edit-headers-alist (&optional widen markers) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
260 "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
|
261 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
|
262 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
|
263 and has a final newline. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
264 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
|
265 is an integer and we use consecutive integers. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
266 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
267 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
|
268 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
269 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
|
270 \(HEADER-NAME ENTIRE-STRING BEG-MARKER END-MARKER)." |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
271 (let (header-alist (no-good-header-count 1)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
272 (save-excursion |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
273 (save-restriction |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
274 (if widen (widen)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
275 (goto-char (point-min)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
276 (search-forward "\n\n") |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
277 (narrow-to-region (point-min) (1- (point))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
278 (goto-char (point-min)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
279 (while (not (eobp)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
280 (let ((start (point)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
281 name header) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
282 ;; Match the name. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
283 (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
|
284 (setq name (match-string-no-properties 1)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
285 (setq name no-good-header-count |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
286 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
|
287 (forward-line 1) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
288 (while (looking-at "[ \t]") |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
289 (forward-line 1)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
290 (setq header (buffer-substring-no-properties start (point))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
291 (if markers |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
292 (push (list header (copy-marker start) (point-marker)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
293 header-alist) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
294 (push (cons name header) header-alist)))))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
295 (nreverse header-alist))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
296 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
297 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
298 (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
|
299 "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
|
300 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
|
301 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
302 INSERTED's elements describe inserted header fields |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
303 and each looks like (AFTER-WHAT INSERT-WHAT) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
308 DELETED's elements are elements of OLD-HEADERS. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
309 CHANGED's elements have the form (OLD . NEW) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
310 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
|
311 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
312 (let ((reverse-new (reverse new-headers)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
313 inserted deleted changed) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
314 (dolist (old old-headers) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
315 (let ((new (assoc (car old) new-headers))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
316 ;; 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
|
317 ;; it is a deletion. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
318 (if (null new) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
319 (push old deleted) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
320 ;; 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
|
321 (unless (equal (cdr old) (cdr new)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
322 (push (cons old new) changed)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
323 ;; 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
|
324 (setq new-headers (remq new new-headers))))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
325 ;; 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
|
326 (dolist (new new-headers) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
327 (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
|
328 ;; 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
|
329 ;; 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
|
330 (push (list prev new) inserted))) |
102023
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
331 ;; 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
|
332 ;; 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
|
333 ;; after a new field. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
334 (list (nreverse inserted) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
335 (nreverse deleted) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
336 (nreverse changed)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
337 |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
338 (defun rmail-edit-update-headers (header-diff) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
339 "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
|
340 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
|
341 (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
|
342 ;; Change all the fields scheduled for being changed. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
343 (dolist (chg (nth 2 header-diff)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
344 (let* ((match (assoc (cdar chg) buf-headers)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
345 (end (marker-position (nth 2 match)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
346 (goto-char end) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
347 ;; Insert the new, then delete the old. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
348 ;; That avoids collapsing markers. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
349 (insert-before-markers (cddr chg)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
350 (delete-region (nth 1 match) end) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
351 ;; Remove the old field from BUF-HEADERS. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
352 (setq buf-headers (delq match buf-headers)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
353 ;; Update BUF-HEADERS to show the changed field. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
354 (push (list (cddr chg) (point-marker) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
355 (copy-marker (- (point) (length (cddr chg)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
356 (point-marker)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
357 buf-headers))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
358 ;; Delete all the fields scheduled for deletion. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
359 ;; We do deletion after changes |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
360 ;; 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
|
361 ;; the first of them is considered changed |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
362 ;; and the second is considered deleted. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
363 (dolist (del (nth 1 header-diff)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
364 (let ((match (assoc (cdr del) buf-headers))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
365 (delete-region (nth 1 match) (nth 2 match)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
366 ;; Insert all the fields scheduled for insertion. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
367 (dolist (ins (nth 0 header-diff)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
368 (let* ((new (cadr ins)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
369 (after (car ins)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
370 (match (assoc (cdr after) buf-headers))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
371 (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
|
372 (insert (cdr new)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
373 ;; Update BUF-HEADERS to show the inserted field. |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
374 (push (list (cdr new) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
375 (copy-marker (- (point) (length (cdr new)))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
376 (point-marker)) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
377 buf-headers))) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
378 ;; Disconnect the markers |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
379 (dolist (hdr buf-headers) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
380 (set-marker (nth 1 hdr) nil) |
a92cde59fabc
Handle editing of header fields.
Richard M. Stallman <rms@gnu.org>
parents:
101917
diff
changeset
|
381 (set-marker (nth 2 hdr) nil)))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
382 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
383 (provide 'rmailedit) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
384 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
385 ;; arch-tag: 9524f335-12cc-4e95-9e9b-3208dc30550b |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
386 ;;; rmailedit.el ends here |