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