~ubuntu-branches/ubuntu/utopic/semi/utopic-proposed

1 by Tatsuya Kinoshita
Import upstream version 1.14.6+0.20040418
1
;;; semi-def.el --- definition module for SEMI -*- coding: iso-8859-4; -*-
2
3
;; Copyright (C) 1995,96,97,98,99,2000,01,03 Free Software Foundation, Inc.
4
5
;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6
;; Keywords: definition, MIME, multimedia, mail, news
7
8
;; This file is part of SEMI (Sample of Emacs MIME Implementation).
9
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.
14
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.
19
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
1.1.3 by Tatsuya Kinoshita
Import upstream version 1.14.6+0.20060328
22
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23
;; Boston, MA 02110-1301, USA.
1 by Tatsuya Kinoshita
Import upstream version 1.14.6+0.20040418
24
25
;;; Code:
26
27
(eval-when-compile (require 'cl))
28
29
(require 'custom)
30
31
(defconst mime-user-interface-product ["SEMI" (1 14 6) "Maruoka"]
32
  "Product name, version number and code name of MIME-kernel package.")
33
34
(autoload 'mule-caesar-region "mule-caesar"
35
  "Caesar rotation of current region." t)
36
37
38
;;; @ constants
39
;;;
40
41
(defconst mime-echo-buffer-name "*MIME-echo*"
42
  "Name of buffer to display MIME-playing information.")
43
44
(defconst mime-temp-buffer-name " *MIME-temp*")
45
46
47
;;; @ button
48
;;;
49
50
(defcustom mime-button-face 'bold
51
  "Face used for content-button or URL-button of MIME-Preview buffer."
52
  :group 'mime
53
  :type 'face)
54
55
(defcustom mime-button-mouse-face 'highlight
56
  "Face used for MIME-preview buffer mouse highlighting."
57
  :group 'mime
58
  :type 'face)
59
60
(defsubst mime-add-button (from to function &optional data)
61
  "Create a button between FROM and TO with callback FUNCTION and DATA."
62
  (and mime-button-face
63
       (put-text-property from to 'face mime-button-face))
64
  (and mime-button-mouse-face
65
       (put-text-property from to 'mouse-face mime-button-mouse-face))
66
  (put-text-property from to 'mime-button-callback function)
67
  (and data
68
       (put-text-property from to 'mime-button-data data))
69
  )
70
71
(defsubst mime-insert-button (string function &optional data)
72
  "Insert STRING as button with callback FUNCTION and DATA."
73
  (save-restriction
74
    (narrow-to-region (point)(point))
75
    (insert (concat "[" string "]\n"))
76
    (mime-add-button (point-min)(point-max) function data)
77
    ))
78
79
(defvar mime-button-mother-dispatcher nil)
80
81
(defun mime-button-dispatcher (event)
82
  "Select the button under point."
83
  (interactive "e")
84
  (let (buf point func data)
85
    (save-window-excursion
86
      (mouse-set-point event)
87
      (setq buf (current-buffer)
88
	    point (point)
89
	    func (get-text-property (point) 'mime-button-callback)
90
	    data (get-text-property (point) 'mime-button-data)
91
	    ))
92
    (save-excursion
93
      (set-buffer buf)
94
      (goto-char point)
95
      (if func
96
	  (apply func data)
97
	(if (fboundp mime-button-mother-dispatcher)
98
	    (funcall mime-button-mother-dispatcher event)
99
	  )))))
100
101
102
;;; @ for URL
103
;;;
104
105
(defcustom mime-browse-url-regexp
106
  (concat "\\(https?\\|ftps?\\|file\\|gopher\\|news\\|nntps?\\|telnets?\\|wais\\|mailto\\):"
107
	  "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
108
	  "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
109
  "*Regexp to match URL in text body."
110
  :group 'mime
111
  :type 'regexp)
112
113
(defcustom mime-browse-url-function (function browse-url)
114
  "*Function to browse URL."
115
  :group 'mime
116
  :type 'function)
117
118
(defsubst mime-add-url-buttons ()
119
  "Add URL-buttons for text body."
120
  (goto-char (point-min))
121
  (while (re-search-forward mime-browse-url-regexp nil t)
122
    (let ((beg (match-beginning 0))
123
	  (end (match-end 0)))
124
      (mime-add-button beg end mime-browse-url-function
125
		       (list (buffer-substring beg end))))))
126
127
128
;;; @ menu
129
;;;
130
131
(static-cond ((featurep 'xemacs)
132
	      (defun mime-should-use-popup-menu ()
133
		(and window-system
134
		     (mouse-event-p last-command-event)))
135
	      (defun mime-select-menu-alist (title menu-alist)
136
		(if (mime-should-use-popup-menu)
137
		    (let (ret)
138
		      (popup-menu
139
		       (list* title
140
			      "---"
141
			      (mapcar (function
142
				       (lambda (cell)
143
					 (vector (car cell)
144
						 `(progn
145
						    (setq ret ',(cdr cell))
146
						    (throw 'exit nil))
147
						 t)))
148
				      menu-alist)))
149
		      (recursive-edit)
150
		      ret)
151
		  (cdr
152
		   (assoc (completing-read (concat title " : ") menu-alist)
153
			  menu-alist)))))
154
	     (t
155
	      (defun mime-should-use-popup-menu ()
156
		(and window-system
157
		     (memq (event-basic-type last-command-event)
158
			   '(mouse-1 mouse-2 mouse-3))))
159
	      (defun mime-select-menu-alist (title menu-alist)
160
		(if (mime-should-use-popup-menu)
161
		    (x-popup-menu
162
		     (list '(1 1) (selected-window))
163
		     (list title (cons title menu-alist)))
164
		  (cdr
165
		   (assoc (completing-read (concat title " : ") menu-alist)
166
			  menu-alist))))))
167
168
;;; @ Other Utility
169
;;;
170
171
(defvar mime-condition-type-alist
172
  '((preview . mime-preview-condition)
173
    (action . mime-acting-condition)))
174
175
(defvar mime-condition-mode-alist
176
  '((with-default . ctree-set-calist-with-default)
177
    (t . ctree-set-calist-strictly)))
178
179
(defun mime-add-condition (target-type condition &optional mode file)
180
  "Add CONDITION to database specified by TARGET-TYPE.
181
TARGET-TYPE must be 'preview or 'action.  
182
If optional argument MODE is 'strict or nil (omitted), CONDITION is
183
added strictly.
184
If optional argument MODE is 'with-default, CONDITION is added with
185
default rule.
186
If optional argument FILE is specified, it is loaded when CONDITION is
187
activate."
188
  (let ((sym (cdr (assq target-type mime-condition-type-alist))))
189
    (if sym
190
	(let ((func (cdr (or (assq mode mime-condition-mode-alist)
191
			     (assq t mime-condition-mode-alist)))))
192
	  (if (fboundp func)
193
	      (progn
194
		(funcall func sym condition)
195
		(if file
196
		    (let ((method (cdr (assq 'method condition))))
197
		      (autoload method file)
198
		      ))
199
		)
200
	    (error "Function for mode `%s' is not found." mode)
201
	    ))
202
      (error "Variable for target-type `%s' is not found." target-type)
203
      )))
204
205
206
;;; @ end
207
;;;
208
209
(provide 'semi-def)
210
211
;;; semi-def.el ends here