tm 7.73.
[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.20 1996/07/23 14:58:47 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
37         emacs-version
38         (string-match (format "%d\\." emacs-major-version) emacs-version)
39         ))))
40
41 (defvar running-emacs-18 (<= emacs-major-version 18))
42 (defvar running-xemacs (string-match "XEmacs" emacs-version))
43 (defvar running-xemacs-19 (and running-xemacs
44                                (= emacs-major-version 19)))
45 (defvar running-xemacs-20 (and running-xemacs
46                                (= emacs-major-version 20)))
47 (defvar running-xemacs-20-or-later (and running-xemacs
48                                         (>= emacs-major-version 20)))
49 (defvar running-xemacs-19_14-or-later
50   (or (and running-xemacs-19 (>= emacs-minor-version 14))
51       running-xemacs-20-or-later))
52 (defvar running-emacs-19 (and (not running-xemacs)
53                               (= emacs-major-version 19)))
54 (defvar running-emacs-19_29-or-later
55   (or (and running-emacs-19 (>= emacs-minor-version 29))
56       (and (not running-xemacs)(>= emacs-major-version 20))))
57
58 (cond ((boundp 'MULE)
59        (require 'emu-mule)
60        )
61       ((and running-xemacs-20 (featurep 'mule))
62        (require 'emu-x20)
63        )
64       ((boundp 'NEMACS)
65        (require 'emu-nemacs)
66        )
67       (t
68        (require 'emu-e19)
69        ))
70
71
72 ;;; @ MIME charset
73 ;;;
74
75 (defun charsets-to-mime-charset (charsets)
76   "Return MIME charset from list of charset CHARSETS.
77 This function refers variable `charsets-mime-charset-alist'
78 and `default-mime-charset'. [emu.el]"
79   (if charsets
80       (or (catch 'tag
81             (let ((rest charsets-mime-charset-alist)
82                   cell csl)
83               (while (setq cell (car rest))
84                 (if (catch 'not-subset
85                       (let ((set1 charsets)
86                             (set2 (car cell))
87                             obj)
88                         (while set1
89                           (setq obj (car set1))
90                           (or (memq obj set2)
91                               (throw 'not-subset nil)
92                               )
93                           (setq set1 (cdr set1))
94                           )
95                         t))
96                     (throw 'tag (cdr cell))
97                   )
98                 (setq rest (cdr rest))
99                 )))
100           default-mime-charset)))
101
102
103 ;;; @ Emacs 19.29 emulation
104 ;;;
105
106 (or (fboundp 'buffer-substring-no-properties)
107     (defun buffer-substring-no-properties (beg end)
108       "Return the text from BEG to END, without text properties, as a string."
109       (let ((string (buffer-substring beg end)))
110         (tl:set-text-properties 0 (length string) nil string)
111         string))
112     )
113
114 (cond ((or running-emacs-19_29-or-later running-xemacs)
115        ;; for Emacs 19.29 or later and XEmacs
116        (defalias 'tl:read-string 'read-string)
117        )
118       (t
119        ;; for Emacs 19.28 or earlier
120        (defun tl:read-string (prompt &optional initial-input history)
121          (read-string prompt initial-input)
122          )
123        ))
124
125 (or (fboundp 'add-to-list)
126     ;; This function was imported Emacs 19.30.
127     (defun add-to-list (list-var element)
128       "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
129 If you want to use `add-to-list' on a variable that is not defined
130 until a certain package is loaded, you should put the call to `add-to-list'
131 into a hook function that will be run only after loading the package.
132 \[emu.el; Emacs 19.30 emulating function]"
133       (or (member element (symbol-value list-var))
134           (set list-var (cons element (symbol-value list-var)))))
135     )
136
137
138 ;;; @ XEmacs emulation
139 ;;;
140
141 (or (fboundp 'functionp)
142     (defun functionp (obj)
143       "Returns t if OBJ is a function, nil otherwise.
144 \[emu.el; XEmacs emulating function]"
145       (or (subrp obj)
146           (byte-code-function-p obj)
147           (and (symbolp obj)(fboundp obj))
148           (and (consp obj)(eq (car obj) 'lambda))
149           ))
150     )
151         
152
153 ;;; @ for XEmacs 20
154 ;;;
155
156 (or (fboundp 'char-int)
157     (fset 'char-int (symbol-function 'identity))
158     )
159 (or (fboundp 'int-char)
160     (fset 'int-char (symbol-function 'identity))
161     )
162
163
164 ;;; @ for text/richtext and text/enriched
165 ;;;
166
167 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
168        ;; have enriched.el
169        (autoload 'richtext-decode "richtext")
170        (or (assq 'text/richtext format-alist)
171            (setq format-alist
172                  (cons
173                   (cons 'text/richtext
174                         '("Extended MIME text/richtext format."
175                           "Content-[Tt]ype:[ \t]*text/richtext"
176                           richtext-decode richtext-encode t enriched-mode))
177                   format-alist)))
178        )
179       (t
180        ;; don't have enriched.el
181        (autoload 'richtext-decode "tinyrich")
182        (autoload 'enriched-decode "tinyrich")
183        ))
184
185
186 ;;; @ end
187 ;;;
188
189 (provide 'emu)
190
191 ;;; emu.el ends here