1 ;;; emu.el --- Emulation module for each Emacs variants
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu.el,v 7.38 1997/02/13 08:21:59 morioka Exp $
7 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
9 ;; This file is part of emu.
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 (defmacro defun-maybe (name &rest everything-else)
29 (or (and (fboundp name)
30 (not (get name 'defun-maybe))
32 (` (or (fboundp (quote (, name)))
34 (defun (, name) (,@ everything-else))
35 (put (quote (, name)) 'defun-maybe t)
39 (put 'defun-maybe 'lisp-indent-function 'defun)
42 (or (boundp 'emacs-major-version)
43 (defconst emacs-major-version (string-to-int emacs-version)))
44 (or (boundp 'emacs-minor-version)
45 (defconst emacs-minor-version
49 (string-match (format "%d\\." emacs-major-version) emacs-version)
52 (defvar running-emacs-18 (<= emacs-major-version 18))
53 (defvar running-xemacs (string-match "XEmacs" emacs-version))
55 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
56 (not running-xemacs) (featurep 'mule)))
57 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
59 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
60 (defvar running-emacs-19_29-or-later
61 (or (and running-emacs-19 (>= emacs-minor-version 29))
62 (and (not running-xemacs)(>= emacs-major-version 20))))
64 (defvar running-xemacs-19 (and running-xemacs
65 (= emacs-major-version 19)))
66 (defvar running-xemacs-20-or-later (and running-xemacs
67 (>= emacs-major-version 20)))
68 (defvar running-xemacs-19_14-or-later
69 (or (and running-xemacs-19 (>= emacs-minor-version 14))
70 running-xemacs-20-or-later))
72 (cond (running-mule-merged-emacs
73 ;; for mule merged EMACS
76 (running-xemacs-with-mule
81 ;; for MULE 1.* and 2.*
85 ;; for NEmacs and NEpoch
89 ;; for EMACS 19 and XEmacs 19 (without mule)
97 (defun charsets-to-mime-charset (charsets)
98 "Return MIME charset from list of charset CHARSETS.
99 This function refers variable `charsets-mime-charset-alist'
100 and `default-mime-charset'. [emu.el]"
103 (let ((rest charsets-mime-charset-alist)
105 (while (setq cell (car rest))
106 (if (catch 'not-subset
107 (let ((set1 charsets)
111 (setq obj (car set1))
113 (throw 'not-subset nil)
115 (setq set1 (cdr set1))
118 (throw 'tag (cdr cell))
120 (setq rest (cdr rest))
122 default-mime-charset)))
125 ;;; @ EMACS 19.29 emulation
128 (defvar path-separator ":"
129 "Character used to separate concatenated paths.")
131 (defun-maybe buffer-substring-no-properties (beg end)
132 "Return the text from BEG to END, without text properties, as a string.
133 \[emu.el; EMACS 19.29 emulating function]"
134 (let ((string (buffer-substring beg end)))
135 (tl:set-text-properties 0 (length string) nil string)
138 (defun-maybe match-string (num &optional string)
139 "Return string of text matched by last search.
140 NUM specifies which parenthesized expression in the last regexp.
141 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
142 Zero means the entire text matched by the whole regexp or whole string.
143 STRING should be given if the last search was by `string-match' on STRING.
144 \[emu.el; EMACS 19.29 emulating function]"
145 (if (match-beginning num)
147 (substring string (match-beginning num) (match-end num))
148 (buffer-substring (match-beginning num) (match-end num)))))
150 (or running-emacs-19_29-or-later
152 ;; for Emacs 19.28 or earlier
153 (fboundp 'si:read-string)
155 (fset 'si:read-string (symbol-function 'read-string))
157 (defun read-string (prompt &optional initial-input history)
158 "Read a string from the minibuffer, prompting with string PROMPT.
159 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
160 The third arg HISTORY, is dummy for compatibility. [emu.el]
161 See `read-from-minibuffer' for details of HISTORY argument."
162 (si:read-string prompt initial-input)
166 ;; This function was imported Emacs 19.30.
167 (defun-maybe add-to-list (list-var element)
168 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
169 If you want to use `add-to-list' on a variable that is not defined
170 until a certain package is loaded, you should put the call to `add-to-list'
171 into a hook function that will be run only after loading the package.
172 \[emu.el; EMACS 19.30 emulating function]"
173 (or (member element (symbol-value list-var))
174 (set list-var (cons element (symbol-value list-var)))
178 ;;; @ EMACS 19.30 emulation
181 (cond ((fboundp 'insert-file-contents-literally)
183 ((boundp 'file-name-handler-alist)
184 (defun insert-file-contents-literally
185 (filename &optional visit beg end replace)
186 "Like `insert-file-contents', q.v., but only reads in the file.
187 A buffer may be modified in several ways after reading into the buffer due
188 to advanced Emacs features, such as file-name-handlers, format decoding,
189 find-file-hooks, etc.
190 This function ensures that none of these modifications will take place.
191 \[emu.el; Emacs 19.30 emulating function]"
192 (let (file-name-handler-alist)
193 (insert-file-contents filename visit beg end replace)
197 (defalias 'insert-file-contents-literally 'insert-file-contents)
201 ;;; @ EMACS 19.31 emulation
204 (defun-maybe buffer-live-p (object)
205 "Return non-nil if OBJECT is a buffer which has not been killed.
206 Value is nil if OBJECT is not a buffer or if it has been killed.
207 \[emu.el; EMACS 19.31 emulating function]"
210 (buffer-name (get-buffer object))
213 (or (fboundp 'save-selected-window)
214 ;; This function was imported Emacs 19.33.
215 (defmacro save-selected-window (&rest body)
216 "Execute BODY, then select the window that was selected before BODY.
217 \[emu.el; EMACS 19.31 emulating function]"
219 '((save-selected-window-window (selected-window)))
220 (list 'unwind-protect
222 (list 'select-window 'save-selected-window-window))))
226 ;;; @ XEmacs emulation
229 (defun-maybe functionp (obj)
230 "Returns t if OBJ is a function, nil otherwise.
231 \[emu.el; XEmacs emulating function]"
233 (byte-code-function-p obj)
234 (and (symbolp obj)(fboundp obj))
235 (and (consp obj)(eq (car obj) 'lambda))
242 (or (fboundp 'char-int)
243 (fset 'char-int (symbol-function 'identity))
245 (or (fboundp 'int-char)
246 (fset 'int-char (symbol-function 'identity))
250 ;;; @ for text/richtext and text/enriched
253 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
255 (autoload 'richtext-decode "richtext")
256 (or (assq 'text/richtext format-alist)
260 '("Extended MIME text/richtext format."
261 "Content-[Tt]ype:[ \t]*text/richtext"
262 richtext-decode richtext-encode t enriched-mode))
266 ;; don't have enriched.el
267 (autoload 'richtext-decode "tinyrich")
268 (autoload 'enriched-decode "tinyrich")