annotate lisp/mail/mail-hist.el @ 13933:efd6ce432dc5

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