tm4.7.0.
[elisp/tm.git] / tm-mh-e3.el
1 ;;;
2 ;;; $Id: tm-mh-e3.el,v 1.1 1994/07/10 20:03:10 morioka Exp morioka $
3 ;;;
4 ;;; This is a part of tm-mh-e.el which is a module for old mh-e
5 ;;; to emulate mh-e 4.0.
6 ;;;
7 ;;; This module imports from mh-e 3.8 and 4.0.
8 ;;;
9
10 (provide 'tm-mh-e3)
11
12 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
13 (put 'mh-show-mode 'mode-class 'special)
14
15 (defun mh-show-mode ()
16   "Major mode for showing messages in mh-e.
17 The value of mh-show-mode-hook is called when a new message is displayed."
18   (kill-all-local-variables)
19   (setq major-mode 'mh-show-mode)
20   (mh-set-mode-name "MH-Show")
21   (run-hooks 'mh-show-mode-hook))
22
23 (defun mh-display-msg (msg-num folder)
24   ;; Display message NUMBER of FOLDER.
25   ;; Sets the current buffer to the show buffer.
26   (set-buffer folder)
27   ;; Bind variables in folder buffer in case they are local
28   (let ((formfile mhl-formfile)
29         (clean-message-header mh-clean-message-header)
30         (invisible-headers mh-invisible-headers)
31         (visible-headers mh-visible-headers)
32         (msg-filename (mh-msg-filename msg-num))
33         (show-buffer mh-show-buffer)
34         (folder mh-current-folder))
35     (if (not (file-exists-p msg-filename))
36         (error "Message %d does not exist" msg-num))
37     (switch-to-buffer show-buffer)
38     (if mh-bury-show-buffer (bury-buffer (current-buffer)))
39     (mh-when (or (not (equal msg-filename buffer-file-name)))
40              ;; Buffer does not yet contain message.
41              (clear-visited-file-modtime)
42              (unlock-buffer)
43              (setq buffer-file-name nil)        ; no locking during setup
44              (erase-buffer)
45              (if formfile
46                  (if (stringp formfile)
47                      (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
48                                              "-form" formfile msg-filename)
49                    (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
50                                            msg-filename))
51                (insert-file-contents msg-filename))
52              (goto-char (point-min))
53              (cond (clean-message-header
54                     (mh-clean-msg-header (point-min)
55                                          invisible-headers
56                                          visible-headers)
57                     (goto-char (point-min)))
58                    (t
59                     (let ((case-fold-search t))
60                       (re-search-forward
61                        "^To:\\|^From:\\|^Subject:\\|^Date:" nil t)
62                       (beginning-of-line)
63                       (mh-recenter 0))))
64              (set-buffer-modified-p nil)
65              (setq buffer-file-name msg-filename)
66              (set-mark nil)
67              (mh-show-mode)
68              (setq mode-line-buffer-identification
69                    (list (format mh-show-buffer-mode-line-buffer-id
70                                  folder msg-num))))))
71
72 (fset 'mh-show-msg 'mh-show)