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.34 1996/09/23 17:42:26 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 insert-binary-file-contents-literally
84 (filename &optional visit beg end replace)
85 "Like `insert-file-contents-literally', q.v., but don't code conversion.
86 A buffer may be modified in several ways after reading into the buffer due
87 to advanced Emacs features, such as file-name-handlers, format decoding,
89 This function ensures that none of these modifications will take place.
92 (insert-file-contents-literally filename visit beg end replace)
99 (defun charsets-to-mime-charset (charsets)
100 "Return MIME charset from list of charset CHARSETS.
101 This function refers variable `charsets-mime-charset-alist'
102 and `default-mime-charset'. [emu.el]"
105 (let ((rest charsets-mime-charset-alist)
107 (while (setq cell (car rest))
108 (if (catch 'not-subset
109 (let ((set1 charsets)
113 (setq obj (car set1))
115 (throw 'not-subset nil)
117 (setq set1 (cdr set1))
120 (throw 'tag (cdr cell))
122 (setq rest (cdr rest))
124 default-mime-charset)))
127 ;;; @ EMACS 19.29 emulation
130 (defvar path-separator ":"
131 "Character used to separate concatenated paths.")
133 (or (fboundp 'buffer-substring-no-properties)
134 (defun buffer-substring-no-properties (beg end)
135 "Return the text from BEG to END, without text properties, as a string.
136 \[emu.el; EMACS 19.29 emulating function]"
137 (let ((string (buffer-substring beg end)))
138 (tl:set-text-properties 0 (length string) nil string)
142 (or running-emacs-19_29-or-later
144 ;; for Emacs 19.28 or earlier
145 (fboundp 'si:read-string)
147 (fset 'si:read-string (symbol-function 'read-string))
149 (defun read-string (prompt &optional initial-input history)
150 "Read a string from the minibuffer, prompting with string PROMPT.
151 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
152 The third arg HISTORY, is dummy for compatibility. [emu.el]
153 See `read-from-minibuffer' for details of HISTORY argument."
154 (si:read-string prompt initial-input)
158 (or (fboundp 'add-to-list)
159 ;; This function was imported Emacs 19.30.
160 (defun add-to-list (list-var element)
161 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
162 If you want to use `add-to-list' on a variable that is not defined
163 until a certain package is loaded, you should put the call to `add-to-list'
164 into a hook function that will be run only after loading the package.
165 \[emu.el; EMACS 19.30 emulating function]"
166 (or (member element (symbol-value list-var))
167 (set list-var (cons element (symbol-value list-var)))))
171 ;;; @ EMACS 19.30 emulation
174 (cond ((fboundp 'insert-file-contents-literally)
176 ((boundp 'file-name-handler-alist)
177 (defun insert-file-contents-literally
178 (filename &optional visit beg end replace)
179 "Like `insert-file-contents', q.v., but only reads in the file.
180 A buffer may be modified in several ways after reading into the buffer due
181 to advanced Emacs features, such as file-name-handlers, format decoding,
182 find-file-hooks, etc.
183 This function ensures that none of these modifications will take place.
184 \[emu.el; Emacs 19.30 emulating function]"
185 (let (file-name-handler-alist)
186 (insert-file-contents filename visit beg end replace)
190 (defalias 'insert-file-contents-literally 'insert-file-contents)
194 ;;; @ EMACS 19.31 emulation
197 (or (fboundp 'buffer-live-p)
198 (defun buffer-live-p (object)
199 "Return non-nil if OBJECT is a buffer which has not been killed.
200 Value is nil if OBJECT is not a buffer or if it has been killed.
201 \[emu.el; EMACS 19.31 emulating function]"
204 (buffer-name (get-buffer object))
208 (or (fboundp 'save-selected-window)
209 ;; This function was imported Emacs 19.33.
210 (defmacro save-selected-window (&rest body)
211 "Execute BODY, then select the window that was selected before BODY.
212 \[emu.el; EMACS 19.31 emulating function]"
214 '((save-selected-window-window (selected-window)))
215 (list 'unwind-protect
217 (list 'select-window 'save-selected-window-window))))
221 ;;; @ XEmacs emulation
224 (or (fboundp 'functionp)
225 (defun functionp (obj)
226 "Returns t if OBJ is a function, nil otherwise.
227 \[emu.el; XEmacs emulating function]"
229 (byte-code-function-p obj)
230 (and (symbolp obj)(fboundp obj))
231 (and (consp obj)(eq (car obj) 'lambda))
239 (or (fboundp 'char-int)
240 (fset 'char-int (symbol-function 'identity))
242 (or (fboundp 'int-char)
243 (fset 'int-char (symbol-function 'identity))
247 ;;; @ for text/richtext and text/enriched
250 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
252 (autoload 'richtext-decode "richtext")
253 (or (assq 'text/richtext format-alist)
257 '("Extended MIME text/richtext format."
258 "Content-[Tt]ype:[ \t]*text/richtext"
259 richtext-decode richtext-encode t enriched-mode))
263 ;; don't have enriched.el
264 (autoload 'richtext-decode "tinyrich")
265 (autoload 'enriched-decode "tinyrich")