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