Mercurial > emacs
annotate lisp/mail/mh-seq.el @ 48367:116b9f9915e6
*** empty log message ***
author | Markus Rost <rost@math.uni-bielefeld.de> |
---|---|
date | Sat, 16 Nov 2002 19:19:35 +0000 |
parents | 2568d5a27317 |
children | 8aaba207e44b |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
14425
diff
changeset
|
1 ;;; mh-seq.el --- mh-e sequences support |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
2 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
3 ;; Copyright (C) 1993, 1995, 2001, 2002 Free Software Foundation, Inc. |
6365 | 4 |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
5 ;; Author: Bill Wohler <wohler@newt.com> |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
6 ;; Maintainer: Bill Wohler <wohler@newt.com> |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
7 ;; Keywords: mail |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
8 ;; See: mh-e.el |
6365 | 9 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
14425
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
6365 | 11 |
11333 | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
6365 | 13 ;; it under the terms of the GNU General Public License as published by |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
11333 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
6365 | 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
6365 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; Internal support for mh-e package. | |
30 | |
11332 | 31 ;;; Change Log: |
32 | |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
33 ;; $Id: mh-seq.el,v 1.14 2002/04/07 19:20:56 wohler Exp $ |
11332 | 34 |
6365 | 35 ;;; Code: |
36 | |
37 (provide 'mh-seq) | |
38 (require 'mh-e) | |
39 | |
11332 | 40 ;;; Internal variables: |
41 | |
42 (defvar mh-last-seq-used nil) ;Name of seq to which a msg was last added. | |
43 | |
44 (defvar mh-non-seq-mode-line-annotation nil) ;Saved value of mh-mode-line-annotation when narrowed to a seq. | |
6365 | 45 |
46 | |
11332 | 47 (defun mh-delete-seq (sequence) |
6365 | 48 "Delete the SEQUENCE." |
49 (interactive (list (mh-read-seq-default "Delete" t))) | |
11332 | 50 (mh-map-to-seq-msgs 'mh-notate-if-in-one-seq sequence ? (1+ mh-cmd-note) |
51 sequence) | |
52 (mh-undefine-sequence sequence '("all")) | |
53 (mh-delete-seq-locally sequence)) | |
6365 | 54 |
55 | |
56 (defun mh-list-sequences (folder) | |
57 "List the sequences defined in FOLDER." | |
58 (interactive (list (mh-prompt-for-folder "List sequences in" | |
59 mh-current-folder t))) | |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
60 (let ((temp-buffer mh-temp-sequences-buffer) |
6365 | 61 (seq-list mh-seq-list)) |
62 (with-output-to-temp-buffer temp-buffer | |
63 (save-excursion | |
64 (set-buffer temp-buffer) | |
65 (erase-buffer) | |
66 (message "Listing sequences ...") | |
67 (insert "Sequences in folder " folder ":\n") | |
68 (while seq-list | |
69 (let ((name (mh-seq-name (car seq-list))) | |
70 (sorted-seq-msgs | |
71 (sort (copy-sequence (mh-seq-msgs (car seq-list))) '<)) | |
72 (last-col (- (window-width) 4)) | |
73 name-spec) | |
74 (insert (setq name-spec (format "%20s:" name))) | |
75 (while sorted-seq-msgs | |
76 (if (> (current-column) last-col) | |
77 (progn | |
78 (insert "\n") | |
79 (move-to-column (length name-spec)))) | |
80 (insert (format " %s" (car sorted-seq-msgs))) | |
81 (setq sorted-seq-msgs (cdr sorted-seq-msgs))) | |
82 (insert "\n")) | |
83 (setq seq-list (cdr seq-list))) | |
84 (goto-char (point-min)) | |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
85 (view-mode 1) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
86 (setq view-exit-action 'kill-buffer) |
6365 | 87 (message "Listing sequences...done"))))) |
88 | |
89 | |
11332 | 90 (defun mh-msg-is-in-seq (message) |
91 "Display the sequences that contain MESSAGE (default: current message)." | |
6365 | 92 (interactive (list (mh-get-msg-num t))) |
93 (message "Message %d is in sequences: %s" | |
11332 | 94 message |
6365 | 95 (mapconcat 'concat |
11332 | 96 (mh-list-to-string (mh-seq-containing-msg message t)) |
6365 | 97 " "))) |
98 | |
99 | |
11332 | 100 (defun mh-narrow-to-seq (sequence) |
101 "Restrict display of this folder to just messages in SEQUENCE. | |
102 Use \\<mh-folder-mode-map>\\[mh-widen] to undo this command." | |
6365 | 103 (interactive (list (mh-read-seq "Narrow to" t))) |
11332 | 104 (with-mh-folder-updating (t) |
105 (cond ((mh-seq-to-msgs sequence) | |
106 (mh-widen) | |
107 (let ((eob (point-max))) | |
108 (mh-copy-seq-to-point sequence eob) | |
6365 | 109 (narrow-to-region eob (point-max)) |
11332 | 110 (make-variable-buffer-local 'mh-non-seq-mode-line-annotation) |
111 (setq mh-non-seq-mode-line-annotation mh-mode-line-annotation) | |
112 (setq mh-mode-line-annotation (symbol-name sequence)) | |
113 (mh-make-folder-mode-line) | |
6365 | 114 (mh-recenter nil) |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
115 (if (and (boundp 'tool-bar-mode) tool-bar-mode) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
116 (set (make-local-variable 'tool-bar-map) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
117 mh-folder-seq-tool-bar-map)) |
11332 | 118 (setq mh-narrowed-to-seq sequence))) |
119 (t | |
120 (error "No messages in sequence `%s'" (symbol-name sequence)))))) | |
6365 | 121 |
122 | |
11332 | 123 (defun mh-put-msg-in-seq (msg-or-seq sequence) |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
124 "Add MSG-OR-SEQ (default: displayed message) to SEQUENCE. |
6365 | 125 If optional prefix argument provided, then prompt for the message sequence." |
126 (interactive (list (if current-prefix-arg | |
127 (mh-read-seq-default "Add messages from" t) | |
128 (mh-get-msg-num t)) | |
129 (mh-read-seq-default "Add to" nil))) | |
11332 | 130 (if (not (mh-internal-seq sequence)) |
131 (setq mh-last-seq-used sequence)) | |
6365 | 132 (mh-add-msgs-to-seq (if (numberp msg-or-seq) |
133 msg-or-seq | |
134 (mh-seq-to-msgs msg-or-seq)) | |
11332 | 135 sequence)) |
6365 | 136 |
137 | |
138 (defun mh-widen () | |
139 "Remove restrictions from current folder, thereby showing all messages." | |
140 (interactive) | |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
141 (let ((msg (mh-get-msg-num nil))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
142 (when mh-narrowed-to-seq |
6365 | 143 (with-mh-folder-updating (t) |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
144 (delete-region (point-min) (point-max)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
145 (widen) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
146 (setq mh-mode-line-annotation mh-non-seq-mode-line-annotation) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
147 (mh-make-folder-mode-line)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
148 (if msg |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
149 (mh-goto-msg msg t nil)))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
150 (mh-notate-deleted-and-refiled) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
151 (if (and (boundp 'tool-bar-mode) tool-bar-mode) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
152 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)) |
6365 | 153 (setq mh-narrowed-to-seq nil)) |
154 | |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
155 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
156 ;; FIXME? We may want to clear all notations and add one for current-message |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
157 ;; and process user sequences. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
158 (defun mh-notate-deleted-and-refiled () |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
159 ;; notate the sequence 'deleted as well as all the sequences in |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
160 ;; mh-refile-list. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
161 ;; |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
162 ;; First, the 'deleted sequence is straightforward |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
163 (mh-notate-seq 'deleted mh-note-deleted mh-cmd-note) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
164 ;; Second, refiles are stored in multiple sequences, one for each folder |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
165 ;; name to refile to. This list of buffer names is stored in |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
166 ;; mh-refile-list |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
167 (mh-mapc |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
168 (function |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
169 (lambda (dest) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
170 ;; foreach folder name, get the keyed sequence from mh-seq-list |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
171 (let ((msg-list (cdr (assoc dest mh-seq-list)))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
172 (mapcar (lambda (msg) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
173 ;; foreach msg in a sequence, do the mh-notate |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
174 (mh-notate msg mh-note-refiled mh-cmd-note)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
175 msg-list)))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
176 mh-refile-list)) |
6365 | 177 |
178 | |
179 ;;; Commands to manipulate sequences. Sequences are stored in an alist | |
180 ;;; of the form: | |
181 ;;; ((seq-name msgs ...) (seq-name msgs ...) ...) | |
182 | |
183 | |
184 (defun mh-read-seq-default (prompt not-empty) | |
185 ;; Read and return sequence name with default narrowed or previous sequence. | |
11332 | 186 (mh-read-seq prompt not-empty |
187 (or mh-narrowed-to-seq | |
188 mh-last-seq-used | |
189 (car (mh-seq-containing-msg (mh-get-msg-num nil) nil))))) | |
6365 | 190 |
191 | |
192 (defun mh-read-seq (prompt not-empty &optional default) | |
193 ;; Read and return a sequence name. Prompt with PROMPT, raise an error | |
194 ;; if the sequence is empty and the NOT-EMPTY flag is non-nil, and supply | |
195 ;; an optional DEFAULT sequence. | |
196 ;; A reply of '%' defaults to the first sequence containing the current | |
197 ;; message. | |
198 (let* ((input (completing-read (format "%s %s %s" prompt "sequence:" | |
199 (if default | |
200 (format "[%s] " default) | |
201 "")) | |
202 (mh-seq-names mh-seq-list))) | |
11332 | 203 (seq (cond ((equal input "%") |
204 (car (mh-seq-containing-msg (mh-get-msg-num t) nil))) | |
6365 | 205 ((equal input "") default) |
206 (t (intern input)))) | |
207 (msgs (mh-seq-to-msgs seq))) | |
208 (if (and (null msgs) not-empty) | |
14425
8109feeaf627
(mh-read-seq): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
209 (error "No messages in sequence `%s'" seq)) |
6365 | 210 seq)) |
211 | |
212 | |
213 (defun mh-seq-names (seq-list) | |
214 ;; Return an alist containing the names of the SEQUENCES. | |
215 (mapcar (function (lambda (entry) (list (symbol-name (mh-seq-name entry))))) | |
216 seq-list)) | |
217 | |
218 | |
11332 | 219 (defun mh-rename-seq (sequence new-name) |
220 "Rename SEQUENCE to have NEW-NAME." | |
6365 | 221 (interactive (list (mh-read-seq "Old" t) |
222 (intern (read-string "New sequence name: ")))) | |
11332 | 223 (let ((old-seq (mh-find-seq sequence))) |
6365 | 224 (or old-seq |
11332 | 225 (error "Sequence %s does not exist" sequence)) |
226 ;; create new sequence first, since it might raise an error. | |
6365 | 227 (mh-define-sequence new-name (mh-seq-msgs old-seq)) |
11332 | 228 (mh-undefine-sequence sequence (mh-seq-msgs old-seq)) |
6365 | 229 (rplaca old-seq new-name))) |
230 | |
231 | |
232 (defun mh-map-to-seq-msgs (func seq &rest args) | |
233 ;; Invoke the FUNCTION at each message in the SEQUENCE, passing the | |
234 ;; remaining ARGS as arguments. | |
235 (save-excursion | |
236 (let ((msgs (mh-seq-to-msgs seq))) | |
237 (while msgs | |
238 (if (mh-goto-msg (car msgs) t t) | |
239 (apply func (car msgs) args)) | |
240 (setq msgs (cdr msgs)))))) | |
241 | |
242 | |
243 (defun mh-notate-seq (seq notation offset) | |
244 ;; Mark the scan listing of all messages in the SEQUENCE with the CHARACTER | |
245 ;; at the given OFFSET from the beginning of the listing line. | |
246 (mh-map-to-seq-msgs 'mh-notate seq notation offset)) | |
247 | |
248 | |
249 (defun mh-add-to-sequence (seq msgs) | |
250 ;; Add to a SEQUENCE each message the list of MSGS. | |
251 (if (not (mh-folder-name-p seq)) | |
252 (if msgs | |
253 (apply 'mh-exec-cmd "mark" mh-current-folder "-add" | |
254 "-sequence" (symbol-name seq) | |
11332 | 255 (mh-coalesce-msg-list msgs))))) |
6365 | 256 |
257 | |
258 (defun mh-copy-seq-to-point (seq location) | |
259 ;; Copy the scan listing of the messages in SEQUENCE to after the point | |
260 ;; LOCATION in the current buffer. | |
261 (mh-map-to-seq-msgs 'mh-copy-line-to-point seq location)) | |
262 | |
263 | |
264 (defun mh-copy-line-to-point (msg location) | |
265 ;; Copy the current line to the LOCATION in the current buffer. | |
266 (beginning-of-line) | |
11332 | 267 (save-excursion |
268 (let ((beginning-of-line (point)) | |
269 end) | |
270 (forward-line 1) | |
271 (setq end (point)) | |
272 (goto-char location) | |
273 (insert-buffer-substring (current-buffer) beginning-of-line end)))) | |
6365 | 274 |
47730
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
275 (defun mh-region-to-sequence (begin end) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
276 "Define sequence 'region as the messages between point and mark. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
277 When called programmatically, use arguments BEGIN and END to define region." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
278 (interactive "r") |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
279 (mh-delete-seq-locally 'region) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
280 (save-excursion |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
281 (goto-char begin) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
282 (while (<= (point) end) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
283 (mh-add-msgs-to-seq (mh-get-msg-num t) 'region t) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
284 (forward-line 1)))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
285 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
286 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
287 ;;; Commands to handle new 'subject sequence. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
288 ;;; Or "Poor man's threading" by psg. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
289 (defun mh-subject-thread-to-sequence (all) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
290 "Put all following messages with same subject in sequence 'subject. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
291 If arg ALL is t, move to beginning of folder buffer to collect all messages. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
292 If arg ALL is nil, collect only messages fron current one on forward. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
293 Return number of messages put in the sequence: |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
294 nil -> there was no subject line. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
295 0 -> there were no later messages with the same subject (sequence not made) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
296 >1 -> the total number of messages including current one." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
297 (if (not (eq major-mode 'mh-folder-mode)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
298 (error "Not in a folder buffer")) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
299 (save-excursion |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
300 (beginning-of-line) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
301 (if (or (not (looking-at mh-scan-subject-regexp)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
302 (not (match-string 2)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
303 (string-equal "" (match-string 2))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
304 (progn (message "No subject line.") |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
305 nil) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
306 (let ((subject (match-string-no-properties 2)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
307 (end (point-max)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
308 (list)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
309 (if (> (length subject) 41) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
310 (setq subject (substring subject 0 41))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
311 (save-excursion |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
312 (if all |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
313 (goto-char (point-min))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
314 (while (re-search-forward mh-scan-subject-regexp nil t) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
315 (let ((this-subject (match-string-no-properties 2))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
316 (if (> (length this-subject) 41) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
317 (setq this-subject (substring this-subject 0 41))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
318 (if (string-equal this-subject subject) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
319 (setq list (cons (mh-get-msg-num t) list)))))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
320 (cond |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
321 (list |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
322 ;; If we created a new sequence, add the initial message to it too. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
323 (if (not (member (mh-get-msg-num t) list)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
324 (setq list (cons (mh-get-msg-num t) list))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
325 (mh-delete-seq-locally 'subject) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
326 ;; sort the result into a sequence |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
327 (let ((sorted-list (sort (copy-sequence list) 'mh-lessp)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
328 (msg)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
329 (while sorted-list |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
330 (mh-add-msgs-to-seq (car sorted-list) 'subject t) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
331 (setq sorted-list (cdr sorted-list))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
332 (safe-length list))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
333 (t |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
334 0)))))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
335 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
336 (defun mh-narrow-to-subject-thread () |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
337 "Narrow to a sequence containing all following messages with same subject." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
338 (interactive) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
339 (let ((num (mh-get-msg-num nil)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
340 (count (mh-subject-thread-to-sequence t))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
341 (cond |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
342 ((not count) ; No subject line, delete msg anyway |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
343 nil) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
344 ((= 0 count) ; No other msgs, delete msg anyway. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
345 (message "No other messages with same Subject following this one.") |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
346 nil) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
347 (t ; We have a subject sequence. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
348 (message "Found %d messages for subject sequence." count) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
349 (mh-narrow-to-seq 'subject) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
350 (if (numberp num) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
351 (mh-goto-msg num t t)))))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
352 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
353 (defun mh-toggle-subject-thread () |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
354 "Narrow to or widen from a sequence containing current subject sequence." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
355 (interactive) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
356 (if (and (stringp mh-mode-line-annotation) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
357 (string-equal mh-mode-line-annotation "subject")) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
358 (progn |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
359 (goto-char (point-min)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
360 (mh-widen)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
361 (mh-narrow-to-subject-thread))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
362 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
363 (defun mh-delete-subject-thread () |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
364 "Mark all following messages with same subject to be deleted." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
365 (interactive) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
366 (let ((count (mh-subject-thread-to-sequence nil))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
367 (cond |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
368 ((not count) ; No subject line, delete msg anyway |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
369 (mh-delete-msg (mh-get-msg-num t))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
370 ((= 0 count) ; No other msgs, delete msg anyway. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
371 (message "No other messages with same Subject following this one.") |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
372 (mh-delete-msg (mh-get-msg-num t))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
373 (t ; We have a subject sequence. |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
374 (message "Marked %d messages for deletion" count) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
375 (mh-delete-msg 'subject))))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
376 |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
377 (defun mh-next-unseen-subject-thread () |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
378 "Get the next unseen subject thread." |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
379 (interactive) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
380 (if (and mh-mode-line-annotation |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
381 (string-equal mh-mode-line-annotation "subject")) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
382 (goto-char (point-min))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
383 (if (or (not mh-mode-line-annotation) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
384 (not (string-equal mh-mode-line-annotation "unseen"))) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
385 (mh-narrow-to-seq 'unseen)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
386 (mh-next-undeleted-msg) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
387 (mh-narrow-to-subject-thread)) |
2568d5a27317
Upgraded to mh-e version 6.1.1.
Bill Wohler <wohler@newt.com>
parents:
38414
diff
changeset
|
388 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
14425
diff
changeset
|
389 ;;; mh-seq.el ends here |