Add arch tagline
[emacs.git] / lisp / mh-e / mh-show.el
blobf8728edb3e4d5d76058d0a0557ef16dbffb9ac7e
1 ;;; mh-show.el --- MH-Show mode
3 ;; Copyright (C) 1993, 1995, 1997,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Bill Wohler <wohler@newt.com>
7 ;; Maintainer: Bill Wohler <wohler@newt.com>
8 ;; Keywords: mail
9 ;; See: mh-e.el
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Commentary:
30 ;; Mode for showing messages.
32 ;;; Change Log:
34 ;;; Code:
36 (require 'mh-e)
37 (require 'mh-scan)
39 (require 'gnus-cite)
40 (require 'gnus-util)
42 (autoload 'mh-make-buffer-data "mh-mime") ;can't be automatically generated
44 (require 'font-lock)
48 ;;; MH-Folder Commands
50 (defvar mh-showing-with-headers nil
51 "If non-nil, MH-Show buffer contains message with all header fields.
52 If nil, MH-Show buffer contains message processed normally.")
54 ;;;###mh-autoload
55 (defun mh-show (&optional message redisplay-flag)
56 "Display message\\<mh-folder-mode-map>.
58 If the message under the cursor is already displayed, this command
59 scrolls to the beginning of the message. MH-E normally hides a lot of
60 the superfluous header fields that mailers add to a message, but if
61 you wish to see all of them, use the command \\[mh-header-display].
63 Two hooks can be used to control how messages are displayed. The
64 first hook, `mh-show-mode-hook', is called early on in the
65 process of the message display. It is usually used to perform
66 some action on the message's content. The second hook,
67 `mh-show-hook', is the last thing called after messages are
68 displayed. It's used to affect the behavior of MH-E in general or
69 when `mh-show-mode-hook' is too early.
71 From a program, optional argument MESSAGE can be used to display an
72 alternative message. The optional argument REDISPLAY-FLAG forces the
73 redisplay of the message even if the show buffer was already
74 displaying the correct message.
76 See the \"mh-show\" customization group for a litany of options that
77 control what displayed messages look like."
78 (interactive (list nil t))
79 (when (or redisplay-flag
80 (and mh-showing-with-headers
81 (or mh-mhl-format-file mh-clean-message-header-flag)))
82 (mh-invalidate-show-buffer))
83 (mh-show-msg message))
85 ;;;###mh-autoload
86 (defun mh-header-display ()
87 "Display message with all header fields\\<mh-folder-mode-map>.
89 Use the command \\[mh-show] to show the message normally again."
90 (interactive)
91 (and (not mh-showing-with-headers)
92 (or mh-mhl-format-file mh-clean-message-header-flag)
93 (mh-invalidate-show-buffer))
94 (let ((mh-decode-mime-flag nil)
95 (mh-mhl-format-file nil)
96 (mh-clean-message-header-flag nil))
97 (mh-show-msg nil)
98 (mh-in-show-buffer (mh-show-buffer)
99 (goto-char (point-min))
100 (mh-recenter 0))
101 (setq mh-showing-with-headers t)))
105 ;;; Support Routines for MH-Folder Commands
107 ;;;###mh-autoload
108 (defun mh-maybe-show (&optional msg)
109 "Display message at cursor, but only if in show mode.
110 If optional arg MSG is non-nil, display that message instead."
111 (if mh-showing-mode (mh-show msg)))
113 (defun mh-show-msg (msg)
114 "Show MSG.
116 The hook `mh-show-hook' is called after the message has been
117 displayed."
118 (if (not msg)
119 (setq msg (mh-get-msg-num t)))
120 (mh-showing-mode t)
121 (setq mh-page-to-next-msg-flag nil)
122 (let ((folder mh-current-folder)
123 (folders (list mh-current-folder))
124 (clean-message-header mh-clean-message-header-flag)
125 (show-window (get-buffer-window mh-show-buffer))
126 (display-mime-buttons-flag mh-display-buttons-for-inline-parts-flag))
127 (if (not (eq (next-window (minibuffer-window)) (selected-window)))
128 (delete-other-windows)) ; force ourself to the top window
129 (mh-in-show-buffer (mh-show-buffer)
130 (setq mh-display-buttons-for-inline-parts-flag display-mime-buttons-flag)
131 (if (and show-window
132 (equal (mh-msg-filename msg folder) buffer-file-name))
133 (progn ;just back up to start
134 (goto-char (point-min))
135 (if (not clean-message-header)
136 (mh-start-of-uncleaned-message)))
137 (mh-display-msg msg folder)))
138 (if (not (= (1+ (window-height)) (frame-height))) ;not horizontally split
139 (shrink-window (- (window-height) (or mh-summary-height
140 (mh-summary-height)))))
141 (mh-recenter nil)
142 ;; The following line is a nop which forces update of the scan line so
143 ;; that font-lock will update it (if needed)...
144 (mh-notate nil nil mh-cmd-note)
145 (if (not (memq msg mh-seen-list))
146 (setq mh-seen-list (cons msg mh-seen-list)))
147 (when mh-update-sequences-after-mh-show-flag
148 (mh-update-sequences)
149 (when mh-index-data
150 (setq folders
151 (append (mh-index-delete-from-sequence mh-unseen-seq (list msg))
152 folders)))
153 (when (mh-speed-flists-active-p)
154 (apply #'mh-speed-flists t folders)))
155 (run-hooks 'mh-show-hook)))
157 ;;;###mh-autoload
158 (defun mh-showing-mode (&optional arg)
159 "Change whether messages should be displayed.
161 With ARG, display messages iff ARG is positive."
162 (setq mh-showing-mode
163 (if (null arg)
164 (not mh-showing-mode)
165 (> (prefix-numeric-value arg) 0))))
167 ;;;###mh-autoload
168 (defun mh-start-of-uncleaned-message ()
169 "Position uninteresting headers off the top of the window."
170 (let ((case-fold-search t))
171 (re-search-forward
172 "^To:\\|^Cc:\\|^From:\\|^Subject:\\|^Date:" nil t)
173 (beginning-of-line)
174 (mh-recenter 0)))
176 (defvar mh-show-buffer-mode-line-buffer-id " {show-%s} %d"
177 "Format string to produce `mode-line-buffer-identification' for show buffers.
179 First argument is folder name. Second is message number.")
181 ;;;###mh-autoload
182 (defun mh-display-msg (msg-num folder-name)
183 "Display MSG-NUM of FOLDER-NAME.
184 Sets the current buffer to the show buffer."
185 (let ((folder (mh-msg-folder folder-name)))
186 (set-buffer folder)
187 ;; When Gnus uses external displayers it has to keep handles longer. So
188 ;; we will delete these handles when mh-quit is called on the folder. It
189 ;; would be nicer if there are weak pointers in emacs lisp, then we could
190 ;; get the garbage collector to do this for us.
191 (unless (mh-buffer-data)
192 (setf (mh-buffer-data) (mh-make-buffer-data)))
193 ;; Bind variables in folder buffer in case they are local
194 (let ((formfile mh-mhl-format-file)
195 (clean-message-header mh-clean-message-header-flag)
196 (invisible-headers mh-invisible-header-fields-compiled)
197 (visible-headers nil)
198 (msg-filename (mh-msg-filename msg-num folder-name))
199 (show-buffer mh-show-buffer)
200 (mm-inline-media-tests mh-mm-inline-media-tests))
201 (if (not (file-exists-p msg-filename))
202 (error "Message %d does not exist" msg-num))
203 (if (and (> mh-show-maximum-size 0)
204 (> (elt (file-attributes msg-filename) 7)
205 mh-show-maximum-size)
206 (not (y-or-n-p
207 (format
208 "Message %d (%d bytes) exceeds %d bytes. Display it? "
209 msg-num (elt (file-attributes msg-filename) 7)
210 mh-show-maximum-size))))
211 (error "Message %d not displayed" msg-num))
212 (set-buffer show-buffer)
213 (cond ((not (equal msg-filename buffer-file-name))
214 (mh-unvisit-file)
215 (setq buffer-read-only nil)
216 ;; Cleanup old mime handles
217 (mh-mime-cleanup)
218 (erase-buffer)
219 ;; Changing contents, so this hook needs to be reinitialized.
220 ;; pgp.el uses this.
221 (if (boundp 'write-contents-hooks) ;Emacs 19
222 (kill-local-variable 'write-contents-hooks))
223 (if formfile
224 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
225 (if (stringp formfile)
226 (list "-form" formfile))
227 msg-filename)
228 (insert-file-contents-literally msg-filename))
229 ;; Use mm to display buffer
230 (when (and mh-decode-mime-flag (not formfile))
231 (mh-add-missing-mime-version-header)
232 (setf (mh-buffer-data) (mh-make-buffer-data))
233 (mh-mime-display))
234 (mh-show-mode)
235 ;; Header cleanup
236 (goto-char (point-min))
237 (cond (clean-message-header
238 (mh-clean-msg-header (point-min)
239 invisible-headers
240 visible-headers)
241 (goto-char (point-min)))
243 (mh-start-of-uncleaned-message)))
244 (mh-decode-message-header)
245 ;; the parts of visiting we want to do (no locking)
246 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
247 (setq buffer-undo-list nil))
248 (set-buffer-auto-saved)
249 ;; the parts of set-visited-file-name we want to do (no locking)
250 (setq buffer-file-name msg-filename)
251 (setq buffer-backed-up nil)
252 (auto-save-mode 1)
253 (set-mark nil)
254 (unwind-protect
255 (when (and mh-decode-mime-flag (not formfile))
256 (setq buffer-read-only nil)
257 (mh-display-smileys)
258 (mh-display-emphasis))
259 (setq buffer-read-only t))
260 (set-buffer-modified-p nil)
261 (setq mh-show-folder-buffer folder)
262 (setq mode-line-buffer-identification
263 (list (format mh-show-buffer-mode-line-buffer-id
264 folder-name msg-num)))
265 (mh-logo-display)
266 (set-buffer folder)
267 (setq mh-showing-with-headers nil))))))
269 (defun mh-msg-folder (folder-name)
270 "Return the name of the buffer for FOLDER-NAME."
271 folder-name)
273 ;;;###mh-autoload
274 (defun mh-clean-msg-header (start invisible-headers visible-headers)
275 "Flush extraneous lines in message header.
277 Header is cleaned from START to the end of the message header.
278 INVISIBLE-HEADERS contains a regular expression specifying lines
279 to delete from the header. VISIBLE-HEADERS contains a regular
280 expression specifying the lines to display. INVISIBLE-HEADERS is
281 ignored if VISIBLE-HEADERS is non-nil."
282 ;; XXX Note that MH-E no longer supports the `mh-visible-headers'
283 ;; variable, so this function could be trimmed of this feature too."
284 (let ((case-fold-search t)
285 (buffer-read-only nil))
286 (save-restriction
287 (goto-char start)
288 (if (search-forward "\n\n" nil 'move)
289 (backward-char 1))
290 (narrow-to-region start (point))
291 (goto-char (point-min))
292 (if visible-headers
293 (while (< (point) (point-max))
294 (cond ((looking-at visible-headers)
295 (forward-line 1)
296 (while (looking-at "[ \t]") (forward-line 1)))
298 (mh-delete-line 1)
299 (while (looking-at "[ \t]")
300 (mh-delete-line 1)))))
301 (while (re-search-forward invisible-headers nil t)
302 (beginning-of-line)
303 (mh-delete-line 1)
304 (while (looking-at "[ \t]")
305 (mh-delete-line 1)))))
306 (let ((mh-compose-skipped-header-fields ()))
307 (mh-letter-hide-all-skipped-fields))
308 (unlock-buffer)))
310 ;;;###mh-autoload
311 (defun mh-invalidate-show-buffer ()
312 "Invalidate the show buffer so we must update it to use it."
313 (if (get-buffer mh-show-buffer)
314 (save-excursion
315 (set-buffer mh-show-buffer)
316 (mh-unvisit-file))))
318 (defun mh-unvisit-file ()
319 "Separate current buffer from the message file it was visiting."
320 (or (not (buffer-modified-p))
321 (null buffer-file-name) ;we've been here before
322 (yes-or-no-p (format "Message %s modified; flush changes? "
323 (file-name-nondirectory buffer-file-name)))
324 (error "Flushing changes not confirmed"))
325 (clear-visited-file-modtime)
326 (unlock-buffer)
327 (setq buffer-file-name nil))
329 (defun mh-summary-height ()
330 "Return ideal value for the variable `mh-summary-height'.
331 The current frame height is taken into consideration."
332 (or (and (fboundp 'frame-height)
333 (> (frame-height) 24)
334 (min 10 (/ (frame-height) 6)))
339 ;; Infrastructure to generate show-buffer functions from folder functions
340 ;; XEmacs does not have deactivate-mark? What is the equivalent of
341 ;; transient-mark-mode for XEmacs? Should we be restoring the mark in the
342 ;; folder buffer after the operation has been carried out.
343 (defmacro mh-defun-show-buffer (function original-function
344 &optional dont-return)
345 "Define FUNCTION to run ORIGINAL-FUNCTION in folder buffer.
346 If the buffer we start in is still visible and DONT-RETURN is nil
347 then switch to it after that."
348 `(defun ,function ()
349 ,(format "Calls %s from the message's folder.\n%s\nSee \"%s\" for more info.\n"
350 original-function
351 (if dont-return ""
352 "When function completes, returns to the show buffer if it is
353 still visible.\n")
354 original-function)
355 (interactive)
356 (when (buffer-live-p (get-buffer mh-show-folder-buffer))
357 (let ((config (current-window-configuration))
358 (folder-buffer mh-show-folder-buffer)
359 (normal-exit nil)
360 ,@(if dont-return () '((cur-buffer-name (buffer-name)))))
361 (pop-to-buffer mh-show-folder-buffer nil)
362 (unless (equal (buffer-name
363 (window-buffer (frame-first-window (selected-frame))))
364 folder-buffer)
365 (delete-other-windows))
366 (mh-goto-cur-msg t)
367 (mh-funcall-if-exists deactivate-mark)
368 (unwind-protect
369 (prog1 (call-interactively (function ,original-function))
370 (setq normal-exit t))
371 (mh-funcall-if-exists deactivate-mark)
372 (when (eq major-mode 'mh-folder-mode)
373 (mh-funcall-if-exists hl-line-highlight))
374 (cond ((not normal-exit)
375 (set-window-configuration config))
376 ,(if dont-return
377 `(t (setq mh-previous-window-config config))
378 `((and (get-buffer cur-buffer-name)
379 (window-live-p (get-buffer-window
380 (get-buffer cur-buffer-name))))
381 (pop-to-buffer (get-buffer cur-buffer-name) nil)))))))))
383 ;; Generate interactive functions for the show buffer from the corresponding
384 ;; folder functions.
385 (mh-defun-show-buffer mh-show-previous-undeleted-msg
386 mh-previous-undeleted-msg)
387 (mh-defun-show-buffer mh-show-next-undeleted-msg
388 mh-next-undeleted-msg)
389 (mh-defun-show-buffer mh-show-quit mh-quit)
390 (mh-defun-show-buffer mh-show-delete-msg mh-delete-msg)
391 (mh-defun-show-buffer mh-show-refile-msg mh-refile-msg)
392 (mh-defun-show-buffer mh-show-undo mh-undo)
393 (mh-defun-show-buffer mh-show-execute-commands mh-execute-commands)
394 (mh-defun-show-buffer mh-show-reply mh-reply t)
395 (mh-defun-show-buffer mh-show-redistribute mh-redistribute)
396 (mh-defun-show-buffer mh-show-forward mh-forward t)
397 (mh-defun-show-buffer mh-show-header-display mh-header-display)
398 (mh-defun-show-buffer mh-show-refile-or-write-again
399 mh-refile-or-write-again)
400 (mh-defun-show-buffer mh-show-show mh-show)
401 (mh-defun-show-buffer mh-show-write-message-to-file
402 mh-write-msg-to-file)
403 (mh-defun-show-buffer mh-show-extract-rejected-mail
404 mh-extract-rejected-mail t)
405 (mh-defun-show-buffer mh-show-delete-msg-no-motion
406 mh-delete-msg-no-motion)
407 (mh-defun-show-buffer mh-show-first-msg mh-first-msg)
408 (mh-defun-show-buffer mh-show-last-msg mh-last-msg)
409 (mh-defun-show-buffer mh-show-copy-msg mh-copy-msg)
410 (mh-defun-show-buffer mh-show-edit-again mh-edit-again t)
411 (mh-defun-show-buffer mh-show-goto-msg mh-goto-msg)
412 (mh-defun-show-buffer mh-show-inc-folder mh-inc-folder)
413 (mh-defun-show-buffer mh-show-delete-subject-or-thread
414 mh-delete-subject-or-thread)
415 (mh-defun-show-buffer mh-show-delete-subject mh-delete-subject)
416 (mh-defun-show-buffer mh-show-print-msg mh-print-msg)
417 (mh-defun-show-buffer mh-show-send mh-send t)
418 (mh-defun-show-buffer mh-show-toggle-showing mh-toggle-showing t)
419 (mh-defun-show-buffer mh-show-pipe-msg mh-pipe-msg t)
420 (mh-defun-show-buffer mh-show-sort-folder mh-sort-folder)
421 (mh-defun-show-buffer mh-show-visit-folder mh-visit-folder t)
422 (mh-defun-show-buffer mh-show-rescan-folder mh-rescan-folder)
423 (mh-defun-show-buffer mh-show-pack-folder mh-pack-folder)
424 (mh-defun-show-buffer mh-show-kill-folder mh-kill-folder t)
425 (mh-defun-show-buffer mh-show-list-folders mh-list-folders t)
426 (mh-defun-show-buffer mh-show-undo-folder mh-undo-folder)
427 (mh-defun-show-buffer mh-show-delete-msg-from-seq
428 mh-delete-msg-from-seq)
429 (mh-defun-show-buffer mh-show-delete-seq mh-delete-seq)
430 (mh-defun-show-buffer mh-show-list-sequences mh-list-sequences)
431 (mh-defun-show-buffer mh-show-narrow-to-seq mh-narrow-to-seq)
432 (mh-defun-show-buffer mh-show-put-msg-in-seq mh-put-msg-in-seq)
433 (mh-defun-show-buffer mh-show-msg-is-in-seq mh-msg-is-in-seq)
434 (mh-defun-show-buffer mh-show-widen mh-widen)
435 (mh-defun-show-buffer mh-show-narrow-to-subject mh-narrow-to-subject)
436 (mh-defun-show-buffer mh-show-narrow-to-from mh-narrow-to-from)
437 (mh-defun-show-buffer mh-show-narrow-to-cc mh-narrow-to-cc)
438 (mh-defun-show-buffer mh-show-narrow-to-range mh-narrow-to-range)
439 (mh-defun-show-buffer mh-show-narrow-to-to mh-narrow-to-to)
440 (mh-defun-show-buffer mh-show-store-msg mh-store-msg)
441 (mh-defun-show-buffer mh-show-page-digest mh-page-digest)
442 (mh-defun-show-buffer mh-show-page-digest-backwards
443 mh-page-digest-backwards)
444 (mh-defun-show-buffer mh-show-burst-digest mh-burst-digest)
445 (mh-defun-show-buffer mh-show-page-msg mh-page-msg)
446 (mh-defun-show-buffer mh-show-previous-page mh-previous-page)
447 (mh-defun-show-buffer mh-show-modify mh-modify t)
448 (mh-defun-show-buffer mh-show-next-button mh-next-button)
449 (mh-defun-show-buffer mh-show-prev-button mh-prev-button)
450 (mh-defun-show-buffer mh-show-toggle-mime-part mh-folder-toggle-mime-part)
451 (mh-defun-show-buffer mh-show-save-mime-part mh-folder-save-mime-part)
452 (mh-defun-show-buffer mh-show-inline-mime-part mh-folder-inline-mime-part)
453 (mh-defun-show-buffer mh-show-toggle-threads mh-toggle-threads)
454 (mh-defun-show-buffer mh-show-thread-delete mh-thread-delete)
455 (mh-defun-show-buffer mh-show-thread-refile mh-thread-refile)
456 (mh-defun-show-buffer mh-show-update-sequences mh-update-sequences)
457 (mh-defun-show-buffer mh-show-next-unread-msg mh-next-unread-msg)
458 (mh-defun-show-buffer mh-show-previous-unread-msg mh-previous-unread-msg)
459 (mh-defun-show-buffer mh-show-thread-ancestor mh-thread-ancestor)
460 (mh-defun-show-buffer mh-show-thread-next-sibling mh-thread-next-sibling)
461 (mh-defun-show-buffer mh-show-thread-previous-sibling
462 mh-thread-previous-sibling)
463 (mh-defun-show-buffer mh-show-index-visit-folder mh-index-visit-folder t)
464 (mh-defun-show-buffer mh-show-toggle-tick mh-toggle-tick)
465 (mh-defun-show-buffer mh-show-narrow-to-tick mh-narrow-to-tick)
466 (mh-defun-show-buffer mh-show-junk-blacklist mh-junk-blacklist)
467 (mh-defun-show-buffer mh-show-junk-whitelist mh-junk-whitelist)
468 (mh-defun-show-buffer mh-show-index-new-messages mh-index-new-messages)
469 (mh-defun-show-buffer mh-show-index-ticked-messages mh-index-ticked-messages)
470 (mh-defun-show-buffer mh-show-index-sequenced-messages
471 mh-index-sequenced-messages)
472 (mh-defun-show-buffer mh-show-catchup mh-catchup)
473 (mh-defun-show-buffer mh-show-ps-print-toggle-color mh-ps-print-toggle-color)
474 (mh-defun-show-buffer mh-show-ps-print-toggle-faces mh-ps-print-toggle-faces)
475 (mh-defun-show-buffer mh-show-ps-print-msg-file mh-ps-print-msg-file)
476 (mh-defun-show-buffer mh-show-ps-print-msg mh-ps-print-msg)
477 (mh-defun-show-buffer mh-show-toggle-mime-buttons mh-toggle-mime-buttons)
478 (mh-defun-show-buffer mh-show-display-with-external-viewer
479 mh-display-with-external-viewer)
483 ;;; Sequence Menu
485 (easy-menu-define
486 mh-show-sequence-menu mh-show-mode-map "Menu for MH-E folder-sequence."
487 '("Sequence"
488 ["Add Message to Sequence..." mh-show-put-msg-in-seq t]
489 ["List Sequences for Message" mh-show-msg-is-in-seq t]
490 ["Delete Message from Sequence..." mh-show-delete-msg-from-seq t]
491 ["List Sequences in Folder..." mh-show-list-sequences t]
492 ["Delete Sequence..." mh-show-delete-seq t]
493 ["Narrow to Sequence..." mh-show-narrow-to-seq t]
494 ["Widen from Sequence" mh-show-widen t]
495 "--"
496 ["Narrow to Subject Sequence" mh-show-narrow-to-subject t]
497 ["Narrow to Tick Sequence" mh-show-narrow-to-tick
498 (save-excursion
499 (set-buffer mh-show-folder-buffer)
500 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq))))]
501 ["Delete Rest of Same Subject" mh-show-delete-subject t]
502 ["Toggle Tick Mark" mh-show-toggle-tick t]
503 "--"
504 ["Push State Out to MH" mh-show-update-sequences t]))
506 ;;; Message Menu
508 (easy-menu-define
509 mh-show-message-menu mh-show-mode-map "Menu for MH-E folder-message."
510 '("Message"
511 ["Show Message" mh-show-show t]
512 ["Show Message with Header" mh-show-header-display t]
513 ["Next Message" mh-show-next-undeleted-msg t]
514 ["Previous Message" mh-show-previous-undeleted-msg t]
515 ["Go to First Message" mh-show-first-msg t]
516 ["Go to Last Message" mh-show-last-msg t]
517 ["Go to Message by Number..." mh-show-goto-msg t]
518 ["Modify Message" mh-show-modify t]
519 ["Delete Message" mh-show-delete-msg t]
520 ["Refile Message" mh-show-refile-msg t]
521 ["Undo Delete/Refile" mh-show-undo t]
522 ["Process Delete/Refile" mh-show-execute-commands t]
523 "--"
524 ["Compose a New Message" mh-send t]
525 ["Reply to Message..." mh-show-reply t]
526 ["Forward Message..." mh-show-forward t]
527 ["Redistribute Message..." mh-show-redistribute t]
528 ["Edit Message Again" mh-show-edit-again t]
529 ["Re-edit a Bounced Message" mh-show-extract-rejected-mail t]
530 "--"
531 ["Copy Message to Folder..." mh-show-copy-msg t]
532 ["Print Message" mh-show-print-msg t]
533 ["Write Message to File..." mh-show-write-msg-to-file t]
534 ["Pipe Message to Command..." mh-show-pipe-msg t]
535 ["Unpack Uuencoded Message..." mh-show-store-msg t]
536 ["Burst Digest Message" mh-show-burst-digest t]))
538 ;;; Folder Menu
540 (easy-menu-define
541 mh-show-folder-menu mh-show-mode-map "Menu for MH-E folder."
542 '("Folder"
543 ["Incorporate New Mail" mh-show-inc-folder t]
544 ["Toggle Show/Folder" mh-show-toggle-showing t]
545 ["Execute Delete/Refile" mh-show-execute-commands t]
546 ["Rescan Folder" mh-show-rescan-folder t]
547 ["Thread Folder" mh-show-toggle-threads t]
548 ["Pack Folder" mh-show-pack-folder t]
549 ["Sort Folder" mh-show-sort-folder t]
550 "--"
551 ["List Folders" mh-show-list-folders t]
552 ["Visit a Folder..." mh-show-visit-folder t]
553 ["View New Messages" mh-show-index-new-messages t]
554 ["Search..." mh-search t]
555 "--"
556 ["Quit MH-E" mh-quit t]))
560 ;;; MH-Show Keys
562 (gnus-define-keys mh-show-mode-map
563 " " mh-show-page-msg
564 "!" mh-show-refile-or-write-again
565 "'" mh-show-toggle-tick
566 "," mh-show-header-display
567 "." mh-show-show
568 ">" mh-show-write-message-to-file
569 "?" mh-help
570 "E" mh-show-extract-rejected-mail
571 "M" mh-show-modify
572 "\177" mh-show-previous-page
573 "\C-d" mh-show-delete-msg-no-motion
574 "\t" mh-show-next-button
575 [backtab] mh-show-prev-button
576 "\M-\t" mh-show-prev-button
577 "\ed" mh-show-redistribute
578 "^" mh-show-refile-msg
579 "c" mh-show-copy-msg
580 "d" mh-show-delete-msg
581 "e" mh-show-edit-again
582 "f" mh-show-forward
583 "g" mh-show-goto-msg
584 "i" mh-show-inc-folder
585 "k" mh-show-delete-subject-or-thread
586 "m" mh-show-send
587 "n" mh-show-next-undeleted-msg
588 "\M-n" mh-show-next-unread-msg
589 "o" mh-show-refile-msg
590 "p" mh-show-previous-undeleted-msg
591 "\M-p" mh-show-previous-unread-msg
592 "q" mh-show-quit
593 "r" mh-show-reply
594 "s" mh-show-send
595 "t" mh-show-toggle-showing
596 "u" mh-show-undo
597 "x" mh-show-execute-commands
598 "v" mh-show-index-visit-folder
599 "|" mh-show-pipe-msg)
601 (gnus-define-keys (mh-show-folder-map "F" mh-show-mode-map)
602 "?" mh-prefix-help
603 "'" mh-index-ticked-messages
604 "S" mh-show-sort-folder
605 "c" mh-show-catchup
606 "f" mh-show-visit-folder
607 "k" mh-show-kill-folder
608 "l" mh-show-list-folders
609 "n" mh-index-new-messages
610 "o" mh-show-visit-folder
611 "q" mh-show-index-sequenced-messages
612 "r" mh-show-rescan-folder
613 "s" mh-search
614 "t" mh-show-toggle-threads
615 "u" mh-show-undo-folder
616 "v" mh-show-visit-folder)
618 (gnus-define-keys (mh-show-sequence-map "S" mh-show-mode-map)
619 "'" mh-show-narrow-to-tick
620 "?" mh-prefix-help
621 "d" mh-show-delete-msg-from-seq
622 "k" mh-show-delete-seq
623 "l" mh-show-list-sequences
624 "n" mh-show-narrow-to-seq
625 "p" mh-show-put-msg-in-seq
626 "s" mh-show-msg-is-in-seq
627 "w" mh-show-widen)
629 (define-key mh-show-mode-map "I" mh-inc-spool-map)
631 (gnus-define-keys (mh-show-junk-map "J" mh-show-mode-map)
632 "?" mh-prefix-help
633 "b" mh-show-junk-blacklist
634 "w" mh-show-junk-whitelist)
636 (gnus-define-keys (mh-show-ps-print-map "P" mh-show-mode-map)
637 "?" mh-prefix-help
638 "C" mh-show-ps-print-toggle-color
639 "F" mh-show-ps-print-toggle-faces
640 "f" mh-show-ps-print-msg-file
641 "l" mh-show-print-msg
642 "p" mh-show-ps-print-msg)
644 (gnus-define-keys (mh-show-thread-map "T" mh-show-mode-map)
645 "?" mh-prefix-help
646 "u" mh-show-thread-ancestor
647 "p" mh-show-thread-previous-sibling
648 "n" mh-show-thread-next-sibling
649 "t" mh-show-toggle-threads
650 "d" mh-show-thread-delete
651 "o" mh-show-thread-refile)
653 (gnus-define-keys (mh-show-limit-map "/" mh-show-mode-map)
654 "'" mh-show-narrow-to-tick
655 "?" mh-prefix-help
656 "c" mh-show-narrow-to-cc
657 "g" mh-show-narrow-to-range
658 "m" mh-show-narrow-to-from
659 "s" mh-show-narrow-to-subject
660 "t" mh-show-narrow-to-to
661 "w" mh-show-widen)
663 (gnus-define-keys (mh-show-extract-map "X" mh-show-mode-map)
664 "?" mh-prefix-help
665 "s" mh-show-store-msg
666 "u" mh-show-store-msg)
668 (gnus-define-keys (mh-show-digest-map "D" mh-show-mode-map)
669 "?" mh-prefix-help
670 " " mh-show-page-digest
671 "\177" mh-show-page-digest-backwards
672 "b" mh-show-burst-digest)
674 (gnus-define-keys (mh-show-mime-map "K" mh-show-mode-map)
675 "?" mh-prefix-help
676 "a" mh-mime-save-parts
677 "e" mh-show-display-with-external-viewer
678 "v" mh-show-toggle-mime-part
679 "o" mh-show-save-mime-part
680 "i" mh-show-inline-mime-part
681 "t" mh-show-toggle-mime-buttons
682 "\t" mh-show-next-button
683 [backtab] mh-show-prev-button
684 "\M-\t" mh-show-prev-button)
688 ;;; MH-Show Font Lock
690 (defun mh-header-field-font-lock (field limit)
691 "Return the value of a header field FIELD to font-lock.
692 Argument LIMIT limits search."
693 (if (= (point) limit)
695 (let* ((mail-header-end (mh-mail-header-end))
696 (lesser-limit (if (< mail-header-end limit) mail-header-end limit))
697 (case-fold-search t))
698 (when (and (< (point) mail-header-end) ;Only within header
699 (re-search-forward (format "^%s" field) lesser-limit t))
700 (let ((match-one-b (match-beginning 0))
701 (match-one-e (match-end 0)))
702 (mh-header-field-end)
703 (if (> (point) limit) ;Don't search for end beyond limit
704 (goto-char limit))
705 (set-match-data (list match-one-b match-one-e
706 (1+ match-one-e) (point)))
707 t)))))
709 (defun mh-header-to-font-lock (limit)
710 "Return the value of a header field To to font-lock.
711 Argument LIMIT limits search."
712 (mh-header-field-font-lock "To:" limit))
714 (defun mh-header-cc-font-lock (limit)
715 "Return the value of a header field cc to font-lock.
716 Argument LIMIT limits search."
717 (mh-header-field-font-lock "cc:" limit))
719 (defun mh-header-subject-font-lock (limit)
720 "Return the value of a header field Subject to font-lock.
721 Argument LIMIT limits search."
722 (mh-header-field-font-lock "Subject:" limit))
724 (defun mh-letter-header-font-lock (limit)
725 "Return the entire mail header to font-lock.
726 Argument LIMIT limits search."
727 (if (= (point) limit)
729 (let* ((mail-header-end (save-match-data (mh-mail-header-end)))
730 (lesser-limit (if (< mail-header-end limit) mail-header-end limit)))
731 (when (mh-in-header-p)
732 (set-match-data (list 1 lesser-limit))
733 (goto-char lesser-limit)
734 t))))
736 (defun mh-show-font-lock-fontify-region (beg end loudly)
737 "Limit font-lock in `mh-show-mode' to the header.
739 Used when the option `mh-highlight-citation-style' is set to
740 \"Gnus\", leaving the body to be dealt with by Gnus highlighting.
741 The region between BEG and END is given over to be fontified and
742 LOUDLY controls if a user sees a message about the fontification
743 operation."
744 (let ((header-end (mh-mail-header-end)))
745 (cond
746 ((and (< beg header-end)(< end header-end))
747 (font-lock-default-fontify-region beg end loudly))
748 ((and (< beg header-end)(>= end header-end))
749 (font-lock-default-fontify-region beg header-end loudly))
751 nil))))
753 (defvar mh-show-font-lock-keywords
754 '(("^\\(From:\\|Sender:\\)\\(.*\\)"
755 (1 'default)
756 (2 'mh-show-from))
757 (mh-header-to-font-lock
758 (0 'default)
759 (1 'mh-show-to))
760 (mh-header-cc-font-lock
761 (0 'default)
762 (1 'mh-show-cc))
763 ("^\\(Reply-To:\\|Return-Path:\\)\\(.*\\)$"
764 (1 'default)
765 (2 'mh-show-from))
766 (mh-header-subject-font-lock
767 (0 'default)
768 (1 'mh-show-subject))
769 ("^\\(Apparently-To:\\|Newsgroups:\\)\\(.*\\)"
770 (1 'default)
771 (2 'mh-show-cc))
772 ("^\\(In-reply-to\\|Date\\):\\(.*\\)$"
773 (1 'default)
774 (2 'mh-show-date))
775 (mh-letter-header-font-lock
776 (0 'mh-show-header append t)))
777 "Additional expressions to highlight in MH-Show buffers.")
779 ;;;###mh-autoload
780 (defun mh-show-font-lock-keywords ()
781 "Return variable `mh-show-font-lock-keywords'."
782 mh-show-font-lock-keywords)
784 (defvar mh-show-font-lock-keywords-with-cite
785 (let* ((cite-chars "[>|}]")
786 (cite-prefix "A-Za-z")
787 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
788 (append
789 mh-show-font-lock-keywords
790 (list
791 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
792 `(,cite-chars
793 (,(concat "\\=[ \t]*"
794 "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
795 "\\(" cite-chars "[ \t]*\\)\\)+"
796 "\\(.*\\)")
797 (beginning-of-line) (end-of-line)
798 (2 font-lock-constant-face nil t)
799 (4 font-lock-comment-face nil t))))))
800 "Additional expressions to highlight in MH-Show buffers.")
802 ;;;###mh-autoload
803 (defun mh-show-font-lock-keywords-with-cite ()
804 "Return variable `mh-show-font-lock-keywords-with-cite'."
805 mh-show-font-lock-keywords-with-cite)
809 ;;; MH-Show Mode
811 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
812 (put 'mh-show-mode 'mode-class 'special)
814 ;; Shush compiler.
815 (eval-when-compile (defvar font-lock-auto-fontify))
817 ;;;###mh-autoload
818 (define-derived-mode mh-show-mode text-mode "MH-Show"
819 "Major mode for showing messages in MH-E.\\<mh-show-mode-map>
821 The hook `mh-show-mode-hook' is called upon entry to this mode.
823 See also `mh-folder-mode'.
825 \\{mh-show-mode-map}"
826 (set (make-local-variable 'mail-header-separator) mh-mail-header-separator)
827 (setq paragraph-start (default-value 'paragraph-start))
828 (mh-show-unquote-From)
829 (mh-show-xface)
830 (mh-show-addr)
831 (setq buffer-invisibility-spec '((vanish . t) t))
832 (set (make-local-variable 'line-move-ignore-invisible) t)
833 (make-local-variable 'font-lock-defaults)
834 ;;(set (make-local-variable 'font-lock-support-mode) nil)
835 (cond
836 ((equal mh-highlight-citation-style 'font-lock)
837 (setq font-lock-defaults '(mh-show-font-lock-keywords-with-cite t)))
838 ((equal mh-highlight-citation-style 'gnus)
839 (setq font-lock-defaults '((mh-show-font-lock-keywords)
840 t nil nil nil
841 (font-lock-fontify-region-function
842 . mh-show-font-lock-fontify-region)))
843 (mh-gnus-article-highlight-citation))
845 (setq font-lock-defaults '(mh-show-font-lock-keywords t))))
846 (if (and mh-xemacs-flag
847 font-lock-auto-fontify)
848 (turn-on-font-lock))
849 (set (make-local-variable 'tool-bar-map) mh-show-tool-bar-map)
850 (mh-funcall-if-exists mh-tool-bar-init :show)
851 (when mh-decode-mime-flag
852 (mh-make-local-hook 'kill-buffer-hook)
853 (add-hook 'kill-buffer-hook 'mh-mime-cleanup nil t))
854 (easy-menu-add mh-show-sequence-menu)
855 (easy-menu-add mh-show-message-menu)
856 (easy-menu-add mh-show-folder-menu)
857 (make-local-variable 'mh-show-folder-buffer)
858 (buffer-disable-undo)
859 (setq buffer-read-only t)
860 (use-local-map mh-show-mode-map))
864 ;;; Support Routines
866 (defun mh-show-unquote-From ()
867 "Decode >From at beginning of lines for `mh-show-mode'."
868 (save-excursion
869 (let ((modified (buffer-modified-p))
870 (case-fold-search nil)
871 (buffer-read-only nil))
872 (goto-char (mh-mail-header-end))
873 (while (re-search-forward "^>From" nil t)
874 (replace-match "From"))
875 (set-buffer-modified-p modified))))
877 ;;;###mh-autoload
878 (defun mh-show-addr ()
879 "Use `goto-address'."
880 (when mh-show-use-goto-addr-flag
881 (require 'goto-addr nil t)
882 (if (fboundp 'goto-address)
883 (goto-address))))
885 ;;;###mh-autoload
886 (defun mh-gnus-article-highlight-citation ()
887 "Highlight cited text in current buffer using Gnus."
888 (interactive)
889 ;; Don't allow Gnus to create buttons while highlighting, maybe this is bad
890 ;; style?
891 (flet ((gnus-article-add-button (&rest args) nil))
892 (let* ((modified (buffer-modified-p))
893 (gnus-article-buffer (buffer-name))
894 (gnus-cite-face-list `(,@(cdr gnus-cite-face-list)
895 ,(car gnus-cite-face-list))))
896 (gnus-article-highlight-citation t)
897 (set-buffer-modified-p modified))))
899 (provide 'mh-show)
901 ;; Local Variables:
902 ;; indent-tabs-mode: nil
903 ;; sentence-end-double-space: nil
904 ;; End:
906 ;; arch-tag: 8607a80a-9b5c-43a7-a25d-d7e4a848c25b
907 ;;; mh-show.el ends here