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.48 1997/09/07 02:37:40 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 (defmacro defsubst-maybe (name &rest everything-else)
40 (or (and (fboundp name)
41 (not (get name 'defsubst-maybe))
43 (` (or (fboundp (quote (, name)))
45 (defsubst (, name) (,@ everything-else))
46 (put (quote (, name)) 'defsubst-maybe t)
50 (defmacro defmacro-maybe (name &rest everything-else)
51 (or (and (fboundp name)
52 (not (get name 'defmacro-maybe))
54 (` (or (fboundp (quote (, name)))
56 (defmacro (, name) (,@ everything-else))
57 (put (quote (, name)) 'defmacro-maybe t)
61 (put 'defun-maybe 'lisp-indent-function 'defun)
62 (put 'defsubst-maybe 'lisp-indent-function 'defun)
63 (put 'defmacro-maybe 'lisp-indent-function 'defun)
65 (defmacro defconst-maybe (name &rest everything-else)
66 (or (and (boundp name)
67 (not (get name 'defconst-maybe))
69 (` (or (boundp (quote (, name)))
71 (defconst (, name) (,@ everything-else))
72 (put (quote (, name)) 'defconst-maybe t)
77 (defconst-maybe emacs-major-version (string-to-int emacs-version))
78 (defconst-maybe emacs-minor-version
80 (substring emacs-version
81 (string-match (format "%d\\." emacs-major-version)
84 (defvar running-emacs-18 (<= emacs-major-version 18))
85 (defvar running-xemacs (string-match "XEmacs" emacs-version))
87 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
88 (not running-xemacs) (featurep 'mule)))
89 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
91 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
92 (defvar running-emacs-19_29-or-later
93 (or (and running-emacs-19 (>= emacs-minor-version 29))
94 (and (not running-xemacs)(>= emacs-major-version 20))))
96 (defvar running-xemacs-19 (and running-xemacs
97 (= emacs-major-version 19)))
98 (defvar running-xemacs-20-or-later (and running-xemacs
99 (>= emacs-major-version 20)))
100 (defvar running-xemacs-19_14-or-later
101 (or (and running-xemacs-19 (>= emacs-minor-version 14))
102 running-xemacs-20-or-later))
104 (cond (running-mule-merged-emacs
105 ;; for Emacs 20.1 and 20.2
108 (running-xemacs-with-mule
109 ;; for XEmacs with mule
113 ;; for MULE 1.* and 2.*
117 ;; for NEmacs and NEpoch
118 (require 'emu-nemacs)
121 ;; for Emacs 19 and XEmacs without mule
122 (require 'emu-latin1)
129 (defun charsets-to-mime-charset (charsets)
130 "Return MIME charset from list of charset CHARSETS.
131 This function refers variable `charsets-mime-charset-alist'
132 and `default-mime-charset'."
135 (let ((rest charsets-mime-charset-alist)
137 (while (setq cell (car rest))
138 (if (catch 'not-subset
139 (let ((set1 charsets)
143 (setq obj (car set1))
145 (throw 'not-subset nil)
147 (setq set1 (cdr set1))
150 (throw 'tag (cdr cell))
152 (setq rest (cdr rest))
154 default-mime-charset)))
157 ;;; @ Emacs 19 emulation
160 (defun-maybe minibuffer-prompt-width ()
161 "Return the display width of the minibuffer prompt."
163 (set-buffer (window-buffer (minibuffer-window)))
168 ;;; @ Emacs 19.29 emulation
171 (defvar path-separator ":"
172 "Character used to separate concatenated paths.")
174 (defun-maybe buffer-substring-no-properties (start end)
175 "Return the characters of part of the buffer, without the text properties.
176 The two arguments START and END are character positions;
177 they can be in either order. [Emacs 19.29 emulating function]"
178 (let ((string (buffer-substring start end)))
179 (set-text-properties 0 (length string) nil string)
182 (defun-maybe match-string (num &optional string)
183 "Return string of text matched by last search.
184 NUM specifies which parenthesized expression in the last regexp.
185 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
186 Zero means the entire text matched by the whole regexp or whole string.
187 STRING should be given if the last search was by `string-match' on STRING.
188 \[Emacs 19.29 emulating function]"
189 (if (match-beginning num)
191 (substring string (match-beginning num) (match-end num))
192 (buffer-substring (match-beginning num) (match-end num)))))
194 (or running-emacs-19_29-or-later
196 ;; for Emacs 19.28 or earlier
197 (fboundp 'si:read-string)
199 (fset 'si:read-string (symbol-function 'read-string))
201 (defun read-string (prompt &optional initial-input history)
202 "Read a string from the minibuffer, prompting with string PROMPT.
203 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
204 The third arg HISTORY, is dummy for compatibility. [emu.el]
205 See `read-from-minibuffer' for details of HISTORY argument."
206 (si:read-string prompt initial-input)
211 ;;; @ Emacs 19.30 emulation
214 ;; This function was imported Emacs 19.30.
215 (defun-maybe add-to-list (list-var element)
216 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
217 If you want to use `add-to-list' on a variable that is not defined
218 until a certain package is loaded, you should put the call to `add-to-list'
219 into a hook function that will be run only after loading the package.
220 \[Emacs 19.30 emulating function]"
221 (or (member element (symbol-value list-var))
222 (set list-var (cons element (symbol-value list-var)))
225 (cond ((fboundp 'insert-file-contents-literally)
227 ((boundp 'file-name-handler-alist)
228 (defun insert-file-contents-literally
229 (filename &optional visit beg end replace)
230 "Like `insert-file-contents', q.v., but only reads in the file.
231 A buffer may be modified in several ways after reading into the buffer due
232 to advanced Emacs features, such as file-name-handlers, format decoding,
233 find-file-hooks, etc.
234 This function ensures that none of these modifications will take place.
235 \[Emacs 19.30 emulating function]"
236 (let (file-name-handler-alist)
237 (insert-file-contents filename visit beg end replace)
241 (defalias 'insert-file-contents-literally 'insert-file-contents)
245 ;;; @ Emacs 19.31 emulation
248 (defun-maybe buffer-live-p (object)
249 "Return non-nil if OBJECT is a buffer which has not been killed.
250 Value is nil if OBJECT is not a buffer or if it has been killed.
251 \[Emacs 19.31 emulating function]"
254 (buffer-name (get-buffer object))
257 ;; This macro was imported Emacs 19.33.
258 (defmacro-maybe save-selected-window (&rest body)
259 "Execute BODY, then select the window that was selected before BODY.
260 \[Emacs 19.31 emulating function]"
262 '((save-selected-window-window (selected-window)))
263 (list 'unwind-protect
265 (list 'select-window 'save-selected-window-window))))
268 ;;; @ XEmacs emulation
271 (defun-maybe functionp (obj)
272 "Returns t if OBJ is a function, nil otherwise.
273 \[XEmacs emulating function]"
275 (byte-code-function-p obj)
276 (and (symbolp obj)(fboundp obj))
277 (and (consp obj)(eq (car obj) 'lambda))
280 (defun-maybe point-at-eol (&optional arg buffer)
281 "Return the character position of the last character on the current line.
282 With argument N not nil or 1, move forward N - 1 lines first.
283 If scan reaches end of buffer, return that position.
284 This function does not move point. [XEmacs emulating function]"
290 (forward-line (1- arg))
300 (or (fboundp 'char-int)
301 (fset 'char-int (symbol-function 'identity))
303 (or (fboundp 'int-char)
304 (fset 'int-char (symbol-function 'identity))
306 (or (fboundp 'char-or-char-int-p)
307 (fset 'char-or-char-int-p (symbol-function 'integerp))
311 ;;; @ for text/richtext and text/enriched
314 (cond ((fboundp 'richtext-decode)
317 ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
319 (autoload 'richtext-decode "richtext")
320 (or (assq 'text/richtext format-alist)
324 '("Extended MIME text/richtext format."
325 "Content-[Tt]ype:[ \t]*text/richtext"
326 richtext-decode richtext-encode t enriched-mode))
330 ;; don't have enriched.el
331 (autoload 'richtext-decode "tinyrich")
332 (autoload 'enriched-decode "tinyrich")