Require alist.
[elisp/semi.git] / mime-setup.el
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 ;; Version:
7 ;;      $Id: mime-setup.el,v 0.8 1997-02-28 02:22:38 tmorioka Exp $
8 ;; Keywords: MIME, multimedia, multilingual, mail, news
9
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'semi-setup)
30 (require 'alist)
31
32 (autoload 'mime-edit-mode "mime-edit"
33   "Minor mode for editing MIME message." t)
34 (autoload 'eword-decode-header "eword-decode"
35   "Decode MIME encoded-words in header fields." t)
36
37 (defun mime-setup-decode-message-header ()
38   (save-excursion
39     (save-restriction
40       (goto-char (point-min))
41       (narrow-to-region
42        (point-min)
43        (if (re-search-forward
44             (concat "^" (regexp-quote mail-header-separator) "$")
45             nil t)
46            (match-beginning 0)
47          (point-max)
48          ))
49       (eword-decode-header)
50       (set-buffer-modified-p nil)
51       )))
52
53 (add-hook 'mime-edit-mode-hook 'mime-setup-decode-message-header)
54
55
56 ;;; @ variables
57 ;;;
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-edit-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 ;;; @ for mu-cite
90 ;;;
91
92 (add-hook 'mu-cite/pre-cite-hook 'eword-decode-header)
93
94
95 ;;; @ for mail-mode, RMAIL and VM
96 ;;;
97
98 (add-hook 'mail-setup-hook 'eword-decode-header)
99 (add-hook 'mail-setup-hook 'mime-edit-mode 'append)
100 (add-hook 'mail-send-hook  'mime-edit-maybe-translate)
101 (set-alist 'mime-edit-split-message-sender-alist
102            'mail-mode (function
103                        (lambda ()
104                          (interactive)
105                          (funcall send-mail-function)
106                          )))
107
108 ;;; @ for mh-e
109 ;;;
110
111 (defun mime-setup-mh-draft-setting ()
112   (mime-edit-mode)
113   (make-local-variable 'mail-header-separator)
114   (setq mail-header-separator "--------")
115   (save-excursion
116     (goto-char (point-min))
117     (setq buffer-read-only nil)
118     (if (re-search-forward "^-*$" nil t)
119         (progn
120           (replace-match mail-header-separator)
121           (set-buffer-modified-p (buffer-modified-p))
122           ))
123     ))
124
125 (add-hook 'mh-letter-mode-hook 'mime-setup-mh-draft-setting t)
126 (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
127
128
129 ;;; @ for message (September Gnus 0.58 or later)
130 ;;;
131
132 (defun message-maybe-setup-default-charset ()
133   (let ((charset
134          (and (boundp 'gnus-summary-buffer)
135               (buffer-live-p gnus-summary-buffer)
136               (save-excursion
137                 (set-buffer gnus-summary-buffer)
138                 default-mime-charset))))
139     (if charset
140         (progn
141           (make-local-variable 'default-mime-charset)
142           (setq default-mime-charset charset)
143           ))))
144
145 (or (boundp 'epoch::version)
146     (progn
147       (add-hook 'message-setup-hook  'mime-edit-mode)
148       (add-hook 'message-setup-hook  'message-maybe-setup-default-charset)
149       (add-hook 'message-send-hook   'mime-edit-maybe-translate)
150       (add-hook 'message-header-hook 'eword-encode-header)
151       
152       (call-after-loaded
153        'message
154        (function
155         (lambda ()
156           (require 'message-mime)
157           )))
158       ))
159
160
161 ;;; @ end
162 ;;;
163
164 (provide 'mime-setup)
165
166 (run-hooks 'mime-setup-load-hook)
167
168 ;;; mime-setup.el ends here