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