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.65 1997-09-25 16:36:10 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 (defun-maybe butlast (x &optional n)
31 "Returns a copy of LIST with the last N elements removed."
32 (if (and n (<= n 0)) x
33 (nbutlast (copy-sequence x) n)))
35 (defun-maybe nbutlast (x &optional n)
36 "Modifies LIST to remove the last N elements."
41 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
44 (defconst semi-version-name "Hinomiko")
46 (autoload 'mule-caesar-region "mule-caesar"
47 "Caesar rotation of current region." t)
53 (defvar mime/use-multi-frame
54 (and (>= emacs-major-version 19) window-system))
56 (defvar mime/find-file-function
57 (if mime/use-multi-frame
58 (function find-file-other-frame)
66 (defconst mime-echo-buffer-name "*MIME-echo*"
67 "Name of buffer to display MIME-playing information.")
69 (defconst mime-temp-buffer-name " *MIME-temp*")
72 ;;; @ definitions about MIME
75 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
76 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
77 (defconst mime-charset-regexp mime-token-regexp)
79 (defconst mime-media-type/subtype-regexp
80 (concat mime-token-regexp "/" mime-token-regexp))
86 (defvar mime-button-face 'bold
87 "Face used for content-button or URL-button of MIME-Preview buffer.")
89 (defvar mime-button-mouse-face 'highlight
90 "Face used for MIME-preview buffer mouse highlighting.")
92 (defsubst mime-add-button (from to function &optional data)
93 "Create a button between FROM and TO with callback FUNCTION and DATA."
94 (let ((overlay (make-overlay from to)))
96 (overlay-put overlay 'face mime-button-face))
97 (and mime-button-mouse-face
98 (overlay-put overlay 'mouse-face mime-button-mouse-face))
99 (add-text-properties from to (list 'mime-button-callback function))
101 (add-text-properties from to (list 'mime-button-data data)))
102 ;;(add-text-properties from to (list 'keymap widget-keymap))
105 (defsubst mime-insert-button (string function &optional data)
106 "Insert STRING as button with callback FUNCTION and DATA."
108 (narrow-to-region (point)(point))
109 (insert (concat "[" string "]"))
110 ;; (widget-push-button-value-create
111 ;; (widget-convert 'push-button
112 ;; :notify (lambda (&rest ignore)
113 ;; (mime-view-play-current-entity)
117 (mime-add-button (point-min)(point-max) function data)
120 (defvar mime-button-mother-dispatcher nil)
122 (defun mime-button-dispatcher (event)
123 "Select the button under point."
125 (let (buf point func data)
126 (save-window-excursion
127 (mouse-set-point event)
128 (setq buf (current-buffer)
130 func (get-text-property (point) 'mime-button-callback)
131 data (get-text-property (point) 'mime-button-data)
139 (if (fboundp mime-button-mother-dispatcher)
140 (funcall mime-button-mother-dispatcher event)
148 (defvar pgp-function-alist
151 (verify mc-verify "mc-toplev")
152 (decrypt mc-decrypt "mc-toplev")
153 (fetch-key mc-pgp-fetch-key "mc-pgp")
154 (snarf-keys mc-snarf-keys "mc-toplev")
156 (mime-sign mime-mc-pgp-sign-region "mime-mc")
157 (traditional-sign mc-pgp-sign-region "mc-pgp")
158 (encrypt mime-mc-pgp-encrypt-region "mime-mc")
159 (insert-key mc-insert-public-key "mc-toplev")
161 "Alist of service names vs. corresponding functions and its filenames.
162 Each element looks like (SERVICE FUNCTION FILE).
164 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
165 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
168 Function is a symbol of function to do specified SERVICE.
170 FILE is string of filename which has definition of corresponding
173 (defmacro pgp-function (method)
174 "Return function to do service METHOD."
175 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
180 (autoload (second method)(third method))
185 ;;; @ method selector kernel
193 (defun field-unifier-for-mode (a b)
206 (defsubst regexp-or (&rest args)
207 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
209 (defun tm:set-fields (sym field-list &optional regexp-sym)
212 (let ((name (symbol-name sym)))
214 (concat (if (string-match "\\(.*\\)-list" name)
215 (substring name 0 (match-end 1))
222 (concat "^" (apply (function regexp-or) field-list) ":"))
225 (defun tm:add-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))
236 (let ((fields (eval sym)))
239 (or (member field fields)
240 (setq fields (cons field fields))
246 (concat "^" (apply (function regexp-or) fields) ":"))
250 (defun tm:delete-fields (sym field-list &optional regexp-sym)
253 (let ((name (symbol-name sym)))
255 (concat (if (string-match "\\(.*\\)-list" name)
256 (substring name 0 (match-end 1))
261 (let ((fields (eval sym)))
264 (setq fields (delete field fields))
268 (concat "^" (apply (function regexp-or) fields) ":"))
276 (defsubst get-version-string (id)
277 "Return a version-string from RCS ID."
278 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
279 (substring id (match-beginning 1)(match-end 1))
286 (defsubst eliminate-top-spaces (string)
287 "Eliminate top sequence of space or tab in STRING."
288 (if (string-match "^[ \t]+" string)
289 (substring string (match-end 0))
292 (defun call-after-loaded (module func &optional hook-name)
293 "If MODULE is provided, then FUNC is called.
294 Otherwise func is set to MODULE-load-hook.
295 If optional argument HOOK-NAME is specified,
296 it is used as hook to set."
297 (if (featurep module)
300 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
302 (add-hook hook-name func)
311 ;;; mime-def.el ends here