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