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.
54 Variable `widget-button-face' is equivalent for it if widget is used."
58 (defcustom mime-button-mouse-face 'highlight
59 "Face used for MIME-preview buffer mouse highlighting.
60 Variable `widget-mouse-face' is equivalent for it if widget is used."
64 (defcustom mime-use-widget nil
65 "If t, use widget to display buttons."
69 (defun mime-create-widget-button (string function)
70 "Display STRING as a widget button with the callback FUNCTION.
71 Under XEmacs, the function `mime-create-xpm-button' might be identical
72 to the function `mime-create-widget-button' if the feature `xpm' is not
73 provided or the TTY frame is used."
74 (let ((start (point)))
77 :action `(lambda (widget &optional event) (,function))
78 :mouse-down-action `(lambda (widget event)
80 (save-window-excursion
81 (mouse-set-point event)
82 (setq buf (current-buffer)
89 ;; There may be only one string "*" behind the widget button. We
90 ;; should replace it with the string as it can be seen because it
91 ;; will be yanked into the reply messages.
92 (static-when (featurep 'xemacs)
95 (insert "[" string "]")
96 (while (setq extent (extent-at start nil nil extent))
97 ;; Avoid removing extents of next part.
98 (if (eq (extent-end-position extent) end)
99 (set-extent-endpoints extent end (point))))
100 (delete-region start end)))
101 (add-text-properties start (point)
106 (static-when (featurep 'xemacs)
107 (defcustom mime-xpm-button-shadow-thickness 3
108 "A number of pixels should be used for the shadows on the edges of
113 (defcustom mime-xpm-button-foreground "Yellow"
114 "A color used to display the text."
118 (defcustom mime-xpm-button-background "#a0a0d0"
119 "A background color the text will be displayed upon."
123 (defvar mime-xpm-button-glyph-cache nil)
126 (defun mime-create-xpm-button (string function)
127 "Display STRING as a XPM button with the callback FUNCTION.
128 It might be identical to the function `mime-create-widget-button'
129 if the TTY frame is used."
130 ;; `device-on-widow-system-p' must be checked at run-time.
131 (if (device-on-window-system-p)
133 (set-extent-properties (make-extent (point)
135 (insert "[" string "]")
137 '(invisible t intangible t))
138 (let* ((spec (list string
139 mime-xpm-button-shadow-thickness
140 mime-xpm-button-foreground
141 mime-xpm-button-background))
142 (button (cdr (assoc spec mime-xpm-button-glyph-cache))))
144 (set-alist 'mime-xpm-button-glyph-cache spec
145 (setq button (apply (function xpm-button-create)
147 (let* ((extent (make-extent (point) (point)))
148 (down-glyph (make-glyph (car (cdr button))))
149 (up-glyph (make-glyph (car button)))
150 (down-func `(lambda (event)
152 (set-extent-begin-glyph ,extent
154 (up-func `(lambda (event)
156 (mouse-set-point event)
157 (set-extent-begin-glyph ,extent ,up-glyph)
159 (keymap (make-sparse-keymap)))
160 (define-key keymap 'button1 down-func)
161 (define-key keymap 'button2 down-func)
162 (define-key keymap 'button1up up-func)
163 (define-key keymap 'button2up up-func)
164 (set-extent-begin-glyph extent up-glyph)
165 (set-extent-property extent 'keymap keymap))
167 (mime-create-widget-button string function)))
168 (fset 'mime-create-xpm-button 'mime-create-widget-button)))
170 (defcustom mime-create-button-function 'mime-create-widget-button
171 "A function called to create the content button."
182 '((const :tag "Widget button" mime-create-widget-button))
183 (static-when (featurep 'xemacs)
184 '((const :tag "Xpm button" mime-create-xpm-button)))
185 '((function :tag "Other"))))))))
187 (defsubst mime-add-button (from to function &optional data)
188 "Create a button between FROM and TO with callback FUNCTION and DATA."
189 (and mime-button-face
190 (put-text-property from to 'face mime-button-face))
191 (and mime-button-mouse-face
192 (put-text-property from to 'mouse-face mime-button-mouse-face))
193 (add-text-properties from to (list 'mime-button-callback function
197 (add-text-properties from to (list 'mime-button-data data))))
199 (defsubst mime-insert-button (string function &optional data)
200 "Insert STRING as button with callback FUNCTION and DATA."
204 (narrow-to-region (point) (point))
208 (funcall mime-create-button-function line function)))
209 (split-string string "\n"))
211 ;; One more newline to avoid concatenation of face property.
212 (insert (concat "[" string "]\n\n"))
213 (mime-add-button (point-min) (1- (point-max)) function data)
216 (defvar mime-button-mother-dispatcher nil)
218 (defun mime-button-dispatcher (event)
219 "Select the button under point."
221 (let (buf point func data)
222 (save-window-excursion
223 (mouse-set-point event)
224 (setq buf (current-buffer)
226 func (get-text-property (point) 'mime-button-callback)
227 data (get-text-property (point) 'mime-button-data)))
233 (if (fboundp mime-button-mother-dispatcher)
234 (funcall mime-button-mother-dispatcher event))))))
240 (defcustom mime-browse-url-regexp
241 (concat "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):"
242 "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
243 "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
244 "*Regexp to match URL in text body."
248 (defcustom mime-browse-url-function (function browse-url)
249 "*Function to browse URL."
253 (defsubst mime-add-url-buttons ()
254 "Add URL-buttons for text body."
255 (goto-char (point-min))
256 (while (re-search-forward mime-browse-url-regexp nil t)
257 (let ((beg (match-beginning 0))
261 (widget-convert-button 'mime-url-link beg end
262 (buffer-substring beg end))
263 (static-unless (featurep 'xemacs)
264 (overlay-put (make-overlay beg end) 'local-map widget-keymap)))
265 (mime-add-button beg end mime-browse-url-function
266 (list (buffer-substring beg end)))))))
268 (define-widget 'mime-url-link 'link
269 "A link to an www page."
270 :help-echo 'widget-url-link-help-echo
271 :action 'widget-mime-url-link-action)
273 (defun widget-mime-url-link-action (widget &optional event)
274 "Open the url specified by WIDGET."
275 (funcall mime-browse-url-function (widget-value widget)))
282 (if (featurep 'xemacs)
283 (defun select-menu-alist (title menu-alist)
292 (setq ret ',(cdr cell))
298 (defun select-menu-alist (title menu-alist)
300 (list '(1 1) (selected-window))
301 (list title (cons title menu-alist)))))
302 (defun select-menu-alist (title menu-alist)
304 (assoc (completing-read (concat title " : ") menu-alist)
311 (defvar mime-condition-type-alist
312 '((preview . mime-preview-condition)
313 (action . mime-acting-condition)))
315 (defvar mime-condition-mode-alist
316 '((with-default . ctree-set-calist-with-default)
317 (t . ctree-set-calist-strictly)))
319 (defun mime-add-condition (target-type condition &optional mode file)
320 "Add CONDITION to database specified by TARGET-TYPE.
321 TARGET-TYPE must be 'preview or 'action.
322 If optional argument MODE is 'strict or nil (omitted), CONDITION is
324 If optional argument MODE is 'with-default, CONDITION is added with
326 If optional argument FILE is specified, it is loaded when CONDITION is
328 (let ((sym (cdr (assq target-type mime-condition-type-alist))))
330 (let ((func (cdr (or (assq mode mime-condition-mode-alist)
331 (assq t mime-condition-mode-alist)))))
334 (funcall func sym condition)
336 (let ((method (cdr (assq 'method condition))))
337 (autoload method file))))
338 (error "Function for mode `%s' is not found." mode)))
339 (error "Variable for target-type `%s' is not found." target-type))))
347 ;;; semi-def.el ends here