update.
[elisp/semi.git] / semi-setup.el
1 ;;; semi-setup.el --- setup file for MIME-View.
2
3 ;; Copyright (C) 1994,1995,1996,1997,1998 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 SEMI (Setting for Emacs MIME Interfaces).
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 'semi-def)
28 (require 'path-util)
29
30 (defun call-after-loaded (module func &optional hook-name)
31   "If MODULE is provided, then FUNC is called.
32 Otherwise func is set to MODULE-load-hook.
33 If optional argument HOOK-NAME is specified,
34 it is used as hook to set."
35   (if (featurep module)
36       (funcall func)
37     (or hook-name
38         (setq hook-name (intern (concat (symbol-name module) "-load-hook"))))
39     (add-hook hook-name func)))
40
41
42 ;; for image/* and X-Face
43 (defvar mime-setup-enable-inline-image
44   (and window-system
45        (or (featurep 'xemacs) (featurep 'mule)))
46   "*If it is non-nil, semi-setup sets up to use mime-image.")
47
48 (if mime-setup-enable-inline-image
49     (eval-after-load "mime-view"
50       '(require 'mime-image)))
51
52 ;; for text/html
53 (defvar mime-setup-enable-inline-html
54   (module-installed-p 'w3)
55   "*If it is non-nil, semi-setup sets up to use mime-w3.")
56
57 (if mime-setup-enable-inline-html
58     (call-after-loaded
59      'mime-view
60      (function
61       (lambda ()
62         (autoload 'mime-preview-text/html "mime-w3")
63         
64         (ctree-set-calist-strictly
65          'mime-preview-condition
66          '((type . text)(subtype . html)
67            (body . visible)
68            (body-presentation-method . mime-preview-text/html)))
69         
70         (set-alist 'mime-view-type-subtype-score-alist
71                    '(text . html) 3)))))
72
73
74 ;; for PGP
75 (defvar mime-setup-enable-pgp t
76   "*If it is non-nil, semi-setup sets up to use mime-pgp.")
77
78 (if mime-setup-enable-pgp
79     (eval-after-load "mime-view"
80       '(progn
81          (mime-add-condition
82           'preview '((type . application)(subtype . pgp)
83                      (message-button . visible)))
84          (mime-add-condition
85           'action '((type . application)(subtype . pgp)
86                     (method . mime-view-application/pgp))
87           'strict "mime-pgp")
88          (mime-add-condition
89           'action '((type . text)(subtype . x-pgp)
90                     (method . mime-view-application/pgp)))
91          
92          (mime-add-condition
93           'action '((type . multipart)(subtype . signed)
94                     (method . mime-verify-multipart/signed))
95           'strict "mime-pgp")
96          
97          (mime-add-condition
98           'action
99           '((type . application)(subtype . pgp-signature)
100             (method . mime-verify-application/pgp-signature))
101           'strict "mime-pgp")
102          
103          (mime-add-condition
104           'action
105           '((type . application)(subtype . pgp-encrypted)
106             (method . mime-decrypt-application/pgp-encrypted))
107           'strict "mime-pgp")
108          
109          (mime-add-condition
110           'action
111           '((type . application)(subtype . pgp-keys)
112             (method . mime-add-application/pgp-keys))
113           'strict "mime-pgp")
114
115          (mime-add-condition
116           'action
117           '((type . application)(subtype . pkcs7-signature)
118             (method . mime-verify-application/pkcs7-signature))
119           'strict "mime-pgp")
120
121          (mime-add-condition
122           'action
123           '((type . application)(subtype . x-pkcs7-signature)
124             (method . mime-verify-application/pkcs7-signature))
125           'strict "mime-pgp")
126          
127          (mime-add-condition
128           'action
129           '((type . application)(subtype . pkcs7-mime)
130             (method . mime-view-application/pkcs7-mime))
131           'strict "mime-pgp")
132
133          (mime-add-condition
134           'action
135           '((type . application)(subtype . x-pkcs7-mime)
136             (method . mime-view-application/pkcs7-mime))
137           'strict "mime-pgp"))))
138
139
140 ;;; @ for mime-edit
141 ;;;
142
143 (defun mime-setup-decode-message-header ()
144   (save-excursion
145     (save-restriction
146       (goto-char (point-min))
147       (narrow-to-region
148        (point-min)
149        (if (re-search-forward
150             (concat "^" (regexp-quote mail-header-separator) "$")
151             nil t)
152            (match-beginning 0)
153          (point-max)))
154       (mime-decode-header-in-buffer)
155       (set-buffer-modified-p nil))))
156
157 (add-hook 'mime-edit-mode-hook 'mime-setup-decode-message-header)
158
159
160 ;;; @@ variables
161 ;;;
162
163 (defvar mime-setup-use-signature t
164   "If it is not nil, mime-setup sets up to use signature.el.")
165
166 (defvar mime-setup-default-signature-key "\C-c\C-s"
167   "*Key to insert signature.")
168
169 (defvar mime-setup-signature-key-alist '((mail-mode . "\C-c\C-w"))
170   "Alist of major-mode vs. key to insert signature.")
171
172
173 ;;; @@ for signature
174 ;;;
175
176 (defun mime-setup-set-signature-key ()
177   (let ((keymap (current-local-map)))
178     (if keymap
179         (let ((key
180                (or (cdr (assq major-mode mime-setup-signature-key-alist))
181                    mime-setup-default-signature-key)))
182           (define-key keymap key (function insert-signature))))))
183
184 (when mime-setup-use-signature
185   (autoload 'insert-signature "signature" "Insert signature" t)
186   (add-hook 'mime-edit-mode-hook 'mime-setup-set-signature-key)
187   ;; (setq message-signature nil)
188   )
189
190
191 ;;; @ for mu-cite
192 ;;;
193
194 (add-hook 'mu-cite/pre-cite-hook 'eword-decode-header)
195
196
197 ;;; @ end
198 ;;;
199
200 (provide 'semi-setup)
201
202 ;;; semi-setup.el ends here