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.68 1997-10-02 07:46:27 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.
30 (unless (fboundp 'butlast)
31 (defun butlast (x &optional n)
32 "Returns a copy of LIST with the last N elements removed."
33 (if (and n (<= n 0)) x
34 (nbutlast (copy-sequence x) n)))
36 (defun nbutlast (x &optional n)
37 "Modifies LIST to remove the last N elements."
42 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
46 (defconst semi-version-name "Oyanagi")
48 (autoload 'mule-caesar-region "mule-caesar"
49 "Caesar rotation of current region." t)
55 (defvar mime/use-multi-frame
56 (and (>= emacs-major-version 19) window-system))
58 (defvar mime/find-file-function
59 (if mime/use-multi-frame
60 (function find-file-other-frame)
68 (defconst mime-echo-buffer-name "*MIME-echo*"
69 "Name of buffer to display MIME-playing information.")
71 (defconst mime-temp-buffer-name " *MIME-temp*")
74 ;;; @ definitions about MIME
77 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
78 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
79 (defconst mime-charset-regexp mime-token-regexp)
81 (defconst mime-media-type/subtype-regexp
82 (concat mime-token-regexp "/" mime-token-regexp))
88 (defvar mime-button-face 'bold
89 "Face used for content-button or URL-button of MIME-Preview buffer.")
91 (defvar mime-button-mouse-face 'highlight
92 "Face used for MIME-preview buffer mouse highlighting.")
94 (defsubst mime-add-button (from to function &optional data)
95 "Create a button between FROM and TO with callback FUNCTION and DATA."
96 (let ((overlay (make-overlay from to)))
98 (overlay-put overlay 'face mime-button-face))
99 (and mime-button-mouse-face
100 (overlay-put overlay 'mouse-face mime-button-mouse-face))
101 (add-text-properties from to (list 'mime-button-callback function))
103 (add-text-properties from to (list 'mime-button-data data)))
104 ;;(add-text-properties from to (list 'keymap widget-keymap))
107 (defsubst mime-insert-button (string function &optional data)
108 "Insert STRING as button with callback FUNCTION and DATA."
110 (narrow-to-region (point)(point))
111 (insert (concat "[" string "]"))
112 ;; (widget-push-button-value-create
113 ;; (widget-convert 'push-button
114 ;; :notify (lambda (&rest ignore)
115 ;; (mime-view-play-current-entity)
119 (mime-add-button (point-min)(point-max) function data)
122 (defvar mime-button-mother-dispatcher nil)
124 (defun mime-button-dispatcher (event)
125 "Select the button under point."
127 (let (buf point func data)
128 (save-window-excursion
129 (mouse-set-point event)
130 (setq buf (current-buffer)
132 func (get-text-property (point) 'mime-button-callback)
133 data (get-text-property (point) 'mime-button-data)
141 (if (fboundp mime-button-mother-dispatcher)
142 (funcall mime-button-mother-dispatcher event)
150 (defvar pgp-function-alist
153 (verify mc-verify "mc-toplev")
154 (decrypt mc-decrypt "mc-toplev")
155 (fetch-key mc-pgp-fetch-key "mc-pgp")
156 (snarf-keys mc-snarf-keys "mc-toplev")
158 (mime-sign mime-mc-pgp-sign-region "mime-mc")
159 (traditional-sign mc-pgp-sign-region "mc-pgp")
160 (encrypt mime-mc-pgp-encrypt-region "mime-mc")
161 (insert-key mc-insert-public-key "mc-toplev")
163 "Alist of service names vs. corresponding functions and its filenames.
164 Each element looks like (SERVICE FUNCTION FILE).
166 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
167 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
170 Function is a symbol of function to do specified SERVICE.
172 FILE is string of filename which has definition of corresponding
175 (defmacro pgp-function (method)
176 "Return function to do service METHOD."
177 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
182 (autoload (cadr method)(third method))
187 ;;; @ method selector kernel
195 (defun field-unifier-for-mode (a b)
208 (defsubst regexp-or (&rest args)
209 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
211 (defun tm:set-fields (sym field-list &optional regexp-sym)
214 (let ((name (symbol-name sym)))
216 (concat (if (string-match "\\(.*\\)-list" name)
217 (substring name 0 (match-end 1))
224 (concat "^" (apply (function regexp-or) field-list) ":"))
227 (defun tm:add-fields (sym field-list &optional regexp-sym)
230 (let ((name (symbol-name sym)))
232 (concat (if (string-match "\\(.*\\)-list" name)
233 (substring name 0 (match-end 1))
238 (let ((fields (eval sym)))
241 (or (member field fields)
242 (setq fields (cons field fields))
248 (concat "^" (apply (function regexp-or) fields) ":"))
252 (defun tm:delete-fields (sym field-list &optional regexp-sym)
255 (let ((name (symbol-name sym)))
257 (concat (if (string-match "\\(.*\\)-list" name)
258 (substring name 0 (match-end 1))
263 (let ((fields (eval sym)))
266 (setq fields (delete field fields))
270 (concat "^" (apply (function regexp-or) fields) ":"))
278 (defsubst get-version-string (id)
279 "Return a version-string from RCS ID."
280 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
281 (substring id (match-beginning 1)(match-end 1))
288 (defsubst eliminate-top-spaces (string)
289 "Eliminate top sequence of space or tab in STRING."
290 (if (string-match "^[ \t]+" string)
291 (substring string (match-end 0))
294 (defun call-after-loaded (module func &optional hook-name)
295 "If MODULE is provided, then FUNC is called.
296 Otherwise func is set to MODULE-load-hook.
297 If optional argument HOOK-NAME is specified,
298 it is used as hook to set."
299 (if (featurep module)
302 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
304 (add-hook hook-name func)
313 ;;; mime-def.el ends here