1 ;;; semi-def.el --- definition module for SEMI -*- coding: iso-8859-4; -*-
3 ;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: definition, MIME, multimedia, mail, news
8 ;; This file is part of SEMI (Sample of Emacs MIME Implementation).
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.
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.
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.
29 (eval-when-compile (require 'cl))
33 (defconst mime-user-interface-product ["EMIKO" (1 14 0) "Zoomastigophora"]
34 "Product name, version number and code name of MIME-kernel package.")
36 (autoload 'mule-caesar-region "mule-caesar"
37 "Caesar rotation of current region." t)
39 (autoload 'widget-convert-button "wid-edit")
44 (defconst mime-echo-buffer-name "*MIME-echo*"
45 "Name of buffer to display MIME-playing information.")
47 (defconst mime-temp-buffer-name " *MIME-temp*")
53 (define-widget 'mime-button 'link
54 "Widget for MIME button."
55 :action 'mime-button-action)
57 (defun mime-button-action (widget &optional event)
58 (let ((function (widget-get widget :mime-button-callback))
59 (data (widget-get widget :mime-button-data)))
61 (funcall function data))))
63 (defsubst mime-insert-button (string function &optional data)
64 "Insert STRING as button with callback FUNCTION and DATA."
66 (narrow-to-region (point)(point))
67 ;; Maybe we should introduce button formatter such as
68 ;; `gnus-mime-button-line-format'.
69 (insert "[" string "]")
70 ;; XEmacs -- when `widget-glyph-enable' is non nil, widget values are not
71 ;; guaranteed to be underlain.
72 (widget-convert-button 'mime-button (point-min)(point-max)
73 :mime-button-callback function
74 :mime-button-data data)
81 (defcustom mime-browse-url-regexp
82 (concat "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):"
83 "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
84 "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
85 "Regexp to match URL in text body."
89 (defcustom mime-browse-url-function (function browse-url)
90 "Function to browse URL."
94 (define-widget 'mime-url-link 'url-link
95 "A link to an www page.")
97 (defsubst mime-add-url-buttons ()
98 "Add URL-buttons for text body."
99 (goto-char (point-min))
100 (while (re-search-forward mime-browse-url-regexp nil t)
101 (widget-convert-button 'mime-url-link (match-beginning 0)(match-end 0)
102 (match-string-no-properties 0))))
108 (defmacro mime-popup-menu-bogus-filter-constructor (menu)
109 ;; #### Kludge for FSF Emacs-style menu.
110 (let ((bogus-menu (make-symbol "bogus-menu")))
111 `(let (,bogus-menu selection function)
112 (easy-menu-define ,bogus-menu nil nil ,menu)
113 (setq selection (x-popup-menu t ,bogus-menu))
115 (setq function (lookup-key ,bogus-menu (apply #'vector selection)))
116 ;; If a callback entry has no name, easy-menu wraps its value.
117 ;; See `easy-menu-make-symbol'.
118 (if (eq t (compare-strings "menu-function-" 0 nil (symbol-name function) 0 14))
119 (car (last (symbol-function function)))
122 ;;; While XEmacs can have both X and tty frames at the same time with
123 ;;; gnuclient, we shouldn't emulate in text-mode here.
125 (static-if (featurep 'xemacs)
126 (defalias 'mime-popup-menu-popup 'popup-menu)
127 (defun mime-popup-menu-popup (menu &optional event)
128 (let ((function (mime-popup-menu-bogus-filter-constructor menu)))
129 (when (symbolp function)
130 (funcall function)))))
132 (static-if (featurep 'xemacs)
133 (defun mime-popup-menu-select (menu &optional event)
134 (let ((selection (get-popup-menu-response menu event)))
135 (event-object selection)))
136 (defun mime-popup-menu-select (menu &optional event)
137 (mime-popup-menu-bogus-filter-constructor menu)))
143 (defvar mime-condition-type-alist
144 '((preview . mime-preview-condition)
145 (action . mime-acting-condition)))
147 (defvar mime-condition-mode-alist
148 '((with-default . ctree-set-calist-with-default)
149 (t . ctree-set-calist-strictly)))
151 (defun mime-add-condition (target-type condition &optional mode file)
152 "Add CONDITION to database specified by TARGET-TYPE.
153 TARGET-TYPE must be 'preview or 'action.
154 If optional argument MODE is 'strict or nil (omitted), CONDITION is
156 If optional argument MODE is 'with-default, CONDITION is added with
158 If optional argument FILE is specified, it is loaded when CONDITION is
160 (let ((sym (cdr (assq target-type mime-condition-type-alist))))
162 (let ((func (cdr (or (assq mode mime-condition-mode-alist)
163 (assq t mime-condition-mode-alist)))))
166 (funcall func sym condition)
168 (let ((method (cdr (assq 'method condition))))
169 (autoload method file))))
170 (error "Function for mode `%s' is not found." mode)))
171 (error "Variable for target-type `%s' is not found." target-type))))
179 ;;; semi-def.el ends here