update.
[elisp/semi.git] / semi-def.el
1 ;;; semi-def.el --- definition module for SEMI
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: definition, MIME, multimedia, mail, news
7
8 ;; This file is part of SEMI (Spadework 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 'emu)
28
29 (defconst mime-module-version '("SEMI" "Arimagawa" 1 2 4)
30   "Implementation name, version name and numbers of MIME-kernel package.")
31
32 (autoload 'mule-caesar-region "mule-caesar"
33   "Caesar rotation of current region." t)
34
35
36 ;;; @ variables
37 ;;;
38
39 (defvar mime/use-multi-frame
40   (and (>= emacs-major-version 19) window-system))
41
42 (defvar mime/find-file-function
43   (if mime/use-multi-frame
44       (function find-file-other-frame)
45     (function find-file)
46     ))
47
48
49 ;;; @ constants
50 ;;;
51
52 (defconst mime-echo-buffer-name "*MIME-echo*"
53   "Name of buffer to display MIME-playing information.")
54
55 (defconst mime-temp-buffer-name " *MIME-temp*")
56
57
58 ;;; @ button
59 ;;;
60
61 (defcustom mime-button-face 'bold
62   "Face used for content-button or URL-button of MIME-Preview buffer."
63   :group 'mime
64   :type 'face)
65
66 (defcustom mime-button-mouse-face 'highlight
67   "Face used for MIME-preview buffer mouse highlighting."
68   :group 'mime
69   :type 'face)
70
71 (defsubst mime-add-button (from to function &optional data)
72   "Create a button between FROM and TO with callback FUNCTION and DATA."
73   (let ((overlay (make-overlay from to)))
74     (and mime-button-face
75          (overlay-put overlay 'face mime-button-face))
76     (and mime-button-mouse-face
77          (overlay-put overlay 'mouse-face mime-button-mouse-face))
78     (add-text-properties from to (list 'mime-button-callback function))
79     (and data
80          (add-text-properties from to (list 'mime-button-data data)))
81     ;;(add-text-properties from to (list 'keymap widget-keymap))
82     ))
83
84 (defsubst mime-insert-button (string function &optional data)
85   "Insert STRING as button with callback FUNCTION and DATA."
86   (save-restriction
87     (narrow-to-region (point)(point))
88     (insert (concat "[" string "]"))
89     ;; (widget-push-button-value-create
90     ;;  (widget-convert 'push-button
91     ;;                  :notify (lambda (&rest ignore)
92     ;;                            (mime-preview-play-current-entity)
93     ;;                            )
94     ;;                  string))
95     (insert "\n")
96     (mime-add-button (point-min)(point-max) function data)
97     ))
98
99 (defvar mime-button-mother-dispatcher nil)
100
101 (defun mime-button-dispatcher (event)
102   "Select the button under point."
103   (interactive "e")
104   (let (buf point func data)
105     (save-window-excursion
106       (mouse-set-point event)
107       (setq buf (current-buffer)
108             point (point)
109             func (get-text-property (point) 'mime-button-callback)
110             data (get-text-property (point) 'mime-button-data)
111             )
112       )
113     (save-excursion
114       (set-buffer buf)
115       (goto-char point)
116       (if func
117           (apply func data)
118         (if (fboundp mime-button-mother-dispatcher)
119             (funcall mime-button-mother-dispatcher event)
120           )
121         ))))
122
123
124 ;;; @ PGP
125 ;;;
126
127 (defvar pgp-function-alist
128   '(
129     ;; for mime-pgp
130     (verify             mc-verify                       "mc-toplev")
131     (decrypt            mc-decrypt                      "mc-toplev")
132     (fetch-key          mc-pgp-fetch-key                "mc-pgp")
133     (snarf-keys         mc-snarf-keys                   "mc-toplev")
134     ;; for mime-edit
135     (mime-sign          mime-mc-pgp-sign-region         "mime-mc")
136     (traditional-sign   mc-pgp-sign-region              "mc-pgp")
137     (encrypt            mime-mc-pgp-encrypt-region      "mime-mc")
138     (insert-key         mc-insert-public-key            "mc-toplev")
139     )
140   "Alist of service names vs. corresponding functions and its filenames.
141 Each element looks like (SERVICE FUNCTION FILE).
142
143 SERVICE is a symbol of PGP processing.  It allows `verify', `decrypt',
144 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
145 or `insert-key'.
146
147 Function is a symbol of function to do specified SERVICE.
148
149 FILE is string of filename which has definition of corresponding
150 FUNCTION.")
151
152 (defmacro pgp-function (method)
153   "Return function to do service METHOD."
154   `(cadr (assq ,method (symbol-value 'pgp-function-alist)))
155   )
156
157 (mapcar (function
158          (lambda (method)
159            (autoload (cadr method)(nth 2 method))
160            ))
161         pgp-function-alist)
162
163
164 ;;; @ method selector kernel
165 ;;;
166
167 (require 'atype)
168
169 ;;; @@ field unifier
170 ;;;
171
172 (defun field-unifier-for-mode (a b)
173   (let ((va (cdr a)))
174     (if (if (consp va)
175             (member (cdr b) va)
176           (equal va (cdr b))
177           )
178         (list nil b nil)
179       )))
180
181
182 ;;; @ field
183 ;;;
184
185 (defun tm:set-fields (sym field-list &optional regexp-sym)
186   (or regexp-sym
187       (setq regexp-sym
188             (let ((name (symbol-name sym)))
189               (intern
190                (concat (if (string-match "\\(.*\\)-list" name)
191                            (substring name 0 (match-end 1))
192                          name)
193                        "-regexp")
194                )))
195       )
196   (set sym field-list)
197   (set regexp-sym
198        (concat "^" (apply (function regexp-or) field-list) ":"))
199   )
200
201 (defun tm:add-fields (sym field-list &optional regexp-sym)
202   (or regexp-sym
203       (setq regexp-sym
204             (let ((name (symbol-name sym)))
205               (intern
206                (concat (if (string-match "\\(.*\\)-list" name)
207                            (substring name 0 (match-end 1))
208                          name)
209                        "-regexp")
210                )))
211       )
212   (let ((fields (eval sym)))
213     (mapcar (function
214              (lambda (field)
215                (or (member field fields)
216                    (setq fields (cons field fields))
217                    )
218                ))
219             (reverse field-list)
220             )
221     (set regexp-sym
222          (concat "^" (apply (function regexp-or) fields) ":"))
223     (set sym fields)
224     ))
225
226 (defun tm:delete-fields (sym field-list &optional regexp-sym)
227   (or regexp-sym
228       (setq regexp-sym
229             (let ((name (symbol-name sym)))
230               (intern
231                (concat (if (string-match "\\(.*\\)-list" name)
232                            (substring name 0 (match-end 1))
233                          name)
234                        "-regexp")
235                )))
236       )
237   (let ((fields (eval sym)))
238     (mapcar (function
239              (lambda (field)
240                (setq fields (delete field fields))
241                ))
242             field-list)
243     (set regexp-sym
244          (concat "^" (apply (function regexp-or) fields) ":"))
245     (set sym fields)
246     ))
247
248
249 ;;; @ RCS version
250 ;;;
251
252 (defsubst get-version-string (id)
253   "Return a version-string from RCS ID."
254   (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
255        (substring id (match-beginning 1)(match-end 1))
256        ))
257
258
259 ;;; @ Other Utility
260 ;;;
261
262 (defun call-after-loaded (module func &optional hook-name)
263   "If MODULE is provided, then FUNC is called.
264 Otherwise func is set to MODULE-load-hook.
265 If optional argument HOOK-NAME is specified,
266 it is used as hook to set."
267   (if (featurep module)
268       (funcall func)
269     (or hook-name
270         (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
271         )
272     (add-hook hook-name func)
273     ))
274
275
276 ;;; @ end
277 ;;;
278
279 (provide 'semi-def)
280
281 ;;; semi-def.el ends here