tm 7.85.
[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.30 1996/09/15 07:27:12 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
41 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
42                                        (not running-xemacs) (featurep 'mule)))
43 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
44
45 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
46 (defvar running-emacs-19_29-or-later
47   (or (and running-emacs-19 (>= emacs-minor-version 29))
48       (and (not running-xemacs)(>= emacs-major-version 20))))
49
50 (defvar running-xemacs-19 (and running-xemacs
51                                (= emacs-major-version 19)))
52 (defvar running-xemacs-20-or-later (and running-xemacs
53                                         (>= emacs-major-version 20)))
54 (defvar running-xemacs-19_14-or-later
55   (or (and running-xemacs-19 (>= emacs-minor-version 14))
56       running-xemacs-20-or-later))
57
58 (cond (running-mule-merged-emacs
59        ;; for mule merged EMACS
60        (require 'emu-e20)
61        )
62       (running-xemacs-with-mule
63        ;; for XEmacs/mule
64        (require 'emu-x20)
65        )
66       ((boundp 'MULE)
67        ;; for MULE 1.* and 2.*
68        (require 'emu-mule)
69        )
70       ((boundp 'NEMACS)
71        ;; for NEmacs and NEpoch
72        (require 'emu-nemacs)
73        )
74       (t
75        ;; for EMACS 19 and XEmacs 19 (without mule)
76        (require 'emu-e19)
77        ))
78
79
80 ;;; @ MIME charset
81 ;;;
82
83 (defun charsets-to-mime-charset (charsets)
84   "Return MIME charset from list of charset CHARSETS.
85 This function refers variable `charsets-mime-charset-alist'
86 and `default-mime-charset'. [emu.el]"
87   (if charsets
88       (or (catch 'tag
89             (let ((rest charsets-mime-charset-alist)
90                   cell csl)
91               (while (setq cell (car rest))
92                 (if (catch 'not-subset
93                       (let ((set1 charsets)
94                             (set2 (car cell))
95                             obj)
96                         (while set1
97                           (setq obj (car set1))
98                           (or (memq obj set2)
99                               (throw 'not-subset nil)
100                               )
101                           (setq set1 (cdr set1))
102                           )
103                         t))
104                     (throw 'tag (cdr cell))
105                   )
106                 (setq rest (cdr rest))
107                 )))
108           default-mime-charset)))
109
110
111 ;;; @ EMACS 19.29 emulation
112 ;;;
113
114 (or (fboundp 'buffer-substring-no-properties)
115     (defun buffer-substring-no-properties (beg end)
116       "Return the text from BEG to END, without text properties, as a string.
117 \[emu.el; EMACS 19.29 emulating function]"
118       (let ((string (buffer-substring beg end)))
119         (tl:set-text-properties 0 (length string) nil string)
120         string))
121     )
122
123 (or running-emacs-19_29-or-later
124     running-xemacs
125     ;; for Emacs 19.28 or earlier
126     (fboundp 'si:read-string)
127     (progn
128       (fset 'si:read-string (symbol-function 'read-string))
129       
130       (defun read-string (prompt &optional initial-input history)
131         "Read a string from the minibuffer, prompting with string PROMPT.
132 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
133 The third arg HISTORY, is dummy for compatibility. [emu.el]
134 See `read-from-minibuffer' for details of HISTORY argument."
135         (si:read-string prompt initial-input)
136         )
137       ))
138
139 (or (fboundp 'add-to-list)
140     ;; This function was imported Emacs 19.30.
141     (defun add-to-list (list-var element)
142       "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
143 If you want to use `add-to-list' on a variable that is not defined
144 until a certain package is loaded, you should put the call to `add-to-list'
145 into a hook function that will be run only after loading the package.
146 \[emu.el; EMACS 19.30 emulating function]"
147       (or (member element (symbol-value list-var))
148           (set list-var (cons element (symbol-value list-var)))))
149     )
150
151
152 ;;; @ EMACS 19.31 emulation
153 ;;;
154
155 (or (fboundp 'buffer-live-p)
156     (defun buffer-live-p (object)
157       "Return non-nil if OBJECT is a buffer which has not been killed.
158 Value is nil if OBJECT is not a buffer or if it has been killed.
159 \[emu.el; EMACS 19.31 emulating function]"
160       (and object
161            (get-buffer object)
162            (buffer-name (get-buffer object))
163            ))
164     )
165
166 (or (fboundp 'save-selected-window)
167     ;; This function was imported Emacs 19.33.
168     (defmacro save-selected-window (&rest body)
169       "Execute BODY, then select the window that was selected before BODY.
170 \[emu.el; EMACS 19.31 emulating function]"
171       (list 'let
172             '((save-selected-window-window (selected-window)))
173             (list 'unwind-protect
174                   (cons 'progn body)
175                   (list 'select-window 'save-selected-window-window)))) 
176     )
177
178
179 ;;; @ XEmacs emulation
180 ;;;
181
182 (or (fboundp 'functionp)
183     (defun functionp (obj)
184       "Returns t if OBJ is a function, nil otherwise.
185 \[emu.el; XEmacs emulating function]"
186       (or (subrp obj)
187           (byte-code-function-p obj)
188           (and (symbolp obj)(fboundp obj))
189           (and (consp obj)(eq (car obj) 'lambda))
190           ))
191     )
192         
193
194 ;;; @ for XEmacs 20
195 ;;;
196
197 (or (fboundp 'char-int)
198     (fset 'char-int (symbol-function 'identity))
199     )
200 (or (fboundp 'int-char)
201     (fset 'int-char (symbol-function 'identity))
202     )
203
204
205 ;;; @ for text/richtext and text/enriched
206 ;;;
207
208 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
209        ;; have enriched.el
210        (autoload 'richtext-decode "richtext")
211        (or (assq 'text/richtext format-alist)
212            (setq format-alist
213                  (cons
214                   (cons 'text/richtext
215                         '("Extended MIME text/richtext format."
216                           "Content-[Tt]ype:[ \t]*text/richtext"
217                           richtext-decode richtext-encode t enriched-mode))
218                   format-alist)))
219        )
220       (t
221        ;; don't have enriched.el
222        (autoload 'richtext-decode "tinyrich")
223        (autoload 'enriched-decode "tinyrich")
224        ))
225
226
227 ;;; @ end
228 ;;;
229
230 (provide 'emu)
231
232 ;;; emu.el ends here