* pgg-pgp.el (pgg-pgp-process-region): bind process-environment
[elisp/semi.git] / semi-def.el
1 ;;; semi-def.el --- definition module for SEMI -*- coding: iso-8859-4; -*-
2
3 ;; Copyright (C) 1995,96,97,98,99,2000 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
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'poe)
28
29 (eval-when-compile (require 'cl))
30
31 (require 'custom)
32
33 (defconst mime-user-interface-product ["EMIKO" (1 14 0) "Zoomastigophora"]
34   "Product name, version number and code name of MIME-kernel package.")
35
36 (autoload 'mule-caesar-region "mule-caesar"
37   "Caesar rotation of current region." t)
38
39 (autoload 'widget-convert-button "wid-edit")
40
41 ;;; @ constants
42 ;;;
43
44 (defconst mime-echo-buffer-name "*MIME-echo*"
45   "Name of buffer to display MIME-playing information.")
46
47 (defconst mime-temp-buffer-name " *MIME-temp*")
48
49
50 ;;; @ button
51 ;;;
52
53 (define-widget 'mime-button 'link
54   "Widget for MIME button."
55   :action 'mime-button-action)
56
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)))
60     (when function
61       (funcall function data))))
62     
63 (defsubst mime-insert-button (string function &optional data)
64   "Insert STRING as button with callback FUNCTION and DATA."
65   (save-restriction
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)
75     (insert "\n")))
76
77
78 ;;; @ for URL
79 ;;;
80
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."
86   :group 'mime
87   :type 'regexp)
88
89 (defcustom mime-browse-url-function (function browse-url)
90   "Function to browse URL."
91   :group 'mime
92   :type 'function)
93
94 (define-widget 'mime-url-link 'url-link
95   "A link to an www page.")
96
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))))
103
104
105 ;;; @ menu
106 ;;;
107
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))
114        (when selection
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)))
120            function)))))
121
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.
124
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)))))
131
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)))
138
139
140 ;;; @ Other Utility
141 ;;;
142
143 (defvar mime-condition-type-alist
144   '((preview . mime-preview-condition)
145     (action . mime-acting-condition)))
146
147 (defvar mime-condition-mode-alist
148   '((with-default . ctree-set-calist-with-default)
149     (t . ctree-set-calist-strictly)))
150
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
155 added strictly.
156 If optional argument MODE is 'with-default, CONDITION is added with
157 default rule.
158 If optional argument FILE is specified, it is loaded when CONDITION is
159 activate."
160   (let ((sym (cdr (assq target-type mime-condition-type-alist))))
161     (if sym
162         (let ((func (cdr (or (assq mode mime-condition-mode-alist)
163                              (assq t mime-condition-mode-alist)))))
164           (if (fboundp func)
165               (progn
166                 (funcall func sym condition)
167                 (if file
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))))
172
173
174 ;;; @ end
175 ;;;
176
177 (provide 'semi-def)
178
179 ;;; semi-def.el ends here