tm 7.10.
[elisp/tm.git] / tm-def.el
1 ;;;
2 ;;; tm-def.el --- definition module for tm
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version:
9 ;;;     $Id: tm-def.el,v 7.0 1995/10/05 13:27:34 morioka Exp $
10 ;;; Keywords: mail, news, MIME, multimedia, definition
11 ;;;
12 ;;; This file is part of tm (Tools for MIME).
13 ;;;
14
15 (require 'emu)
16 (require 'tl-822)
17
18
19 ;;; @ variables
20 ;;;
21
22 (defvar mime/tmp-dir (or (getenv "TM_TMP_DIR") "/tmp/"))
23
24 (defvar mime/use-multi-frame
25   (and (>= emacs-major-version 19) window-system))
26
27 (defvar mime/find-file-function
28   (if mime/use-multi-frame
29       (function find-file-other-frame)
30     (function find-file)
31     ))
32
33
34 ;;; @ constants
35 ;;;
36
37 (defconst mime/output-buffer-name "*MIME-out*")
38 (defconst mime/decoding-buffer-name "*MIME-decoding*")
39
40
41 ;;; @ for various Emacs variants
42 ;;;
43
44 (cond ((boundp 'MULE)  (require 'tm-mule))
45       ((boundp 'NEMACS)(require 'tm-nemacs))
46       (t               (require 'tm-orig))
47       )
48
49
50 ;;; @ button
51 ;;;
52
53 (defun tm:set-face-region (b e face)
54   (let ((overlay (tl:make-overlay b e)))
55     (tl:overlay-put overlay 'face face)
56     ))
57
58 (setq tm:button-face 'bold)
59 (setq tm:mouse-face 'highlight)
60
61 (defun tm:add-button (from to func &optional data)
62   "Create a button between FROM and TO with callback FUNC and data DATA."
63   (and tm:button-face
64        (tl:overlay-put (tl:make-overlay from to) 'face tm:button-face))
65   (tl:add-text-properties from to
66                           (append (and tm:mouse-face
67                                        (list 'mouse-face tm:mouse-face))
68                                   (list 'tm-callback func)
69                                   (and data (list 'tm-data data))
70                                   ))
71   )
72
73 (defvar tm:mother-button-dispatcher nil)
74
75 (defun tm:button-dispatcher (event)
76   "Select the button under point."
77   (interactive "e")
78   (mouse-set-point event)
79   (let ((func (get-text-property (point) 'tm-callback))
80         (data (get-text-property (point) 'tm-data))
81         )
82     (if func
83         (apply func data)
84       (if (fboundp tm:mother-button-dispatcher)
85           (funcall tm:mother-button-dispatcher event)
86         )
87       )))
88
89
90 ;;; @ for URL
91 ;;;
92
93 (defvar tm:URL-regexp
94   "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
95
96 (defvar browse-url-browser-function nil)
97
98 (defun tm:browse-url ()
99   (if (fboundp browse-url-browser-function)
100       (call-interactively browse-url-browser-function)
101     (if (fboundp tm:mother-button-dispatcher)
102         (call-interactively tm:mother-button-dispatcher)
103       )
104     ))
105
106
107 ;;; @ definitions about MIME
108 ;;;
109
110 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
111 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
112 (defconst mime/charset-regexp mime/token-regexp)
113
114 (defconst mime/content-type-subtype-regexp
115   (concat mime/token-regexp "/" mime/token-regexp))
116 (defconst mime/content-parameter-value-regexp
117   (concat "\\("
118           rfc822/quoted-string-regexp
119           "\\|[^; \t\n]*\\)"))
120
121
122 ;;; @@ Base64
123 ;;;
124
125 (defconst base64-token-regexp "[A-Za-z0-9+/=]")
126
127 (defconst mime/B-encoded-text-regexp
128   (concat "\\("
129           base64-token-regexp
130           base64-token-regexp
131           base64-token-regexp
132           base64-token-regexp
133           "\\)+"))
134 (defconst mime/B-encoding-and-encoded-text-regexp
135   (concat "\\(B\\)\\?" mime/B-encoded-text-regexp))
136
137
138 ;;; @@ Quoted-Printable
139 ;;;
140
141 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
142 (defconst quoted-printable-octet-regexp
143   (concat "=[" quoted-printable-hex-chars
144           "][" quoted-printable-hex-chars "]"))
145
146 (defconst mime/Q-encoded-text-regexp
147   (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
148 (defconst mime/Q-encoding-and-encoded-text-regexp
149   (concat "\\(Q\\)\\?" mime/Q-encoded-text-regexp))
150
151
152 ;;; @ end
153 ;;;
154
155 (provide 'tm-def)