1 ;;; emu.el --- Emulation module for each Emacs variants
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu.el,v 7.32 1996/09/21 16:08:35 morioka Exp $
7 ;; Keywords: emulation, compatibility, NEmacs, MULE, XEmacs
9 ;; This file is part of tl (Tiny Library).
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.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
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
35 (string-match (format "%d\\." emacs-major-version) emacs-version)
38 (defvar running-emacs-18 (<= emacs-major-version 18))
39 (defvar running-xemacs (string-match "XEmacs" emacs-version))
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)))
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))))
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))
58 (cond (running-mule-merged-emacs
59 ;; for mule merged EMACS
62 (running-xemacs-with-mule
67 ;; for MULE 1.* and 2.*
71 ;; for NEmacs and NEpoch
75 ;; for EMACS 19 and XEmacs 19 (without mule)
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]"
89 (let ((rest charsets-mime-charset-alist)
91 (while (setq cell (car rest))
92 (if (catch 'not-subset
99 (throw 'not-subset nil)
101 (setq set1 (cdr set1))
104 (throw 'tag (cdr cell))
106 (setq rest (cdr rest))
108 default-mime-charset)))
111 ;;; @ EMACS 19.29 emulation
114 (defvar path-separator ":"
115 "Character used to separate concatenated paths.")
117 (or (fboundp 'buffer-substring-no-properties)
118 (defun buffer-substring-no-properties (beg end)
119 "Return the text from BEG to END, without text properties, as a string.
120 \[emu.el; EMACS 19.29 emulating function]"
121 (let ((string (buffer-substring beg end)))
122 (tl:set-text-properties 0 (length string) nil string)
126 (or running-emacs-19_29-or-later
128 ;; for Emacs 19.28 or earlier
129 (fboundp 'si:read-string)
131 (fset 'si:read-string (symbol-function 'read-string))
133 (defun read-string (prompt &optional initial-input history)
134 "Read a string from the minibuffer, prompting with string PROMPT.
135 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
136 The third arg HISTORY, is dummy for compatibility. [emu.el]
137 See `read-from-minibuffer' for details of HISTORY argument."
138 (si:read-string prompt initial-input)
142 (or (fboundp 'add-to-list)
143 ;; This function was imported Emacs 19.30.
144 (defun add-to-list (list-var element)
145 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
146 If you want to use `add-to-list' on a variable that is not defined
147 until a certain package is loaded, you should put the call to `add-to-list'
148 into a hook function that will be run only after loading the package.
149 \[emu.el; EMACS 19.30 emulating function]"
150 (or (member element (symbol-value list-var))
151 (set list-var (cons element (symbol-value list-var)))))
155 ;;; @ EMACS 19.30 emulation
158 (or (fboundp 'insert-file-contents-literally)
159 (defalias 'insert-file-contents-literally 'insert-file-contents)
163 ;;; @ EMACS 19.31 emulation
166 (or (fboundp 'buffer-live-p)
167 (defun buffer-live-p (object)
168 "Return non-nil if OBJECT is a buffer which has not been killed.
169 Value is nil if OBJECT is not a buffer or if it has been killed.
170 \[emu.el; EMACS 19.31 emulating function]"
173 (buffer-name (get-buffer object))
177 (or (fboundp 'save-selected-window)
178 ;; This function was imported Emacs 19.33.
179 (defmacro save-selected-window (&rest body)
180 "Execute BODY, then select the window that was selected before BODY.
181 \[emu.el; EMACS 19.31 emulating function]"
183 '((save-selected-window-window (selected-window)))
184 (list 'unwind-protect
186 (list 'select-window 'save-selected-window-window))))
190 ;;; @ XEmacs emulation
193 (or (fboundp 'functionp)
194 (defun functionp (obj)
195 "Returns t if OBJ is a function, nil otherwise.
196 \[emu.el; XEmacs emulating function]"
198 (byte-code-function-p obj)
199 (and (symbolp obj)(fboundp obj))
200 (and (consp obj)(eq (car obj) 'lambda))
208 (or (fboundp 'char-int)
209 (fset 'char-int (symbol-function 'identity))
211 (or (fboundp 'int-char)
212 (fset 'int-char (symbol-function 'identity))
216 ;;; @ for text/richtext and text/enriched
219 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
221 (autoload 'richtext-decode "richtext")
222 (or (assq 'text/richtext format-alist)
226 '("Extended MIME text/richtext format."
227 "Content-[Tt]ype:[ \t]*text/richtext"
228 richtext-decode richtext-encode t enriched-mode))
232 ;; don't have enriched.el
233 (autoload 'richtext-decode "tinyrich")
234 (autoload 'enriched-decode "tinyrich")