annotate lisp/mail/mail-hist.el @ 21689:95c0fe8d25a7

(easy-menu-do-add-item): Do the right thing when nil is specified as criterion for activeness. Fix string used to report an invalid item.
author Richard M. Stallman <rms@gnu.org>
date Tue, 21 Apr 1998 04:54:46 +0000
parents 54413501e4a9
children 14f3c9f7e356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
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
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: March, 1994
8277
824fb42f33ab Make sure that headers are case-insensitive.
Richard M. Stallman <rms@gnu.org>
parents: 7639
diff changeset
7 ;; Keywords: mail, history
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
21 ;; 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
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
24 ;; Boston, MA 02111-1307, USA.
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
25
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; 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
29 ;; time.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; 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
32 ;; put this in your .emacs file:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; (load "mail-hist" nil t)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Or you could do it with autoloads and hooks in your .emacs:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; (add-hook 'mail-mode-hook 'mail-hist-define-keys)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; (add-hook 'mail-send-hook 'mail-hist-put-headers-into-history)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (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
41 ;; (autoload 'mail-hist-define-keys "mail-hist")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; (autoload 'mail-hist-put-headers-into-history "mail-hist")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 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
45 ;; previous/next contents in the history for that header, or, in the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; body of the message, to recover previous/next text of the message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; This only applies to outgoing mail -- mail-hist ignores received
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; messages.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; Although repeated history requests do clear out the text from the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; previous request, an isolated request just inserts its text at
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; point, so that you can mix the histories of different messages
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; easily. This might be confusing at times, but there should be no
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; problems that undo can't handle.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; Code:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (require 'ring)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
59 (defgroup mail-hist nil
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
60 "Headers and message body history for outgoing mail."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
61 :prefix "mail-hist-"
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
62 :group 'mail)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
63
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;;###autoload
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defun mail-hist-define-keys ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "Define keys for accessing mail header history. For use in hooks."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (local-set-key "\M-p" 'mail-hist-previous-input)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (local-set-key "\M-n" 'mail-hist-next-input))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;;###autoload
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
71 (defun mail-hist-enable ()
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
72 (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
73 (add-hook 'mail-send-hook 'mail-hist-put-headers-into-history))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (defvar mail-hist-header-ring-alist nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "Alist of form (header-name . history-ring).
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 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
78 previous/next input.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
80 (defcustom mail-hist-history-size (or kill-ring-max 1729)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 "*The maximum number of elements in a mail field's history.
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
82 Oldest elements are dumped first."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
83 :type 'integer
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
84 :group 'mail-hist)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;;###autoload
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
87 (defcustom mail-hist-keep-history t
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
88 "*Non-nil means keep a history for headers and text of outgoing mail."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
89 :type 'boolean
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
90 :group 'mail-hist)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; For handling repeated history requests
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defvar mail-hist-access-count 0)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defvar mail-hist-last-bounds nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; (start . end) A pair indicating the buffer positions delimiting the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; 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
98 ;; command is repeated.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (defvar mail-hist-header-regexp "^[^:]*:"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "Regular expression for matching headers in a mail message.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (defsubst mail-hist-current-header-name ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "Get name of mail header point is currently in, without the colon.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 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
106 the message."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (if (save-excursion
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
108 (re-search-backward (concat "^" (regexp-quote mail-header-separator)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
109 "$")
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
110 nil t))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 nil ; then we are in the body of the message
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (let* ((body-start ; limit possibility of false headers
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (save-excursion
9425
7d0509b6f039 (mail-hist-put-headers-into-history)
Richard M. Stallman <rms@gnu.org>
parents: 8277
diff changeset
115 (re-search-forward
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
116 (concat "^" (regexp-quote mail-header-separator) "$")
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
117 nil t)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (name-start
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (re-search-backward mail-hist-header-regexp nil t))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (name-end
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (prog2 (search-forward ":" body-start t) (1- (point)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 name-start
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 name-end
15581
4d843931581c (mail-hist-current-header-name): Use buffer-substring-no-properties.
Miles Bader <miles@gnu.org>
parents: 15191
diff changeset
125 (downcase (buffer-substring-no-properties name-start name-end)))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defsubst mail-hist-forward-header (count)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "Move forward COUNT headers (backward if COUNT is negative).
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 If last/first header is encountered first, stop there and returns
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
130 nil.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
132 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
133 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
134 the header is empty."
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
135 (let ((boundary (save-excursion
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
136 (re-search-forward
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
137 (concat "^" (regexp-quote mail-header-separator) "$")
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
138 nil t))))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
139 (and
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
140 boundary
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
141 (let ((unstopped t))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
142 (setq boundary (save-excursion
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
143 (goto-char boundary)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
144 (beginning-of-line)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
145 (1- (point))))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
146 (if (> count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
147 (while (> count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
148 (setq
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
149 unstopped
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
150 (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
151 (setq count (1- count)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
152 ;; because the current header will match too.
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
153 (setq count (1- count))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
154 ;; count is negative
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
155 (while (< count 0)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
156 (setq
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
157 unstopped
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
158 (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
159 (setq count (1+ count)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
160 ;; 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
161 (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
162 ;; Now we are right after the colon
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
163 (and (looking-at "\\s-") (forward-char 1))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
164 ;; 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
165 unstopped))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (defsubst mail-hist-beginning-of-header ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 "Move to the start of the current header.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 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
170 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
171 ;; this is slick as all heck:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (if (mail-hist-forward-header -1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (mail-hist-forward-header -1)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (defsubst mail-hist-current-header-contents ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 "Get the contents of the mail header in which point is located."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (mail-hist-beginning-of-header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (let ((start (point)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (or (mail-hist-forward-header 1)
9425
7d0509b6f039 (mail-hist-put-headers-into-history)
Richard M. Stallman <rms@gnu.org>
parents: 8277
diff changeset
183 (re-search-forward
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
184 (concat "^" (regexp-quote mail-header-separator) "$")))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (beginning-of-line)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (buffer-substring start (1- (point))))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defsubst mail-hist-get-header-ring (header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Get HEADER's history ring, or nil if none.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 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
191 (setq header (downcase header))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (cdr (assoc header mail-hist-header-ring-alist)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
194 (defcustom mail-hist-text-size-limit nil
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
195 "*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
196 If the value is nil, that means no limit on text size."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
197 :type '(choice (const nil) integer)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 15740
diff changeset
198 :group 'mail-hist)
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
199
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
200 (defun mail-hist-text-too-long-p (text)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
201 "Return t if TEXT does not exceed mail-hist's size limit.
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
202 The variable `mail-hist-text-size-limit' defines this limit."
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
203 (if mail-hist-text-size-limit
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
204 (> (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
205
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (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
207 "Add the contents of HEADER to the header history ring.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 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
209 \(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
210 (setq header (downcase header))
12374
5888dd3f1a72 (mail-hist-text-size-limit): New var.
Richard M. Stallman <rms@gnu.org>
parents: 12366
diff changeset
211 (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
212 (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
213 (if (mail-hist-text-too-long-p ctnts) (setq ctnts ""))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (or ring
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; 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
216 ;; to the mail-header-ring-alist:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (prog1
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (setq ring (make-ring mail-hist-history-size))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (setq mail-hist-header-ring-alist
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (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
221 (ring-insert ring ctnts)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;;;###autoload
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (defun mail-hist-put-headers-into-history ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 "Put headers and contents of this message into mail header history.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 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
227 message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 This function normally would be called when the message is sent."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 mail-hist-keep-history
11377
2de0b88cc028 (mail-hist-put-headers-into-history):
Richard M. Stallman <rms@gnu.org>
parents: 11249
diff changeset
232 (save-excursion
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (goto-char (point-min))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (while (mail-hist-forward-header 1)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (mail-hist-add-header-contents-to-ring
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (mail-hist-current-header-name)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (let ((body-contents
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (save-excursion
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
239 (goto-char (point-min))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
240 (re-search-forward
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
241 (concat "^" (regexp-quote mail-header-separator) "$")
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
242 nil)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
243 (forward-line 1)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
244 (buffer-substring (point) (point-max)))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (mail-hist-add-header-contents-to-ring "body" body-contents)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (defun mail-hist-previous-input (header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 "Insert the previous contents of this mail header or message body.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 Moves back through the history of sent mail messages. Each header has
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 its own independent history, as does the body of the message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 The history only contains the contents of outgoing messages, not
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 received mail."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (interactive (list (or (mail-hist-current-header-name) "body")))
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
255 (setq header (downcase header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
256 (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
257 (len (ring-length ring))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
258 (repeat (eq last-command 'mail-hist-input-access)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
259 (if repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
260 (setq mail-hist-access-count
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
261 (ring-plus1 mail-hist-access-count len))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
262 (setq mail-hist-access-count 0))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
263 (if (null ring)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
264 (progn
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
265 (ding)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
266 (message "No history for \"%s\"." header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
267 (if (ring-empty-p ring)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
268 (error "\"%s\" ring is empty." header)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
269 (and repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
270 (delete-region (car mail-hist-last-bounds)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
271 (cdr mail-hist-last-bounds)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
272 (let ((start (point)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
273 (insert (ring-ref ring mail-hist-access-count))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
274 (setq mail-hist-last-bounds (cons start (point)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
275 (setq this-command 'mail-hist-input-access))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (defun mail-hist-next-input (header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 "Insert next contents of this mail header or message body.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 Moves back through the history of sent mail messages. Each header has
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 its own independent history, as does the body of the message.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 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
283 without having called `mail-hist-previous-header' first
8277
824fb42f33ab Make sure that headers are case-insensitive.
Richard M. Stallman <rms@gnu.org>
parents: 7639
diff changeset
284 (\\[mail-hist-previous-header]).
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 The history only contains the contents of outgoing messages, not
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 received mail."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (interactive (list (or (mail-hist-current-header-name) "body")))
15191
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
289 (setq header (downcase header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
290 (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
291 (len (ring-length ring))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
292 (repeat (eq last-command 'mail-hist-input-access)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
293 (if repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
294 (setq mail-hist-access-count
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
295 (ring-minus1 mail-hist-access-count len))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
296 (setq mail-hist-access-count 0))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
297 (if (null ring)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
298 (progn
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
299 (ding)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
300 (message "No history for \"%s\"." header))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
301 (if (ring-empty-p ring)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
302 (error "\"%s\" ring is empty." header)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
303 (and repeat
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
304 (delete-region (car mail-hist-last-bounds)
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
305 (cdr mail-hist-last-bounds)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
306 (let ((start (point)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
307 (insert (ring-ref ring mail-hist-access-count))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
308 (setq mail-hist-last-bounds (cons start (point)))
282d941a8073 Revert to version 1.9.
Richard M. Stallman <rms@gnu.org>
parents: 15184
diff changeset
309 (setq this-command 'mail-hist-input-access))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (provide 'mail-hist)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; mail-hist.el ends here