tm 7.82.
[elisp/apel.git] / emu.el
1 ;;; emu.el --- Emulation module for each Emacs variants
2
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu.el,v 7.24 1996/09/04 15:49:30 morioka Exp $
7 ;; Keywords: emulation, compatibility, NEmacs, Mule, XEmacs
8
9 ;; This file is part of tl (Tiny Library).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (or (boundp 'emacs-major-version)
29     (defconst emacs-major-version (string-to-int emacs-version)))
30 (or (boundp 'emacs-minor-version)
31     (defconst emacs-minor-version
32       (string-to-int
33        (substring
34         emacs-version
35         (string-match (format "%d\\." emacs-major-version) emacs-version)
36         ))))
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 \[emu.el; EMACS 19.29 emulating function]"
107       (let ((string (buffer-substring beg end)))
108         (tl:set-text-properties 0 (length string) nil string)
109         string))
110     )
111
112 (or running-emacs-19_29-or-later
113     running-xemacs
114     ;; for Emacs 19.28 or earlier
115     (fboundp 'si:read-string)
116     (progn
117       (fset 'si:read-string (symbol-function 'read-string))
118       
119       (defun read-string (prompt &optional initial-input history)
120         "Read a string from the minibuffer, prompting with string PROMPT.
121 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
122 The third arg HISTORY, is dummy for compatibility. [emu.el]
123 See `read-from-minibuffer' for details of HISTORY argument."
124         (si:read-string prompt initial-input)
125         )
126       ))
127
128 (or (fboundp 'add-to-list)
129     ;; This function was imported Emacs 19.30.
130     (defun add-to-list (list-var element)
131       "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
132 If you want to use `add-to-list' on a variable that is not defined
133 until a certain package is loaded, you should put the call to `add-to-list'
134 into a hook function that will be run only after loading the package.
135 \[emu.el; EMACS 19.30 emulating function]"
136       (or (member element (symbol-value list-var))
137           (set list-var (cons element (symbol-value list-var)))))
138     )
139
140
141 ;;; @ EMACS 19.32 emulation
142 ;;;
143
144 (or (fboundp 'buffer-live-p)
145     (defun buffer-live-p (object)
146       "Return non-nil if OBJECT is a buffer which has not been killed.
147 Value is nil if OBJECT is not a buffer or if it has been killed.
148 \[emu.el; EMACS 19.32 emulating function]"
149       (and object
150            (get-buffer object)
151            (buffer-name (get-buffer object))
152            ))
153     )
154
155
156 ;;; @ XEmacs emulation
157 ;;;
158
159 (or (fboundp 'functionp)
160     (defun functionp (obj)
161       "Returns t if OBJ is a function, nil otherwise.
162 \[emu.el; XEmacs emulating function]"
163       (or (subrp obj)
164           (byte-code-function-p obj)
165           (and (symbolp obj)(fboundp obj))
166           (and (consp obj)(eq (car obj) 'lambda))
167           ))
168     )
169         
170
171 ;;; @ for XEmacs 20
172 ;;;
173
174 (or (fboundp 'char-int)
175     (fset 'char-int (symbol-function 'identity))
176     )
177 (or (fboundp 'int-char)
178     (fset 'int-char (symbol-function 'identity))
179     )
180
181
182 ;;; @ for text/richtext and text/enriched
183 ;;;
184
185 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
186        ;; have enriched.el
187        (autoload 'richtext-decode "richtext")
188        (or (assq 'text/richtext format-alist)
189            (setq format-alist
190                  (cons
191                   (cons 'text/richtext
192                         '("Extended MIME text/richtext format."
193                           "Content-[Tt]ype:[ \t]*text/richtext"
194                           richtext-decode richtext-encode t enriched-mode))
195                   format-alist)))
196        )
197       (t
198        ;; don't have enriched.el
199        (autoload 'richtext-decode "tinyrich")
200        (autoload 'enriched-decode "tinyrich")
201        ))
202
203
204 ;;; @ end
205 ;;;
206
207 (provide 'emu)
208
209 ;;; emu.el ends here