6
|
1 ;;; emu.el --- Emulation module for each Emacs variants
|
|
2
|
|
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
6 ;; Version: $Id: emu.el,v 1.1.1.1 1996/12/18 04:06:19 steve Exp $
|
|
7 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
|
|
8
|
|
9 ;; This file is part of emu.
|
|
10
|
|
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.
|
|
15
|
|
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.
|
|
20
|
|
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.
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (defmacro defun-maybe (name &rest everything-else)
|
|
29 (or (and (fboundp name)
|
|
30 (not (get name 'defun-maybe))
|
|
31 )
|
|
32 (` (or (fboundp (quote (, name)))
|
|
33 (progn
|
|
34 (defun (, name) (,@ everything-else))
|
|
35 (put (quote (, name)) 'defun-maybe t)
|
|
36 ))
|
|
37 )))
|
|
38
|
|
39 (put 'defun-maybe 'lisp-indent-function 'defun)
|
|
40
|
|
41
|
|
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
|
|
46 (string-to-int
|
|
47 (substring
|
|
48 emacs-version
|
|
49 (string-match (format "%d\\." emacs-major-version) emacs-version)
|
|
50 ))))
|
|
51
|
|
52 (defvar running-emacs-18 (<= emacs-major-version 18))
|
|
53 (defvar running-xemacs (string-match "XEmacs" emacs-version))
|
|
54
|
|
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)))
|
|
58
|
|
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))))
|
|
63
|
|
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))
|
|
71
|
|
72 (cond (running-mule-merged-emacs
|
|
73 ;; for mule merged EMACS
|
|
74 (require 'emu-e20)
|
|
75 )
|
|
76 (running-xemacs-with-mule
|
|
77 ;; for XEmacs/mule
|
|
78 (require 'emu-x20)
|
|
79 )
|
|
80 ((boundp 'MULE)
|
|
81 ;; for MULE 1.* and 2.*
|
|
82 (require 'emu-mule)
|
|
83 )
|
|
84 ((boundp 'NEMACS)
|
|
85 ;; for NEmacs and NEpoch
|
|
86 (require 'emu-nemacs)
|
|
87 )
|
|
88 (t
|
|
89 ;; for EMACS 19 and XEmacs 19 (without mule)
|
|
90 (require 'emu-e19)
|
|
91 ))
|
|
92
|
|
93
|
|
94 ;;; @ binary access
|
|
95 ;;;
|
|
96
|
|
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.
|
|
104 \[emu.el]"
|
|
105 (as-binary-input-file
|
|
106 (insert-file-contents-literally filename visit beg end replace)
|
|
107 ))
|
|
108
|
|
109
|
|
110 ;;; @ MIME charset
|
|
111 ;;;
|
|
112
|
|
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]"
|
|
117 (if charsets
|
|
118 (or (catch 'tag
|
|
119 (let ((rest charsets-mime-charset-alist)
|
|
120 cell csl)
|
|
121 (while (setq cell (car rest))
|
|
122 (if (catch 'not-subset
|
|
123 (let ((set1 charsets)
|
|
124 (set2 (car cell))
|
|
125 obj)
|
|
126 (while set1
|
|
127 (setq obj (car set1))
|
|
128 (or (memq obj set2)
|
|
129 (throw 'not-subset nil)
|
|
130 )
|
|
131 (setq set1 (cdr set1))
|
|
132 )
|
|
133 t))
|
|
134 (throw 'tag (cdr cell))
|
|
135 )
|
|
136 (setq rest (cdr rest))
|
|
137 )))
|
|
138 default-mime-charset)))
|
|
139
|
|
140
|
|
141 ;;; @ EMACS 19.29 emulation
|
|
142 ;;;
|
|
143
|
|
144 (defvar path-separator ":"
|
|
145 "Character used to separate concatenated paths.")
|
|
146
|
|
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)
|
|
152 string))
|
|
153
|
|
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)
|
|
162 (if string
|
|
163 (substring string (match-beginning num) (match-end num))
|
|
164 (buffer-substring (match-beginning num) (match-end num)))))
|
|
165
|
|
166 (or running-emacs-19_29-or-later
|
|
167 running-xemacs
|
|
168 ;; for Emacs 19.28 or earlier
|
|
169 (fboundp 'si:read-string)
|
|
170 (progn
|
|
171 (fset 'si:read-string (symbol-function 'read-string))
|
|
172
|
|
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)
|
|
179 )
|
|
180 ))
|
|
181
|
|
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)))
|
|
191 ))
|
|
192
|
|
193
|
|
194 ;;; @ EMACS 19.30 emulation
|
|
195 ;;;
|
|
196
|
|
197 (cond ((fboundp 'insert-file-contents-literally)
|
|
198 )
|
|
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)
|
|
210 ))
|
|
211 )
|
|
212 (t
|
|
213 (defalias 'insert-file-contents-literally 'insert-file-contents)
|
|
214 ))
|
|
215
|
|
216
|
|
217 ;;; @ EMACS 19.31 emulation
|
|
218 ;;;
|
|
219
|
|
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]"
|
|
224 (and object
|
|
225 (get-buffer object)
|
|
226 (buffer-name (get-buffer object))
|
|
227 ))
|
|
228
|
|
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]"
|
|
234 (list 'let
|
|
235 '((save-selected-window-window (selected-window)))
|
|
236 (list 'unwind-protect
|
|
237 (cons 'progn body)
|
|
238 (list 'select-window 'save-selected-window-window))))
|
|
239 )
|
|
240
|
|
241
|
|
242 ;;; @ XEmacs emulation
|
|
243 ;;;
|
|
244
|
|
245 (defun-maybe functionp (obj)
|
|
246 "Returns t if OBJ is a function, nil otherwise.
|
|
247 \[emu.el; XEmacs emulating function]"
|
|
248 (or (subrp obj)
|
|
249 (byte-code-function-p obj)
|
|
250 (and (symbolp obj)(fboundp obj))
|
|
251 (and (consp obj)(eq (car obj) 'lambda))
|
|
252 ))
|
|
253
|
|
254
|
|
255 ;;; @ for XEmacs 20
|
|
256 ;;;
|
|
257
|
|
258 (or (fboundp 'char-int)
|
|
259 (fset 'char-int (symbol-function 'identity))
|
|
260 )
|
|
261 (or (fboundp 'int-char)
|
|
262 (fset 'int-char (symbol-function 'identity))
|
|
263 )
|
|
264
|
|
265
|
|
266 ;;; @ for text/richtext and text/enriched
|
|
267 ;;;
|
|
268
|
|
269 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
|
|
270 ;; have enriched.el
|
|
271 (autoload 'richtext-decode "richtext")
|
|
272 (or (assq 'text/richtext format-alist)
|
|
273 (setq format-alist
|
|
274 (cons
|
|
275 (cons 'text/richtext
|
|
276 '("Extended MIME text/richtext format."
|
|
277 "Content-[Tt]ype:[ \t]*text/richtext"
|
|
278 richtext-decode richtext-encode t enriched-mode))
|
|
279 format-alist)))
|
|
280 )
|
|
281 (t
|
|
282 ;; don't have enriched.el
|
|
283 (autoload 'richtext-decode "tinyrich")
|
|
284 (autoload 'enriched-decode "tinyrich")
|
|
285 ))
|
|
286
|
|
287
|
|
288 ;;; @ end
|
|
289 ;;;
|
|
290
|
|
291 (provide 'emu)
|
|
292
|
|
293 ;;; emu.el ends here
|