tm 7.71.
[elisp/apel.git] / emu.el
1 ;;;
2 ;;; emu.el --- Emulation module for each Emacs variants
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995,1996 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; modified by KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
9 ;;; Version:
10 ;;;     $Id: emu.el,v 7.19 1996/07/11 14:11:12 morioka Exp $
11 ;;; Keywords: emulation, compatibility, NEmacs, Mule, XEmacs
12 ;;;
13 ;;; This file is part of tl (Tiny Library).
14 ;;;
15 ;;; This program is free software; you can redistribute it and/or
16 ;;; modify it under the terms of the GNU General Public License as
17 ;;; published by the Free Software Foundation; either version 2, or
18 ;;; (at your option) any later version.
19 ;;;
20 ;;; This program is distributed in the hope that it will be useful,
21 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23 ;;; General Public License for more details.
24 ;;;
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with This program.  If not, write to the Free Software
27 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;;;
29 ;;; Code:
30
31 (or (boundp 'emacs-major-version)
32     (defconst emacs-major-version (string-to-int emacs-version)))
33 (or (boundp 'emacs-minor-version)
34     (defconst emacs-minor-version
35       (string-to-int
36        (substring emacs-version (string-match "18\\." emacs-version)))))
37
38 (defvar running-emacs-18 (<= emacs-major-version 18))
39 (defvar running-xemacs (string-match "XEmacs" emacs-version))
40 (defvar running-xemacs-19 (and running-xemacs
41                                (= emacs-major-version 19)))
42 (defvar running-xemacs-20 (and running-xemacs
43                                (= emacs-major-version 20)))
44 (defvar running-xemacs-20-or-later (and running-xemacs
45                                         (>= emacs-major-version 20)))
46 (defvar running-xemacs-19_14-or-later
47   (or (and running-xemacs-19 (>= emacs-minor-version 14))
48       running-xemacs-20-or-later))
49 (defvar running-emacs-19 (and (not running-xemacs)
50                               (= emacs-major-version 19)))
51 (defvar running-emacs-19_29-or-later
52   (or (and running-emacs-19 (>= emacs-minor-version 29))
53       (and (not running-xemacs)(>= emacs-major-version 20))))
54
55 (cond ((boundp 'MULE)
56        (require 'emu-mule)
57        )
58       ((and running-xemacs-20 (featurep 'mule))
59        (require 'emu-x20)
60        )
61       ((boundp 'NEMACS)
62        (require 'emu-nemacs)
63        )
64       (t
65        (require 'emu-e19)
66        ))
67
68
69 ;;; @ MIME charset
70 ;;;
71
72 (defun charsets-to-mime-charset (charsets)
73   "Return MIME charset from list of charset CHARSETS.
74 This function refers variable `charsets-mime-charset-alist'
75 and `default-mime-charset'. [emu.el]"
76   (if charsets
77       (or (catch 'tag
78             (let ((rest charsets-mime-charset-alist)
79                   cell csl)
80               (while (setq cell (car rest))
81                 (if (catch 'not-subset
82                       (let ((set1 charsets)
83                             (set2 (car cell))
84                             obj)
85                         (while set1
86                           (setq obj (car set1))
87                           (or (memq obj set2)
88                               (throw 'not-subset nil)
89                               )
90                           (setq set1 (cdr set1))
91                           )
92                         t))
93                     (throw 'tag (cdr cell))
94                   )
95                 (setq rest (cdr rest))
96                 )))
97           default-mime-charset)))
98
99
100 ;;; @ Emacs 19.29 emulation
101 ;;;
102
103 (or (fboundp 'buffer-substring-no-properties)
104     (defun buffer-substring-no-properties (beg end)
105       "Return the text from BEG to END, without text properties, as a string."
106       (let ((string (buffer-substring beg end)))
107         (tl:set-text-properties 0 (length string) nil string)
108         string))
109     )
110
111 (cond ((or running-emacs-19_29-or-later running-xemacs)
112        ;; for Emacs 19.29 or later and XEmacs
113        (defalias 'tl:read-string 'read-string)
114        )
115       (t
116        ;; for Emacs 19.28 or earlier
117        (defun tl:read-string (prompt &optional initial-input history)
118          (read-string prompt initial-input)
119          )
120        ))
121
122 (or (fboundp 'add-to-list)
123     ;; This function was imported Emacs 19.30.
124     (defun add-to-list (list-var element)
125       "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
126 If you want to use `add-to-list' on a variable that is not defined
127 until a certain package is loaded, you should put the call to `add-to-list'
128 into a hook function that will be run only after loading the package.
129 \[emu.el; Emacs 19.30 emulating function]"
130       (or (member element (symbol-value list-var))
131           (set list-var (cons element (symbol-value list-var)))))
132     )
133
134
135 ;;; @ XEmacs emulation
136 ;;;
137
138 (or (fboundp 'functionp)
139     (defun functionp (obj)
140       "Returns t if OBJ is a function, nil otherwise.
141 \[emu.el; XEmacs emulating function]"
142       (or (subrp obj)
143           (byte-code-function-p obj)
144           (and (symbolp obj)(fboundp obj))
145           (and (consp obj)(eq (car obj) 'lambda))
146           ))
147     )
148         
149
150 ;;; @ for XEmacs 20
151 ;;;
152
153 (or (fboundp 'char-int)
154     (fset 'char-int (symbol-function 'identity))
155     )
156 (or (fboundp 'int-char)
157     (fset 'int-char (symbol-function 'identity))
158     )
159
160
161 ;;; @ for text/richtext and text/enriched
162 ;;;
163
164 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
165        ;; have enriched.el
166        (autoload 'richtext-decode "richtext")
167        (or (assq 'text/richtext format-alist)
168            (setq format-alist
169                  (cons
170                   (cons 'text/richtext
171                         '("Extended MIME text/richtext format."
172                           "Content-[Tt]ype:[ \t]*text/richtext"
173                           richtext-decode richtext-encode t enriched-mode))
174                   format-alist)))
175        )
176       (t
177        ;; don't have enriched.el
178        (autoload 'richtext-decode "tinyrich")
179        (autoload 'enriched-decode "tinyrich")
180        ))
181
182
183 ;;; @ end
184 ;;;
185
186 (provide 'emu)
187
188 ;;; emu.el ends here