tm 7.80.
[elisp/tm.git] / tm-mh-e3.el
1 ;;;
2 ;;; $Id: tm-mh-e3.el,v 1.2 1994/11/01 18:06:16 morioka Exp $
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 &optional show-buffer)
24   ;; Display message NUMBER of FOLDER.
25   ;; Sets the current buffer to the show buffer.
26   (set-buffer folder)
27   (or show-buffer
28       (setq show-buffer mh-show-buffer))
29   ;; Bind variables in folder buffer in case they are local
30   (let ((formfile mhl-formfile)
31         (clean-message-header mh-clean-message-header)
32         (invisible-headers mh-invisible-headers)
33         (visible-headers mh-visible-headers)
34         (msg-filename (mh-msg-filename msg-num))
35         (folder mh-current-folder))
36     (if (not (file-exists-p msg-filename))
37         (error "Message %d does not exist" msg-num))
38     (switch-to-buffer show-buffer)
39     (if mh-bury-show-buffer (bury-buffer (current-buffer)))
40     (mh-when (or (not (equal msg-filename buffer-file-name)))
41              ;; Buffer does not yet contain message.
42              (clear-visited-file-modtime)
43              (unlock-buffer)
44              (setq buffer-file-name nil)        ; no locking during setup
45              (erase-buffer)
46              (if formfile
47                  (if (stringp formfile)
48                      (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
49                                              "-form" formfile msg-filename)
50                    (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
51                                            msg-filename))
52                (insert-file-contents msg-filename))
53              (goto-char (point-min))
54              (cond (clean-message-header
55                     (mh-clean-msg-header (point-min)
56                                          invisible-headers
57                                          visible-headers)
58                     (goto-char (point-min)))
59                    (t
60                     (let ((case-fold-search t))
61                       (re-search-forward
62                        "^To:\\|^From:\\|^Subject:\\|^Date:" nil t)
63                       (beginning-of-line)
64                       (mh-recenter 0))))
65              (set-buffer-modified-p nil)
66              (setq buffer-file-name msg-filename)
67              (set-mark nil)
68              (mh-show-mode)
69              (setq mode-line-buffer-identification
70                    (list (format mh-show-buffer-mode-line-buffer-id
71                                  folder msg-num))))))
72
73 (fset 'mh-show-msg 'mh-show)