1 ;;; semi-def.el --- definition module for SEMI
3 ;; Copyright (C) 1995,1996,1997,1998,1999 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.
28 (eval-when-compile (require 'cl))
31 (defconst mime-user-interface-product ["EMY" (1 13 6) "Life is balance"]
32 "Product name, version number and code name of MIME-kernel package.")
34 (autoload 'mule-caesar-region "mule-caesar"
35 "Caesar rotation of current region." t)
37 (autoload 'widget-convert-button "wid-edit")
43 (defconst mime-echo-buffer-name "*MIME-echo*"
44 "Name of buffer to display MIME-playing information.")
46 (defconst mime-temp-buffer-name " *MIME-temp*")
52 (defcustom mime-button-face 'bold
53 "Face used for content-button or URL-button of MIME-Preview buffer."
57 (defcustom mime-button-mouse-face 'highlight
58 "Face used for MIME-preview buffer mouse highlighting."
62 (defcustom mime-use-widget nil
63 "If t, use widget to display buttons."
67 (defun mime-create-widget-button (string function)
68 "Display STRING as a widget button with the callback FUNCTION.
69 Under XEmacs, the function `mime-create-xpm-button' might be identical
70 to the function `mime-create-widget-button' if the feature `xpm' is not
71 provided or the TTY frame is used."
72 (let ((start (point)))
75 :action `(lambda (widget &optional event) (,function))
76 :mouse-down-action `(lambda (widget event)
78 (save-window-excursion
79 (mouse-set-point event)
80 (setq buf (current-buffer)
88 ;; (static-when (featurep 'xemacs)
89 ;; (let ((end (point))
91 ;; (insert "[" string "]")
92 ;; (while (setq extent (extent-at start nil nil extent))
93 ;; (set-extent-endpoints extent end (point)))
94 ;; (delete-region start end))))
95 (add-text-properties start (point)
100 (static-when (featurep 'xemacs)
101 (defcustom mime-xpm-button-shadow-thickness 3
102 "A number of pixels should be used for the shadows on the edges of
107 (defcustom mime-xpm-button-foreground "Yellow"
108 "A color used to display the text."
112 (defcustom mime-xpm-button-background "#a0a0d0"
113 "A background color the text will be displayed upon."
117 (defvar mime-xpm-button-glyph-cache nil)
119 ;; #### device-on-widow-system-p must be checked at run-time.
120 (if (and (featurep 'xpm) (device-on-window-system-p))
121 (defun mime-create-xpm-button (string function)
122 "Display STRING as a XPM button with the callback FUNCTION.
123 It might be identical to the function `mime-create-widget-button'
124 if the feature `xpm' is not provided or the TTY frame is used."
125 (set-extent-properties (make-extent (point)
127 (insert "[" string "]")
129 '(invisible t intangible t))
130 (let* ((spec (list string
131 mime-xpm-button-shadow-thickness
132 mime-xpm-button-foreground
133 mime-xpm-button-background))
134 (button (cdr (assoc spec mime-xpm-button-glyph-cache))))
136 (set-alist 'mime-xpm-button-glyph-cache spec
137 (setq button (apply (function xpm-button-create)
139 (let* ((extent (make-extent (point) (point)))
140 (down-glyph (make-glyph (car (cdr button))))
141 (up-glyph (make-glyph (car button)))
142 (down-func `(lambda (event)
144 (set-extent-begin-glyph ,extent ,down-glyph)))
145 (up-func `(lambda (event)
147 (mouse-set-point event)
148 (set-extent-begin-glyph ,extent ,up-glyph)
150 (keymap (make-sparse-keymap)))
151 (define-key keymap 'button1 down-func)
152 (define-key keymap 'button2 down-func)
153 (define-key keymap 'button1up up-func)
154 (define-key keymap 'button2up up-func)
155 (set-extent-begin-glyph extent up-glyph)
156 (set-extent-property extent 'keymap keymap))
158 (fset 'mime-create-xpm-button 'mime-create-widget-button)))
160 (defcustom mime-create-button-function 'mime-create-widget-button
161 "A function called to create the content button."
172 '((const :tag "Widget button" mime-create-widget-button))
173 (static-when (featurep 'xemacs)
174 '((const :tag "Xpm button" mime-create-xpm-button)))
175 '((function :tag "Other"))))))))
177 (defsubst mime-add-button (from to function &optional data)
178 "Create a button between FROM and TO with callback FUNCTION and DATA."
179 (and mime-button-face
180 (put-text-property from to 'face mime-button-face))
181 (and mime-button-mouse-face
182 (put-text-property from to 'mouse-face mime-button-mouse-face))
183 (add-text-properties from to (list 'mime-button-callback function
187 (add-text-properties from to (list 'mime-button-data data))))
189 (defsubst mime-insert-button (string function &optional data)
190 "Insert STRING as button with callback FUNCTION and DATA."
194 (narrow-to-region (point) (point))
198 (funcall mime-create-button-function line function)))
199 (split-string string "\n"))
201 ;; One more newline to avoid concatenation of face property.
202 (insert (concat "[" string "]\n\n"))
203 (mime-add-button (point-min) (1- (point-max)) function data)
206 (defvar mime-button-mother-dispatcher nil)
208 (defun mime-button-dispatcher (event)
209 "Select the button under point."
211 (let (buf point func data)
212 (save-window-excursion
213 (mouse-set-point event)
214 (setq buf (current-buffer)
216 func (get-text-property (point) 'mime-button-callback)
217 data (get-text-property (point) 'mime-button-data)))
223 (if (fboundp mime-button-mother-dispatcher)
224 (funcall mime-button-mother-dispatcher event))))))
230 (defcustom mime-browse-url-regexp
231 (concat "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):"
232 "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
233 "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
234 "*Regexp to match URL in text body."
238 (defcustom mime-browse-url-function (function browse-url)
239 "*Function to browse URL."
243 (defsubst mime-add-url-buttons ()
244 "Add URL-buttons for text body."
245 (goto-char (point-min))
246 (while (re-search-forward mime-browse-url-regexp nil t)
247 (let ((beg (match-beginning 0))
251 (widget-convert-button 'mime-url-link beg end
252 (buffer-substring beg end))
253 (static-unless (featurep 'xemacs)
254 (overlay-put (make-overlay beg end) 'local-map widget-keymap)))
255 (mime-add-button beg end mime-browse-url-function
256 (list (buffer-substring beg end)))))))
258 (define-widget 'mime-url-link 'link
259 "A link to an www page."
260 :help-echo 'widget-url-link-help-echo
261 :action 'widget-mime-url-link-action)
263 (defun widget-mime-url-link-action (widget &optional event)
264 "Open the url specified by WIDGET."
265 (funcall mime-browse-url-function (widget-value widget)))
272 (if (featurep 'xemacs)
273 (defun select-menu-alist (title menu-alist)
282 (setq ret ',(cdr cell))
288 (defun select-menu-alist (title menu-alist)
290 (list '(1 1) (selected-window))
291 (list title (cons title menu-alist)))))
292 (defun select-menu-alist (title menu-alist)
294 (assoc (completing-read (concat title " : ") menu-alist)
301 (defvar mime-condition-type-alist
302 '((preview . mime-preview-condition)
303 (action . mime-acting-condition)))
305 (defvar mime-condition-mode-alist
306 '((with-default . ctree-set-calist-with-default)
307 (t . ctree-set-calist-strictly)))
309 (defun mime-add-condition (target-type condition &optional mode file)
310 "Add CONDITION to database specified by TARGET-TYPE.
311 TARGET-TYPE must be 'preview or 'action.
312 If optional argument MODE is 'strict or nil (omitted), CONDITION is
314 If optional argument MODE is 'with-default, CONDITION is added with
316 If optional argument FILE is specified, it is loaded when CONDITION is
318 (let ((sym (cdr (assq target-type mime-condition-type-alist))))
320 (let ((func (cdr (or (assq mode mime-condition-mode-alist)
321 (assq t mime-condition-mode-alist)))))
324 (funcall func sym condition)
326 (let ((method (cdr (assq 'method condition))))
327 (autoload method file))))
328 (error "Function for mode `%s' is not found." mode)))
329 (error "Variable for target-type `%s' is not found." target-type))))
337 ;;; semi-def.el ends here