4
|
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 03:55:31 steve Exp $
|
|
7 ;; Keywords: emulation, compatibility, NEmacs, MULE, XEmacs
|
|
8
|
|
9 ;; This file is part of tl (Tiny Library).
|
|
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 (or (boundp 'emacs-major-version)
|
|
29 (defconst emacs-major-version (string-to-int emacs-version)))
|
|
30 (or (boundp 'emacs-minor-version)
|
|
31 (defconst emacs-minor-version
|
|
32 (string-to-int
|
|
33 (substring
|
|
34 emacs-version
|
|
35 (string-match (format "%d\\." emacs-major-version) emacs-version)
|
|
36 ))))
|
|
37
|
|
38 (defvar running-emacs-18 (<= emacs-major-version 18))
|
|
39 (defvar running-xemacs (string-match "XEmacs" emacs-version))
|
|
40
|
|
41 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
|
|
42 (not running-xemacs) (featurep 'mule)))
|
|
43 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
|
|
44
|
|
45 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
|
|
46 (defvar running-emacs-19_29-or-later
|
|
47 (or (and running-emacs-19 (>= emacs-minor-version 29))
|
|
48 (and (not running-xemacs)(>= emacs-major-version 20))))
|
|
49
|
|
50 (defvar running-xemacs-19 (and running-xemacs
|
|
51 (= emacs-major-version 19)))
|
|
52 (defvar running-xemacs-20-or-later (and running-xemacs
|
|
53 (>= emacs-major-version 20)))
|
|
54 (defvar running-xemacs-19_14-or-later
|
|
55 (or (and running-xemacs-19 (>= emacs-minor-version 14))
|
|
56 running-xemacs-20-or-later))
|
|
57
|
|
58 (cond (running-mule-merged-emacs
|
|
59 ;; for mule merged EMACS
|
|
60 (require 'emu-e20)
|
|
61 )
|
|
62 (running-xemacs-with-mule
|
|
63 ;; for XEmacs/mule
|
|
64 (require 'emu-x20)
|
|
65 )
|
|
66 ((boundp 'MULE)
|
|
67 ;; for MULE 1.* and 2.*
|
|
68 (require 'emu-mule)
|
|
69 )
|
|
70 ((boundp 'NEMACS)
|
|
71 ;; for NEmacs and NEpoch
|
|
72 (require 'emu-nemacs)
|
|
73 )
|
|
74 (t
|
|
75 ;; for EMACS 19 and XEmacs 19 (without mule)
|
|
76 (require 'emu-e19)
|
|
77 ))
|
|
78
|
|
79
|
|
80 ;;; @ binary access
|
|
81 ;;;
|
|
82
|
|
83 (defun insert-binary-file-contents-literally
|
|
84 (filename &optional visit beg end replace)
|
|
85 "Like `insert-file-contents-literally', q.v., but don't code conversion.
|
|
86 A buffer may be modified in several ways after reading into the buffer due
|
|
87 to advanced Emacs features, such as file-name-handlers, format decoding,
|
|
88 find-file-hooks, etc.
|
|
89 This function ensures that none of these modifications will take place.
|
|
90 \[emu.el]"
|
|
91 (as-binary-input-file
|
|
92 (insert-file-contents-literally filename visit beg end replace)
|
|
93 ))
|
|
94
|
|
95
|
|
96 ;;; @ MIME charset
|
|
97 ;;;
|
|
98
|
|
99 (defun charsets-to-mime-charset (charsets)
|
|
100 "Return MIME charset from list of charset CHARSETS.
|
|
101 This function refers variable `charsets-mime-charset-alist'
|
|
102 and `default-mime-charset'. [emu.el]"
|
|
103 (if charsets
|
|
104 (or (catch 'tag
|
|
105 (let ((rest charsets-mime-charset-alist)
|
|
106 cell csl)
|
|
107 (while (setq cell (car rest))
|
|
108 (if (catch 'not-subset
|
|
109 (let ((set1 charsets)
|
|
110 (set2 (car cell))
|
|
111 obj)
|
|
112 (while set1
|
|
113 (setq obj (car set1))
|
|
114 (or (memq obj set2)
|
|
115 (throw 'not-subset nil)
|
|
116 )
|
|
117 (setq set1 (cdr set1))
|
|
118 )
|
|
119 t))
|
|
120 (throw 'tag (cdr cell))
|
|
121 )
|
|
122 (setq rest (cdr rest))
|
|
123 )))
|
|
124 default-mime-charset)))
|
|
125
|
|
126
|
|
127 ;;; @ EMACS 19.29 emulation
|
|
128 ;;;
|
|
129
|
|
130 (defvar path-separator ":"
|
|
131 "Character used to separate concatenated paths.")
|
|
132
|
|
133 (or (fboundp 'buffer-substring-no-properties)
|
|
134 (defun buffer-substring-no-properties (beg end)
|
|
135 "Return the text from BEG to END, without text properties, as a string.
|
|
136 \[emu.el; EMACS 19.29 emulating function]"
|
|
137 (let ((string (buffer-substring beg end)))
|
|
138 (tl:set-text-properties 0 (length string) nil string)
|
|
139 string))
|
|
140 )
|
|
141
|
|
142 (or running-emacs-19_29-or-later
|
|
143 running-xemacs
|
|
144 ;; for Emacs 19.28 or earlier
|
|
145 (fboundp 'si:read-string)
|
|
146 (progn
|
|
147 (fset 'si:read-string (symbol-function 'read-string))
|
|
148
|
|
149 (defun read-string (prompt &optional initial-input history)
|
|
150 "Read a string from the minibuffer, prompting with string PROMPT.
|
|
151 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
|
|
152 The third arg HISTORY, is dummy for compatibility. [emu.el]
|
|
153 See `read-from-minibuffer' for details of HISTORY argument."
|
|
154 (si:read-string prompt initial-input)
|
|
155 )
|
|
156 ))
|
|
157
|
|
158 (or (fboundp 'add-to-list)
|
|
159 ;; This function was imported Emacs 19.30.
|
|
160 (defun add-to-list (list-var element)
|
|
161 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
|
|
162 If you want to use `add-to-list' on a variable that is not defined
|
|
163 until a certain package is loaded, you should put the call to `add-to-list'
|
|
164 into a hook function that will be run only after loading the package.
|
|
165 \[emu.el; EMACS 19.30 emulating function]"
|
|
166 (or (member element (symbol-value list-var))
|
|
167 (set list-var (cons element (symbol-value list-var)))))
|
|
168 )
|
|
169
|
|
170
|
|
171 ;;; @ EMACS 19.30 emulation
|
|
172 ;;;
|
|
173
|
|
174 (cond ((fboundp 'insert-file-contents-literally)
|
|
175 )
|
|
176 ((boundp 'file-name-handler-alist)
|
|
177 (defun insert-file-contents-literally
|
|
178 (filename &optional visit beg end replace)
|
|
179 "Like `insert-file-contents', q.v., but only reads in the file.
|
|
180 A buffer may be modified in several ways after reading into the buffer due
|
|
181 to advanced Emacs features, such as file-name-handlers, format decoding,
|
|
182 find-file-hooks, etc.
|
|
183 This function ensures that none of these modifications will take place.
|
|
184 \[emu.el; Emacs 19.30 emulating function]"
|
|
185 (let (file-name-handler-alist)
|
|
186 (insert-file-contents filename visit beg end replace)
|
|
187 ))
|
|
188 )
|
|
189 (t
|
|
190 (defalias 'insert-file-contents-literally 'insert-file-contents)
|
|
191 ))
|
|
192
|
|
193
|
|
194 ;;; @ EMACS 19.31 emulation
|
|
195 ;;;
|
|
196
|
|
197 (or (fboundp 'buffer-live-p)
|
|
198 (defun buffer-live-p (object)
|
|
199 "Return non-nil if OBJECT is a buffer which has not been killed.
|
|
200 Value is nil if OBJECT is not a buffer or if it has been killed.
|
|
201 \[emu.el; EMACS 19.31 emulating function]"
|
|
202 (and object
|
|
203 (get-buffer object)
|
|
204 (buffer-name (get-buffer object))
|
|
205 ))
|
|
206 )
|
|
207
|
|
208 (or (fboundp 'save-selected-window)
|
|
209 ;; This function was imported Emacs 19.33.
|
|
210 (defmacro save-selected-window (&rest body)
|
|
211 "Execute BODY, then select the window that was selected before BODY.
|
|
212 \[emu.el; EMACS 19.31 emulating function]"
|
|
213 (list 'let
|
|
214 '((save-selected-window-window (selected-window)))
|
|
215 (list 'unwind-protect
|
|
216 (cons 'progn body)
|
|
217 (list 'select-window 'save-selected-window-window))))
|
|
218 )
|
|
219
|
|
220
|
|
221 ;;; @ XEmacs emulation
|
|
222 ;;;
|
|
223
|
|
224 (or (fboundp 'functionp)
|
|
225 (defun functionp (obj)
|
|
226 "Returns t if OBJ is a function, nil otherwise.
|
|
227 \[emu.el; XEmacs emulating function]"
|
|
228 (or (subrp obj)
|
|
229 (byte-code-function-p obj)
|
|
230 (and (symbolp obj)(fboundp obj))
|
|
231 (and (consp obj)(eq (car obj) 'lambda))
|
|
232 ))
|
|
233 )
|
|
234
|
|
235
|
|
236 ;;; @ for XEmacs 20
|
|
237 ;;;
|
|
238
|
|
239 (or (fboundp 'char-int)
|
|
240 (fset 'char-int (symbol-function 'identity))
|
|
241 )
|
|
242 (or (fboundp 'int-char)
|
|
243 (fset 'int-char (symbol-function 'identity))
|
|
244 )
|
|
245
|
|
246
|
|
247 ;;; @ for text/richtext and text/enriched
|
|
248 ;;;
|
|
249
|
|
250 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
|
|
251 ;; have enriched.el
|
|
252 (autoload 'richtext-decode "richtext")
|
|
253 (or (assq 'text/richtext format-alist)
|
|
254 (setq format-alist
|
|
255 (cons
|
|
256 (cons 'text/richtext
|
|
257 '("Extended MIME text/richtext format."
|
|
258 "Content-[Tt]ype:[ \t]*text/richtext"
|
|
259 richtext-decode richtext-encode t enriched-mode))
|
|
260 format-alist)))
|
|
261 )
|
|
262 (t
|
|
263 ;; don't have enriched.el
|
|
264 (autoload 'richtext-decode "tinyrich")
|
|
265 (autoload 'enriched-decode "tinyrich")
|
|
266 ))
|
|
267
|
|
268
|
|
269 ;;; @ end
|
|
270 ;;;
|
|
271
|
|
272 (provide 'emu)
|
|
273
|
|
274 ;;; emu.el ends here
|