aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-05-08 20:18:35 +0000
committerRichard M. Stallman1996-05-08 20:18:35 +0000
commit25e2c3c7784674828dcdc99f16c75c8afc24e9b8 (patch)
treeef00fd8e7e40f78216c6243276fd0be132783225
parentcf3a09b2585096657c4e42b89c765ad055a9e3c3 (diff)
downloademacs-25e2c3c7784674828dcdc99f16c75c8afc24e9b8.tar.gz
emacs-25e2c3c7784674828dcdc99f16c75c8afc24e9b8.zip
Revert to version 1.9.
-rw-r--r--lisp/mail/mail-hist.el206
1 files changed, 98 insertions, 108 deletions
diff --git a/lisp/mail/mail-hist.el b/lisp/mail/mail-hist.el
index eb131df4496..25bdcc2e55f 100644
--- a/lisp/mail/mail-hist.el
+++ b/lisp/mail/mail-hist.el
@@ -1,9 +1,9 @@
1;;; mail-hist.el --- Headers and message body history for outgoing mail. 1;;; mail-hist.el --- Headers and message body history for outgoing mail.
2
2;; Copyright (C) 1994 Free Software Foundation, Inc. 3;; Copyright (C) 1994 Free Software Foundation, Inc.
3 4
4;; Author: Karl Fogel <kfogel@cs.oberlin.edu> 5;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
5;; Created: March, 1994 6;; Created: March, 1994
6;; Version: See variable `mail-hist-version'.
7;; Keywords: mail, history 7;; Keywords: mail, history
8 8
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
@@ -18,6 +18,11 @@
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details. 19;; GNU General Public License for more details.
20 20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
21;;; Commentary: 26;;; Commentary:
22 27
23;; You should have received a copy of the GNU General Public License 28;; You should have received a copy of the GNU General Public License
@@ -55,9 +60,6 @@
55;;; Code: 60;;; Code:
56(require 'ring) 61(require 'ring)
57 62
58(defconst mail-hist-version "1.3.4"
59 "The version number of this mail-hist package.")
60
61;;;###autoload 63;;;###autoload
62(defun mail-hist-define-keys () 64(defun mail-hist-define-keys ()
63 "Define keys for accessing mail header history. For use in hooks." 65 "Define keys for accessing mail header history. For use in hooks."
@@ -65,13 +67,9 @@
65 (local-set-key "\M-n" 'mail-hist-next-input)) 67 (local-set-key "\M-n" 'mail-hist-next-input))
66 68
67;;;###autoload 69;;;###autoload
68(add-hook 'mail-mode-hook 'mail-hist-define-keys) 70(defun mail-hist-enable ()
69 71 (add-hook 'mail-mode-hook 'mail-hist-define-keys)
70;;;###autoload 72 (add-hook 'mail-send-hook 'mail-hist-put-headers-into-history))
71(add-hook 'vm-mail-mode-hook 'mail-hist-define-keys)
72
73;;;###autoload
74(add-hook 'mail-send-hook 'mail-hist-put-headers-into-history)
75 73
76(defvar mail-hist-header-ring-alist nil 74(defvar mail-hist-header-ring-alist nil
77 "Alist of form (header-name . history-ring). 75 "Alist of form (header-name . history-ring).
@@ -102,14 +100,16 @@ Oldest elements are dumped first.")
102Returns nil if not in a header, implying that point is in the body of 100Returns nil if not in a header, implying that point is in the body of
103the message." 101the message."
104 (if (save-excursion 102 (if (save-excursion
105 (re-search-backward 103 (re-search-backward (concat "^" (regexp-quote mail-header-separator)
106 (concat "^" (regexp-quote mail-header-separator)) nil t)) 104 "$")
105 nil t))
107 nil ; then we are in the body of the message 106 nil ; then we are in the body of the message
108 (save-excursion 107 (save-excursion
109 (let* ((body-start ; limit possibility of false headers 108 (let* ((body-start ; limit possibility of false headers
110 (save-excursion 109 (save-excursion
111 (re-search-forward 110 (re-search-forward
112 (concat "^" (regexp-quote mail-header-separator)) nil t))) 111 (concat "^" (regexp-quote mail-header-separator) "$")
112 nil t)))
113 (name-start 113 (name-start
114 (re-search-backward mail-hist-header-regexp nil t)) 114 (re-search-backward mail-hist-header-regexp nil t))
115 (name-end 115 (name-end
@@ -122,40 +122,42 @@ the message."
122(defsubst mail-hist-forward-header (count) 122(defsubst mail-hist-forward-header (count)
123 "Move forward COUNT headers (backward if COUNT is negative). 123 "Move forward COUNT headers (backward if COUNT is negative).
124If last/first header is encountered first, stop there and returns 124If last/first header is encountered first, stop there and returns
125nil. 125nil.
126Places point directly after the colon." 126
127 (let ((boundary 127Places point on the first non-whitespace on the line following the
128 (save-excursion 128colon after the header name, or on the second space following that if
129 (if (re-search-forward 129the header is empty."
130 (concat "^" (regexp-quote mail-header-separator)) nil t) 130 (let ((boundary (save-excursion
131 (progn 131 (re-search-forward
132 (beginning-of-line) 132 (concat "^" (regexp-quote mail-header-separator) "$")
133 (1- (point))) 133 nil t))))
134 nil)))) 134 (and
135 135 boundary
136 (if boundary 136 (let ((unstopped t))
137 (let ((unstopped t)) 137 (setq boundary (save-excursion
138 (if (> count 0) 138 (goto-char boundary)
139 ;; Moving forward. 139 (beginning-of-line)
140 (while (> count 0) 140 (1- (point))))
141 (setq 141 (if (> count 0)
142 unstopped 142 (while (> count 0)
143 (re-search-forward mail-hist-header-regexp boundary t)) 143 (setq
144 (setq count (1- count))) 144 unstopped
145 ;; Else moving backward. 145 (re-search-forward mail-hist-header-regexp boundary t))
146 ;; Decrement because the current header will match too. 146 (setq count (1- count)))
147 (setq count (1- count)) 147 ;; because the current header will match too.
148 ;; count is negative 148 (setq count (1- count))
149 (while (< count 0) 149 ;; count is negative
150 (setq 150 (while (< count 0)
151 unstopped 151 (setq
152 (re-search-backward mail-hist-header-regexp nil t)) 152 unstopped
153 (setq count (1+ count))) 153 (re-search-backward mail-hist-header-regexp nil t))
154 ;; We end up behind the header, so must move to the front. 154 (setq count (1+ count)))
155 (re-search-forward mail-hist-header-regexp boundary t)) 155 ;; we end up behind the header, so must move to the front
156 ;; Poof! Now we're sitting just past the colon. Finito. 156 (re-search-forward mail-hist-header-regexp boundary t))
157 ;; Return nil if didn't go as far as asked, otherwise point 157 ;; Now we are right after the colon
158 unstopped)))) 158 (and (looking-at "\\s-") (forward-char 1))
159 ;; return nil if didn't go as far as asked, otherwise point
160 unstopped))))
159 161
160(defsubst mail-hist-beginning-of-header () 162(defsubst mail-hist-beginning-of-header ()
161 "Move to the start of the current header. 163 "Move to the start of the current header.
@@ -174,7 +176,7 @@ colon, or just after the colon if it is not followed by whitespace."
174 (let ((start (point))) 176 (let ((start (point)))
175 (or (mail-hist-forward-header 1) 177 (or (mail-hist-forward-header 1)
176 (re-search-forward 178 (re-search-forward
177 (concat "^" (regexp-quote mail-header-separator)))) 179 (concat "^" (regexp-quote mail-header-separator) "$")))
178 (beginning-of-line) 180 (beginning-of-line)
179 (buffer-substring start (1- (point)))))) 181 (buffer-substring start (1- (point))))))
180 182
@@ -184,26 +186,24 @@ HEADER is a string without the colon."
184 (setq header (downcase header)) 186 (setq header (downcase header))
185 (cdr (assoc header mail-hist-header-ring-alist))) 187 (cdr (assoc header mail-hist-header-ring-alist)))
186 188
187
188(defvar mail-hist-text-size-limit nil 189(defvar mail-hist-text-size-limit nil
189 "*Don't store any header or body with more than this many 190 "*Don't store any header or body with more than this many characters.
190characters, plus one. Nil means there will be no limit on text size.") 191If the value is nil, that means no limit on text size.")
191 192
193(defun mail-hist-text-too-long-p (text)
194 "Return t if TEXT does not exceed mail-hist's size limit.
195The variable `mail-hist-text-size-limit' defines this limit."
196 (if mail-hist-text-size-limit
197 (> (length text) mail-hist-text-size-limit)))
192 198
193(defsubst mail-hist-add-header-contents-to-ring (header &optional contents) 199(defsubst mail-hist-add-header-contents-to-ring (header &optional contents)
194 "Add the contents of the current HEADER to the header history ring. 200 "Add the contents of HEADER to the header history ring.
195HEADER is a string; it will be downcased.
196Optional argument CONTENTS is a string which will be the contents 201Optional argument CONTENTS is a string which will be the contents
197\(instead of whatever's found in the header\)." 202\(instead of whatever's found in the header)."
198 (setq header (downcase header)) 203 (setq header (downcase header))
199 (let ((ctnts (or contents (mail-hist-current-header-contents))) 204 (let ((ctnts (or contents (mail-hist-current-header-contents)))
200 (ring (cdr (assoc header mail-hist-header-ring-alist)))) 205 (ring (cdr (assoc header mail-hist-header-ring-alist))))
201 206 (if (mail-hist-text-too-long-p ctnts) (setq ctnts ""))
202 ;; Possibly truncate the text. Note that
203 ;; `mail-hist-text-size-limit' might be nil, in which case no
204 ;; truncation would take place.
205 (setq ctnts (substring ctnts 0 mail-hist-text-size-limit))
206
207 (or ring 207 (or ring
208 ;; If the ring doesn't exist, we'll have to make it and add it 208 ;; If the ring doesn't exist, we'll have to make it and add it
209 ;; to the mail-header-ring-alist: 209 ;; to the mail-header-ring-alist:
@@ -213,7 +213,6 @@ Optional argument CONTENTS is a string which will be the contents
213 (cons (cons header ring) mail-hist-header-ring-alist)))) 213 (cons (cons header ring) mail-hist-header-ring-alist))))
214 (ring-insert ring ctnts))) 214 (ring-insert ring ctnts)))
215 215
216
217;;;###autoload 216;;;###autoload
218(defun mail-hist-put-headers-into-history () 217(defun mail-hist-put-headers-into-history ()
219 "Put headers and contents of this message into mail header history. 218 "Put headers and contents of this message into mail header history.
@@ -228,40 +227,31 @@ This function normally would be called when the message is sent."
228 (while (mail-hist-forward-header 1) 227 (while (mail-hist-forward-header 1)
229 (mail-hist-add-header-contents-to-ring 228 (mail-hist-add-header-contents-to-ring
230 (mail-hist-current-header-name))) 229 (mail-hist-current-header-name)))
231 ;; We do body contents specially. This is bad. Had I thought to
232 ;; include body-saving when I first wrote mail-hist, things might
233 ;; be cleaner now. Sigh.
234 (let ((body-contents 230 (let ((body-contents
235 (save-excursion 231 (save-excursion
236 (goto-char (point-min)) 232 (goto-char (point-min))
237 (re-search-forward 233 (re-search-forward
238 (concat "^" (regexp-quote mail-header-separator)) nil) 234 (concat "^" (regexp-quote mail-header-separator) "$")
239 (forward-line 1) 235 nil)
240 (buffer-substring (point) (point-max))))) 236 (forward-line 1)
237 (buffer-substring (point) (point-max)))))
241 (mail-hist-add-header-contents-to-ring "body" body-contents))))) 238 (mail-hist-add-header-contents-to-ring "body" body-contents)))))
242 239
243(defun mail-hist-header-virgin-p () 240(defun mail-hist-previous-input (header)
244 "Return non-nil if it looks like this header had no contents. 241 "Insert the previous contents of this mail header or message body.
245If it has exactly one space following the colon, then we consider it
246virgin."
247 (save-excursion
248 (mail-hist-forward-header -1)
249 (mail-hist-forward-header 1)
250 (looking-at " \n")))
251
252(defun mail-hist-next-or-previous-input (header nextp)
253 "Insert next or previous contents of this mail header or message body.
254Moves back through the history of sent mail messages. Each header has 242Moves back through the history of sent mail messages. Each header has
255its own independent history, as does the body of the message." 243its own independent history, as does the body of the message.
256 (if (null header) (error "Not in a header.")) 244
245The history only contains the contents of outgoing messages, not
246received mail."
247 (interactive (list (or (mail-hist-current-header-name) "body")))
257 (setq header (downcase header)) 248 (setq header (downcase header))
258 (let* ((ring (cdr (assoc header mail-hist-header-ring-alist))) 249 (let* ((ring (cdr (assoc header mail-hist-header-ring-alist)))
259 (len (ring-length ring)) 250 (len (ring-length ring))
260 (repeat (eq last-command 'mail-hist-input-access))) 251 (repeat (eq last-command 'mail-hist-input-access)))
261 (if repeat 252 (if repeat
262 (setq mail-hist-access-count 253 (setq mail-hist-access-count
263 (funcall (if nextp 'ring-minus1 'ring-plus1) 254 (ring-plus1 mail-hist-access-count len))
264 mail-hist-access-count len))
265 (setq mail-hist-access-count 0)) 255 (setq mail-hist-access-count 0))
266 (if (null ring) 256 (if (null ring)
267 (progn 257 (progn
@@ -269,33 +259,14 @@ its own independent history, as does the body of the message."
269 (message "No history for \"%s\"." header)) 259 (message "No history for \"%s\"." header))
270 (if (ring-empty-p ring) 260 (if (ring-empty-p ring)
271 (error "\"%s\" ring is empty." header) 261 (error "\"%s\" ring is empty." header)
272 (if repeat 262 (and repeat
273 (delete-region (car mail-hist-last-bounds) 263 (delete-region (car mail-hist-last-bounds)
274 (cdr mail-hist-last-bounds)) 264 (cdr mail-hist-last-bounds)))
275 ;; Else if this looks like a virgin header, we'll want to
276 ;; get rid of its single space, because saved header
277 ;; contents already include that space, and it's usually
278 ;; desirable to have only one space between the colon and
279 ;; the start of your header contents.
280 (if (mail-hist-header-virgin-p)
281 (delete-backward-char 1)))
282 (let ((start (point))) 265 (let ((start (point)))
283 (insert (ring-ref ring mail-hist-access-count)) 266 (insert (ring-ref ring mail-hist-access-count))
284 (setq mail-hist-last-bounds (cons start (point))) 267 (setq mail-hist-last-bounds (cons start (point)))
285 (setq this-command 'mail-hist-input-access)))))) 268 (setq this-command 'mail-hist-input-access))))))
286 269
287
288(defun mail-hist-previous-input (header)
289 "Insert the previous contents of this mail header or message body.
290Moves back through the history of sent mail messages. Each header has
291its own independent history, as does the body of the message.
292
293The history only contains the contents of outgoing messages, not
294received mail."
295 (interactive (list (or (mail-hist-current-header-name) "body")))
296 (mail-hist-next-or-previous-input header nil))
297
298
299(defun mail-hist-next-input (header) 270(defun mail-hist-next-input (header)
300 "Insert next contents of this mail header or message body. 271 "Insert next contents of this mail header or message body.
301Moves back through the history of sent mail messages. Each header has 272Moves back through the history of sent mail messages. Each header has
@@ -308,8 +279,27 @@ without having called `mail-hist-previous-header' first
308The history only contains the contents of outgoing messages, not 279The history only contains the contents of outgoing messages, not
309received mail." 280received mail."
310 (interactive (list (or (mail-hist-current-header-name) "body"))) 281 (interactive (list (or (mail-hist-current-header-name) "body")))
311 (mail-hist-next-or-previous-input header t)) 282 (setq header (downcase header))
312 283 (let* ((ring (cdr (assoc header mail-hist-header-ring-alist)))
284 (len (ring-length ring))
285 (repeat (eq last-command 'mail-hist-input-access)))
286 (if repeat
287 (setq mail-hist-access-count
288 (ring-minus1 mail-hist-access-count len))
289 (setq mail-hist-access-count 0))
290 (if (null ring)
291 (progn
292 (ding)
293 (message "No history for \"%s\"." header))
294 (if (ring-empty-p ring)
295 (error "\"%s\" ring is empty." header)
296 (and repeat
297 (delete-region (car mail-hist-last-bounds)
298 (cdr mail-hist-last-bounds)))
299 (let ((start (point)))
300 (insert (ring-ref ring mail-hist-access-count))
301 (setq mail-hist-last-bounds (cons start (point)))
302 (setq this-command 'mail-hist-input-access))))))
313 303
314(provide 'mail-hist) 304(provide 'mail-hist)
315 305