annotate lisp/mail/mail-hist.el @ 92571:35628f10d78a

*** empty log message ***
author Alan Mackenzie <acm@muc.de>
date Fri, 07 Mar 2008 22:31:59 +0000
parents de499b20517a
children 606f2d163a64 1e3a407766b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35027
diff changeset
1 ;;; mail-hist.el --- headers and message body history for outgoing mail
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
2
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68648
diff changeset
3 ;; Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005,
79712
de499b20517a Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78232
diff changeset
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
6 ;; Author: Karl Fogel <kfogel@red-bean.com>
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: March, 1994
8277
824fb42f33ab Make sure that headers are case-insensitive.
Richard M. Stallman <rms@gnu.org>
parents: 7639
diff changeset
8 ;; Keywords: mail, history
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
78232
8e27d63c45eb Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
14 ;; the Free Software Foundation; either version 3, or (at your option)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
22 ;; You should have received a copy of the GNU General Public License
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
25 ;; Boston, MA 02110-1301, USA.
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
26
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Thanks to Jim Blandy for mentioning ring.el. It saved a lot of
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; time.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; To use this package, put it in a directory in your load-path, and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; put this in your .emacs file:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; (load "mail-hist" nil t)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Or you could do it with autoloads and hooks in your .emacs:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; (add-hook 'mail-mode-hook 'mail-hist-define-keys)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (add-hook 'mail-send-hook 'mail-hist-put-headers-into-history)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; (add-hook 'vm-mail-mode-hook 'mail-hist-define-keys) ;or rmail, etc
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; (autoload 'mail-hist-define-keys "mail-hist")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; (autoload 'mail-hist-put-headers-into-history "mail-hist")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; Once it's installed, use M-p and M-n from mail headers to recover
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; previous/next contents in the history for that header, or, in the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; body of the message, to recover previous/next text of the message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; This only applies to outgoing mail -- mail-hist ignores received
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; messages.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; Although repeated history requests do clear out the text from the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; previous request, an isolated request just inserts its text at
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; point, so that you can mix the histories of different messages
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; easily. This might be confusing at times, but there should be no
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; problems that undo can't handle.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; Code:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (require 'ring)
21868
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
59 (require 'sendmail)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
61 (defgroup mail-hist nil
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
62 "Headers and message body history for outgoing mail."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
63 :prefix "mail-hist-"
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
64 :group 'mail)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
65
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;;###autoload
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (defun mail-hist-define-keys ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 "Define keys for accessing mail header history. For use in hooks."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (local-set-key "\M-p" 'mail-hist-previous-input)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (local-set-key "\M-n" 'mail-hist-next-input))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;;###autoload
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
73 (defun mail-hist-enable ()
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
74 (add-hook 'mail-mode-hook 'mail-hist-define-keys)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
75 (add-hook 'mail-send-hook 'mail-hist-put-headers-into-history))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (defvar mail-hist-header-ring-alist nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "Alist of form (header-name . history-ring).
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 Used for knowing which history list to look in when the user asks for
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 previous/next input.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
82 (defcustom mail-hist-history-size (or kill-ring-max 1729)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "*The maximum number of elements in a mail field's history.
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
84 Oldest elements are dumped first."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
85 :type 'integer
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
86 :group 'mail-hist)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;;###autoload
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
89 (defcustom mail-hist-keep-history t
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
90 "*Non-nil means keep a history for headers and text of outgoing mail."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
91 :type 'boolean
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
92 :group 'mail-hist)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; For handling repeated history requests
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defvar mail-hist-access-count 0)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defvar mail-hist-last-bounds nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; (start . end) A pair indicating the buffer positions delimiting the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; last inserted history, so it can be replaced by a new input if the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; command is repeated.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defvar mail-hist-header-regexp "^[^:]*:"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 "Regular expression for matching headers in a mail message.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defsubst mail-hist-current-header-name ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "Get name of mail header point is currently in, without the colon.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 Returns nil if not in a header, implying that point is in the body of
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 the message."
24519
2a1ffba95a70 (mail-hist-current-header-name): Don't make
Karl Heuer <kwzh@gnu.org>
parents: 23194
diff changeset
109 (if (>= (point) (mail-text-start))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 nil ; then we are in the body of the message
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (save-excursion
21868
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
112 (let* ((body-start
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
113 (mail-text-start))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (name-start
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (re-search-backward mail-hist-header-regexp nil t))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (name-end
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (prog2 (search-forward ":" body-start t) (1- (point)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 name-start
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 name-end
15581
4d843931581c (mail-hist-current-header-name): Use buffer-substring-no-properties.
Miles Bader <miles@gnu.org>
parents: 15191
diff changeset
121 (downcase (buffer-substring-no-properties name-start name-end)))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defsubst mail-hist-forward-header (count)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 "Move forward COUNT headers (backward if COUNT is negative).
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 If last/first header is encountered first, stop there and returns
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47637
diff changeset
126 nil.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
128 Places point on the first non-whitespace on the line following the
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
129 colon after the header name, or on the second space following that if
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
130 the header is empty."
21868
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
131 (let ((boundary (mail-header-end)))
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
132 (and
21868
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
133 (> boundary 0)
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
134 (let ((unstopped t))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
135 (setq boundary (save-excursion
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
136 (goto-char boundary)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
137 (beginning-of-line)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
138 (1- (point))))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
139 (if (> count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
140 (while (> count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
141 (setq
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
142 unstopped
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
143 (re-search-forward mail-hist-header-regexp boundary t))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
144 (setq count (1- count)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
145 ;; because the current header will match too.
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
146 (setq count (1- count))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
147 ;; count is negative
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
148 (while (< count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
149 (setq
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
150 unstopped
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
151 (re-search-backward mail-hist-header-regexp nil t))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
152 (setq count (1+ count)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
153 ;; we end up behind the header, so must move to the front
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
154 (re-search-forward mail-hist-header-regexp boundary t))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
155 ;; Now we are right after the colon
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
156 (and (looking-at "\\s-") (forward-char 1))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
157 ;; return nil if didn't go as far as asked, otherwise point
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
158 unstopped))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defsubst mail-hist-beginning-of-header ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 "Move to the start of the current header.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 The start of the current header is defined as one space after the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 colon, or just after the colon if it is not followed by whitespace."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; this is slick as all heck:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (if (mail-hist-forward-header -1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (mail-hist-forward-header -1)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defsubst mail-hist-current-header-contents ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 "Get the contents of the mail header in which point is located."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (mail-hist-beginning-of-header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (let ((start (point)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (or (mail-hist-forward-header 1)
23194
d9b783c53049 (mail-hist-current-header-contents):
Karl Heuer <kwzh@gnu.org>
parents: 23106
diff changeset
176 (goto-char (mail-header-end)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (beginning-of-line)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (buffer-substring start (1- (point))))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (defsubst mail-hist-get-header-ring (header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 "Get HEADER's history ring, or nil if none.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 HEADER is a string without the colon."
8277
824fb42f33ab Make sure that headers are case-insensitive.
Richard M. Stallman <rms@gnu.org>
parents: 7639
diff changeset
183 (setq header (downcase header))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (cdr (assoc header mail-hist-header-ring-alist)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
186 (defcustom mail-hist-text-size-limit nil
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
187 "*Don't store any header or body with more than this many characters.
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
188 If the value is nil, that means no limit on text size."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
189 :type '(choice (const nil) integer)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
190 :group 'mail-hist)
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
191
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
192 (defun mail-hist-text-too-long-p (text)
35027
5664773f9e07 mail/mail-hist.el (mail-hist-text-too-long-p): doc fix.
Karl Fogel <kfogel@red-bean.com>
parents: 30519
diff changeset
193 "Return non-nil if TEXT's length exceeds `mail-hist-text-size-limit'."
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
194 (if mail-hist-text-size-limit
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
195 (> (length text) mail-hist-text-size-limit)))
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
196
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (defsubst mail-hist-add-header-contents-to-ring (header &optional contents)
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
198 "Add the contents of HEADER to the header history ring.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 Optional argument CONTENTS is a string which will be the contents
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
200 \(instead of whatever's found in the header)."
8277
824fb42f33ab Make sure that headers are case-insensitive.
Richard M. Stallman <rms@gnu.org>
parents: 7639
diff changeset
201 (setq header (downcase header))
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
202 (let ((ctnts (or contents (mail-hist-current-header-contents)))
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
203 (ring (cdr (assoc header mail-hist-header-ring-alist))))
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
204 (if (mail-hist-text-too-long-p ctnts) (setq ctnts ""))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (or ring
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; If the ring doesn't exist, we'll have to make it and add it
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; to the mail-header-ring-alist:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (prog1
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq ring (make-ring mail-hist-history-size))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (setq mail-hist-header-ring-alist
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (cons (cons header ring) mail-hist-header-ring-alist))))
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
212 (ring-insert ring ctnts)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;;;###autoload
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (defun mail-hist-put-headers-into-history ()
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47637
diff changeset
216 "Put headers and contents of this message into mail header history.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 Each header has its own independent history, as does the body of the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47637
diff changeset
220 This function normally would be called when the message is sent."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 mail-hist-keep-history
11377
2de0b88cc028 (mail-hist-put-headers-into-history):
Richard M. Stallman <rms@gnu.org>
parents: 11249
diff changeset
223 (save-excursion
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (goto-char (point-min))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (while (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (mail-hist-add-header-contents-to-ring
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (mail-hist-current-header-name)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (let ((body-contents
21868
14f3c9f7e356 Require sendmail.
Richard M. Stallman <rms@gnu.org>
parents: 20962
diff changeset
229 (buffer-substring (mail-text-start) (point-max))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (mail-hist-add-header-contents-to-ring "body" body-contents)))))
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
231
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
232
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
234 (defun mail-hist-retrieve-and-insert (header access-func)
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
235 "Helper for `mail-hist-previous-input' and `mail-hist-next-input'."
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
236 (setq header (downcase header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
237 (let* ((ring (cdr (assoc header mail-hist-header-ring-alist)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
238 (len (ring-length ring))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
239 (repeat (eq last-command 'mail-hist-input-access)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
240 (if repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
241 (setq mail-hist-access-count
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
242 (funcall access-func mail-hist-access-count len))
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
243 (setq mail-hist-access-count 0))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
244 (if (null ring)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
245 (progn
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
246 (ding)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
247 (message "No history for \"%s\"." header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
248 (if (ring-empty-p ring)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35027
diff changeset
249 (error "\"%s\" ring is empty" header)
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
250 (and repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
251 (delete-region (car mail-hist-last-bounds)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
252 (cdr mail-hist-last-bounds)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
253 (let ((start (point)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
254 (insert (ring-ref ring mail-hist-access-count))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
255 (setq mail-hist-last-bounds (cons start (point)))
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
256 (setq this-command 'mail-hist-input-access)
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
257 ;; Special case: when flipping through message bodies, it's
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
258 ;; usually most useful for point to stay at the top. This
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
259 ;; is because the unique part of a message in a thread is
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
260 ;; more likely to be at the top than the bottom, as the
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
261 ;; bottom is often just the same quoted history for every
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
262 ;; message in the thread, differing only in indentation
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
263 ;; level.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47637
diff changeset
264 (if (string-equal header "body")
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
265 (goto-char start)))
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
266 ))))
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
267
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
268
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
269 (defun mail-hist-previous-input (header)
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
270 "Insert the previous contents of this mail header or message body.
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
271 Moves back through the history of sent mail messages. Each header has
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
272 its own independent history, as does the body of the message.
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
273
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
274 The history only contains the contents of outgoing messages, not
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
275 received mail."
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
276 (interactive (list (or (mail-hist-current-header-name) "body")))
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
277 (mail-hist-retrieve-and-insert header 'ring-plus1))
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
278
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (defun mail-hist-next-input (header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 "Insert next contents of this mail header or message body.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 Moves back through the history of sent mail messages. Each header has
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 its own independent history, as does the body of the message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 Although you can do so, it does not make much sense to call this
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 without having called `mail-hist-previous-header' first
47637
61adc32aad68 (mail-hist-next-input): Fix docstring.
Simon Josefsson <jas@extundo.com>
parents: 38436
diff changeset
287 \(\\[mail-hist-previous-header]).
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 The history only contains the contents of outgoing messages, not
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 received mail."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (interactive (list (or (mail-hist-current-header-name) "body")))
30519
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
292 (mail-hist-retrieve-and-insert header 'ring-minus1))
d732477f0678 (mail-hist-previous-input, mail-hist-next-input): do the obvious code
Karl Fogel <kfogel@red-bean.com>
parents: 24519
diff changeset
293
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (provide 'mail-hist)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
297 ;;; arch-tag: 9ff9a07c-9dca-482d-ba87-54f42778559d
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35027
diff changeset
298 ;;; mail-hist.el ends here