Mercurial > emacs
annotate lisp/mh-e/mh-folder.el @ 69423:cb37d3ec5eb1
Add period to last sentence added.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Sat, 11 Mar 2006 22:50:06 +0000 |
parents | 0b84cb235f62 |
children | 5259cc742763 |
rev | line source |
---|---|
68465 | 1 ;;; mh-folder.el --- MH-Folder mode |
2 | |
3 ;; Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Bill Wohler <wohler@newt.com> | |
6 ;; Maintainer: Bill Wohler <wohler@newt.com> | |
7 ;; Keywords: mail | |
8 ;; See: mh-e.el | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
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 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
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 | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
25 ;; Boston, MA 02110-1301, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; Mode for browsing folders | |
30 | |
31 ;;; Change Log: | |
32 | |
33 ;;; Code: | |
34 | |
35 (require 'mh-e) | |
36 (require 'mh-scan) | |
37 (mh-require-cl) | |
38 | |
69245
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
39 ;; Dynamically-created functions not found in mh-loaddefs.el. |
68465 | 40 (autoload 'mh-tool-bar-folder-buttons-init "mh-tool-bar") |
69245
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
41 (autoload 'mh-tool-bar-init "mh-tool-bar") |
68465 | 42 |
43 (require 'gnus-util) | |
44 (autoload 'message-fetch-field "message") | |
45 | |
46 | |
47 | |
48 ;;; MH-E Entry Points | |
49 | |
50 ;;;###autoload | |
51 (defun mh-rmail (&optional arg) | |
52 "Incorporate new mail with MH. | |
53 Scan an MH folder if ARG is non-nil. | |
54 | |
55 This function is an entry point to MH-E, the Emacs interface to | |
56 the MH mail system." | |
57 (interactive "P") | |
58 (mh-find-path) | |
59 (if arg | |
60 (call-interactively 'mh-visit-folder) | |
61 (unless (get-buffer mh-inbox) | |
62 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq))) | |
63 (mh-inc-folder))) | |
64 | |
65 ;;;###autoload | |
66 (defun mh-nmail (&optional arg) | |
67 "Check for new mail in inbox folder. | |
68 Scan an MH folder if ARG is non-nil. | |
69 | |
70 This function is an entry point to MH-E, the Emacs interface to | |
71 the MH mail system." | |
72 (interactive "P") | |
73 (mh-find-path) ; init mh-inbox | |
74 (if arg | |
75 (call-interactively 'mh-visit-folder) | |
76 (mh-visit-folder mh-inbox))) | |
77 | |
78 | |
79 ;;; Desktop Integration | |
80 | |
81 ;; desktop-buffer-mode-handlers appeared in Emacs 22. | |
82 (if (fboundp 'desktop-buffer-mode-handlers) | |
83 (add-to-list 'desktop-buffer-mode-handlers | |
84 '(mh-folder-mode . mh-restore-desktop-buffer))) | |
85 | |
86 (defun mh-restore-desktop-buffer (desktop-buffer-file-name | |
87 desktop-buffer-name | |
88 desktop-buffer-misc) | |
89 "Restore an MH folder buffer specified in a desktop file. | |
90 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the | |
91 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer | |
92 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info | |
93 used by the `desktop-buffer-handlers' functions." | |
94 (mh-find-path) | |
95 (mh-visit-folder desktop-buffer-name) | |
96 (current-buffer)) | |
97 | |
98 | |
99 | |
100 ;;; Variables | |
101 | |
102 (defvar mh-folder-filename nil | |
103 "Full path of directory for this folder.") | |
104 | |
105 (defvar mh-partial-folder-mode-line-annotation "select" | |
106 "Annotation when displaying part of a folder. | |
107 The string is displayed after the folder's name. nil for no | |
108 annotation.") | |
109 | |
110 (defvar mh-last-destination nil | |
111 "Destination of last refile or write command.") | |
112 | |
113 (defvar mh-last-destination-folder nil | |
114 "Destination of last refile command.") | |
115 | |
116 (defvar mh-last-destination-write nil | |
117 "Destination of last write command.") | |
118 | |
119 (defvar mh-first-msg-num nil | |
120 "Number of first message in buffer.") | |
121 | |
122 (defvar mh-last-msg-num nil | |
123 "Number of last msg in buffer.") | |
124 | |
125 (defvar mh-msg-count nil | |
126 "Number of msgs in buffer.") | |
127 | |
128 | |
129 | |
130 ;;; Sequence Menu | |
131 | |
132 (easy-menu-define | |
133 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence." | |
134 '("Sequence" | |
135 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)] | |
136 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)] | |
137 ["Delete Message from Sequence..." mh-delete-msg-from-seq | |
138 (mh-get-msg-num nil)] | |
139 ["List Sequences in Folder..." mh-list-sequences t] | |
140 ["Delete Sequence..." mh-delete-seq t] | |
141 ["Narrow to Sequence..." mh-narrow-to-seq t] | |
142 ["Widen from Sequence" mh-widen mh-folder-view-stack] | |
143 "--" | |
144 ["Narrow to Subject Sequence" mh-narrow-to-subject t] | |
145 ["Narrow to Tick Sequence" mh-narrow-to-tick | |
146 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))] | |
147 ["Delete Rest of Same Subject" mh-delete-subject t] | |
148 ["Toggle Tick Mark" mh-toggle-tick t] | |
149 "--" | |
150 ["Push State Out to MH" mh-update-sequences t])) | |
151 | |
152 ;;; Message Menu | |
153 | |
154 (easy-menu-define | |
155 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message." | |
156 '("Message" | |
157 ["Show Message" mh-show (mh-get-msg-num nil)] | |
158 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)] | |
159 ["Next Message" mh-next-undeleted-msg t] | |
160 ["Previous Message" mh-previous-undeleted-msg t] | |
161 ["Go to First Message" mh-first-msg t] | |
162 ["Go to Last Message" mh-last-msg t] | |
163 ["Go to Message by Number..." mh-goto-msg t] | |
164 ["Modify Message" mh-modify t] | |
165 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)] | |
166 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)] | |
167 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)] | |
168 ["Execute Delete/Refile" mh-execute-commands | |
169 (mh-outstanding-commands-p)] | |
170 "--" | |
171 ["Compose a New Message" mh-send t] | |
172 ["Reply to Message..." mh-reply (mh-get-msg-num nil)] | |
173 ["Forward Message..." mh-forward (mh-get-msg-num nil)] | |
174 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)] | |
175 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)] | |
176 ["Re-edit a Bounced Message" mh-extract-rejected-mail t] | |
177 "--" | |
178 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)] | |
179 ["Print Message" mh-print-msg (mh-get-msg-num nil)] | |
180 ["Write Message to File..." mh-write-msg-to-file | |
181 (mh-get-msg-num nil)] | |
182 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)] | |
183 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)] | |
184 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)])) | |
185 | |
186 ;;; Folder Menu | |
187 | |
188 (easy-menu-define | |
189 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder." | |
190 '("Folder" | |
191 ["Incorporate New Mail" mh-inc-folder t] | |
192 ["Toggle Show/Folder" mh-toggle-showing t] | |
193 ["Execute Delete/Refile" mh-execute-commands | |
194 (mh-outstanding-commands-p)] | |
195 ["Rescan Folder" mh-rescan-folder t] | |
196 ["Thread Folder" mh-toggle-threads | |
197 (not (memq 'unthread mh-view-ops))] | |
198 ["Pack Folder" mh-pack-folder t] | |
199 ["Sort Folder" mh-sort-folder t] | |
200 "--" | |
201 ["List Folders" mh-list-folders t] | |
202 ["Visit a Folder..." mh-visit-folder t] | |
203 ["View New Messages" mh-index-new-messages t] | |
204 ["Search..." mh-search t] | |
205 "--" | |
206 ["Quit MH-E" mh-quit t])) | |
207 | |
208 | |
209 | |
210 ;;; MH-Folder Keys | |
211 | |
212 (suppress-keymap mh-folder-mode-map) | |
213 | |
214 ;; Use defalias to make sure the documented primary key bindings | |
215 ;; appear in menu lists. | |
216 (defalias 'mh-alt-show 'mh-show) | |
217 (defalias 'mh-alt-refile-msg 'mh-refile-msg) | |
218 (defalias 'mh-alt-send 'mh-send) | |
219 (defalias 'mh-alt-visit-folder 'mh-visit-folder) | |
220 | |
221 ;; Save the "b" binding for a future `back'. Maybe? | |
222 (gnus-define-keys mh-folder-mode-map | |
223 " " mh-page-msg | |
224 "!" mh-refile-or-write-again | |
225 "'" mh-toggle-tick | |
226 "," mh-header-display | |
227 "." mh-alt-show | |
228 ";" mh-toggle-mh-decode-mime-flag | |
229 ">" mh-write-msg-to-file | |
230 "?" mh-help | |
231 "E" mh-extract-rejected-mail | |
232 "M" mh-modify | |
233 "\177" mh-previous-page | |
234 "\C-d" mh-delete-msg-no-motion | |
235 "\t" mh-index-next-folder | |
236 [backtab] mh-index-previous-folder | |
237 "\M-\t" mh-index-previous-folder | |
238 "\e<" mh-first-msg | |
239 "\e>" mh-last-msg | |
240 "\ed" mh-redistribute | |
241 "\r" mh-show | |
242 "^" mh-alt-refile-msg | |
243 "c" mh-copy-msg | |
244 "d" mh-delete-msg | |
245 "e" mh-edit-again | |
246 "f" mh-forward | |
247 "g" mh-goto-msg | |
248 "i" mh-inc-folder | |
249 "k" mh-delete-subject-or-thread | |
250 "m" mh-alt-send | |
251 "n" mh-next-undeleted-msg | |
252 "\M-n" mh-next-unread-msg | |
253 "o" mh-refile-msg | |
254 "p" mh-previous-undeleted-msg | |
255 "\M-p" mh-previous-unread-msg | |
256 "q" mh-quit | |
257 "r" mh-reply | |
258 "s" mh-send | |
259 "t" mh-toggle-showing | |
260 "u" mh-undo | |
261 "v" mh-index-visit-folder | |
262 "x" mh-execute-commands | |
263 "|" mh-pipe-msg) | |
264 | |
265 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map) | |
266 "?" mh-prefix-help | |
267 "'" mh-index-ticked-messages | |
268 "S" mh-sort-folder | |
269 "c" mh-catchup | |
270 "f" mh-alt-visit-folder | |
271 "k" mh-kill-folder | |
272 "l" mh-list-folders | |
273 "n" mh-index-new-messages | |
274 "o" mh-alt-visit-folder | |
275 "p" mh-pack-folder | |
276 "q" mh-index-sequenced-messages | |
277 "r" mh-rescan-folder | |
278 "s" mh-search | |
279 "u" mh-undo-folder | |
280 "v" mh-visit-folder) | |
281 | |
282 (define-key mh-folder-mode-map "I" mh-inc-spool-map) | |
283 | |
284 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map) | |
285 "?" mh-prefix-help | |
286 "b" mh-junk-blacklist | |
287 "w" mh-junk-whitelist) | |
288 | |
289 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map) | |
290 "?" mh-prefix-help | |
291 "C" mh-ps-print-toggle-color | |
292 "F" mh-ps-print-toggle-faces | |
293 "f" mh-ps-print-msg-file | |
294 "l" mh-print-msg | |
295 "p" mh-ps-print-msg) | |
296 | |
297 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map) | |
298 "'" mh-narrow-to-tick | |
299 "?" mh-prefix-help | |
300 "d" mh-delete-msg-from-seq | |
301 "k" mh-delete-seq | |
302 "l" mh-list-sequences | |
303 "n" mh-narrow-to-seq | |
304 "p" mh-put-msg-in-seq | |
305 "s" mh-msg-is-in-seq | |
306 "w" mh-widen) | |
307 | |
308 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map) | |
309 "?" mh-prefix-help | |
310 "u" mh-thread-ancestor | |
311 "p" mh-thread-previous-sibling | |
312 "n" mh-thread-next-sibling | |
313 "t" mh-toggle-threads | |
314 "d" mh-thread-delete | |
315 "o" mh-thread-refile) | |
316 | |
317 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map) | |
318 "'" mh-narrow-to-tick | |
319 "?" mh-prefix-help | |
320 "c" mh-narrow-to-cc | |
321 "g" mh-narrow-to-range | |
322 "m" mh-narrow-to-from | |
323 "s" mh-narrow-to-subject | |
324 "t" mh-narrow-to-to | |
325 "w" mh-widen) | |
326 | |
327 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map) | |
328 "?" mh-prefix-help | |
329 "s" mh-store-msg ;shar | |
330 "u" mh-store-msg) ;uuencode | |
331 | |
332 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map) | |
333 " " mh-page-digest | |
334 "?" mh-prefix-help | |
335 "\177" mh-page-digest-backwards | |
336 "b" mh-burst-digest) | |
337 | |
338 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map) | |
339 "?" mh-prefix-help | |
340 "a" mh-mime-save-parts | |
341 "e" mh-display-with-external-viewer | |
342 "i" mh-folder-inline-mime-part | |
343 "o" mh-folder-save-mime-part | |
344 "t" mh-toggle-mime-buttons | |
345 "v" mh-folder-toggle-mime-part | |
346 "\t" mh-next-button | |
347 [backtab] mh-prev-button | |
348 "\M-\t" mh-prev-button) | |
349 | |
350 (cond | |
351 (mh-xemacs-flag | |
352 (define-key mh-folder-mode-map [button2] 'mh-show-mouse)) | |
353 (t | |
354 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse))) | |
355 | |
356 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt | |
357 | |
358 | |
359 | |
360 ;;; MH-Folder Help Messages | |
361 | |
362 ;; If you add a new prefix, add appropriate text to the nil key. | |
363 | |
364 ;; In general, messages are grouped logically. Taking the main commands for | |
365 ;; example, the first line is "ways to view messages," the second line is | |
366 ;; "things you can do with messages", and the third is "composing" messages. | |
367 | |
368 ;; When adding a new prefix, ensure that the help message contains "what" the | |
369 ;; prefix is for. For example, if the word "folder" were not present in the | |
370 ;; "F" entry, it would not be clear what these commands operated upon. | |
371 (defvar mh-folder-mode-help-messages | |
372 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n" | |
373 "[d]elete, [o]refile, e[x]ecute,\n" | |
374 "[s]end, [r]eply,\n" | |
375 "[;]toggle MIME decoding.\n" | |
376 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys," | |
377 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.") | |
378 | |
379 (?F "[l]ist; [v]isit folder;\n" | |
380 "[n]ew messages; [']ticked messages; [s]earch;\n" | |
381 "[p]ack; [S]ort; [r]escan; [k]ill") | |
382 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n" | |
383 "Toggle printing of [C]olors, [F]aces") | |
384 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n" | |
385 "[s]equences, [l]ist,\n" | |
386 "[d]elete message from sequence, [k]ill sequence") | |
387 (?T "[t]oggle, [d]elete, [o]refile thread") | |
388 (?/ "Limit to [c]c, ran[g]e, fro[m], [s]ubject, [t]o; [w]iden") | |
389 (?X "un[s]har, [u]udecode message") | |
390 (?D "[b]urst digest") | |
391 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n" | |
392 "[TAB] next; [SHIFT-TAB] previous") | |
393 (?J "[b]lacklist, [w]hitelist message")) | |
394 "Key binding cheat sheet. | |
395 See `mh-set-help'.") | |
396 | |
397 | |
398 | |
399 ;;; MH-Folder Font Lock | |
400 | |
401 (defvar mh-folder-font-lock-keywords | |
402 (list | |
403 ;; Folders when displaying index buffer | |
404 (list "^\\+.*" | |
405 '(0 'mh-search-folder)) | |
406 ;; Marked for deletion | |
407 (list (concat mh-scan-deleted-msg-regexp ".*") | |
408 '(0 'mh-folder-deleted)) | |
409 ;; Marked for refile | |
410 (list (concat mh-scan-refiled-msg-regexp ".*") | |
411 '(0 'mh-folder-refiled)) | |
412 ;; After subject | |
413 (list mh-scan-body-regexp | |
414 '(1 'mh-folder-body nil t)) | |
415 ;; Subject | |
416 '(mh-folder-font-lock-subject | |
417 (1 'mh-folder-followup append t) | |
418 (2 'mh-folder-subject append t)) | |
419 ;; Current message number | |
420 (list mh-scan-cur-msg-number-regexp | |
421 '(1 'mh-folder-cur-msg-number)) | |
422 ;; Message number | |
423 (list mh-scan-good-msg-regexp | |
424 '(1 'mh-folder-msg-number)) | |
425 ;; Date | |
426 (list mh-scan-date-regexp | |
427 '(1 'mh-folder-date)) | |
428 ;; Messages from me (To:) | |
429 (list mh-scan-rcpt-regexp | |
430 '(1 'mh-folder-to) | |
431 '(2 'mh-folder-address)) | |
432 ;; Messages to me | |
433 (list mh-scan-sent-to-me-sender-regexp | |
434 '(1 'mh-folder-sent-to-me-hint) | |
435 '(2 'mh-folder-sent-to-me-sender))) | |
436 "Keywords (regular expressions) used to fontify the MH-Folder buffer.") | |
437 | |
438 (defun mh-folder-font-lock-subject (limit) | |
439 "Return MH-E scan subject strings to font-lock between point and LIMIT." | |
440 (if (not (re-search-forward mh-scan-subject-regexp limit t)) | |
441 nil | |
442 (if (match-beginning 1) | |
443 (set-match-data (list (match-beginning 1) (match-end 3) | |
444 (match-beginning 1) (match-end 3) nil nil)) | |
445 (set-match-data (list (match-beginning 3) (match-end 3) | |
446 nil nil (match-beginning 3) (match-end 3)))) | |
447 t)) | |
448 | |
449 ;; Fontify unseen messages in bold. | |
450 | |
451 (defmacro mh-generate-sequence-font-lock (seq prefix face) | |
452 "Generate the appropriate code to fontify messages in SEQ. | |
453 PREFIX is used to generate unique names for the variables and | |
454 functions defined by the macro. So a different prefix should be | |
455 provided for every invocation. | |
456 FACE is the font-lock face used to display the matching scan lines." | |
457 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix))) | |
458 (func (intern (format "mh-folder-font-lock-%s" prefix)))) | |
459 `(progn | |
460 (defvar ,cache nil | |
461 "Internal cache variable used for font-lock in MH-E. | |
462 Should only be non-nil through font-lock stepping, and nil once | |
463 font-lock is done highlighting.") | |
464 (make-variable-buffer-local ',cache) | |
465 | |
466 (defun ,func (limit) | |
467 "Return unseen message lines to font-lock between point and LIMIT." | |
468 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq)))) | |
469 (let ((cur-msg (mh-get-msg-num nil))) | |
470 (cond ((not ,cache) | |
471 nil) | |
472 ((>= (point) limit) ;Presumably at end of buffer | |
473 (setq ,cache nil) | |
474 nil) | |
475 ((member cur-msg ,cache) | |
476 (let ((bpoint (progn (beginning-of-line)(point))) | |
477 (epoint (progn (forward-line 1)(point)))) | |
478 (if (<= limit (point)) (setq ,cache nil)) | |
479 (set-match-data (list bpoint epoint bpoint epoint)) | |
480 t)) | |
481 (t | |
482 ;; move forward one line at a time, checking each message | |
483 (while (and (= 0 (forward-line 1)) | |
484 (> limit (point)) | |
485 (not (member (mh-get-msg-num nil) ,cache)))) | |
486 ;; Examine how we must have exited the loop... | |
487 (let ((cur-msg (mh-get-msg-num nil))) | |
488 (cond ((or (<= limit (point)) | |
489 (not (member cur-msg ,cache))) | |
490 (setq ,cache nil) | |
491 nil) | |
492 ((member cur-msg ,cache) | |
493 (let ((bpoint (progn (beginning-of-line) (point))) | |
494 (epoint (progn (forward-line 1) (point)))) | |
495 (if (<= limit (point)) (setq ,cache nil)) | |
496 (set-match-data | |
497 (list bpoint epoint bpoint epoint)) | |
498 t)))))))) | |
499 | |
500 (setq mh-folder-font-lock-keywords | |
501 (append mh-folder-font-lock-keywords | |
502 (list (list ',func (list 1 '',face 'prepend t)))))))) | |
503 | |
504 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold) | |
505 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick) | |
506 | |
507 | |
508 | |
509 ;;; MH-Folder Mode | |
510 | |
511 (defmacro mh-remove-xemacs-horizontal-scrollbar () | |
512 "Get rid of the horizontal scrollbar that XEmacs insists on putting in." | |
513 (when mh-xemacs-flag | |
514 `(if (and (featurep 'scrollbar) | |
515 (fboundp 'set-specifier)) | |
516 (set-specifier horizontal-scrollbar-visible-p nil | |
517 (cons (current-buffer) nil))))) | |
518 | |
519 ;; Register mh-folder-mode as supporting which-function-mode... | |
68529
7daec5f4a289
* mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents:
68520
diff
changeset
|
520 (mh-require 'which-func nil t) |
68465 | 521 (when (boundp 'which-func-modes) |
522 (add-to-list 'which-func-modes 'mh-folder-mode)) | |
523 | |
524 ;; Shush compiler. | |
525 (eval-when-compile | |
526 (defvar desktop-save-buffer) | |
527 (defvar font-lock-auto-fontify) | |
528 (mh-do-in-xemacs (defvar font-lock-defaults))) | |
529 | |
530 (defvar mh-folder-buttons-init-flag nil) | |
531 | |
532 ;; Ensure new buffers won't get this mode if default-major-mode is nil. | |
533 (put 'mh-folder-mode 'mode-class 'special) | |
534 | |
535 ;; Autoload cookie needed by desktop.el | |
536 ;;;###autoload | |
537 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder" | |
538 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map> | |
539 | |
540 You can show the message the cursor is pointing to, and step through | |
541 the messages. Messages can be marked for deletion or refiling into | |
542 another folder; these commands are executed all at once with a | |
543 separate command. | |
544 | |
545 Options that control this mode can be changed with | |
546 \\[customize-group]; specify the \"mh\" group. In particular, please | |
547 see the `mh-scan-format-file' option if you wish to modify scan's | |
548 format. | |
549 | |
550 When a folder is visited, the hook `mh-folder-mode-hook' is run. | |
551 | |
552 Ranges | |
553 ====== | |
554 Many commands that operate on individual messages, such as | |
555 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument | |
556 can be used in several ways. | |
557 | |
558 If you provide the prefix argument (\\[universal-argument]) to | |
559 these commands, then you will be prompted for the message range. | |
560 This can be any valid MH range which can include messages, | |
561 sequences, and the abbreviations (described in the mh(1) man | |
562 page): | |
563 | |
564 <num1>-<num2> | |
565 Indicates all messages in the range <num1> to <num2>, inclusive. | |
566 The range must be nonempty. | |
567 | |
568 <num>:N | |
569 <num>:+N | |
570 <num>:-N | |
571 Up to N messages beginning with (or ending with) message num. Num | |
572 may be any of the predefined symbols: first, prev, cur, next or | |
573 last. | |
574 | |
575 first:N | |
576 prev:N | |
577 next:N | |
578 last:N | |
579 The first, previous, next or last messages, if they exist. | |
580 | |
581 all | |
582 All of the messages. | |
583 | |
584 For example, a range that shows all of these things is `1 2 3 | |
585 5-10 last:5 unseen'. | |
586 | |
587 If the option `transient-mark-mode' is set to t and you set a | |
588 region in the MH-Folder buffer, then the MH-E command will | |
589 perform the operation on all messages in that region. | |
590 | |
591 \\{mh-folder-mode-map}" | |
592 (mh-do-in-gnu-emacs | |
69245
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
593 (unless mh-folder-buttons-init-flag |
69286
0b84cb235f62
* mh-folder.el (mh-folder-mode): Drop 'load-path argument when calling
Bill Wohler <wohler@newt.com>
parents:
69273
diff
changeset
|
594 (let ((load-path (mh-image-load-path-for-library "mh-e" "mh-logo.xpm")) |
69273
b52e0cc8af61
* mh-folder.el (mh-folder-mode): Rename mh-image-load-path to
Bill Wohler <wohler@newt.com>
parents:
69245
diff
changeset
|
595 (image-load-path (mh-image-load-path-for-library |
b52e0cc8af61
* mh-folder.el (mh-folder-mode): Rename mh-image-load-path to
Bill Wohler <wohler@newt.com>
parents:
69245
diff
changeset
|
596 "mh-e" "mh-logo.xpm" 'image-load-path))) |
69245
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
597 (mh-tool-bar-folder-buttons-init) |
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
598 (setq mh-folder-buttons-init-flag t))) |
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
599 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)) |
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
600 (mh-do-in-xemacs |
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
601 (mh-tool-bar-init :folder)) |
68465 | 602 (make-local-variable 'font-lock-defaults) |
603 (setq font-lock-defaults '(mh-folder-font-lock-keywords t)) | |
604 (make-local-variable 'desktop-save-buffer) | |
605 (setq desktop-save-buffer t) | |
606 (mh-make-local-vars | |
607 'mh-colors-available-flag (mh-colors-available-p) | |
608 ; Do we have colors available | |
609 'mh-current-folder (buffer-name) ; Name of folder, a string | |
610 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs | |
611 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/" | |
612 (file-name-as-directory (mh-expand-file-name (buffer-name))) | |
613 'mh-display-buttons-for-inline-parts-flag | |
614 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to | |
615 ; be toggled. | |
616 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed | |
617 'overlay-arrow-position nil ; Allow for simultaneous display in | |
618 'overlay-arrow-string ">" ; different MH-E buffers. | |
619 'mh-showing-mode nil ; Show message also? | |
620 'mh-delete-list nil ; List of msgs nums to delete | |
621 'mh-refile-list nil ; List of folder names in mh-seq-list | |
622 'mh-seq-list nil ; Alist of (seq . msgs) nums | |
623 'mh-seen-list nil ; List of displayed messages | |
624 'mh-next-direction 'forward ; Direction to move to next message | |
625 'mh-view-ops () ; Stack that keeps track of the order | |
626 ; in which narrowing/threading has been | |
627 ; carried out. | |
628 'mh-folder-view-stack () ; Stack of previous views of the | |
629 ; folder. | |
630 'mh-index-data nil ; If the folder was created by a call | |
631 ; to mh-search, this contains info | |
632 ; about the search results. | |
633 'mh-index-previous-search nil ; folder, indexer, search-regexp | |
634 'mh-index-msg-checksum-map nil ; msg -> checksum map | |
635 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg ) | |
636 'mh-index-sequence-search-flag nil ; folder resulted from sequence search | |
637 'mh-first-msg-num nil ; Number of first msg in buffer | |
638 'mh-last-msg-num nil ; Number of last msg in buffer | |
639 'mh-msg-count nil ; Number of msgs in buffer | |
640 'mh-mode-line-annotation nil ; Indicates message range | |
641 'mh-sequence-notation-history (make-hash-table) | |
642 ; Remember what is overwritten by | |
643 ; mh-note-seq. | |
644 'imenu-create-index-function 'mh-index-create-imenu-index | |
645 ; Setup imenu support | |
646 'mh-previous-window-config nil) ; Previous window configuration | |
647 (mh-remove-xemacs-horizontal-scrollbar) | |
648 (setq truncate-lines t) | |
649 (auto-save-mode -1) | |
650 (setq buffer-offer-save t) | |
68520
6a7173abcf59
* mh-acros.el (mh-defun-compat, mh-defmacro-compat): Add name argument
Bill Wohler <wohler@newt.com>
parents:
68474
diff
changeset
|
651 (mh-make-local-hook (mh-write-file-functions)) |
6a7173abcf59
* mh-acros.el (mh-defun-compat, mh-defmacro-compat): Add name argument
Bill Wohler <wohler@newt.com>
parents:
68474
diff
changeset
|
652 (add-hook (mh-write-file-functions) 'mh-execute-commands nil t) |
68465 | 653 (make-local-variable 'revert-buffer-function) |
654 (make-local-variable 'hl-line-mode) ; avoid pollution | |
655 (mh-funcall-if-exists hl-line-mode 1) | |
656 (setq revert-buffer-function 'mh-undo-folder) | |
68474
07c20c57ee3d
(mh-folder-mode): Use add-to-list to modify minor-mode-alias.
Bill Wohler <wohler@newt.com>
parents:
68470
diff
changeset
|
657 (add-to-list 'minor-mode-alist '(mh-showing-mode " Show")) |
68465 | 658 (easy-menu-add mh-folder-sequence-menu) |
659 (easy-menu-add mh-folder-message-menu) | |
660 (easy-menu-add mh-folder-folder-menu) | |
661 (mh-inc-spool-make) | |
662 (mh-set-help mh-folder-mode-help-messages) | |
663 (if (and mh-xemacs-flag | |
664 font-lock-auto-fontify) | |
665 (turn-on-font-lock))) ; Force font-lock in XEmacs. | |
666 | |
667 | |
668 | |
669 ;;; MH-Folder Commands | |
670 | |
671 ;; Alphabetical. | |
672 ;; See also mh-comp.el, mh-junk.el, mh-mime.el, mh-print.el, | |
673 ;; mh-search.el, and mh-seq.el. | |
674 | |
675 ;;;###mh-autoload | |
676 (defun mh-delete-msg (range) | |
677 "Delete RANGE\\<mh-folder-mode-map>. | |
678 | |
679 To mark a message for deletion, use this command. A \"D\" is | |
680 placed by the message in the scan window, and the next undeleted | |
681 message is displayed. If the previous command had been | |
682 \\[mh-previous-undeleted-msg], then the next message displayed is | |
683 the first undeleted message previous to the message just deleted. | |
684 Use \\[mh-next-undeleted-msg] to force subsequent | |
685 \\[mh-delete-msg] commands to move forward to the next undeleted | |
686 message after deleting the message under the cursor. | |
687 | |
688 The hook `mh-delete-msg-hook' is called after you mark a message | |
689 for deletion. For example, a past maintainer of MH-E used this | |
690 once when he kept statistics on his mail usage. | |
691 | |
692 Check the documentation of `mh-interactive-range' to see how | |
693 RANGE is read in interactive use." | |
694 (interactive (list (mh-interactive-range "Delete"))) | |
695 (mh-delete-msg-no-motion range) | |
696 (if (looking-at mh-scan-deleted-msg-regexp) | |
697 (mh-next-msg))) | |
698 | |
699 ;;;###mh-autoload | |
700 (defun mh-delete-msg-no-motion (range) | |
701 "Delete RANGE, don't move to next message. | |
702 | |
703 This command marks the RANGE for deletion but leaves the cursor | |
704 at the current message in case you wish to perform other | |
705 operations on the message. | |
706 | |
707 Check the documentation of `mh-interactive-range' to see how | |
708 RANGE is read in interactive use." | |
709 (interactive (list (mh-interactive-range "Delete"))) | |
710 (mh-iterate-on-range () range | |
711 (mh-delete-a-msg nil))) | |
712 | |
713 ;;;###mh-autoload | |
714 (defun mh-execute-commands () | |
715 "Process outstanding delete and refile requests\\<mh-folder-mode-map>. | |
716 | |
717 If you've marked messages to be deleted or refiled and you want | |
718 to go ahead and delete or refile the messages, use this command. | |
719 Many MH-E commands that may affect the numbering of the | |
720 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder]) | |
721 will ask if you want to process refiles or deletes first and then | |
722 either run this command for you or undo the pending refiles and | |
723 deletes, which are lost. | |
724 | |
725 This function runs `mh-before-commands-processed-hook' before the | |
726 commands are processed and `mh-after-commands-processed-hook' | |
727 after the commands are processed." | |
728 (interactive) | |
729 (if mh-folder-view-stack (mh-widen t)) | |
730 (mh-process-commands mh-current-folder) | |
731 (mh-set-scan-mode) | |
732 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency | |
733 (mh-make-folder-mode-line) | |
734 t) ; return t for write-file-functions | |
735 | |
736 ;;;###mh-autoload | |
737 (defun mh-first-msg () | |
738 "Display first message." | |
739 (interactive) | |
740 (goto-char (point-min)) | |
741 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp))) | |
742 (forward-line 1))) | |
743 | |
744 ;;;###mh-autoload | |
745 (defun mh-goto-msg (number &optional no-error-if-no-message dont-show) | |
746 "Go to a message\\<mh-folder-mode-map>. | |
747 | |
748 You can enter the message NUMBER either before or after typing | |
749 \\[mh-goto-msg]. In the latter case, Emacs prompts you. | |
750 | |
751 In a program, optional non-nil second argument NO-ERROR-IF-NO-MESSAGE | |
752 means return nil instead of signaling an error if message does not | |
753 exist\; in this case, the cursor is positioned near where the message | |
754 would have been. Non-nil third argument DONT-SHOW means not to show | |
755 the message." | |
756 (interactive "NGo to message: ") | |
757 (setq number (prefix-numeric-value number)) | |
758 (let ((point (point)) | |
759 (return-value t)) | |
760 (goto-char (point-min)) | |
761 (unless (re-search-forward (format (mh-scan-msg-search-regexp) number) | |
762 nil t) | |
763 (goto-char point) | |
764 (unless no-error-if-no-message | |
765 (error "No message %d" number)) | |
766 (setq return-value nil)) | |
767 (beginning-of-line) | |
768 (or dont-show (not return-value) (mh-maybe-show number)) | |
769 return-value)) | |
770 | |
771 ;;;###mh-autoload | |
772 (defun mh-inc-folder (&optional file folder) | |
773 "Incorporate new mail into a folder. | |
774 | |
775 You can incorporate mail from any file into the current folder by | |
776 specifying a prefix argument; you'll be prompted for the name of | |
777 the FILE to use as well as the destination FOLDER | |
778 | |
779 The hook `mh-inc-folder-hook' is run after incorporating new | |
780 mail. | |
781 | |
782 Do not call this function from outside MH-E; use \\[mh-rmail] | |
783 instead." | |
784 (interactive (list (if current-prefix-arg | |
785 (expand-file-name | |
786 (read-file-name "inc mail from file: " | |
787 mh-user-path))) | |
788 (if current-prefix-arg | |
789 (mh-prompt-for-folder "inc mail into" mh-inbox t)))) | |
790 (if (not folder) | |
791 (setq folder mh-inbox)) | |
792 (let ((threading-needed-flag nil)) | |
793 (let ((config (current-window-configuration))) | |
794 (when (and mh-show-buffer (get-buffer mh-show-buffer)) | |
795 (delete-windows-on mh-show-buffer)) | |
796 (cond ((not (get-buffer folder)) | |
797 (mh-make-folder folder) | |
798 (setq threading-needed-flag mh-show-threads-flag) | |
799 (setq mh-previous-window-config config)) | |
800 ((not (eq (current-buffer) (get-buffer folder))) | |
801 (switch-to-buffer folder) | |
802 (setq mh-previous-window-config config)))) | |
803 (mh-get-new-mail file) | |
804 (when (and threading-needed-flag | |
805 (save-excursion | |
806 (goto-char (point-min)) | |
807 (or (null mh-large-folder) | |
808 (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
809 (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
810 nil)))) | |
811 (mh-toggle-threads)) | |
812 (beginning-of-line) | |
813 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show)) | |
814 (run-hooks 'mh-inc-folder-hook))) | |
815 | |
816 ;;;###mh-autoload | |
817 (defun mh-last-msg () | |
818 "Display last message." | |
819 (interactive) | |
820 (goto-char (point-max)) | |
821 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp))) | |
822 (forward-line -1)) | |
823 (mh-recenter nil)) | |
824 | |
825 ;;;###mh-autoload | |
826 (defun mh-modify (&optional message) | |
827 "Edit message. | |
828 | |
829 There are times when you need to edit a message. For example, you | |
830 may need to fix a broken Content-Type header field. You can do | |
831 this with this command. It displays the raw message in an | |
832 editable buffer. When you are done editing, save and kill the | |
833 buffer as you would any other. | |
834 | |
835 From a program, edit MESSAGE; nil means edit current message." | |
836 (interactive) | |
837 (let* ((message (or message (mh-get-msg-num t))) | |
838 (msg-filename (mh-msg-filename message)) | |
839 edit-buffer) | |
840 (when (not (file-exists-p msg-filename)) | |
841 (error "Message %d does not exist" message)) | |
842 | |
843 ;; Invalidate the show buffer if it is showing the same message that is | |
844 ;; to be edited. | |
845 (when (and (buffer-live-p (get-buffer mh-show-buffer)) | |
846 (equal (save-excursion (set-buffer mh-show-buffer) | |
847 buffer-file-name) | |
848 msg-filename)) | |
849 (mh-invalidate-show-buffer)) | |
850 | |
851 ;; Edit message | |
852 (find-file msg-filename) | |
853 (setq edit-buffer (current-buffer)) | |
854 | |
855 ;; Set buffer properties | |
856 (mh-letter-mode) | |
857 (use-local-map text-mode-map) | |
858 | |
859 ;; Just show the edit buffer... | |
860 (delete-other-windows) | |
861 (switch-to-buffer edit-buffer))) | |
862 | |
863 ;;;###mh-autoload | |
864 (defun mh-next-button (&optional backward-flag) | |
865 "Go to the next button. | |
866 | |
867 If the end of the buffer is reached then the search wraps over to | |
868 the start of the buffer. | |
869 | |
870 If an optional prefix argument BACKWARD-FLAG is given, the cursor | |
871 will move to the previous button." | |
872 (interactive (list current-prefix-arg)) | |
873 (unless mh-showing-mode | |
874 (mh-show)) | |
875 (mh-in-show-buffer (mh-show-buffer) | |
876 (mh-goto-next-button backward-flag))) | |
877 | |
878 ;;;###mh-autoload | |
879 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag) | |
880 "Display next message. | |
881 | |
882 This command can be given a prefix argument COUNT to specify how | |
883 many unread messages to skip. | |
884 | |
885 In a program, pause for a second after printing message if we are | |
886 at the last undeleted message and optional argument | |
887 WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
888 (interactive "p") | |
889 (setq mh-next-direction 'forward) | |
890 (forward-line 1) | |
891 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count) | |
892 (beginning-of-line) | |
893 (mh-maybe-show)) | |
894 (t (forward-line -1) | |
895 (message "No more undeleted messages") | |
896 (if wait-after-complaining-flag (sit-for 1))))) | |
897 | |
898 ;;;###mh-autoload | |
899 (defun mh-next-unread-msg (&optional count) | |
900 "Display next unread message. | |
901 | |
902 This command can be given a prefix argument COUNT to specify how | |
903 many unread messages to skip." | |
904 (interactive "p") | |
905 (unless (> count 0) | |
906 (error "The function `mh-next-unread-msg' expects positive argument")) | |
907 (setq count (1- count)) | |
908 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list)))) | |
909 (cur-msg (mh-get-msg-num nil))) | |
910 (cond ((and (not cur-msg) (not (bobp)) | |
911 ;; If we are at the end of the buffer back up one line and go | |
912 ;; to unread message after that. | |
913 (progn | |
914 (forward-line -1) | |
915 (setq cur-msg (mh-get-msg-num nil))) | |
916 nil)) | |
917 ((or (null unread-sequence) (not cur-msg)) | |
918 ;; No unread message or there aren't any messages in buffer... | |
919 (message "No more unread messages")) | |
920 ((progn | |
921 ;; Skip messages | |
922 (while (and unread-sequence (>= cur-msg (car unread-sequence))) | |
923 (setq unread-sequence (cdr unread-sequence))) | |
924 (while (> count 0) | |
925 (setq unread-sequence (cdr unread-sequence)) | |
926 (setq count (1- count))) | |
927 (not (car unread-sequence))) | |
928 (message "No more unread messages")) | |
929 (t (loop for msg in unread-sequence | |
930 when (mh-goto-msg msg t) return nil | |
931 finally (message "No more unread messages")))))) | |
932 | |
933 ;;;###mh-autoload | |
934 (defun mh-page-msg (&optional lines) | |
935 "Display next page in message. | |
936 | |
937 You can give this command a prefix argument that specifies the | |
938 number of LINES to scroll. This command will also show the next | |
939 undeleted message if it is used at the bottom of a message." | |
940 (interactive "P") | |
941 (if mh-showing-mode | |
942 (if mh-page-to-next-msg-flag | |
943 (if (equal mh-next-direction 'backward) | |
944 (mh-previous-undeleted-msg) | |
945 (mh-next-undeleted-msg)) | |
946 (if (mh-in-show-buffer (mh-show-buffer) | |
947 (pos-visible-in-window-p (point-max))) | |
948 (progn | |
949 (message | |
950 "End of message (Type %s to read %s undeleted message)" | |
951 (single-key-description last-input-event) | |
952 (if (equal mh-next-direction 'backward) | |
953 "previous" | |
954 "next")) | |
955 (setq mh-page-to-next-msg-flag t)) | |
956 (scroll-other-window lines))) | |
957 (mh-show))) | |
958 | |
959 ;;;###mh-autoload | |
960 (defun mh-prev-button () | |
961 "Go to the previous button. | |
962 | |
963 If the beginning of the buffer is reached then the search wraps | |
964 over to the end of the buffer." | |
965 (interactive) | |
966 (mh-next-button t)) | |
967 | |
968 ;;;###mh-autoload | |
969 (defun mh-previous-page (&optional lines) | |
970 "Display next page in message. | |
971 | |
972 You can give this command a prefix argument that specifies the | |
973 number of LINES to scroll." | |
974 (interactive "P") | |
975 (mh-in-show-buffer (mh-show-buffer) | |
976 (scroll-down lines))) | |
977 | |
978 ;;;###mh-autoload | |
979 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag) | |
980 "Display previous message. | |
981 | |
982 This command can be given a prefix argument COUNT to specify how | |
983 many unread messages to skip. | |
984 | |
985 In a program, pause for a second after printing message if we are | |
986 at the last undeleted message and optional argument | |
987 WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
988 (interactive "p") | |
989 (setq mh-next-direction 'backward) | |
990 (beginning-of-line) | |
991 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count) | |
992 (mh-maybe-show)) | |
993 (t (message "No previous undeleted message") | |
994 (if wait-after-complaining-flag (sit-for 1))))) | |
995 | |
996 ;;;###mh-autoload | |
997 (defun mh-previous-unread-msg (&optional count) | |
998 "Display previous unread message. | |
999 | |
1000 This command can be given a prefix argument COUNT to specify how | |
1001 many unread messages to skip." | |
1002 (interactive "p") | |
1003 (unless (> count 0) | |
1004 (error "The function `mh-previous-unread-msg' expects positive argument")) | |
1005 (setq count (1- count)) | |
1006 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list))) | |
1007 (cur-msg (mh-get-msg-num nil))) | |
1008 (cond ((and (not cur-msg) (not (bobp)) | |
1009 ;; If we are at the end of the buffer back up one line and go | |
1010 ;; to unread message after that. | |
1011 (progn | |
1012 (forward-line -1) | |
1013 (setq cur-msg (mh-get-msg-num nil))) | |
1014 nil)) | |
1015 ((or (null unread-sequence) (not cur-msg)) | |
1016 ;; No unread message or there aren't any messages in buffer... | |
1017 (message "No more unread messages")) | |
1018 ((progn | |
1019 ;; Skip count messages... | |
1020 (while (and unread-sequence (>= (car unread-sequence) cur-msg)) | |
1021 (setq unread-sequence (cdr unread-sequence))) | |
1022 (while (> count 0) | |
1023 (setq unread-sequence (cdr unread-sequence)) | |
1024 (setq count (1- count))) | |
1025 (not (car unread-sequence))) | |
1026 (message "No more unread messages")) | |
1027 (t (loop for msg in unread-sequence | |
1028 when (mh-goto-msg msg t) return nil | |
1029 finally (message "No more unread messages")))))) | |
1030 | |
1031 ;;;###mh-autoload | |
1032 (defun mh-quit () | |
1033 "Quit the current MH-E folder. | |
1034 | |
1035 When you want to quit using MH-E and go back to editing, you can use | |
1036 this command. This buries the buffers of the current MH-E folder and | |
1037 restores the buffers that were present when you first ran | |
1038 \\[mh-rmail]. It also removes any MH-E working buffers whose name | |
1039 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E | |
1040 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail] | |
1041 again. | |
1042 | |
1043 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by | |
1044 this function. The former one is called before the quit occurs, so you | |
1045 might use it to perform any MH-E operations; you could perform some | |
1046 query and abort the quit or call `mh-execute-commands', for example. | |
1047 The latter is not run in an MH-E context, so you might use it to | |
1048 modify the window setup." | |
1049 (interactive) | |
1050 (run-hooks 'mh-before-quit-hook) | |
1051 (let ((show-buffer (get-buffer mh-show-buffer))) | |
1052 (when show-buffer | |
1053 (kill-buffer show-buffer))) | |
1054 (mh-update-sequences) | |
1055 (mh-destroy-postponed-handles) | |
1056 (bury-buffer (current-buffer)) | |
1057 | |
1058 ;; Delete all MH-E temporary and working buffers. | |
1059 (dolist (buffer (buffer-list)) | |
1060 (when (or (string-match "^ \\*mh-" (buffer-name buffer)) | |
1061 (string-match "^\\*MH-E " (buffer-name buffer))) | |
1062 (kill-buffer buffer))) | |
1063 | |
1064 (if mh-previous-window-config | |
1065 (set-window-configuration mh-previous-window-config)) | |
1066 (run-hooks 'mh-quit-hook)) | |
1067 | |
1068 ;;;###mh-autoload | |
1069 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag) | |
1070 "Refile (output) RANGE into FOLDER. | |
1071 | |
1072 You are prompted for the folder name. Note that this command can also | |
1073 be used to create folders. If you specify a folder that does not | |
1074 exist, you will be prompted to create it. | |
1075 | |
1076 The hook `mh-refile-msg-hook' is called after a message is marked to | |
1077 be refiled. | |
1078 | |
1079 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1080 read in interactive use. | |
1081 | |
1082 In a program, the variables `mh-last-destination' and | |
1083 `mh-last-destination-folder' are not updated if | |
1084 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil." | |
1085 (interactive (list (mh-interactive-range "Refile") | |
1086 (intern (mh-prompt-for-refile-folder)))) | |
1087 (unless dont-update-last-destination-flag | |
1088 (setq mh-last-destination (cons 'refile folder) | |
1089 mh-last-destination-folder mh-last-destination)) | |
1090 (mh-iterate-on-range () range | |
1091 (mh-refile-a-msg nil folder)) | |
1092 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg))) | |
1093 | |
1094 ;;;###mh-autoload | |
1095 (defun mh-refile-or-write-again (range &optional interactive-flag) | |
1096 "Repeat last output command. | |
1097 | |
1098 If you are refiling several messages into the same folder, you | |
1099 can use this command to repeat the last | |
1100 refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]). | |
1101 You can use a range. | |
1102 | |
1103 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1104 read in interactive use. | |
1105 | |
1106 In a program, a non-nil INTERACTIVE-FLAG means that the function was | |
1107 called interactively." | |
1108 (interactive (list (mh-interactive-range "Redo") t)) | |
1109 (if (null mh-last-destination) | |
1110 (error "No previous refile or write")) | |
1111 (cond ((eq (car mh-last-destination) 'refile) | |
1112 (mh-refile-msg range (cdr mh-last-destination)) | |
1113 (message "Destination folder: %s" (cdr mh-last-destination))) | |
1114 (t | |
1115 (mh-iterate-on-range msg range | |
1116 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination))) | |
1117 (mh-next-msg interactive-flag)))) | |
1118 | |
1119 ;;;###mh-autoload | |
1120 (defun mh-rescan-folder (&optional range dont-exec-pending) | |
1121 "Rescan folder\\<mh-folder-mode-map>. | |
1122 | |
1123 This command is useful to grab all messages in your \"+inbox\" after | |
1124 processing your new mail for the first time. If you don't want to | |
1125 rescan the entire folder, this command will accept a RANGE. Check the | |
1126 documentation of `mh-interactive-range' to see how RANGE is read in | |
1127 interactive use. | |
1128 | |
1129 This command will ask if you want to process refiles or deletes first | |
1130 and then either run \\[mh-execute-commands] for you or undo the | |
1131 pending refiles and deletes, which are lost. | |
1132 | |
1133 In a program, the processing of outstanding commands is not performed | |
1134 if DONT-EXEC-PENDING is non-nil." | |
1135 (interactive (list (if current-prefix-arg | |
1136 (mh-read-range "Rescan" mh-current-folder t nil t | |
1137 mh-interpret-number-as-range-flag) | |
1138 nil))) | |
1139 (setq mh-next-direction 'forward) | |
1140 (let ((threaded-flag (memq 'unthread mh-view-ops)) | |
1141 (msg-num (mh-get-msg-num nil))) | |
1142 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending) | |
1143 ;; If there isn't a cur sequence, mh-scan-folder goes to the first message. | |
1144 ;; Try to stay where we were. | |
1145 (if (null (car (mh-seq-to-msgs 'cur))) | |
1146 (mh-goto-msg msg-num t t)) | |
1147 (cond (threaded-flag (mh-toggle-threads)) | |
1148 (mh-index-data (mh-index-insert-folder-headers))))) | |
1149 | |
1150 (defun mh-show-mouse (event) | |
1151 "Move point to mouse EVENT and show message." | |
1152 (interactive "e") | |
1153 (mouse-set-point event) | |
1154 (mh-show)) | |
1155 | |
1156 ;;;###mh-autoload | |
1157 (defun mh-toggle-showing () | |
1158 "Toggle between MH-Folder and MH-Folder Show modes. | |
1159 | |
1160 This command switches between MH-Folder mode and MH-Folder Show | |
1161 mode. MH-Folder mode turns off the associated show buffer so that | |
1162 you can perform operations on the messages quickly without | |
1163 reading them. This is an excellent way to prune out your junk | |
1164 mail or to refile a group of messages to another folder for later | |
1165 examination." | |
1166 (interactive) | |
1167 (if mh-showing-mode | |
1168 (mh-set-scan-mode) | |
1169 (mh-show))) | |
1170 | |
1171 ;;;###mh-autoload | |
1172 (defun mh-undo (range) | |
1173 "Undo pending deletes or refiles in RANGE. | |
1174 | |
1175 If you've deleted a message or refiled it, but changed your mind, | |
1176 you can cancel the action before you've executed it. Use this | |
1177 command to undo a refile on or deletion of a single message. You | |
1178 can also undo refiles and deletes for messages that are found in | |
1179 a given RANGE. | |
1180 | |
1181 Check the documentation of `mh-interactive-range' to see how | |
1182 RANGE is read in interactive use." | |
1183 (interactive (list (mh-interactive-range "Undo"))) | |
1184 (cond ((numberp range) | |
1185 (let ((original-position (point))) | |
1186 (beginning-of-line) | |
1187 (while (not (or (looking-at mh-scan-deleted-msg-regexp) | |
1188 (looking-at mh-scan-refiled-msg-regexp) | |
1189 (and (eq mh-next-direction 'forward) (bobp)) | |
1190 (and (eq mh-next-direction 'backward) | |
1191 (save-excursion (forward-line) (eobp))))) | |
1192 (forward-line (if (eq mh-next-direction 'forward) -1 1))) | |
1193 (if (or (looking-at mh-scan-deleted-msg-regexp) | |
1194 (looking-at mh-scan-refiled-msg-regexp)) | |
1195 (progn | |
1196 (mh-undo-msg (mh-get-msg-num t)) | |
1197 (mh-maybe-show)) | |
1198 (goto-char original-position) | |
1199 (error "Nothing to undo")))) | |
1200 (t (mh-iterate-on-range () range | |
1201 (mh-undo-msg nil)))) | |
1202 (if (not (mh-outstanding-commands-p)) | |
1203 (mh-set-folder-modified-p nil))) | |
1204 | |
1205 ;;;###mh-autoload | |
1206 (defun mh-visit-folder (folder &optional range index-data) | |
1207 "Visit FOLDER. | |
1208 | |
1209 When you want to read the messages that you have refiled into folders, | |
1210 use this command to visit the folder. You are prompted for the folder | |
1211 name. | |
1212 | |
1213 The folder buffer will show just unseen messages if there are any; | |
1214 otherwise, it will show all the messages in the buffer as long there | |
1215 are fewer than `mh-large-folder' messages. If there are more, then you | |
1216 are prompted for a range of messages to scan. | |
1217 | |
1218 You can provide a prefix argument in order to specify a RANGE of | |
1219 messages to show when you visit the folder. In this case, regions are | |
1220 not used to specify the range and `mh-large-folder' is ignored. Check | |
1221 the documentation of `mh-interactive-range' to see how RANGE is read | |
1222 in interactive use. | |
1223 | |
1224 Note that this command can also be used to create folders. If you | |
1225 specify a folder that does not exist, you will be prompted to create | |
1226 it. | |
1227 | |
1228 Do not call this function from outside MH-E; use \\[mh-rmail] instead. | |
1229 | |
1230 If, in a program, RANGE is nil (the default), then all messages in | |
1231 FOLDER are displayed. If an index buffer is being created then | |
1232 INDEX-DATA is used to initialize the index buffer specific data | |
1233 structures." | |
1234 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t))) | |
1235 (list folder-name | |
1236 (mh-read-range "Scan" folder-name t nil | |
1237 current-prefix-arg | |
1238 mh-interpret-number-as-range-flag)))) | |
1239 (let ((config (current-window-configuration)) | |
1240 (current-buffer (current-buffer)) | |
1241 (threaded-view-flag mh-show-threads-flag)) | |
1242 (delete-other-windows) | |
1243 (save-excursion | |
1244 (when (get-buffer folder) | |
1245 (set-buffer folder) | |
1246 (setq threaded-view-flag (memq 'unthread mh-view-ops)))) | |
1247 (when index-data | |
1248 (mh-make-folder folder) | |
1249 (setq mh-index-data (car index-data) | |
1250 mh-index-msg-checksum-map (make-hash-table :test #'equal) | |
1251 mh-index-checksum-origin-map (make-hash-table :test #'equal)) | |
1252 (mh-index-update-maps folder (cadr index-data)) | |
1253 (mh-index-create-sequences)) | |
1254 (mh-scan-folder folder (or range "all")) | |
1255 (cond ((and threaded-view-flag | |
1256 (save-excursion | |
1257 (goto-char (point-min)) | |
1258 (or (null mh-large-folder) | |
1259 (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
1260 (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
1261 nil)))) | |
1262 (mh-toggle-threads)) | |
1263 (mh-index-data | |
1264 (mh-index-insert-folder-headers))) | |
1265 (unless (eq current-buffer (current-buffer)) | |
1266 (setq mh-previous-window-config config))) | |
1267 nil) | |
1268 | |
1269 ;;;###mh-autoload | |
1270 (defun mh-write-msg-to-file (message file no-header) | |
1271 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>. | |
1272 | |
1273 You are prompted for the filename. If the file already exists, | |
1274 the message is appended to it. You can also write the message to | |
1275 the file without the header by specifying a prefix argument | |
1276 NO-HEADER. Subsequent writes to the same file can be made with | |
1277 the command \\[mh-refile-or-write-again]." | |
1278 (interactive | |
1279 (list (mh-get-msg-num t) | |
1280 (let ((default-dir (if (eq 'write (car mh-last-destination-write)) | |
1281 (file-name-directory | |
1282 (car (cdr mh-last-destination-write))) | |
1283 default-directory))) | |
1284 (read-file-name (format "Save message%s in file: " | |
1285 (if current-prefix-arg " body" "")) | |
1286 default-dir | |
1287 (if (eq 'write (car mh-last-destination-write)) | |
1288 (car (cdr mh-last-destination-write)) | |
1289 (expand-file-name "mail.out" default-dir)))) | |
1290 current-prefix-arg)) | |
1291 (let ((msg-file-to-output (mh-msg-filename message)) | |
1292 (output-file (mh-expand-file-name file))) | |
1293 (setq mh-last-destination (list 'write file (if no-header 'no-header)) | |
1294 mh-last-destination-write mh-last-destination) | |
1295 (save-excursion | |
1296 (set-buffer (get-buffer-create mh-temp-buffer)) | |
1297 (erase-buffer) | |
1298 (insert-file-contents msg-file-to-output) | |
1299 (goto-char (point-min)) | |
1300 (if no-header (search-forward "\n\n")) | |
1301 (append-to-file (point) (point-max) output-file)))) | |
1302 | |
1303 ;;;###mh-autoload | |
1304 (defun mh-update-sequences () | |
1305 "Flush MH-E's state out to MH. | |
1306 | |
1307 This function updates the sequence specified by your | |
1308 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence | |
1309 listed by the `mh-tick-seq' option which is \"tick\" by default. | |
1310 The message at the cursor is used for \"cur\"." | |
1311 (interactive) | |
1312 ;; mh-update-sequences is the opposite of mh-read-folder-sequences, | |
1313 ;; which updates MH-E's state from MH. | |
1314 (let ((folder-set (mh-update-unseen)) | |
1315 (new-cur (mh-get-msg-num nil))) | |
1316 (if new-cur | |
1317 (let ((seq-entry (mh-find-seq 'cur))) | |
1318 (mh-remove-cur-notation) | |
1319 (setcdr seq-entry | |
1320 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq | |
1321 (mh-define-sequence 'cur (list new-cur)) | |
1322 (beginning-of-line) | |
1323 (if (looking-at mh-scan-good-msg-regexp) | |
1324 (mh-notate-cur))) | |
1325 (or folder-set | |
1326 (save-excursion | |
1327 ;; psg - mh-current-folder is nil if mh-summary-height < 4 ! | |
1328 ;; So I added this sanity check. | |
1329 (if (stringp mh-current-folder) | |
1330 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast") | |
1331 (mh-exec-cmd-quiet t "folder" "-fast"))))))) | |
1332 | |
1333 | |
1334 | |
1335 ;;; Support Routines | |
1336 | |
1337 (defun mh-get-new-mail (maildrop-name) | |
1338 "Read new mail from MAILDROP-NAME into the current buffer. | |
1339 Return in the current buffer." | |
1340 (let ((point-before-inc (point)) | |
1341 (folder mh-current-folder) | |
1342 (new-mail-flag nil)) | |
1343 (with-mh-folder-updating (t) | |
1344 (if maildrop-name | |
1345 (message "inc %s -file %s..." folder maildrop-name) | |
1346 (message "inc %s..." folder)) | |
1347 (setq mh-next-direction 'forward) | |
1348 (goto-char (point-max)) | |
1349 (mh-remove-cur-notation) | |
1350 (let ((start-of-inc (point))) | |
1351 (if maildrop-name | |
1352 ;; I think MH 5 used "-ms-file" instead of "-file", | |
1353 ;; which would make inc'ing from maildrops fail. | |
1354 (mh-exec-cmd-output mh-inc-prog nil folder | |
1355 (mh-scan-format) | |
1356 "-file" (expand-file-name maildrop-name) | |
1357 "-width" (window-width) | |
1358 "-truncate") | |
1359 (mh-exec-cmd-output mh-inc-prog nil | |
1360 (mh-scan-format) | |
1361 "-width" (window-width))) | |
1362 (if maildrop-name | |
1363 (message "inc %s -file %s...done" folder maildrop-name) | |
1364 (message "inc %s...done" folder)) | |
1365 (goto-char start-of-inc) | |
1366 (cond ((save-excursion | |
1367 (re-search-forward "^inc: no mail" nil t)) | |
1368 (message "No new mail%s%s" (if maildrop-name " in " "") | |
1369 (if maildrop-name maildrop-name ""))) | |
1370 ((and (when mh-folder-view-stack | |
1371 (let ((saved-text (buffer-substring-no-properties | |
1372 start-of-inc (point-max)))) | |
1373 (delete-region start-of-inc (point-max)) | |
1374 (unwind-protect (mh-widen t) | |
1375 (mh-remove-cur-notation) | |
1376 (goto-char (point-max)) | |
1377 (setq start-of-inc (point)) | |
1378 (insert saved-text) | |
1379 (goto-char start-of-inc)))) | |
1380 nil)) | |
1381 ((re-search-forward "^inc:" nil t) ; Error messages | |
1382 (error "Error incorporating mail")) | |
1383 ((and | |
1384 (equal mh-scan-format-file t) | |
1385 mh-adaptive-cmd-note-flag | |
1386 ;; Have we reached an edge condition? | |
1387 (save-excursion | |
1388 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1)) | |
1389 (setq start-of-inc (mh-generate-new-cmd-note folder)) | |
1390 nil)) | |
1391 (t | |
1392 (setq new-mail-flag t))) | |
1393 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines | |
1394 (let* ((sequences (mh-read-folder-sequences folder t)) | |
1395 (new-cur (assoc 'cur sequences)) | |
1396 (new-unseen (assoc mh-unseen-seq sequences))) | |
1397 (unless (assoc 'cur mh-seq-list) | |
1398 (push (list 'cur) mh-seq-list)) | |
1399 (unless (assoc mh-unseen-seq mh-seq-list) | |
1400 (push (list mh-unseen-seq) mh-seq-list)) | |
1401 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur)) | |
1402 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen))) | |
1403 (when (equal (point-max) start-of-inc) | |
1404 (mh-notate-cur)) | |
1405 (if new-mail-flag | |
1406 (progn | |
1407 (mh-make-folder-mode-line) | |
1408 (when (mh-speed-flists-active-p) | |
1409 (mh-speed-flists t mh-current-folder)) | |
1410 (when (memq 'unthread mh-view-ops) | |
1411 (mh-thread-inc folder start-of-inc)) | |
1412 (mh-goto-cur-msg)) | |
1413 (goto-char point-before-inc)) | |
1414 (mh-notate-user-sequences (cons start-of-inc (point-max))))))) | |
1415 | |
1416 (defun mh-generate-new-cmd-note (folder) | |
1417 "Fix the `mh-cmd-note' value for this FOLDER. | |
1418 | |
1419 After doing an `mh-get-new-mail' operation in this FOLDER, at least | |
1420 one line that looks like a truncated message number was found. | |
1421 | |
1422 Remove the text added by the last `mh-inc' command. It should be the | |
1423 messages cur-last. Call `mh-set-cmd-note', adjusting the notation | |
1424 column with the width of the largest message number in FOLDER. | |
1425 | |
1426 Reformat the message number width on each line in the buffer and trim | |
1427 the line length to fit in the window. | |
1428 | |
1429 Rescan the FOLDER in the range cur-last in order to display the | |
1430 messages that were removed earlier. They should all fit in the scan | |
1431 line now with no message truncation." | |
1432 (save-excursion | |
1433 (let ((maxcol (1- (window-width))) | |
1434 (old-cmd-note mh-cmd-note) | |
1435 mh-cmd-note-fmt | |
1436 msgnum) | |
1437 ;; Nuke all of the lines just added by the last inc | |
1438 (delete-char (- (point-max) (point))) | |
1439 ;; Update the current buffer to reflect the new mh-cmd-note | |
1440 ;; value needed to display messages. | |
1441 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder))) | |
1442 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d")) | |
1443 ;; Cleanup the messages that are in the buffer right now | |
1444 (goto-char (point-min)) | |
1445 (cond ((memq 'unthread mh-view-ops) | |
1446 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note))) | |
1447 (t (while (re-search-forward (mh-scan-msg-number-regexp) nil 0 1) | |
1448 ;; reformat the number to fix in mh-cmd-note columns | |
1449 (setq msgnum (string-to-number | |
1450 (buffer-substring | |
1451 (match-beginning 1) (match-end 1)))) | |
1452 (replace-match (format mh-cmd-note-fmt msgnum)) | |
1453 ;; trim the line to fix in the window | |
1454 (end-of-line) | |
1455 (let ((eol (point))) | |
1456 (move-to-column maxcol) | |
1457 (if (<= (point) eol) | |
1458 (delete-char (- eol (point)))))))) | |
1459 ;; now re-read the lost messages | |
1460 (goto-char (point-max)) | |
1461 (prog1 (point) | |
1462 (mh-regenerate-headers "cur-last" t))))) | |
1463 | |
1464 ;;;###mh-autoload | |
1465 (defun mh-goto-cur-msg (&optional minimal-changes-flag) | |
1466 "Position the cursor at the current message. | |
1467 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the | |
1468 function doesn't recenter the folder buffer." | |
1469 (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) | |
1470 (cond ((and cur-msg | |
1471 (mh-goto-msg cur-msg t t)) | |
1472 (unless minimal-changes-flag | |
1473 (mh-notate-cur) | |
1474 (mh-recenter 0) | |
1475 (mh-maybe-show cur-msg))) | |
1476 (t | |
1477 (setq overlay-arrow-position nil) | |
1478 (message "No current message"))))) | |
1479 | |
1480 ;;;###mh-autoload | |
1481 (defun mh-recenter (arg) | |
1482 "Like recenter but with three improvements: | |
1483 | |
1484 - At the end of the buffer it tries to show fewer empty lines. | |
1485 | |
1486 - operates only if the current buffer is in the selected window. | |
1487 (Commands like `save-some-buffers' can make this false.) | |
1488 | |
1489 - nil ARG means recenter as if prefix argument had been given." | |
1490 (cond ((not (eq (get-buffer-window (current-buffer)) (selected-window))) | |
1491 nil) | |
1492 ((= (point-max) (save-excursion | |
1493 (forward-line (- (/ (window-height) 2) 2)) | |
1494 (point))) | |
1495 (let ((lines-from-end 2)) | |
1496 (save-excursion | |
1497 (while (> (point-max) (progn (forward-line) (point))) | |
1498 (incf lines-from-end))) | |
1499 (recenter (- lines-from-end)))) | |
1500 ;; '(4) is the same as C-u prefix argument. | |
1501 (t (recenter (or arg '(4)))))) | |
1502 | |
1503 (defun mh-update-unseen () | |
1504 "Synchronize the unseen sequence with MH. | |
1505 Return non-nil iff the MH folder was set. | |
1506 The hook `mh-unseen-updated-hook' is called after the unseen sequence | |
1507 is updated." | |
1508 (if mh-seen-list | |
1509 (let* ((unseen-seq (mh-find-seq mh-unseen-seq)) | |
1510 (unseen-msgs (mh-seq-msgs unseen-seq))) | |
1511 (if unseen-msgs | |
1512 (progn | |
1513 (mh-undefine-sequence mh-unseen-seq mh-seen-list) | |
1514 (run-hooks 'mh-unseen-updated-hook) | |
1515 (while mh-seen-list | |
1516 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs)) | |
1517 (setq mh-seen-list (cdr mh-seen-list))) | |
1518 (setcdr unseen-seq unseen-msgs) | |
1519 t) ;since we set the folder | |
1520 (setq mh-seen-list nil))))) | |
1521 | |
1522 ;;;###mh-autoload | |
1523 (defun mh-outstanding-commands-p () | |
1524 "Return non-nil if there are outstanding deletes or refiles." | |
1525 (save-excursion | |
1526 (when (eq major-mode 'mh-show-mode) | |
1527 (set-buffer mh-show-folder-buffer)) | |
1528 (or mh-delete-list mh-refile-list))) | |
1529 | |
1530 ;;;###mh-autoload | |
1531 (defun mh-set-folder-modified-p (flag) | |
1532 "Mark current folder as modified or unmodified according to FLAG." | |
1533 (set-buffer-modified-p flag)) | |
1534 | |
1535 (defun mh-process-commands (folder) | |
1536 "Process outstanding commands for FOLDER. | |
1537 | |
1538 This function runs `mh-before-commands-processed-hook' before the | |
1539 commands are processed and `mh-after-commands-processed-hook' | |
1540 after the commands are processed." | |
1541 (message "Processing deletes and refiles for %s..." folder) | |
1542 (set-buffer folder) | |
1543 (with-mh-folder-updating (nil) | |
1544 ;; Run the before hook -- the refile and delete lists are still valid | |
1545 (run-hooks 'mh-before-commands-processed-hook) | |
1546 | |
1547 ;; Update the unseen sequence if it exists | |
1548 (mh-update-unseen) | |
1549 | |
1550 (let ((redraw-needed-flag mh-index-data) | |
1551 (folders-changed (list mh-current-folder)) | |
1552 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1553 (mh-create-sequence-map mh-seq-list))) | |
1554 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1555 (make-hash-table)))) | |
1556 ;; Remove invalid scan lines if we are in an index folder and then remove | |
1557 ;; the real messages | |
1558 (when mh-index-data | |
1559 (mh-index-delete-folder-headers) | |
1560 (setq folders-changed | |
1561 (append folders-changed (mh-index-execute-commands)))) | |
1562 | |
1563 ;; Then refile messages | |
1564 (mh-mapc #'(lambda (folder-msg-list) | |
1565 (let* ((dest-folder (symbol-name (car folder-msg-list))) | |
1566 (last (car (mh-translate-range dest-folder "last"))) | |
1567 (msgs (cdr folder-msg-list))) | |
1568 (push dest-folder folders-changed) | |
1569 (setq redraw-needed-flag t) | |
1570 (apply #'mh-exec-cmd | |
1571 "refile" "-src" folder dest-folder | |
1572 (mh-coalesce-msg-list msgs)) | |
1573 (mh-delete-scan-msgs msgs) | |
1574 ;; Preserve sequences in destination folder... | |
1575 (when mh-refile-preserves-sequences-flag | |
1576 (clrhash dest-map) | |
1577 (loop for i from (1+ (or last 0)) | |
1578 for msg in (sort (copy-sequence msgs) #'<) | |
1579 do (loop for seq-name in (gethash msg seq-map) | |
1580 do (push i (gethash seq-name dest-map)))) | |
1581 (maphash | |
1582 #'(lambda (seq msgs) | |
1583 ;; Can't be run in the background, since the | |
1584 ;; current folder is changed by mark this could | |
1585 ;; lead to a race condition with the next refile. | |
1586 (apply #'mh-exec-cmd "mark" | |
1587 "-sequence" (symbol-name seq) dest-folder | |
1588 "-add" (mapcar #'(lambda (x) (format "%s" x)) | |
1589 (mh-coalesce-msg-list msgs)))) | |
1590 dest-map)))) | |
1591 mh-refile-list) | |
1592 (setq mh-refile-list ()) | |
1593 | |
1594 ;; Now delete messages | |
1595 (cond (mh-delete-list | |
1596 (setq redraw-needed-flag t) | |
1597 (apply 'mh-exec-cmd "rmm" folder | |
1598 (mh-coalesce-msg-list mh-delete-list)) | |
1599 (mh-delete-scan-msgs mh-delete-list) | |
1600 (setq mh-delete-list nil))) | |
1601 | |
1602 ;; Don't need to remove sequences since delete and refile do so. | |
1603 ;; Mark cur message | |
1604 (if (> (buffer-size) 0) | |
1605 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last")))) | |
1606 | |
1607 ;; Redraw folder buffer if needed | |
1608 (when (and redraw-needed-flag) | |
1609 (when (mh-speed-flists-active-p) | |
1610 (apply #'mh-speed-flists t folders-changed)) | |
1611 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max))) | |
1612 (mh-index-data (mh-index-insert-folder-headers)))) | |
1613 | |
1614 (and (buffer-file-name (get-buffer mh-show-buffer)) | |
1615 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer)))) | |
1616 ;; If "inc" were to put a new msg in this file, | |
1617 ;; we would not notice, so mark it invalid now. | |
1618 (mh-invalidate-show-buffer)) | |
1619 | |
1620 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil)) | |
1621 (mh-remove-all-notation) | |
1622 (mh-notate-user-sequences) | |
1623 | |
1624 ;; Run the after hook -- now folders-changed is valid, | |
1625 ;; but not the lists of specific messages. | |
1626 (let ((mh-folders-changed folders-changed)) | |
1627 (run-hooks 'mh-after-commands-processed-hook))) | |
1628 | |
1629 (message "Processing deletes and refiles for %s...done" folder))) | |
1630 | |
1631 (defun mh-delete-scan-msgs (msgs) | |
1632 "Delete the scan listing lines for MSGS." | |
1633 (save-excursion | |
1634 (while msgs | |
1635 (when (mh-goto-msg (car msgs) t t) | |
1636 (when (memq 'unthread mh-view-ops) | |
1637 (mh-thread-forget-message (car msgs))) | |
1638 (mh-delete-line 1)) | |
1639 (setq msgs (cdr msgs))))) | |
1640 | |
1641 (defun mh-set-scan-mode () | |
1642 "Display the scan listing buffer, but do not show a message." | |
1643 (if (get-buffer mh-show-buffer) | |
1644 (delete-windows-on mh-show-buffer)) | |
1645 (mh-showing-mode 0) | |
1646 (force-mode-line-update) | |
1647 (if mh-recenter-summary-flag | |
1648 (mh-recenter nil))) | |
1649 | |
1650 ;;;###mh-autoload | |
1651 (defun mh-make-folder-mode-line (&optional ignored) | |
1652 "Set the fields of the mode line for a folder buffer. | |
1653 The optional argument is now obsolete and IGNORED. It used to be | |
1654 used to pass in what is now stored in the buffer-local variable | |
1655 `mh-mode-line-annotation'." | |
1656 (save-excursion | |
1657 (save-window-excursion | |
1658 (mh-first-msg) | |
1659 (let ((new-first-msg-num (mh-get-msg-num nil))) | |
1660 (when (or (not (memq 'unthread mh-view-ops)) | |
1661 (null mh-first-msg-num) | |
1662 (null new-first-msg-num) | |
1663 (< new-first-msg-num mh-first-msg-num)) | |
1664 (setq mh-first-msg-num new-first-msg-num))) | |
1665 (mh-last-msg) | |
1666 (let ((new-last-msg-num (mh-get-msg-num nil))) | |
1667 (when (or (not (memq 'unthread mh-view-ops)) | |
1668 (null mh-last-msg-num) | |
1669 (null new-last-msg-num) | |
1670 (> new-last-msg-num mh-last-msg-num)) | |
1671 (setq mh-last-msg-num new-last-msg-num))) | |
1672 (setq mh-msg-count (if mh-first-msg-num | |
1673 (count-lines (point-min) (point-max)) | |
1674 0)) | |
1675 (setq mode-line-buffer-identification | |
1676 (list (format " {%%b%s} %s msg%s" | |
1677 (if mh-mode-line-annotation | |
1678 (format "/%s" mh-mode-line-annotation) | |
1679 "") | |
1680 (if (zerop mh-msg-count) | |
1681 "no" | |
1682 (format "%d" mh-msg-count)) | |
1683 (if (zerop mh-msg-count) | |
1684 "s" | |
1685 (cond ((> mh-msg-count 1) | |
1686 (format "s (%d-%d)" mh-first-msg-num | |
1687 mh-last-msg-num)) | |
1688 (mh-first-msg-num | |
1689 (format " (%d)" mh-first-msg-num)) | |
1690 ("")))))) | |
1691 (mh-logo-display)))) | |
1692 | |
1693 ;;;###mh-autoload | |
1694 (defun mh-scan-folder (folder range &optional dont-exec-pending) | |
1695 "Scan FOLDER over RANGE. | |
1696 | |
1697 After the scan is performed, switch to the buffer associated with | |
1698 FOLDER. | |
1699 | |
1700 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1701 read in interactive use. | |
1702 | |
1703 The processing of outstanding commands is not performed if | |
1704 DONT-EXEC-PENDING is non-nil." | |
1705 (when (stringp range) | |
1706 (setq range (delete "" (split-string range "[ \t\n]")))) | |
1707 (cond ((null (get-buffer folder)) | |
1708 (mh-make-folder folder)) | |
1709 (t | |
1710 (unless dont-exec-pending | |
1711 (mh-process-or-undo-commands folder) | |
1712 (mh-reset-threads-and-narrowing)) | |
1713 (switch-to-buffer folder))) | |
1714 (mh-regenerate-headers range) | |
1715 (if (zerop (buffer-size)) | |
1716 (if (equal range "all") | |
1717 (message "Folder %s is empty" folder) | |
1718 (message "No messages in %s, range %s" folder range)) | |
1719 (mh-goto-cur-msg)) | |
1720 (when (mh-outstanding-commands-p) | |
1721 (mh-notate-deleted-and-refiled))) | |
1722 | |
1723 ;;;###mh-autoload | |
1724 (defun mh-process-or-undo-commands (folder) | |
1725 "If FOLDER has outstanding commands, then either process or discard them. | |
1726 Called by functions like `mh-sort-folder', so also invalidate | |
1727 show buffer." | |
1728 (set-buffer folder) | |
1729 (if (mh-outstanding-commands-p) | |
1730 (if (or mh-do-not-confirm-flag | |
1731 (y-or-n-p | |
1732 "Process outstanding deletes and refiles? ")) | |
1733 (mh-process-commands folder) | |
1734 (set-buffer folder) | |
1735 (mh-undo-folder))) | |
1736 (mh-update-unseen) | |
1737 (mh-invalidate-show-buffer)) | |
1738 | |
1739 ;;;###mh-autoload | |
1740 (defun mh-regenerate-headers (range &optional update) | |
1741 "Scan folder over RANGE. | |
1742 If UPDATE, append the scan lines, otherwise replace." | |
1743 (let ((folder mh-current-folder) | |
1744 (range (if (and range (atom range)) (list range) range)) | |
1745 scan-start) | |
1746 (message "Scanning %s..." folder) | |
1747 (mh-remove-all-notation) | |
1748 (with-mh-folder-updating (nil) | |
1749 (if update | |
1750 (goto-char (point-max)) | |
1751 (delete-region (point-min) (point-max)) | |
1752 (if mh-adaptive-cmd-note-flag | |
1753 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width | |
1754 folder))))) | |
1755 (setq scan-start (point)) | |
1756 (apply #'mh-exec-cmd-output | |
1757 mh-scan-prog nil | |
1758 (mh-scan-format) | |
1759 "-noclear" "-noheader" | |
1760 "-width" (window-width) | |
1761 folder range) | |
1762 (goto-char scan-start) | |
1763 (cond ((looking-at "scan: no messages in") | |
1764 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines | |
1765 ((looking-at (if (mh-variant-p 'mu-mh) | |
1766 "scan: message set .* does not exist" | |
1767 "scan: bad message list ")) | |
1768 (keep-lines mh-scan-valid-regexp)) | |
1769 ((looking-at "scan: ")) ; Keep error messages | |
1770 (t | |
1771 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines | |
1772 (setq mh-seq-list (mh-read-folder-sequences folder nil)) | |
1773 (mh-notate-user-sequences) | |
1774 (or update | |
1775 (setq mh-mode-line-annotation | |
1776 (if (equal range '("all")) | |
1777 nil | |
1778 mh-partial-folder-mode-line-annotation))) | |
1779 (mh-make-folder-mode-line)) | |
1780 (message "Scanning %s...done" folder))) | |
1781 | |
1782 ;;;###mh-autoload | |
1783 (defun mh-reset-threads-and-narrowing () | |
1784 "Reset all variables pertaining to threads and narrowing. | |
1785 Also removes all content from the folder buffer." | |
1786 (setq mh-view-ops ()) | |
1787 (setq mh-folder-view-stack ()) | |
1788 (setq mh-thread-scan-line-map-stack ()) | |
1789 (let ((buffer-read-only nil)) (erase-buffer))) | |
1790 | |
1791 (defun mh-make-folder (name) | |
1792 "Create a new mail folder called NAME. | |
1793 Make it the current folder." | |
1794 (switch-to-buffer name) | |
1795 (setq buffer-read-only nil) | |
1796 (erase-buffer) | |
1797 (if mh-adaptive-cmd-note-flag | |
1798 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name)))) | |
1799 (setq buffer-read-only t) | |
1800 (mh-folder-mode) | |
1801 (mh-set-folder-modified-p nil) | |
1802 (setq buffer-file-name mh-folder-filename) | |
1803 (when (and (not mh-index-data) | |
1804 (file-exists-p (concat buffer-file-name mh-index-data-file))) | |
1805 (mh-index-read-data)) | |
1806 (mh-make-folder-mode-line)) | |
1807 | |
1808 ;;;###mh-autoload | |
1809 (defun mh-next-msg (&optional wait-after-complaining-flag) | |
1810 "Move backward or forward to the next undeleted message in the buffer. | |
1811 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and | |
1812 we are at the last message, then wait for a second after telling | |
1813 the user that there aren't any more unread messages." | |
1814 (if (eq mh-next-direction 'forward) | |
1815 (mh-next-undeleted-msg 1 wait-after-complaining-flag) | |
1816 (mh-previous-undeleted-msg 1 wait-after-complaining-flag))) | |
1817 | |
1818 ;;;###mh-autoload | |
1819 (defun mh-prompt-for-refile-folder () | |
1820 "Prompt the user for a folder in which the message should be filed. | |
1821 The folder is returned as a string. | |
1822 | |
1823 The default folder name is generated by the option | |
1824 `mh-default-folder-for-message-function' if it is non-nil or | |
1825 `mh-folder-from-address'." | |
1826 (mh-prompt-for-folder | |
1827 "Destination" | |
1828 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t))))) | |
1829 (if (null refile-file) "" | |
1830 (save-excursion | |
1831 (set-buffer (get-buffer-create mh-temp-buffer)) | |
1832 (erase-buffer) | |
1833 (insert-file-contents refile-file) | |
1834 (or (and mh-default-folder-for-message-function | |
1835 (let ((buffer-file-name refile-file)) | |
1836 (funcall mh-default-folder-for-message-function))) | |
1837 (mh-folder-from-address) | |
1838 (and (eq 'refile (car mh-last-destination-folder)) | |
1839 (symbol-name (cdr mh-last-destination-folder))) | |
1840 "")))) | |
1841 t)) | |
1842 | |
1843 ;;;###mh-autoload | |
1844 (defun mh-folder-from-address () | |
1845 "Derive folder name from sender. | |
1846 | |
1847 The name of the folder is derived as follows: | |
1848 | |
1849 a) The folder name associated with the first address found in | |
1850 the list `mh-default-folder-list' is used. Each element in | |
1851 this list contains a \"Check Recipient\" item. If this item is | |
1852 turned on, then the address is checked against the recipient | |
1853 instead of the sender. This is useful for mailing lists. | |
1854 | |
1855 b) An alias prefixed by `mh-default-folder-prefix' | |
1856 corresponding to the address is used. The prefix is used to | |
1857 prevent clutter in your mail directory. | |
1858 | |
1859 Return nil if a folder name was not derived, or if the variable | |
1860 `mh-default-folder-must-exist-flag' is t and the folder does not | |
1861 exist." | |
1862 ;; Loop for all entries in mh-default-folder-list | |
1863 (save-restriction | |
1864 (goto-char (point-min)) | |
1865 (re-search-forward "\n\n" nil 'limit) | |
1866 (narrow-to-region (point-min) (point)) | |
1867 (let ((to/cc (concat (or (message-fetch-field "to") "") ", " | |
1868 (or (message-fetch-field "cc") ""))) | |
1869 (from (or (message-fetch-field "from") "")) | |
1870 folder-name) | |
1871 (setq folder-name | |
1872 (loop for list in mh-default-folder-list | |
1873 when (string-match (nth 0 list) (if (nth 2 list) to/cc from)) | |
1874 return (nth 1 list) | |
1875 finally return nil)) | |
1876 | |
1877 ;; Make sure a result from `mh-default-folder-list' begins with "+" | |
1878 ;; since 'mh-expand-file-name below depends on it | |
1879 (when (and folder-name (not (eq (aref folder-name 0) ?+))) | |
1880 (setq folder-name (concat "+" folder-name))) | |
1881 | |
1882 ;; If not, is there an alias for the address? | |
1883 (when (not folder-name) | |
1884 (let* ((from-header (mh-extract-from-header-value)) | |
1885 (address (and from-header | |
1886 (nth 1 (mail-extract-address-components | |
1887 from-header)))) | |
1888 (alias (and address (mh-alias-address-to-alias address)))) | |
1889 (when alias | |
1890 (setq folder-name | |
1891 (and alias (concat "+" mh-default-folder-prefix alias)))))) | |
1892 | |
1893 ;; If mh-default-folder-must-exist-flag set, check that folder exists. | |
1894 (if (and folder-name | |
1895 (or (not mh-default-folder-must-exist-flag) | |
1896 (file-exists-p (mh-expand-file-name folder-name)))) | |
1897 folder-name)))) | |
1898 | |
1899 ;;;###mh-autoload | |
1900 (defun mh-delete-a-msg (message) | |
1901 "Delete MESSAGE. | |
1902 If MESSAGE is nil then the message at point is deleted. | |
1903 The hook `mh-delete-msg-hook' is called after you mark a message | |
1904 for deletion. For example, a past maintainer of MH-E used this | |
1905 once when he kept statistics on his mail usage." | |
1906 (save-excursion | |
1907 (if (numberp message) | |
1908 (mh-goto-msg message nil t) | |
1909 (beginning-of-line) | |
1910 (setq message (mh-get-msg-num t))) | |
1911 (if (looking-at mh-scan-refiled-msg-regexp) | |
1912 (error "Message %d is refiled; undo refile before deleting" message)) | |
1913 (if (looking-at mh-scan-deleted-msg-regexp) | |
1914 nil | |
1915 (mh-set-folder-modified-p t) | |
1916 (setq mh-delete-list (cons message mh-delete-list)) | |
1917 (mh-notate nil mh-note-deleted mh-cmd-note) | |
1918 (run-hooks 'mh-delete-msg-hook)))) | |
1919 | |
1920 ;;;###mh-autoload | |
1921 (defun mh-refile-a-msg (message folder) | |
1922 "Refile MESSAGE in FOLDER. | |
1923 If MESSAGE is nil then the message at point is refiled. | |
1924 Folder is a symbol, not a string. | |
1925 The hook `mh-refile-msg-hook' is called after a message is marked to | |
1926 be refiled." | |
1927 (save-excursion | |
1928 (if (numberp message) | |
1929 (mh-goto-msg message nil t) | |
1930 (beginning-of-line) | |
1931 (setq message (mh-get-msg-num t))) | |
1932 (cond ((looking-at mh-scan-deleted-msg-regexp) | |
1933 (error "Message %d is deleted; undo delete before moving" message)) | |
1934 ((looking-at mh-scan-refiled-msg-regexp) | |
1935 (if (y-or-n-p | |
1936 (format "Message %d already refiled; copy to %s as well? " | |
1937 message folder)) | |
1938 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link" | |
1939 "-src" mh-current-folder | |
1940 (symbol-name folder)) | |
1941 (message "Message not copied"))) | |
1942 (t | |
1943 (mh-set-folder-modified-p t) | |
1944 (cond ((null (assoc folder mh-refile-list)) | |
1945 (push (list folder message) mh-refile-list)) | |
1946 ((not (member message (cdr (assoc folder mh-refile-list)))) | |
1947 (push message (cdr (assoc folder mh-refile-list))))) | |
1948 (mh-notate nil mh-note-refiled mh-cmd-note) | |
1949 (run-hooks 'mh-refile-msg-hook))))) | |
1950 | |
1951 (defun mh-undo-msg (msg) | |
1952 "Undo the deletion or refile of one MSG. | |
1953 If MSG is nil then act on the message at point" | |
1954 (save-excursion | |
1955 (if (numberp msg) | |
1956 (mh-goto-msg msg t t) | |
1957 (beginning-of-line) | |
1958 (setq msg (mh-get-msg-num t))) | |
1959 (cond ((memq msg mh-delete-list) | |
1960 (setq mh-delete-list (delq msg mh-delete-list))) | |
1961 (t | |
1962 (dolist (folder-msg-list mh-refile-list) | |
1963 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list)))) | |
1964 (setq mh-refile-list (loop for x in mh-refile-list | |
1965 unless (null (cdr x)) collect x)))) | |
1966 (mh-notate nil ? mh-cmd-note))) | |
1967 | |
1968 ;;;###mh-autoload | |
1969 (defun mh-msg-filename (msg &optional folder) | |
1970 "Return the file name of MSG in FOLDER (default current folder)." | |
1971 (expand-file-name (int-to-string msg) | |
1972 (if folder | |
1973 (mh-expand-file-name folder) | |
1974 mh-folder-filename))) | |
1975 | |
1976 (provide 'mh-folder) | |
1977 | |
1978 ;; Local Variables: | |
1979 ;; indent-tabs-mode: nil | |
1980 ;; sentence-end-double-space: nil | |
1981 ;; End: | |
1982 | |
68470 | 1983 ;; arch-tag: aa97b758-d4f6-4c86-bc5a-1950921da1e7 |
68465 | 1984 ;;; mh-folder.el ends here |