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.37 1996/11/29 21:22:25 shuhei-k 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 insert-binary-file-contents-literally
98 (filename &optional visit beg end replace)
99 "Like `insert-file-contents-literally', q.v., but don't code conversion.
100 A buffer may be modified in several ways after reading into the buffer due
101 to advanced Emacs features, such as file-name-handlers, format decoding,
102 find-file-hooks, etc.
103 This function ensures that none of these modifications will take place.
105 (as-binary-input-file
106 (insert-file-contents-literally filename visit beg end replace)
113 (defun charsets-to-mime-charset (charsets)
114 "Return MIME charset from list of charset CHARSETS.
115 This function refers variable `charsets-mime-charset-alist'
116 and `default-mime-charset'. [emu.el]"
119 (let ((rest charsets-mime-charset-alist)
121 (while (setq cell (car rest))
122 (if (catch 'not-subset
123 (let ((set1 charsets)
127 (setq obj (car set1))
129 (throw 'not-subset nil)
131 (setq set1 (cdr set1))
134 (throw 'tag (cdr cell))
136 (setq rest (cdr rest))
138 default-mime-charset)))
141 ;;; @ EMACS 19.29 emulation
144 (defvar path-separator ":"
145 "Character used to separate concatenated paths.")
147 (defun-maybe buffer-substring-no-properties (beg end)
148 "Return the text from BEG to END, without text properties, as a string.
149 \[emu.el; EMACS 19.29 emulating function]"
150 (let ((string (buffer-substring beg end)))
151 (tl:set-text-properties 0 (length string) nil string)
154 (defun-maybe match-string (num &optional string)
155 "Return string of text matched by last search.
156 NUM specifies which parenthesized expression in the last regexp.
157 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
158 Zero means the entire text matched by the whole regexp or whole string.
159 STRING should be given if the last search was by `string-match' on STRING.
160 \[emu.el; EMACS 19.29 emulating function]"
161 (if (match-beginning num)
163 (substring string (match-beginning num) (match-end num))
164 (buffer-substring (match-beginning num) (match-end num)))))
166 (or running-emacs-19_29-or-later
168 ;; for Emacs 19.28 or earlier
169 (fboundp 'si:read-string)
171 (fset 'si:read-string (symbol-function 'read-string))
173 (defun read-string (prompt &optional initial-input history)
174 "Read a string from the minibuffer, prompting with string PROMPT.
175 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
176 The third arg HISTORY, is dummy for compatibility. [emu.el]
177 See `read-from-minibuffer' for details of HISTORY argument."
178 (si:read-string prompt initial-input)
182 ;; This function was imported Emacs 19.30.
183 (defun-maybe add-to-list (list-var element)
184 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
185 If you want to use `add-to-list' on a variable that is not defined
186 until a certain package is loaded, you should put the call to `add-to-list'
187 into a hook function that will be run only after loading the package.
188 \[emu.el; EMACS 19.30 emulating function]"
189 (or (member element (symbol-value list-var))
190 (set list-var (cons element (symbol-value list-var)))
194 ;;; @ EMACS 19.30 emulation
197 (cond ((fboundp 'insert-file-contents-literally)
199 ((boundp 'file-name-handler-alist)
200 (defun insert-file-contents-literally
201 (filename &optional visit beg end replace)
202 "Like `insert-file-contents', q.v., but only reads in the file.
203 A buffer may be modified in several ways after reading into the buffer due
204 to advanced Emacs features, such as file-name-handlers, format decoding,
205 find-file-hooks, etc.
206 This function ensures that none of these modifications will take place.
207 \[emu.el; Emacs 19.30 emulating function]"
208 (let (file-name-handler-alist)
209 (insert-file-contents filename visit beg end replace)
213 (defalias 'insert-file-contents-literally 'insert-file-contents)
217 ;;; @ EMACS 19.31 emulation
220 (defun-maybe buffer-live-p (object)
221 "Return non-nil if OBJECT is a buffer which has not been killed.
222 Value is nil if OBJECT is not a buffer or if it has been killed.
223 \[emu.el; EMACS 19.31 emulating function]"
226 (buffer-name (get-buffer object))
229 (or (fboundp 'save-selected-window)
230 ;; This function was imported Emacs 19.33.
231 (defmacro save-selected-window (&rest body)
232 "Execute BODY, then select the window that was selected before BODY.
233 \[emu.el; EMACS 19.31 emulating function]"
235 '((save-selected-window-window (selected-window)))
236 (list 'unwind-protect
238 (list 'select-window 'save-selected-window-window))))
242 ;;; @ XEmacs emulation
245 (defun-maybe functionp (obj)
246 "Returns t if OBJ is a function, nil otherwise.
247 \[emu.el; XEmacs emulating function]"
249 (byte-code-function-p obj)
250 (and (symbolp obj)(fboundp obj))
251 (and (consp obj)(eq (car obj) 'lambda))
258 (or (fboundp 'char-int)
259 (fset 'char-int (symbol-function 'identity))
261 (or (fboundp 'int-char)
262 (fset 'int-char (symbol-function 'identity))
266 ;;; @ for text/richtext and text/enriched
269 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
271 (autoload 'richtext-decode "richtext")
272 (or (assq 'text/richtext format-alist)
276 '("Extended MIME text/richtext format."
277 "Content-[Tt]ype:[ \t]*text/richtext"
278 richtext-decode richtext-encode t enriched-mode))
282 ;; don't have enriched.el
283 (autoload 'richtext-decode "tinyrich")
284 (autoload 'enriched-decode "tinyrich")