(What's tm?): Don't use section number.
[elisp/tm.git] / mime-setup.el.in
1 ;;; mime-setup.el --- setup file for tm viewer and composer.
2
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME, multimedia, multilingual, encoded-word
7
8 ;; This file is part of tm (Tools for MIME).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'tm-setup)
28
29 (autoload 'mime/editor-mode "tm-edit"
30   "Minor mode for editing MIME message." t)
31 (autoload 'mime-decode-header-in-buffer "eword-decode"
32   "Decode MIME encoded-words in message header." t)
33
34 (defun mime-setup-decode-message-header ()
35   (save-excursion
36     (save-restriction
37       (goto-char (point-min))
38       (narrow-to-region
39        (point-min)
40        (if (re-search-forward
41             (concat "^" (regexp-quote mail-header-separator) "$")
42             nil t)
43            (match-beginning 0)
44          (point-max)
45          ))
46       (mime-decode-header-in-buffer)
47       (set-buffer-modified-p nil)
48       )))
49
50 (add-hook 'mime/editor-mode-hook 'mime-setup-decode-message-header)
51
52
53 ;;; @ variables
54 ;;;
55
56 (defvar mime-setup-use-sc nil
57   "If it is not nil, mime-setup requires sc-setup. [mime-setup.el]")
58
59 (defvar mime-setup-use-signature t
60   "If it is not nil, mime-setup sets up to use signature.el.
61 \[mime-setup.el]")
62
63 (defvar mime-setup-default-signature-key "\C-c\C-s"
64   "*Key to insert signature. [mime-setup.el]")
65
66 (defvar mime-setup-signature-key-alist '((mail-mode . "\C-c\C-w"))
67   "Alist of major-mode vs. key to insert signature. [mime-setup.el]")
68
69
70 ;;; @ for signature
71 ;;;
72
73 (defun mime-setup-set-signature-key ()
74   (let ((key (or (cdr (assq major-mode mime-setup-signature-key-alist))
75                  mime-setup-default-signature-key)))
76     (define-key (current-local-map) key (function insert-signature))
77     ))
78
79 (if mime-setup-use-signature
80     (progn
81       (autoload 'insert-signature "signature" "Insert signature" t)
82       (add-hook 'mime/editor-mode-hook 'mime-setup-set-signature-key)
83       (setq gnus-signature-file nil)
84       (setq mail-signature nil)
85       (setq message-signature nil)
86       ))
87
88
89 ;;; @ about SuperCite
90 ;;;
91
92 (if mime-setup-use-sc
93     (require 'sc-setup)
94   )
95
96
97 ;;; @ for mu-cite
98 ;;;
99
100 (add-hook 'mu-cite/pre-cite-hook 'mime-decode-header-in-buffer)
101
102
103 ;;; @ for mail-mode, RMAIL and VM
104 ;;;
105
106 (add-hook 'mail-setup-hook 'mime-decode-header-in-buffer)
107 (add-hook 'mail-setup-hook 'mime/editor-mode 'append)
108 (add-hook 'mail-send-hook  'mime-editor/maybe-translate)
109 (set-alist 'mime-editor/split-message-sender-alist
110            'mail-mode (function
111                        (lambda ()
112                          (interactive)
113                          (funcall send-mail-function)
114                          )))
115
116 ;;; @ for mh-e
117 ;;;
118
119 (defun mime-setup-mh-draft-setting ()
120   (mime/editor-mode)
121   (make-local-variable 'mail-header-separator)
122   (setq mail-header-separator "--------")
123   (save-excursion
124     (goto-char (point-min))
125     (setq buffer-read-only nil)
126     (if (re-search-forward "^-*$" nil t)
127         (progn
128           (replace-match mail-header-separator)
129           (set-buffer-modified-p (buffer-modified-p))
130           ))
131     ))
132
133 (add-hook 'mh-letter-mode-hook 'mime-setup-mh-draft-setting t)
134 (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
135
136
137 ;;; @ for GNUS
138 ;;;
139
140 (add-hook 'news-reply-mode-hook 'mime/editor-mode)
141 (add-hook 'news-inews-hook      'mime-editor/maybe-translate)
142
143
144 ;;; @ for message (September Gnus 0.58 or later)
145 ;;;
146
147 (defun message-maybe-setup-default-charset ()
148   (let ((charset
149          (and (boundp 'gnus-summary-buffer)
150               (buffer-live-p gnus-summary-buffer)
151               (save-excursion
152                 (set-buffer gnus-summary-buffer)
153                 default-mime-charset))))
154     (if charset
155         (progn
156           (make-local-variable 'default-mime-charset)
157           (setq default-mime-charset charset)
158           ))))
159
160 (or (boundp 'epoch::version)
161     (progn
162       (add-hook 'message-setup-hook 'mime/editor-mode)
163       (add-hook 'message-setup-hook 'message-maybe-setup-default-charset)
164       (add-hook 'message-send-hook  'mime-editor/maybe-translate)
165       (add-hook 'message-header-hook 'eword-encode-header)
166       
167       (call-after-loaded
168        'message
169        (function
170         (lambda ()
171           (require 'message-mime)
172           )))
173       ))
174
175
176 ;;; @ end
177 ;;;
178
179 (provide 'mime-setup)
180
181 (run-hooks 'mime-setup-load-hook)
182
183 ;;; mime-setup.el ends here
184 ;;;
185 ;;; Local Variables:
186 ;;; mode: emacs-lisp
187 ;;; End: