Mercurial > emacs
annotate lisp/mh-e/mh-folder.el @ 75248:465067360b90
Change copyright year to 2007.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 16 Jan 2007 02:26:33 +0000 |
parents | 00cb3fe5fed5 |
children | e3694f1cb928 |
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. | |
70028
d81780942bb8
* mh-acros.el (struct, x, y): No need to wrap defvar with
Bill Wohler <wohler@newt.com>
parents:
69712
diff
changeset
|
525 (defvar desktop-save-buffer) |
d81780942bb8
* mh-acros.el (struct, x, y): No need to wrap defvar with
Bill Wohler <wohler@newt.com>
parents:
69712
diff
changeset
|
526 (defvar font-lock-auto-fontify) |
d81780942bb8
* mh-acros.el (struct, x, y): No need to wrap defvar with
Bill Wohler <wohler@newt.com>
parents:
69712
diff
changeset
|
527 (defvar font-lock-defaults) ; XEmacs |
68465 | 528 |
529 ;; Ensure new buffers won't get this mode if default-major-mode is nil. | |
530 (put 'mh-folder-mode 'mode-class 'special) | |
531 | |
532 ;; Autoload cookie needed by desktop.el | |
533 ;;;###autoload | |
534 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder" | |
535 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map> | |
536 | |
537 You can show the message the cursor is pointing to, and step through | |
538 the messages. Messages can be marked for deletion or refiling into | |
539 another folder; these commands are executed all at once with a | |
540 separate command. | |
541 | |
542 Options that control this mode can be changed with | |
543 \\[customize-group]; specify the \"mh\" group. In particular, please | |
544 see the `mh-scan-format-file' option if you wish to modify scan's | |
545 format. | |
546 | |
547 When a folder is visited, the hook `mh-folder-mode-hook' is run. | |
548 | |
549 Ranges | |
550 ====== | |
551 Many commands that operate on individual messages, such as | |
552 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument | |
553 can be used in several ways. | |
554 | |
555 If you provide the prefix argument (\\[universal-argument]) to | |
556 these commands, then you will be prompted for the message range. | |
557 This can be any valid MH range which can include messages, | |
558 sequences, and the abbreviations (described in the mh(1) man | |
559 page): | |
560 | |
561 <num1>-<num2> | |
562 Indicates all messages in the range <num1> to <num2>, inclusive. | |
563 The range must be nonempty. | |
564 | |
565 <num>:N | |
566 <num>:+N | |
567 <num>:-N | |
568 Up to N messages beginning with (or ending with) message num. Num | |
569 may be any of the predefined symbols: first, prev, cur, next or | |
570 last. | |
571 | |
572 first:N | |
573 prev:N | |
574 next:N | |
575 last:N | |
576 The first, previous, next or last messages, if they exist. | |
577 | |
578 all | |
579 All of the messages. | |
580 | |
581 For example, a range that shows all of these things is `1 2 3 | |
582 5-10 last:5 unseen'. | |
583 | |
584 If the option `transient-mark-mode' is set to t and you set a | |
585 region in the MH-Folder buffer, then the MH-E command will | |
586 perform the operation on all messages in that region. | |
587 | |
588 \\{mh-folder-mode-map}" | |
589 (mh-do-in-gnu-emacs | |
70145
00cb3fe5fed5
* mh-tool-bar.el (image-load-path): Define to shush compiler.
Bill Wohler <wohler@newt.com>
parents:
70028
diff
changeset
|
590 (unless mh-folder-tool-bar-map |
00cb3fe5fed5
* mh-tool-bar.el (image-load-path): Define to shush compiler.
Bill Wohler <wohler@newt.com>
parents:
70028
diff
changeset
|
591 (mh-tool-bar-folder-buttons-init)) |
69245
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
592 (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
|
593 (mh-do-in-xemacs |
f3bbf5f32462
* mh-folder.el (mh-tool-bar-init): Autoload.
Bill Wohler <wohler@newt.com>
parents:
68529
diff
changeset
|
594 (mh-tool-bar-init :folder)) |
68465 | 595 (make-local-variable 'font-lock-defaults) |
596 (setq font-lock-defaults '(mh-folder-font-lock-keywords t)) | |
597 (make-local-variable 'desktop-save-buffer) | |
598 (setq desktop-save-buffer t) | |
599 (mh-make-local-vars | |
600 'mh-colors-available-flag (mh-colors-available-p) | |
601 ; Do we have colors available | |
602 'mh-current-folder (buffer-name) ; Name of folder, a string | |
603 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs | |
604 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/" | |
605 (file-name-as-directory (mh-expand-file-name (buffer-name))) | |
606 'mh-display-buttons-for-inline-parts-flag | |
607 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to | |
608 ; be toggled. | |
609 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed | |
610 'overlay-arrow-position nil ; Allow for simultaneous display in | |
611 'overlay-arrow-string ">" ; different MH-E buffers. | |
612 'mh-showing-mode nil ; Show message also? | |
613 'mh-delete-list nil ; List of msgs nums to delete | |
614 'mh-refile-list nil ; List of folder names in mh-seq-list | |
615 'mh-seq-list nil ; Alist of (seq . msgs) nums | |
616 'mh-seen-list nil ; List of displayed messages | |
617 'mh-next-direction 'forward ; Direction to move to next message | |
618 'mh-view-ops () ; Stack that keeps track of the order | |
619 ; in which narrowing/threading has been | |
620 ; carried out. | |
621 'mh-folder-view-stack () ; Stack of previous views of the | |
622 ; folder. | |
623 'mh-index-data nil ; If the folder was created by a call | |
624 ; to mh-search, this contains info | |
625 ; about the search results. | |
626 'mh-index-previous-search nil ; folder, indexer, search-regexp | |
627 'mh-index-msg-checksum-map nil ; msg -> checksum map | |
628 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg ) | |
629 'mh-index-sequence-search-flag nil ; folder resulted from sequence search | |
630 'mh-first-msg-num nil ; Number of first msg in buffer | |
631 'mh-last-msg-num nil ; Number of last msg in buffer | |
632 'mh-msg-count nil ; Number of msgs in buffer | |
633 'mh-mode-line-annotation nil ; Indicates message range | |
634 'mh-sequence-notation-history (make-hash-table) | |
635 ; Remember what is overwritten by | |
636 ; mh-note-seq. | |
637 'imenu-create-index-function 'mh-index-create-imenu-index | |
638 ; Setup imenu support | |
639 'mh-previous-window-config nil) ; Previous window configuration | |
640 (mh-remove-xemacs-horizontal-scrollbar) | |
641 (setq truncate-lines t) | |
642 (auto-save-mode -1) | |
643 (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
|
644 (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
|
645 (add-hook (mh-write-file-functions) 'mh-execute-commands nil t) |
68465 | 646 (make-local-variable 'revert-buffer-function) |
647 (make-local-variable 'hl-line-mode) ; avoid pollution | |
648 (mh-funcall-if-exists hl-line-mode 1) | |
649 (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
|
650 (add-to-list 'minor-mode-alist '(mh-showing-mode " Show")) |
68465 | 651 (easy-menu-add mh-folder-sequence-menu) |
652 (easy-menu-add mh-folder-message-menu) | |
653 (easy-menu-add mh-folder-folder-menu) | |
654 (mh-inc-spool-make) | |
655 (mh-set-help mh-folder-mode-help-messages) | |
656 (if (and mh-xemacs-flag | |
657 font-lock-auto-fontify) | |
658 (turn-on-font-lock))) ; Force font-lock in XEmacs. | |
659 | |
660 | |
661 | |
662 ;;; MH-Folder Commands | |
663 | |
664 ;; Alphabetical. | |
665 ;; See also mh-comp.el, mh-junk.el, mh-mime.el, mh-print.el, | |
666 ;; mh-search.el, and mh-seq.el. | |
667 | |
668 ;;;###mh-autoload | |
669 (defun mh-delete-msg (range) | |
670 "Delete RANGE\\<mh-folder-mode-map>. | |
671 | |
672 To mark a message for deletion, use this command. A \"D\" is | |
673 placed by the message in the scan window, and the next undeleted | |
674 message is displayed. If the previous command had been | |
675 \\[mh-previous-undeleted-msg], then the next message displayed is | |
676 the first undeleted message previous to the message just deleted. | |
677 Use \\[mh-next-undeleted-msg] to force subsequent | |
678 \\[mh-delete-msg] commands to move forward to the next undeleted | |
679 message after deleting the message under the cursor. | |
680 | |
681 The hook `mh-delete-msg-hook' is called after you mark a message | |
682 for deletion. For example, a past maintainer of MH-E used this | |
683 once when he kept statistics on his mail usage. | |
684 | |
685 Check the documentation of `mh-interactive-range' to see how | |
686 RANGE is read in interactive use." | |
687 (interactive (list (mh-interactive-range "Delete"))) | |
688 (mh-delete-msg-no-motion range) | |
689 (if (looking-at mh-scan-deleted-msg-regexp) | |
690 (mh-next-msg))) | |
691 | |
692 ;;;###mh-autoload | |
693 (defun mh-delete-msg-no-motion (range) | |
694 "Delete RANGE, don't move to next message. | |
695 | |
696 This command marks the RANGE for deletion but leaves the cursor | |
697 at the current message in case you wish to perform other | |
698 operations on the message. | |
699 | |
700 Check the documentation of `mh-interactive-range' to see how | |
701 RANGE is read in interactive use." | |
702 (interactive (list (mh-interactive-range "Delete"))) | |
703 (mh-iterate-on-range () range | |
704 (mh-delete-a-msg nil))) | |
705 | |
706 ;;;###mh-autoload | |
707 (defun mh-execute-commands () | |
708 "Process outstanding delete and refile requests\\<mh-folder-mode-map>. | |
709 | |
710 If you've marked messages to be deleted or refiled and you want | |
711 to go ahead and delete or refile the messages, use this command. | |
712 Many MH-E commands that may affect the numbering of the | |
713 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder]) | |
714 will ask if you want to process refiles or deletes first and then | |
715 either run this command for you or undo the pending refiles and | |
69712
3981e84d0b79
* mh-folder.el (mh-execute-commands, mh-rescan-folder):
Bill Wohler <wohler@newt.com>
parents:
69492
diff
changeset
|
716 deletes. |
68465 | 717 |
718 This function runs `mh-before-commands-processed-hook' before the | |
719 commands are processed and `mh-after-commands-processed-hook' | |
720 after the commands are processed." | |
721 (interactive) | |
722 (if mh-folder-view-stack (mh-widen t)) | |
723 (mh-process-commands mh-current-folder) | |
724 (mh-set-scan-mode) | |
725 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency | |
726 (mh-make-folder-mode-line) | |
727 t) ; return t for write-file-functions | |
728 | |
729 ;;;###mh-autoload | |
730 (defun mh-first-msg () | |
731 "Display first message." | |
732 (interactive) | |
733 (goto-char (point-min)) | |
734 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp))) | |
735 (forward-line 1))) | |
736 | |
737 ;;;###mh-autoload | |
738 (defun mh-goto-msg (number &optional no-error-if-no-message dont-show) | |
739 "Go to a message\\<mh-folder-mode-map>. | |
740 | |
741 You can enter the message NUMBER either before or after typing | |
742 \\[mh-goto-msg]. In the latter case, Emacs prompts you. | |
743 | |
744 In a program, optional non-nil second argument NO-ERROR-IF-NO-MESSAGE | |
745 means return nil instead of signaling an error if message does not | |
746 exist\; in this case, the cursor is positioned near where the message | |
747 would have been. Non-nil third argument DONT-SHOW means not to show | |
748 the message." | |
749 (interactive "NGo to message: ") | |
750 (setq number (prefix-numeric-value number)) | |
751 (let ((point (point)) | |
752 (return-value t)) | |
753 (goto-char (point-min)) | |
754 (unless (re-search-forward (format (mh-scan-msg-search-regexp) number) | |
755 nil t) | |
756 (goto-char point) | |
757 (unless no-error-if-no-message | |
758 (error "No message %d" number)) | |
759 (setq return-value nil)) | |
760 (beginning-of-line) | |
761 (or dont-show (not return-value) (mh-maybe-show number)) | |
762 return-value)) | |
763 | |
764 ;;;###mh-autoload | |
765 (defun mh-inc-folder (&optional file folder) | |
766 "Incorporate new mail into a folder. | |
767 | |
768 You can incorporate mail from any file into the current folder by | |
769 specifying a prefix argument; you'll be prompted for the name of | |
770 the FILE to use as well as the destination FOLDER | |
771 | |
772 The hook `mh-inc-folder-hook' is run after incorporating new | |
773 mail. | |
774 | |
775 Do not call this function from outside MH-E; use \\[mh-rmail] | |
776 instead." | |
777 (interactive (list (if current-prefix-arg | |
778 (expand-file-name | |
779 (read-file-name "inc mail from file: " | |
780 mh-user-path))) | |
781 (if current-prefix-arg | |
782 (mh-prompt-for-folder "inc mail into" mh-inbox t)))) | |
783 (if (not folder) | |
784 (setq folder mh-inbox)) | |
785 (let ((threading-needed-flag nil)) | |
786 (let ((config (current-window-configuration))) | |
787 (when (and mh-show-buffer (get-buffer mh-show-buffer)) | |
788 (delete-windows-on mh-show-buffer)) | |
789 (cond ((not (get-buffer folder)) | |
790 (mh-make-folder folder) | |
791 (setq threading-needed-flag mh-show-threads-flag) | |
792 (setq mh-previous-window-config config)) | |
793 ((not (eq (current-buffer) (get-buffer folder))) | |
794 (switch-to-buffer folder) | |
795 (setq mh-previous-window-config config)))) | |
796 (mh-get-new-mail file) | |
797 (when (and threading-needed-flag | |
798 (save-excursion | |
799 (goto-char (point-min)) | |
800 (or (null mh-large-folder) | |
801 (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
802 (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
803 nil)))) | |
804 (mh-toggle-threads)) | |
805 (beginning-of-line) | |
806 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show)) | |
807 (run-hooks 'mh-inc-folder-hook))) | |
808 | |
809 ;;;###mh-autoload | |
810 (defun mh-last-msg () | |
811 "Display last message." | |
812 (interactive) | |
813 (goto-char (point-max)) | |
814 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp))) | |
815 (forward-line -1)) | |
816 (mh-recenter nil)) | |
817 | |
818 ;;;###mh-autoload | |
819 (defun mh-modify (&optional message) | |
820 "Edit message. | |
821 | |
822 There are times when you need to edit a message. For example, you | |
823 may need to fix a broken Content-Type header field. You can do | |
824 this with this command. It displays the raw message in an | |
825 editable buffer. When you are done editing, save and kill the | |
826 buffer as you would any other. | |
827 | |
828 From a program, edit MESSAGE; nil means edit current message." | |
829 (interactive) | |
830 (let* ((message (or message (mh-get-msg-num t))) | |
831 (msg-filename (mh-msg-filename message)) | |
832 edit-buffer) | |
833 (when (not (file-exists-p msg-filename)) | |
834 (error "Message %d does not exist" message)) | |
835 | |
836 ;; Invalidate the show buffer if it is showing the same message that is | |
837 ;; to be edited. | |
838 (when (and (buffer-live-p (get-buffer mh-show-buffer)) | |
839 (equal (save-excursion (set-buffer mh-show-buffer) | |
840 buffer-file-name) | |
841 msg-filename)) | |
842 (mh-invalidate-show-buffer)) | |
843 | |
844 ;; Edit message | |
845 (find-file msg-filename) | |
846 (setq edit-buffer (current-buffer)) | |
847 | |
848 ;; Set buffer properties | |
849 (mh-letter-mode) | |
850 (use-local-map text-mode-map) | |
851 | |
852 ;; Just show the edit buffer... | |
853 (delete-other-windows) | |
854 (switch-to-buffer edit-buffer))) | |
855 | |
856 ;;;###mh-autoload | |
857 (defun mh-next-button (&optional backward-flag) | |
858 "Go to the next button. | |
859 | |
860 If the end of the buffer is reached then the search wraps over to | |
861 the start of the buffer. | |
862 | |
863 If an optional prefix argument BACKWARD-FLAG is given, the cursor | |
864 will move to the previous button." | |
865 (interactive (list current-prefix-arg)) | |
866 (unless mh-showing-mode | |
867 (mh-show)) | |
868 (mh-in-show-buffer (mh-show-buffer) | |
869 (mh-goto-next-button backward-flag))) | |
870 | |
871 ;;;###mh-autoload | |
872 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag) | |
873 "Display next message. | |
874 | |
875 This command can be given a prefix argument COUNT to specify how | |
876 many unread messages to skip. | |
877 | |
878 In a program, pause for a second after printing message if we are | |
879 at the last undeleted message and optional argument | |
880 WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
881 (interactive "p") | |
882 (setq mh-next-direction 'forward) | |
883 (forward-line 1) | |
884 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count) | |
885 (beginning-of-line) | |
886 (mh-maybe-show)) | |
887 (t (forward-line -1) | |
888 (message "No more undeleted messages") | |
889 (if wait-after-complaining-flag (sit-for 1))))) | |
890 | |
891 ;;;###mh-autoload | |
892 (defun mh-next-unread-msg (&optional count) | |
893 "Display next unread message. | |
894 | |
895 This command can be given a prefix argument COUNT to specify how | |
896 many unread messages to skip." | |
897 (interactive "p") | |
898 (unless (> count 0) | |
899 (error "The function `mh-next-unread-msg' expects positive argument")) | |
900 (setq count (1- count)) | |
901 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list)))) | |
902 (cur-msg (mh-get-msg-num nil))) | |
903 (cond ((and (not cur-msg) (not (bobp)) | |
904 ;; If we are at the end of the buffer back up one line and go | |
905 ;; to unread message after that. | |
906 (progn | |
907 (forward-line -1) | |
908 (setq cur-msg (mh-get-msg-num nil))) | |
909 nil)) | |
910 ((or (null unread-sequence) (not cur-msg)) | |
911 ;; No unread message or there aren't any messages in buffer... | |
912 (message "No more unread messages")) | |
913 ((progn | |
914 ;; Skip messages | |
915 (while (and unread-sequence (>= cur-msg (car unread-sequence))) | |
916 (setq unread-sequence (cdr unread-sequence))) | |
917 (while (> count 0) | |
918 (setq unread-sequence (cdr unread-sequence)) | |
919 (setq count (1- count))) | |
920 (not (car unread-sequence))) | |
921 (message "No more unread messages")) | |
922 (t (loop for msg in unread-sequence | |
923 when (mh-goto-msg msg t) return nil | |
924 finally (message "No more unread messages")))))) | |
925 | |
926 ;;;###mh-autoload | |
927 (defun mh-page-msg (&optional lines) | |
928 "Display next page in message. | |
929 | |
930 You can give this command a prefix argument that specifies the | |
931 number of LINES to scroll. This command will also show the next | |
932 undeleted message if it is used at the bottom of a message." | |
933 (interactive "P") | |
934 (if mh-showing-mode | |
935 (if mh-page-to-next-msg-flag | |
936 (if (equal mh-next-direction 'backward) | |
937 (mh-previous-undeleted-msg) | |
938 (mh-next-undeleted-msg)) | |
939 (if (mh-in-show-buffer (mh-show-buffer) | |
940 (pos-visible-in-window-p (point-max))) | |
941 (progn | |
942 (message | |
943 "End of message (Type %s to read %s undeleted message)" | |
944 (single-key-description last-input-event) | |
945 (if (equal mh-next-direction 'backward) | |
946 "previous" | |
947 "next")) | |
948 (setq mh-page-to-next-msg-flag t)) | |
949 (scroll-other-window lines))) | |
950 (mh-show))) | |
951 | |
952 ;;;###mh-autoload | |
953 (defun mh-prev-button () | |
954 "Go to the previous button. | |
955 | |
956 If the beginning of the buffer is reached then the search wraps | |
957 over to the end of the buffer." | |
958 (interactive) | |
959 (mh-next-button t)) | |
960 | |
961 ;;;###mh-autoload | |
962 (defun mh-previous-page (&optional lines) | |
963 "Display next page in message. | |
964 | |
965 You can give this command a prefix argument that specifies the | |
966 number of LINES to scroll." | |
967 (interactive "P") | |
968 (mh-in-show-buffer (mh-show-buffer) | |
969 (scroll-down lines))) | |
970 | |
971 ;;;###mh-autoload | |
972 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag) | |
973 "Display previous message. | |
974 | |
975 This command can be given a prefix argument COUNT to specify how | |
976 many unread messages to skip. | |
977 | |
978 In a program, pause for a second after printing message if we are | |
979 at the last undeleted message and optional argument | |
980 WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
981 (interactive "p") | |
982 (setq mh-next-direction 'backward) | |
983 (beginning-of-line) | |
984 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count) | |
985 (mh-maybe-show)) | |
986 (t (message "No previous undeleted message") | |
987 (if wait-after-complaining-flag (sit-for 1))))) | |
988 | |
989 ;;;###mh-autoload | |
990 (defun mh-previous-unread-msg (&optional count) | |
991 "Display previous unread message. | |
992 | |
993 This command can be given a prefix argument COUNT to specify how | |
994 many unread messages to skip." | |
995 (interactive "p") | |
996 (unless (> count 0) | |
997 (error "The function `mh-previous-unread-msg' expects positive argument")) | |
998 (setq count (1- count)) | |
999 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list))) | |
1000 (cur-msg (mh-get-msg-num nil))) | |
1001 (cond ((and (not cur-msg) (not (bobp)) | |
1002 ;; If we are at the end of the buffer back up one line and go | |
1003 ;; to unread message after that. | |
1004 (progn | |
1005 (forward-line -1) | |
1006 (setq cur-msg (mh-get-msg-num nil))) | |
1007 nil)) | |
1008 ((or (null unread-sequence) (not cur-msg)) | |
1009 ;; No unread message or there aren't any messages in buffer... | |
1010 (message "No more unread messages")) | |
1011 ((progn | |
1012 ;; Skip count messages... | |
1013 (while (and unread-sequence (>= (car unread-sequence) cur-msg)) | |
1014 (setq unread-sequence (cdr unread-sequence))) | |
1015 (while (> count 0) | |
1016 (setq unread-sequence (cdr unread-sequence)) | |
1017 (setq count (1- count))) | |
1018 (not (car unread-sequence))) | |
1019 (message "No more unread messages")) | |
1020 (t (loop for msg in unread-sequence | |
1021 when (mh-goto-msg msg t) return nil | |
1022 finally (message "No more unread messages")))))) | |
1023 | |
1024 ;;;###mh-autoload | |
1025 (defun mh-quit () | |
1026 "Quit the current MH-E folder. | |
1027 | |
1028 When you want to quit using MH-E and go back to editing, you can use | |
1029 this command. This buries the buffers of the current MH-E folder and | |
1030 restores the buffers that were present when you first ran | |
1031 \\[mh-rmail]. It also removes any MH-E working buffers whose name | |
1032 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E | |
1033 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail] | |
1034 again. | |
1035 | |
1036 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by | |
1037 this function. The former one is called before the quit occurs, so you | |
1038 might use it to perform any MH-E operations; you could perform some | |
1039 query and abort the quit or call `mh-execute-commands', for example. | |
1040 The latter is not run in an MH-E context, so you might use it to | |
1041 modify the window setup." | |
1042 (interactive) | |
1043 (run-hooks 'mh-before-quit-hook) | |
1044 (let ((show-buffer (get-buffer mh-show-buffer))) | |
1045 (when show-buffer | |
1046 (kill-buffer show-buffer))) | |
1047 (mh-update-sequences) | |
1048 (mh-destroy-postponed-handles) | |
1049 (bury-buffer (current-buffer)) | |
1050 | |
1051 ;; Delete all MH-E temporary and working buffers. | |
1052 (dolist (buffer (buffer-list)) | |
1053 (when (or (string-match "^ \\*mh-" (buffer-name buffer)) | |
1054 (string-match "^\\*MH-E " (buffer-name buffer))) | |
1055 (kill-buffer buffer))) | |
1056 | |
1057 (if mh-previous-window-config | |
1058 (set-window-configuration mh-previous-window-config)) | |
1059 (run-hooks 'mh-quit-hook)) | |
1060 | |
1061 ;;;###mh-autoload | |
1062 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag) | |
1063 "Refile (output) RANGE into FOLDER. | |
1064 | |
1065 You are prompted for the folder name. Note that this command can also | |
1066 be used to create folders. If you specify a folder that does not | |
1067 exist, you will be prompted to create it. | |
1068 | |
1069 The hook `mh-refile-msg-hook' is called after a message is marked to | |
1070 be refiled. | |
1071 | |
1072 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1073 read in interactive use. | |
1074 | |
1075 In a program, the variables `mh-last-destination' and | |
1076 `mh-last-destination-folder' are not updated if | |
1077 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil." | |
1078 (interactive (list (mh-interactive-range "Refile") | |
1079 (intern (mh-prompt-for-refile-folder)))) | |
1080 (unless dont-update-last-destination-flag | |
1081 (setq mh-last-destination (cons 'refile folder) | |
1082 mh-last-destination-folder mh-last-destination)) | |
1083 (mh-iterate-on-range () range | |
1084 (mh-refile-a-msg nil folder)) | |
1085 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg))) | |
1086 | |
1087 ;;;###mh-autoload | |
1088 (defun mh-refile-or-write-again (range &optional interactive-flag) | |
1089 "Repeat last output command. | |
1090 | |
1091 If you are refiling several messages into the same folder, you | |
1092 can use this command to repeat the last | |
1093 refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]). | |
1094 You can use a range. | |
1095 | |
1096 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1097 read in interactive use. | |
1098 | |
1099 In a program, a non-nil INTERACTIVE-FLAG means that the function was | |
1100 called interactively." | |
1101 (interactive (list (mh-interactive-range "Redo") t)) | |
1102 (if (null mh-last-destination) | |
1103 (error "No previous refile or write")) | |
1104 (cond ((eq (car mh-last-destination) 'refile) | |
1105 (mh-refile-msg range (cdr mh-last-destination)) | |
1106 (message "Destination folder: %s" (cdr mh-last-destination))) | |
1107 (t | |
1108 (mh-iterate-on-range msg range | |
1109 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination))) | |
1110 (mh-next-msg interactive-flag)))) | |
1111 | |
1112 ;;;###mh-autoload | |
1113 (defun mh-rescan-folder (&optional range dont-exec-pending) | |
1114 "Rescan folder\\<mh-folder-mode-map>. | |
1115 | |
1116 This command is useful to grab all messages in your \"+inbox\" after | |
1117 processing your new mail for the first time. If you don't want to | |
1118 rescan the entire folder, this command will accept a RANGE. Check the | |
1119 documentation of `mh-interactive-range' to see how RANGE is read in | |
1120 interactive use. | |
1121 | |
1122 This command will ask if you want to process refiles or deletes first | |
1123 and then either run \\[mh-execute-commands] for you or undo the | |
69712
3981e84d0b79
* mh-folder.el (mh-execute-commands, mh-rescan-folder):
Bill Wohler <wohler@newt.com>
parents:
69492
diff
changeset
|
1124 pending refiles and deletes. |
68465 | 1125 |
1126 In a program, the processing of outstanding commands is not performed | |
1127 if DONT-EXEC-PENDING is non-nil." | |
1128 (interactive (list (if current-prefix-arg | |
1129 (mh-read-range "Rescan" mh-current-folder t nil t | |
1130 mh-interpret-number-as-range-flag) | |
1131 nil))) | |
1132 (setq mh-next-direction 'forward) | |
1133 (let ((threaded-flag (memq 'unthread mh-view-ops)) | |
1134 (msg-num (mh-get-msg-num nil))) | |
1135 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending) | |
1136 ;; If there isn't a cur sequence, mh-scan-folder goes to the first message. | |
1137 ;; Try to stay where we were. | |
1138 (if (null (car (mh-seq-to-msgs 'cur))) | |
1139 (mh-goto-msg msg-num t t)) | |
1140 (cond (threaded-flag (mh-toggle-threads)) | |
1141 (mh-index-data (mh-index-insert-folder-headers))))) | |
1142 | |
1143 (defun mh-show-mouse (event) | |
1144 "Move point to mouse EVENT and show message." | |
1145 (interactive "e") | |
1146 (mouse-set-point event) | |
1147 (mh-show)) | |
1148 | |
1149 ;;;###mh-autoload | |
1150 (defun mh-toggle-showing () | |
1151 "Toggle between MH-Folder and MH-Folder Show modes. | |
1152 | |
1153 This command switches between MH-Folder mode and MH-Folder Show | |
1154 mode. MH-Folder mode turns off the associated show buffer so that | |
1155 you can perform operations on the messages quickly without | |
1156 reading them. This is an excellent way to prune out your junk | |
1157 mail or to refile a group of messages to another folder for later | |
1158 examination." | |
1159 (interactive) | |
1160 (if mh-showing-mode | |
1161 (mh-set-scan-mode) | |
1162 (mh-show))) | |
1163 | |
1164 ;;;###mh-autoload | |
1165 (defun mh-undo (range) | |
1166 "Undo pending deletes or refiles in RANGE. | |
1167 | |
1168 If you've deleted a message or refiled it, but changed your mind, | |
1169 you can cancel the action before you've executed it. Use this | |
1170 command to undo a refile on or deletion of a single message. You | |
1171 can also undo refiles and deletes for messages that are found in | |
1172 a given RANGE. | |
1173 | |
1174 Check the documentation of `mh-interactive-range' to see how | |
1175 RANGE is read in interactive use." | |
1176 (interactive (list (mh-interactive-range "Undo"))) | |
1177 (cond ((numberp range) | |
1178 (let ((original-position (point))) | |
1179 (beginning-of-line) | |
1180 (while (not (or (looking-at mh-scan-deleted-msg-regexp) | |
1181 (looking-at mh-scan-refiled-msg-regexp) | |
1182 (and (eq mh-next-direction 'forward) (bobp)) | |
1183 (and (eq mh-next-direction 'backward) | |
1184 (save-excursion (forward-line) (eobp))))) | |
1185 (forward-line (if (eq mh-next-direction 'forward) -1 1))) | |
1186 (if (or (looking-at mh-scan-deleted-msg-regexp) | |
1187 (looking-at mh-scan-refiled-msg-regexp)) | |
1188 (progn | |
1189 (mh-undo-msg (mh-get-msg-num t)) | |
1190 (mh-maybe-show)) | |
1191 (goto-char original-position) | |
1192 (error "Nothing to undo")))) | |
1193 (t (mh-iterate-on-range () range | |
1194 (mh-undo-msg nil)))) | |
1195 (if (not (mh-outstanding-commands-p)) | |
1196 (mh-set-folder-modified-p nil))) | |
1197 | |
1198 ;;;###mh-autoload | |
1199 (defun mh-visit-folder (folder &optional range index-data) | |
1200 "Visit FOLDER. | |
1201 | |
1202 When you want to read the messages that you have refiled into folders, | |
1203 use this command to visit the folder. You are prompted for the folder | |
1204 name. | |
1205 | |
1206 The folder buffer will show just unseen messages if there are any; | |
1207 otherwise, it will show all the messages in the buffer as long there | |
1208 are fewer than `mh-large-folder' messages. If there are more, then you | |
1209 are prompted for a range of messages to scan. | |
1210 | |
1211 You can provide a prefix argument in order to specify a RANGE of | |
1212 messages to show when you visit the folder. In this case, regions are | |
1213 not used to specify the range and `mh-large-folder' is ignored. Check | |
1214 the documentation of `mh-interactive-range' to see how RANGE is read | |
1215 in interactive use. | |
1216 | |
1217 Note that this command can also be used to create folders. If you | |
1218 specify a folder that does not exist, you will be prompted to create | |
1219 it. | |
1220 | |
1221 Do not call this function from outside MH-E; use \\[mh-rmail] instead. | |
1222 | |
1223 If, in a program, RANGE is nil (the default), then all messages in | |
1224 FOLDER are displayed. If an index buffer is being created then | |
1225 INDEX-DATA is used to initialize the index buffer specific data | |
1226 structures." | |
1227 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t))) | |
1228 (list folder-name | |
1229 (mh-read-range "Scan" folder-name t nil | |
1230 current-prefix-arg | |
1231 mh-interpret-number-as-range-flag)))) | |
1232 (let ((config (current-window-configuration)) | |
1233 (current-buffer (current-buffer)) | |
1234 (threaded-view-flag mh-show-threads-flag)) | |
1235 (delete-other-windows) | |
1236 (save-excursion | |
1237 (when (get-buffer folder) | |
1238 (set-buffer folder) | |
1239 (setq threaded-view-flag (memq 'unthread mh-view-ops)))) | |
1240 (when index-data | |
1241 (mh-make-folder folder) | |
1242 (setq mh-index-data (car index-data) | |
1243 mh-index-msg-checksum-map (make-hash-table :test #'equal) | |
1244 mh-index-checksum-origin-map (make-hash-table :test #'equal)) | |
1245 (mh-index-update-maps folder (cadr index-data)) | |
1246 (mh-index-create-sequences)) | |
1247 (mh-scan-folder folder (or range "all")) | |
1248 (cond ((and threaded-view-flag | |
1249 (save-excursion | |
1250 (goto-char (point-min)) | |
1251 (or (null mh-large-folder) | |
1252 (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
1253 (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
1254 nil)))) | |
1255 (mh-toggle-threads)) | |
1256 (mh-index-data | |
1257 (mh-index-insert-folder-headers))) | |
1258 (unless (eq current-buffer (current-buffer)) | |
1259 (setq mh-previous-window-config config))) | |
1260 nil) | |
1261 | |
1262 ;;;###mh-autoload | |
1263 (defun mh-write-msg-to-file (message file no-header) | |
1264 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>. | |
1265 | |
1266 You are prompted for the filename. If the file already exists, | |
1267 the message is appended to it. You can also write the message to | |
1268 the file without the header by specifying a prefix argument | |
1269 NO-HEADER. Subsequent writes to the same file can be made with | |
1270 the command \\[mh-refile-or-write-again]." | |
1271 (interactive | |
1272 (list (mh-get-msg-num t) | |
1273 (let ((default-dir (if (eq 'write (car mh-last-destination-write)) | |
1274 (file-name-directory | |
1275 (car (cdr mh-last-destination-write))) | |
1276 default-directory))) | |
1277 (read-file-name (format "Save message%s in file: " | |
1278 (if current-prefix-arg " body" "")) | |
1279 default-dir | |
1280 (if (eq 'write (car mh-last-destination-write)) | |
1281 (car (cdr mh-last-destination-write)) | |
1282 (expand-file-name "mail.out" default-dir)))) | |
1283 current-prefix-arg)) | |
1284 (let ((msg-file-to-output (mh-msg-filename message)) | |
1285 (output-file (mh-expand-file-name file))) | |
1286 (setq mh-last-destination (list 'write file (if no-header 'no-header)) | |
1287 mh-last-destination-write mh-last-destination) | |
1288 (save-excursion | |
1289 (set-buffer (get-buffer-create mh-temp-buffer)) | |
1290 (erase-buffer) | |
1291 (insert-file-contents msg-file-to-output) | |
1292 (goto-char (point-min)) | |
1293 (if no-header (search-forward "\n\n")) | |
1294 (append-to-file (point) (point-max) output-file)))) | |
1295 | |
1296 ;;;###mh-autoload | |
1297 (defun mh-update-sequences () | |
1298 "Flush MH-E's state out to MH. | |
1299 | |
1300 This function updates the sequence specified by your | |
1301 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence | |
1302 listed by the `mh-tick-seq' option which is \"tick\" by default. | |
1303 The message at the cursor is used for \"cur\"." | |
1304 (interactive) | |
1305 ;; mh-update-sequences is the opposite of mh-read-folder-sequences, | |
1306 ;; which updates MH-E's state from MH. | |
1307 (let ((folder-set (mh-update-unseen)) | |
1308 (new-cur (mh-get-msg-num nil))) | |
1309 (if new-cur | |
1310 (let ((seq-entry (mh-find-seq 'cur))) | |
1311 (mh-remove-cur-notation) | |
1312 (setcdr seq-entry | |
1313 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq | |
1314 (mh-define-sequence 'cur (list new-cur)) | |
1315 (beginning-of-line) | |
1316 (if (looking-at mh-scan-good-msg-regexp) | |
1317 (mh-notate-cur))) | |
1318 (or folder-set | |
1319 (save-excursion | |
1320 ;; psg - mh-current-folder is nil if mh-summary-height < 4 ! | |
1321 ;; So I added this sanity check. | |
1322 (if (stringp mh-current-folder) | |
1323 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast") | |
1324 (mh-exec-cmd-quiet t "folder" "-fast"))))))) | |
1325 | |
1326 | |
1327 | |
1328 ;;; Support Routines | |
1329 | |
1330 (defun mh-get-new-mail (maildrop-name) | |
1331 "Read new mail from MAILDROP-NAME into the current buffer. | |
1332 Return in the current buffer." | |
1333 (let ((point-before-inc (point)) | |
1334 (folder mh-current-folder) | |
1335 (new-mail-flag nil)) | |
1336 (with-mh-folder-updating (t) | |
1337 (if maildrop-name | |
1338 (message "inc %s -file %s..." folder maildrop-name) | |
1339 (message "inc %s..." folder)) | |
1340 (setq mh-next-direction 'forward) | |
1341 (goto-char (point-max)) | |
1342 (mh-remove-cur-notation) | |
1343 (let ((start-of-inc (point))) | |
1344 (if maildrop-name | |
1345 ;; I think MH 5 used "-ms-file" instead of "-file", | |
1346 ;; which would make inc'ing from maildrops fail. | |
1347 (mh-exec-cmd-output mh-inc-prog nil folder | |
1348 (mh-scan-format) | |
1349 "-file" (expand-file-name maildrop-name) | |
1350 "-width" (window-width) | |
1351 "-truncate") | |
1352 (mh-exec-cmd-output mh-inc-prog nil | |
1353 (mh-scan-format) | |
1354 "-width" (window-width))) | |
1355 (if maildrop-name | |
1356 (message "inc %s -file %s...done" folder maildrop-name) | |
1357 (message "inc %s...done" folder)) | |
1358 (goto-char start-of-inc) | |
1359 (cond ((save-excursion | |
1360 (re-search-forward "^inc: no mail" nil t)) | |
1361 (message "No new mail%s%s" (if maildrop-name " in " "") | |
1362 (if maildrop-name maildrop-name ""))) | |
1363 ((and (when mh-folder-view-stack | |
1364 (let ((saved-text (buffer-substring-no-properties | |
1365 start-of-inc (point-max)))) | |
1366 (delete-region start-of-inc (point-max)) | |
1367 (unwind-protect (mh-widen t) | |
1368 (mh-remove-cur-notation) | |
1369 (goto-char (point-max)) | |
1370 (setq start-of-inc (point)) | |
1371 (insert saved-text) | |
1372 (goto-char start-of-inc)))) | |
1373 nil)) | |
1374 ((re-search-forward "^inc:" nil t) ; Error messages | |
1375 (error "Error incorporating mail")) | |
1376 ((and | |
1377 (equal mh-scan-format-file t) | |
1378 mh-adaptive-cmd-note-flag | |
1379 ;; Have we reached an edge condition? | |
1380 (save-excursion | |
1381 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1)) | |
1382 (setq start-of-inc (mh-generate-new-cmd-note folder)) | |
1383 nil)) | |
1384 (t | |
1385 (setq new-mail-flag t))) | |
1386 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines | |
1387 (let* ((sequences (mh-read-folder-sequences folder t)) | |
1388 (new-cur (assoc 'cur sequences)) | |
1389 (new-unseen (assoc mh-unseen-seq sequences))) | |
1390 (unless (assoc 'cur mh-seq-list) | |
1391 (push (list 'cur) mh-seq-list)) | |
1392 (unless (assoc mh-unseen-seq mh-seq-list) | |
1393 (push (list mh-unseen-seq) mh-seq-list)) | |
1394 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur)) | |
1395 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen))) | |
1396 (when (equal (point-max) start-of-inc) | |
1397 (mh-notate-cur)) | |
1398 (if new-mail-flag | |
1399 (progn | |
1400 (mh-make-folder-mode-line) | |
1401 (when (mh-speed-flists-active-p) | |
1402 (mh-speed-flists t mh-current-folder)) | |
1403 (when (memq 'unthread mh-view-ops) | |
1404 (mh-thread-inc folder start-of-inc)) | |
1405 (mh-goto-cur-msg)) | |
1406 (goto-char point-before-inc)) | |
1407 (mh-notate-user-sequences (cons start-of-inc (point-max))))))) | |
1408 | |
1409 (defun mh-generate-new-cmd-note (folder) | |
1410 "Fix the `mh-cmd-note' value for this FOLDER. | |
1411 | |
1412 After doing an `mh-get-new-mail' operation in this FOLDER, at least | |
1413 one line that looks like a truncated message number was found. | |
1414 | |
1415 Remove the text added by the last `mh-inc' command. It should be the | |
1416 messages cur-last. Call `mh-set-cmd-note', adjusting the notation | |
1417 column with the width of the largest message number in FOLDER. | |
1418 | |
1419 Reformat the message number width on each line in the buffer and trim | |
1420 the line length to fit in the window. | |
1421 | |
1422 Rescan the FOLDER in the range cur-last in order to display the | |
1423 messages that were removed earlier. They should all fit in the scan | |
1424 line now with no message truncation." | |
1425 (save-excursion | |
1426 (let ((maxcol (1- (window-width))) | |
1427 (old-cmd-note mh-cmd-note) | |
1428 mh-cmd-note-fmt | |
1429 msgnum) | |
1430 ;; Nuke all of the lines just added by the last inc | |
1431 (delete-char (- (point-max) (point))) | |
1432 ;; Update the current buffer to reflect the new mh-cmd-note | |
1433 ;; value needed to display messages. | |
1434 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder))) | |
1435 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d")) | |
1436 ;; Cleanup the messages that are in the buffer right now | |
1437 (goto-char (point-min)) | |
1438 (cond ((memq 'unthread mh-view-ops) | |
1439 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note))) | |
1440 (t (while (re-search-forward (mh-scan-msg-number-regexp) nil 0 1) | |
1441 ;; reformat the number to fix in mh-cmd-note columns | |
1442 (setq msgnum (string-to-number | |
1443 (buffer-substring | |
1444 (match-beginning 1) (match-end 1)))) | |
1445 (replace-match (format mh-cmd-note-fmt msgnum)) | |
1446 ;; trim the line to fix in the window | |
1447 (end-of-line) | |
1448 (let ((eol (point))) | |
1449 (move-to-column maxcol) | |
1450 (if (<= (point) eol) | |
1451 (delete-char (- eol (point)))))))) | |
1452 ;; now re-read the lost messages | |
1453 (goto-char (point-max)) | |
1454 (prog1 (point) | |
1455 (mh-regenerate-headers "cur-last" t))))) | |
1456 | |
1457 ;;;###mh-autoload | |
1458 (defun mh-goto-cur-msg (&optional minimal-changes-flag) | |
1459 "Position the cursor at the current message. | |
1460 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the | |
1461 function doesn't recenter the folder buffer." | |
1462 (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) | |
1463 (cond ((and cur-msg | |
1464 (mh-goto-msg cur-msg t t)) | |
1465 (unless minimal-changes-flag | |
1466 (mh-notate-cur) | |
1467 (mh-recenter 0) | |
1468 (mh-maybe-show cur-msg))) | |
1469 (t | |
1470 (setq overlay-arrow-position nil) | |
1471 (message "No current message"))))) | |
1472 | |
1473 ;;;###mh-autoload | |
1474 (defun mh-recenter (arg) | |
1475 "Like recenter but with three improvements: | |
1476 | |
1477 - At the end of the buffer it tries to show fewer empty lines. | |
1478 | |
1479 - operates only if the current buffer is in the selected window. | |
1480 (Commands like `save-some-buffers' can make this false.) | |
1481 | |
1482 - nil ARG means recenter as if prefix argument had been given." | |
1483 (cond ((not (eq (get-buffer-window (current-buffer)) (selected-window))) | |
1484 nil) | |
1485 ((= (point-max) (save-excursion | |
1486 (forward-line (- (/ (window-height) 2) 2)) | |
1487 (point))) | |
1488 (let ((lines-from-end 2)) | |
1489 (save-excursion | |
1490 (while (> (point-max) (progn (forward-line) (point))) | |
1491 (incf lines-from-end))) | |
1492 (recenter (- lines-from-end)))) | |
1493 ;; '(4) is the same as C-u prefix argument. | |
1494 (t (recenter (or arg '(4)))))) | |
1495 | |
1496 (defun mh-update-unseen () | |
1497 "Synchronize the unseen sequence with MH. | |
1498 Return non-nil iff the MH folder was set. | |
1499 The hook `mh-unseen-updated-hook' is called after the unseen sequence | |
1500 is updated." | |
1501 (if mh-seen-list | |
1502 (let* ((unseen-seq (mh-find-seq mh-unseen-seq)) | |
1503 (unseen-msgs (mh-seq-msgs unseen-seq))) | |
1504 (if unseen-msgs | |
1505 (progn | |
1506 (mh-undefine-sequence mh-unseen-seq mh-seen-list) | |
1507 (run-hooks 'mh-unseen-updated-hook) | |
1508 (while mh-seen-list | |
1509 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs)) | |
1510 (setq mh-seen-list (cdr mh-seen-list))) | |
1511 (setcdr unseen-seq unseen-msgs) | |
1512 t) ;since we set the folder | |
1513 (setq mh-seen-list nil))))) | |
1514 | |
1515 ;;;###mh-autoload | |
1516 (defun mh-outstanding-commands-p () | |
1517 "Return non-nil if there are outstanding deletes or refiles." | |
1518 (save-excursion | |
1519 (when (eq major-mode 'mh-show-mode) | |
1520 (set-buffer mh-show-folder-buffer)) | |
1521 (or mh-delete-list mh-refile-list))) | |
1522 | |
1523 ;;;###mh-autoload | |
1524 (defun mh-set-folder-modified-p (flag) | |
1525 "Mark current folder as modified or unmodified according to FLAG." | |
1526 (set-buffer-modified-p flag)) | |
1527 | |
1528 (defun mh-process-commands (folder) | |
1529 "Process outstanding commands for FOLDER. | |
1530 | |
1531 This function runs `mh-before-commands-processed-hook' before the | |
1532 commands are processed and `mh-after-commands-processed-hook' | |
1533 after the commands are processed." | |
1534 (message "Processing deletes and refiles for %s..." folder) | |
1535 (set-buffer folder) | |
1536 (with-mh-folder-updating (nil) | |
1537 ;; Run the before hook -- the refile and delete lists are still valid | |
1538 (run-hooks 'mh-before-commands-processed-hook) | |
1539 | |
1540 ;; Update the unseen sequence if it exists | |
1541 (mh-update-unseen) | |
1542 | |
1543 (let ((redraw-needed-flag mh-index-data) | |
1544 (folders-changed (list mh-current-folder)) | |
1545 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1546 (mh-create-sequence-map mh-seq-list))) | |
1547 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1548 (make-hash-table)))) | |
1549 ;; Remove invalid scan lines if we are in an index folder and then remove | |
1550 ;; the real messages | |
1551 (when mh-index-data | |
1552 (mh-index-delete-folder-headers) | |
1553 (setq folders-changed | |
1554 (append folders-changed (mh-index-execute-commands)))) | |
1555 | |
1556 ;; Then refile messages | |
1557 (mh-mapc #'(lambda (folder-msg-list) | |
1558 (let* ((dest-folder (symbol-name (car folder-msg-list))) | |
1559 (last (car (mh-translate-range dest-folder "last"))) | |
1560 (msgs (cdr folder-msg-list))) | |
1561 (push dest-folder folders-changed) | |
1562 (setq redraw-needed-flag t) | |
1563 (apply #'mh-exec-cmd | |
1564 "refile" "-src" folder dest-folder | |
1565 (mh-coalesce-msg-list msgs)) | |
1566 (mh-delete-scan-msgs msgs) | |
1567 ;; Preserve sequences in destination folder... | |
1568 (when mh-refile-preserves-sequences-flag | |
1569 (clrhash dest-map) | |
1570 (loop for i from (1+ (or last 0)) | |
1571 for msg in (sort (copy-sequence msgs) #'<) | |
1572 do (loop for seq-name in (gethash msg seq-map) | |
1573 do (push i (gethash seq-name dest-map)))) | |
1574 (maphash | |
1575 #'(lambda (seq msgs) | |
1576 ;; Can't be run in the background, since the | |
1577 ;; current folder is changed by mark this could | |
1578 ;; lead to a race condition with the next refile. | |
1579 (apply #'mh-exec-cmd "mark" | |
1580 "-sequence" (symbol-name seq) dest-folder | |
1581 "-add" (mapcar #'(lambda (x) (format "%s" x)) | |
1582 (mh-coalesce-msg-list msgs)))) | |
1583 dest-map)))) | |
1584 mh-refile-list) | |
1585 (setq mh-refile-list ()) | |
1586 | |
1587 ;; Now delete messages | |
1588 (cond (mh-delete-list | |
1589 (setq redraw-needed-flag t) | |
1590 (apply 'mh-exec-cmd "rmm" folder | |
1591 (mh-coalesce-msg-list mh-delete-list)) | |
1592 (mh-delete-scan-msgs mh-delete-list) | |
1593 (setq mh-delete-list nil))) | |
1594 | |
1595 ;; Don't need to remove sequences since delete and refile do so. | |
1596 ;; Mark cur message | |
1597 (if (> (buffer-size) 0) | |
1598 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last")))) | |
1599 | |
1600 ;; Redraw folder buffer if needed | |
1601 (when (and redraw-needed-flag) | |
1602 (when (mh-speed-flists-active-p) | |
1603 (apply #'mh-speed-flists t folders-changed)) | |
1604 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max))) | |
1605 (mh-index-data (mh-index-insert-folder-headers)))) | |
1606 | |
1607 (and (buffer-file-name (get-buffer mh-show-buffer)) | |
1608 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer)))) | |
1609 ;; If "inc" were to put a new msg in this file, | |
1610 ;; we would not notice, so mark it invalid now. | |
1611 (mh-invalidate-show-buffer)) | |
1612 | |
1613 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil)) | |
1614 (mh-remove-all-notation) | |
1615 (mh-notate-user-sequences) | |
1616 | |
1617 ;; Run the after hook -- now folders-changed is valid, | |
1618 ;; but not the lists of specific messages. | |
1619 (let ((mh-folders-changed folders-changed)) | |
1620 (run-hooks 'mh-after-commands-processed-hook))) | |
1621 | |
1622 (message "Processing deletes and refiles for %s...done" folder))) | |
1623 | |
1624 (defun mh-delete-scan-msgs (msgs) | |
1625 "Delete the scan listing lines for MSGS." | |
1626 (save-excursion | |
1627 (while msgs | |
1628 (when (mh-goto-msg (car msgs) t t) | |
1629 (when (memq 'unthread mh-view-ops) | |
1630 (mh-thread-forget-message (car msgs))) | |
1631 (mh-delete-line 1)) | |
1632 (setq msgs (cdr msgs))))) | |
1633 | |
1634 (defun mh-set-scan-mode () | |
1635 "Display the scan listing buffer, but do not show a message." | |
1636 (if (get-buffer mh-show-buffer) | |
1637 (delete-windows-on mh-show-buffer)) | |
1638 (mh-showing-mode 0) | |
1639 (force-mode-line-update) | |
1640 (if mh-recenter-summary-flag | |
1641 (mh-recenter nil))) | |
1642 | |
1643 ;;;###mh-autoload | |
1644 (defun mh-make-folder-mode-line (&optional ignored) | |
1645 "Set the fields of the mode line for a folder buffer. | |
1646 The optional argument is now obsolete and IGNORED. It used to be | |
1647 used to pass in what is now stored in the buffer-local variable | |
1648 `mh-mode-line-annotation'." | |
1649 (save-excursion | |
1650 (save-window-excursion | |
1651 (mh-first-msg) | |
1652 (let ((new-first-msg-num (mh-get-msg-num nil))) | |
1653 (when (or (not (memq 'unthread mh-view-ops)) | |
1654 (null mh-first-msg-num) | |
1655 (null new-first-msg-num) | |
1656 (< new-first-msg-num mh-first-msg-num)) | |
1657 (setq mh-first-msg-num new-first-msg-num))) | |
1658 (mh-last-msg) | |
1659 (let ((new-last-msg-num (mh-get-msg-num nil))) | |
1660 (when (or (not (memq 'unthread mh-view-ops)) | |
1661 (null mh-last-msg-num) | |
1662 (null new-last-msg-num) | |
1663 (> new-last-msg-num mh-last-msg-num)) | |
1664 (setq mh-last-msg-num new-last-msg-num))) | |
1665 (setq mh-msg-count (if mh-first-msg-num | |
1666 (count-lines (point-min) (point-max)) | |
1667 0)) | |
1668 (setq mode-line-buffer-identification | |
1669 (list (format " {%%b%s} %s msg%s" | |
1670 (if mh-mode-line-annotation | |
1671 (format "/%s" mh-mode-line-annotation) | |
1672 "") | |
1673 (if (zerop mh-msg-count) | |
1674 "no" | |
1675 (format "%d" mh-msg-count)) | |
1676 (if (zerop mh-msg-count) | |
1677 "s" | |
1678 (cond ((> mh-msg-count 1) | |
1679 (format "s (%d-%d)" mh-first-msg-num | |
1680 mh-last-msg-num)) | |
1681 (mh-first-msg-num | |
1682 (format " (%d)" mh-first-msg-num)) | |
1683 ("")))))) | |
1684 (mh-logo-display)))) | |
1685 | |
1686 ;;;###mh-autoload | |
1687 (defun mh-scan-folder (folder range &optional dont-exec-pending) | |
1688 "Scan FOLDER over RANGE. | |
1689 | |
1690 After the scan is performed, switch to the buffer associated with | |
1691 FOLDER. | |
1692 | |
1693 Check the documentation of `mh-interactive-range' to see how RANGE is | |
1694 read in interactive use. | |
1695 | |
1696 The processing of outstanding commands is not performed if | |
1697 DONT-EXEC-PENDING is non-nil." | |
1698 (when (stringp range) | |
1699 (setq range (delete "" (split-string range "[ \t\n]")))) | |
1700 (cond ((null (get-buffer folder)) | |
1701 (mh-make-folder folder)) | |
1702 (t | |
1703 (unless dont-exec-pending | |
1704 (mh-process-or-undo-commands folder) | |
1705 (mh-reset-threads-and-narrowing)) | |
1706 (switch-to-buffer folder))) | |
1707 (mh-regenerate-headers range) | |
1708 (if (zerop (buffer-size)) | |
1709 (if (equal range "all") | |
1710 (message "Folder %s is empty" folder) | |
1711 (message "No messages in %s, range %s" folder range)) | |
1712 (mh-goto-cur-msg)) | |
1713 (when (mh-outstanding-commands-p) | |
1714 (mh-notate-deleted-and-refiled))) | |
1715 | |
1716 ;;;###mh-autoload | |
1717 (defun mh-process-or-undo-commands (folder) | |
1718 "If FOLDER has outstanding commands, then either process or discard them. | |
1719 Called by functions like `mh-sort-folder', so also invalidate | |
1720 show buffer." | |
1721 (set-buffer folder) | |
1722 (if (mh-outstanding-commands-p) | |
1723 (if (or mh-do-not-confirm-flag | |
1724 (y-or-n-p | |
1725 "Process outstanding deletes and refiles? ")) | |
1726 (mh-process-commands folder) | |
1727 (set-buffer folder) | |
1728 (mh-undo-folder))) | |
1729 (mh-update-unseen) | |
1730 (mh-invalidate-show-buffer)) | |
1731 | |
1732 ;;;###mh-autoload | |
1733 (defun mh-regenerate-headers (range &optional update) | |
1734 "Scan folder over RANGE. | |
1735 If UPDATE, append the scan lines, otherwise replace." | |
1736 (let ((folder mh-current-folder) | |
1737 (range (if (and range (atom range)) (list range) range)) | |
1738 scan-start) | |
1739 (message "Scanning %s..." folder) | |
1740 (mh-remove-all-notation) | |
1741 (with-mh-folder-updating (nil) | |
1742 (if update | |
1743 (goto-char (point-max)) | |
1744 (delete-region (point-min) (point-max)) | |
1745 (if mh-adaptive-cmd-note-flag | |
1746 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width | |
1747 folder))))) | |
1748 (setq scan-start (point)) | |
1749 (apply #'mh-exec-cmd-output | |
1750 mh-scan-prog nil | |
1751 (mh-scan-format) | |
1752 "-noclear" "-noheader" | |
1753 "-width" (window-width) | |
1754 folder range) | |
1755 (goto-char scan-start) | |
1756 (cond ((looking-at "scan: no messages in") | |
1757 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines | |
1758 ((looking-at (if (mh-variant-p 'mu-mh) | |
1759 "scan: message set .* does not exist" | |
1760 "scan: bad message list ")) | |
1761 (keep-lines mh-scan-valid-regexp)) | |
1762 ((looking-at "scan: ")) ; Keep error messages | |
1763 (t | |
1764 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines | |
1765 (setq mh-seq-list (mh-read-folder-sequences folder nil)) | |
1766 (mh-notate-user-sequences) | |
1767 (or update | |
1768 (setq mh-mode-line-annotation | |
1769 (if (equal range '("all")) | |
1770 nil | |
1771 mh-partial-folder-mode-line-annotation))) | |
1772 (mh-make-folder-mode-line)) | |
1773 (message "Scanning %s...done" folder))) | |
1774 | |
1775 ;;;###mh-autoload | |
1776 (defun mh-reset-threads-and-narrowing () | |
1777 "Reset all variables pertaining to threads and narrowing. | |
1778 Also removes all content from the folder buffer." | |
1779 (setq mh-view-ops ()) | |
1780 (setq mh-folder-view-stack ()) | |
1781 (setq mh-thread-scan-line-map-stack ()) | |
1782 (let ((buffer-read-only nil)) (erase-buffer))) | |
1783 | |
1784 (defun mh-make-folder (name) | |
1785 "Create a new mail folder called NAME. | |
1786 Make it the current folder." | |
1787 (switch-to-buffer name) | |
1788 (setq buffer-read-only nil) | |
1789 (erase-buffer) | |
1790 (if mh-adaptive-cmd-note-flag | |
1791 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name)))) | |
1792 (setq buffer-read-only t) | |
1793 (mh-folder-mode) | |
1794 (mh-set-folder-modified-p nil) | |
1795 (setq buffer-file-name mh-folder-filename) | |
1796 (when (and (not mh-index-data) | |
1797 (file-exists-p (concat buffer-file-name mh-index-data-file))) | |
1798 (mh-index-read-data)) | |
1799 (mh-make-folder-mode-line)) | |
1800 | |
1801 ;;;###mh-autoload | |
1802 (defun mh-next-msg (&optional wait-after-complaining-flag) | |
1803 "Move backward or forward to the next undeleted message in the buffer. | |
1804 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and | |
1805 we are at the last message, then wait for a second after telling | |
1806 the user that there aren't any more unread messages." | |
1807 (if (eq mh-next-direction 'forward) | |
1808 (mh-next-undeleted-msg 1 wait-after-complaining-flag) | |
1809 (mh-previous-undeleted-msg 1 wait-after-complaining-flag))) | |
1810 | |
1811 ;;;###mh-autoload | |
1812 (defun mh-prompt-for-refile-folder () | |
1813 "Prompt the user for a folder in which the message should be filed. | |
1814 The folder is returned as a string. | |
1815 | |
1816 The default folder name is generated by the option | |
1817 `mh-default-folder-for-message-function' if it is non-nil or | |
1818 `mh-folder-from-address'." | |
1819 (mh-prompt-for-folder | |
1820 "Destination" | |
1821 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t))))) | |
1822 (if (null refile-file) "" | |
1823 (save-excursion | |
1824 (set-buffer (get-buffer-create mh-temp-buffer)) | |
1825 (erase-buffer) | |
1826 (insert-file-contents refile-file) | |
1827 (or (and mh-default-folder-for-message-function | |
1828 (let ((buffer-file-name refile-file)) | |
1829 (funcall mh-default-folder-for-message-function))) | |
1830 (mh-folder-from-address) | |
1831 (and (eq 'refile (car mh-last-destination-folder)) | |
1832 (symbol-name (cdr mh-last-destination-folder))) | |
1833 "")))) | |
1834 t)) | |
1835 | |
1836 ;;;###mh-autoload | |
1837 (defun mh-folder-from-address () | |
1838 "Derive folder name from sender. | |
1839 | |
1840 The name of the folder is derived as follows: | |
1841 | |
1842 a) The folder name associated with the first address found in | |
1843 the list `mh-default-folder-list' is used. Each element in | |
1844 this list contains a \"Check Recipient\" item. If this item is | |
1845 turned on, then the address is checked against the recipient | |
1846 instead of the sender. This is useful for mailing lists. | |
1847 | |
1848 b) An alias prefixed by `mh-default-folder-prefix' | |
1849 corresponding to the address is used. The prefix is used to | |
1850 prevent clutter in your mail directory. | |
1851 | |
1852 Return nil if a folder name was not derived, or if the variable | |
1853 `mh-default-folder-must-exist-flag' is t and the folder does not | |
1854 exist." | |
1855 ;; Loop for all entries in mh-default-folder-list | |
1856 (save-restriction | |
1857 (goto-char (point-min)) | |
1858 (re-search-forward "\n\n" nil 'limit) | |
1859 (narrow-to-region (point-min) (point)) | |
1860 (let ((to/cc (concat (or (message-fetch-field "to") "") ", " | |
1861 (or (message-fetch-field "cc") ""))) | |
1862 (from (or (message-fetch-field "from") "")) | |
1863 folder-name) | |
1864 (setq folder-name | |
1865 (loop for list in mh-default-folder-list | |
1866 when (string-match (nth 0 list) (if (nth 2 list) to/cc from)) | |
1867 return (nth 1 list) | |
1868 finally return nil)) | |
1869 | |
1870 ;; Make sure a result from `mh-default-folder-list' begins with "+" | |
1871 ;; since 'mh-expand-file-name below depends on it | |
1872 (when (and folder-name (not (eq (aref folder-name 0) ?+))) | |
1873 (setq folder-name (concat "+" folder-name))) | |
1874 | |
1875 ;; If not, is there an alias for the address? | |
1876 (when (not folder-name) | |
1877 (let* ((from-header (mh-extract-from-header-value)) | |
1878 (address (and from-header | |
1879 (nth 1 (mail-extract-address-components | |
1880 from-header)))) | |
1881 (alias (and address (mh-alias-address-to-alias address)))) | |
1882 (when alias | |
1883 (setq folder-name | |
1884 (and alias (concat "+" mh-default-folder-prefix alias)))))) | |
1885 | |
1886 ;; If mh-default-folder-must-exist-flag set, check that folder exists. | |
1887 (if (and folder-name | |
1888 (or (not mh-default-folder-must-exist-flag) | |
1889 (file-exists-p (mh-expand-file-name folder-name)))) | |
1890 folder-name)))) | |
1891 | |
1892 ;;;###mh-autoload | |
1893 (defun mh-delete-a-msg (message) | |
1894 "Delete MESSAGE. | |
1895 If MESSAGE is nil then the message at point is deleted. | |
1896 The hook `mh-delete-msg-hook' is called after you mark a message | |
1897 for deletion. For example, a past maintainer of MH-E used this | |
1898 once when he kept statistics on his mail usage." | |
1899 (save-excursion | |
1900 (if (numberp message) | |
1901 (mh-goto-msg message nil t) | |
1902 (beginning-of-line) | |
1903 (setq message (mh-get-msg-num t))) | |
1904 (if (looking-at mh-scan-refiled-msg-regexp) | |
1905 (error "Message %d is refiled; undo refile before deleting" message)) | |
1906 (if (looking-at mh-scan-deleted-msg-regexp) | |
1907 nil | |
1908 (mh-set-folder-modified-p t) | |
1909 (setq mh-delete-list (cons message mh-delete-list)) | |
1910 (mh-notate nil mh-note-deleted mh-cmd-note) | |
1911 (run-hooks 'mh-delete-msg-hook)))) | |
1912 | |
1913 ;;;###mh-autoload | |
1914 (defun mh-refile-a-msg (message folder) | |
1915 "Refile MESSAGE in FOLDER. | |
1916 If MESSAGE is nil then the message at point is refiled. | |
1917 Folder is a symbol, not a string. | |
1918 The hook `mh-refile-msg-hook' is called after a message is marked to | |
1919 be refiled." | |
1920 (save-excursion | |
1921 (if (numberp message) | |
1922 (mh-goto-msg message nil t) | |
1923 (beginning-of-line) | |
1924 (setq message (mh-get-msg-num t))) | |
1925 (cond ((looking-at mh-scan-deleted-msg-regexp) | |
1926 (error "Message %d is deleted; undo delete before moving" message)) | |
1927 ((looking-at mh-scan-refiled-msg-regexp) | |
1928 (if (y-or-n-p | |
1929 (format "Message %d already refiled; copy to %s as well? " | |
1930 message folder)) | |
1931 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link" | |
1932 "-src" mh-current-folder | |
1933 (symbol-name folder)) | |
1934 (message "Message not copied"))) | |
1935 (t | |
1936 (mh-set-folder-modified-p t) | |
1937 (cond ((null (assoc folder mh-refile-list)) | |
1938 (push (list folder message) mh-refile-list)) | |
1939 ((not (member message (cdr (assoc folder mh-refile-list)))) | |
1940 (push message (cdr (assoc folder mh-refile-list))))) | |
1941 (mh-notate nil mh-note-refiled mh-cmd-note) | |
1942 (run-hooks 'mh-refile-msg-hook))))) | |
1943 | |
1944 (defun mh-undo-msg (msg) | |
1945 "Undo the deletion or refile of one MSG. | |
1946 If MSG is nil then act on the message at point" | |
1947 (save-excursion | |
1948 (if (numberp msg) | |
1949 (mh-goto-msg msg t t) | |
1950 (beginning-of-line) | |
1951 (setq msg (mh-get-msg-num t))) | |
1952 (cond ((memq msg mh-delete-list) | |
1953 (setq mh-delete-list (delq msg mh-delete-list))) | |
1954 (t | |
1955 (dolist (folder-msg-list mh-refile-list) | |
1956 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list)))) | |
1957 (setq mh-refile-list (loop for x in mh-refile-list | |
1958 unless (null (cdr x)) collect x)))) | |
1959 (mh-notate nil ? mh-cmd-note))) | |
1960 | |
1961 ;;;###mh-autoload | |
1962 (defun mh-msg-filename (msg &optional folder) | |
1963 "Return the file name of MSG in FOLDER (default current folder)." | |
1964 (expand-file-name (int-to-string msg) | |
1965 (if folder | |
1966 (mh-expand-file-name folder) | |
1967 mh-folder-filename))) | |
1968 | |
1969 (provide 'mh-folder) | |
1970 | |
1971 ;; Local Variables: | |
1972 ;; indent-tabs-mode: nil | |
1973 ;; sentence-end-double-space: nil | |
1974 ;; End: | |
1975 | |
68470 | 1976 ;; arch-tag: aa97b758-d4f6-4c86-bc5a-1950921da1e7 |
68465 | 1977 ;;; mh-folder.el ends here |