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