1 ;;; emu.el --- Emulation module for each Emacs variants
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
8 ;; This file is part of emu.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (defmacro defun-maybe (name &rest everything-else)
28 (or (and (fboundp name)
29 (not (get name 'defun-maybe))
31 (` (or (fboundp (quote (, name)))
33 (defun (, name) (,@ everything-else))
34 (put (quote (, name)) 'defun-maybe t)
38 (defmacro defsubst-maybe (name &rest everything-else)
39 (or (and (fboundp name)
40 (not (get name 'defsubst-maybe))
42 (` (or (fboundp (quote (, name)))
44 (defsubst (, name) (,@ everything-else))
45 (put (quote (, name)) 'defsubst-maybe t)
49 (defmacro defmacro-maybe (name &rest everything-else)
50 (or (and (fboundp name)
51 (not (get name 'defmacro-maybe))
53 (` (or (fboundp (quote (, name)))
55 (defmacro (, name) (,@ everything-else))
56 (put (quote (, name)) 'defmacro-maybe t)
60 (put 'defun-maybe 'lisp-indent-function 'defun)
61 (put 'defsubst-maybe 'lisp-indent-function 'defun)
62 (put 'defmacro-maybe 'lisp-indent-function 'defun)
64 (defmacro defconst-maybe (name &rest everything-else)
65 (or (and (boundp name)
66 (not (get name 'defconst-maybe))
68 (` (or (boundp (quote (, name)))
70 (defconst (, name) (,@ everything-else))
71 (put (quote (, name)) 'defconst-maybe t)
76 (defconst-maybe emacs-major-version (string-to-int emacs-version))
77 (defconst-maybe emacs-minor-version
79 (substring emacs-version
80 (string-match (format "%d\\." emacs-major-version)
83 (defvar running-emacs-18 (<= emacs-major-version 18))
84 (defvar running-xemacs (string-match "XEmacs" emacs-version))
86 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
87 (not running-xemacs) (featurep 'mule)))
88 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
90 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
91 (defvar running-emacs-19_29-or-later
92 (or (and running-emacs-19 (>= emacs-minor-version 29))
93 (and (not running-xemacs)(>= emacs-major-version 20))))
95 (defvar running-xemacs-19 (and running-xemacs
96 (= emacs-major-version 19)))
97 (defvar running-xemacs-20-or-later (and running-xemacs
98 (>= emacs-major-version 20)))
99 (defvar running-xemacs-19_14-or-later
100 (or (and running-xemacs-19 (>= emacs-minor-version 14))
101 running-xemacs-20-or-later))
103 (cond (running-xemacs
105 (cond ((featurep 'mule)
106 ;; for XEmacs with MULE
110 ;; for XEmacs without MULE
111 (require 'emu-xemacs)
112 (require 'emu-latin1)
115 (running-mule-merged-emacs
116 ;; for Emacs 20.1 and 20.2
120 ;; for MULE 1.* and 2.*
124 ;; for NEmacs and NEpoch
125 (require 'emu-nemacs)
130 (require 'emu-latin1)
137 (defun charsets-to-mime-charset (charsets)
138 "Return MIME charset from list of charset CHARSETS.
139 This function refers variable `charsets-mime-charset-alist'
140 and `default-mime-charset'."
143 (let ((rest charsets-mime-charset-alist)
145 (while (setq cell (car rest))
146 (if (catch 'not-subset
147 (let ((set1 charsets)
151 (setq obj (car set1))
153 (throw 'not-subset nil)
155 (setq set1 (cdr set1))
158 (throw 'tag (cdr cell))
160 (setq rest (cdr rest))
162 default-mime-charset)))
165 ;;; @ Emacs 19 emulation
168 (defun-maybe minibuffer-prompt-width ()
169 "Return the display width of the minibuffer prompt."
171 (set-buffer (window-buffer (minibuffer-window)))
176 ;;; @ Emacs 19.29 emulation
179 (defvar path-separator ":"
180 "Character used to separate concatenated paths.")
182 (defun-maybe buffer-substring-no-properties (start end)
183 "Return the characters of part of the buffer, without the text properties.
184 The two arguments START and END are character positions;
185 they can be in either order. [Emacs 19.29 emulating function]"
186 (let ((string (buffer-substring start end)))
187 (set-text-properties 0 (length string) nil string)
190 (defun-maybe match-string (num &optional string)
191 "Return string of text matched by last search.
192 NUM specifies which parenthesized expression in the last regexp.
193 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
194 Zero means the entire text matched by the whole regexp or whole string.
195 STRING should be given if the last search was by `string-match' on STRING.
196 \[Emacs 19.29 emulating function]"
197 (if (match-beginning num)
199 (substring string (match-beginning num) (match-end num))
200 (buffer-substring (match-beginning num) (match-end num)))))
202 (or running-emacs-19_29-or-later
204 ;; for Emacs 19.28 or earlier
205 (fboundp 'si:read-string)
207 (fset 'si:read-string (symbol-function 'read-string))
209 (defun read-string (prompt &optional initial-input history)
210 "Read a string from the minibuffer, prompting with string PROMPT.
211 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
212 The third arg HISTORY, is dummy for compatibility. [emu.el]
213 See `read-from-minibuffer' for details of HISTORY argument."
214 (si:read-string prompt initial-input)
219 ;;; @ Emacs 19.30 emulation
222 ;; This function was imported Emacs 19.30.
223 (defun-maybe add-to-list (list-var element)
224 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
225 If you want to use `add-to-list' on a variable that is not defined
226 until a certain package is loaded, you should put the call to `add-to-list'
227 into a hook function that will be run only after loading the package.
228 \[Emacs 19.30 emulating function]"
229 (or (member element (symbol-value list-var))
230 (set list-var (cons element (symbol-value list-var)))
233 (cond ((fboundp 'insert-file-contents-literally)
235 ((boundp 'file-name-handler-alist)
236 (defun insert-file-contents-literally
237 (filename &optional visit beg end replace)
238 "Like `insert-file-contents', q.v., but only reads in the file.
239 A buffer may be modified in several ways after reading into the buffer due
240 to advanced Emacs features, such as file-name-handlers, format decoding,
241 find-file-hooks, etc.
242 This function ensures that none of these modifications will take place.
243 \[Emacs 19.30 emulating function]"
244 (let (file-name-handler-alist)
245 (insert-file-contents filename visit beg end replace)
249 (defalias 'insert-file-contents-literally 'insert-file-contents)
253 ;;; @ Emacs 19.31 emulation
256 (defun-maybe buffer-live-p (object)
257 "Return non-nil if OBJECT is a buffer which has not been killed.
258 Value is nil if OBJECT is not a buffer or if it has been killed.
259 \[Emacs 19.31 emulating function]"
262 (buffer-name (get-buffer object))
265 ;; This macro was imported Emacs 19.33.
266 (defmacro-maybe save-selected-window (&rest body)
267 "Execute BODY, then select the window that was selected before BODY.
268 \[Emacs 19.31 emulating function]"
270 '((save-selected-window-window (selected-window)))
271 (list 'unwind-protect
273 (list 'select-window 'save-selected-window-window))))
276 ;;; @ XEmacs emulation
279 (defun-maybe functionp (obj)
280 "Returns t if OBJ is a function, nil otherwise.
281 \[XEmacs emulating function]"
283 (byte-code-function-p obj)
284 (and (symbolp obj)(fboundp obj))
285 (and (consp obj)(eq (car obj) 'lambda))
288 (defun-maybe point-at-eol (&optional arg buffer)
289 "Return the character position of the last character on the current line.
290 With argument N not nil or 1, move forward N - 1 lines first.
291 If scan reaches end of buffer, return that position.
292 This function does not move point. [XEmacs emulating function]"
298 (forward-line (1- arg))
308 (or (fboundp 'char-int)
309 (fset 'char-int (symbol-function 'identity))
311 (or (fboundp 'int-char)
312 (fset 'int-char (symbol-function 'identity))
314 (or (fboundp 'char-or-char-int-p)
315 (fset 'char-or-char-int-p (symbol-function 'integerp))
319 ;;; @ for text/richtext and text/enriched
322 (cond ((fboundp 'richtext-decode)
325 ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
327 (autoload 'richtext-decode "richtext")
328 (or (assq 'text/richtext format-alist)
332 '("Extended MIME text/richtext format."
333 "Content-[Tt]ype:[ \t]*text/richtext"
334 richtext-decode richtext-encode t enriched-mode))
338 ;; don't have enriched.el
339 (autoload 'richtext-decode "tinyrich")
340 (autoload 'enriched-decode "tinyrich")