1 ;;; mime-def.el --- definition module for SEMI
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: mime-def.el,v 0.76 1998-02-12 14:28:20 morioka Exp $
7 ;; Keywords: definition, MIME, multimedia, mail, news
9 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
32 "Emacs MIME Interfaces"
36 (custom-handle-keyword 'default-mime-charset :group 'mime
39 (unless (fboundp 'butlast)
40 (defun butlast (x &optional n)
41 "Returns a copy of LIST with the last N elements removed."
42 (if (and n (<= n 0)) x
43 (nbutlast (copy-sequence x) n)))
45 (defun nbutlast (x &optional n)
46 "Modifies LIST to remove the last N elements."
51 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
55 (defconst semi-version-name "Otomaru"
56 "Version name of SEMI-kernel package.")
58 (autoload 'mule-caesar-region "mule-caesar"
59 "Caesar rotation of current region." t)
65 (defvar mime/use-multi-frame
66 (and (>= emacs-major-version 19) window-system))
68 (defvar mime/find-file-function
69 (if mime/use-multi-frame
70 (function find-file-other-frame)
78 (defconst mime-echo-buffer-name "*MIME-echo*"
79 "Name of buffer to display MIME-playing information.")
81 (defconst mime-temp-buffer-name " *MIME-temp*")
84 ;;; @ definitions about MIME
87 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
88 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
89 (defconst mime-charset-regexp mime-token-regexp)
91 (defconst mime-media-type/subtype-regexp
92 (concat mime-token-regexp "/" mime-token-regexp))
98 (defcustom mime-button-face 'bold
99 "Face used for content-button or URL-button of MIME-Preview buffer."
103 (defcustom mime-button-mouse-face 'highlight
104 "Face used for MIME-preview buffer mouse highlighting."
108 (defsubst mime-add-button (from to function &optional data)
109 "Create a button between FROM and TO with callback FUNCTION and DATA."
110 (let ((overlay (make-overlay from to)))
111 (and mime-button-face
112 (overlay-put overlay 'face mime-button-face))
113 (and mime-button-mouse-face
114 (overlay-put overlay 'mouse-face mime-button-mouse-face))
115 (add-text-properties from to (list 'mime-button-callback function))
117 (add-text-properties from to (list 'mime-button-data data)))
118 ;;(add-text-properties from to (list 'keymap widget-keymap))
121 (defsubst mime-insert-button (string function &optional data)
122 "Insert STRING as button with callback FUNCTION and DATA."
124 (narrow-to-region (point)(point))
125 (insert (concat "[" string "]"))
126 ;; (widget-push-button-value-create
127 ;; (widget-convert 'push-button
128 ;; :notify (lambda (&rest ignore)
129 ;; (mime-view-play-current-entity)
133 (mime-add-button (point-min)(point-max) function data)
136 (defvar mime-button-mother-dispatcher nil)
138 (defun mime-button-dispatcher (event)
139 "Select the button under point."
141 (let (buf point func data)
142 (save-window-excursion
143 (mouse-set-point event)
144 (setq buf (current-buffer)
146 func (get-text-property (point) 'mime-button-callback)
147 data (get-text-property (point) 'mime-button-data)
155 (if (fboundp mime-button-mother-dispatcher)
156 (funcall mime-button-mother-dispatcher event)
164 (defvar pgp-function-alist
167 (verify mc-verify "mc-toplev")
168 (decrypt mc-decrypt "mc-toplev")
169 (fetch-key mc-pgp-fetch-key "mc-pgp")
170 (snarf-keys mc-snarf-keys "mc-toplev")
172 (mime-sign mime-mc-pgp-sign-region "mime-mc")
173 (traditional-sign mc-pgp-sign-region "mc-pgp")
174 (encrypt mime-mc-pgp-encrypt-region "mime-mc")
175 (insert-key mc-insert-public-key "mc-toplev")
177 "Alist of service names vs. corresponding functions and its filenames.
178 Each element looks like (SERVICE FUNCTION FILE).
180 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
181 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
184 Function is a symbol of function to do specified SERVICE.
186 FILE is string of filename which has definition of corresponding
189 (defmacro pgp-function (method)
190 "Return function to do service METHOD."
191 `(cadr (assq ,method (symbol-value 'pgp-function-alist)))
196 (autoload (cadr method)(nth 2 method))
201 ;;; @ method selector kernel
209 (defun field-unifier-for-mode (a b)
222 (defsubst regexp-or (&rest args)
223 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
225 (defun tm:set-fields (sym field-list &optional regexp-sym)
228 (let ((name (symbol-name sym)))
230 (concat (if (string-match "\\(.*\\)-list" name)
231 (substring name 0 (match-end 1))
238 (concat "^" (apply (function regexp-or) field-list) ":"))
241 (defun tm:add-fields (sym field-list &optional regexp-sym)
244 (let ((name (symbol-name sym)))
246 (concat (if (string-match "\\(.*\\)-list" name)
247 (substring name 0 (match-end 1))
252 (let ((fields (eval sym)))
255 (or (member field fields)
256 (setq fields (cons field fields))
262 (concat "^" (apply (function regexp-or) fields) ":"))
266 (defun tm:delete-fields (sym field-list &optional regexp-sym)
269 (let ((name (symbol-name sym)))
271 (concat (if (string-match "\\(.*\\)-list" name)
272 (substring name 0 (match-end 1))
277 (let ((fields (eval sym)))
280 (setq fields (delete field fields))
284 (concat "^" (apply (function regexp-or) fields) ":"))
292 (defsubst get-version-string (id)
293 "Return a version-string from RCS ID."
294 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
295 (substring id (match-beginning 1)(match-end 1))
302 (defsubst eliminate-top-spaces (string)
303 "Eliminate top sequence of space or tab in STRING."
304 (if (string-match "^[ \t]+" string)
305 (substring string (match-end 0))
308 (defun call-after-loaded (module func &optional hook-name)
309 "If MODULE is provided, then FUNC is called.
310 Otherwise func is set to MODULE-load-hook.
311 If optional argument HOOK-NAME is specified,
312 it is used as hook to set."
313 (if (featurep module)
316 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
318 (add-hook hook-name func)
327 ;;; mime-def.el ends here