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