4
|
1 ;;; emu.el --- Emulation module for each Emacs variants
|
|
2
|
98
|
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
|
4
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
98
|
6 ;; Version: $Id: emu.el,v 1.4 1997/02/15 22:21:25 steve Exp $
|
74
|
7 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
|
4
|
8
|
74
|
9 ;; This file is part of emu.
|
4
|
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
|
74
|
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
|
4
|
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 ;;; @ MIME charset
|
|
95 ;;;
|
|
96
|
|
97 (defun charsets-to-mime-charset (charsets)
|
|
98 "Return MIME charset from list of charset CHARSETS.
|
|
99 This function refers variable `charsets-mime-charset-alist'
|
|
100 and `default-mime-charset'. [emu.el]"
|
|
101 (if charsets
|
|
102 (or (catch 'tag
|
|
103 (let ((rest charsets-mime-charset-alist)
|
|
104 cell csl)
|
|
105 (while (setq cell (car rest))
|
|
106 (if (catch 'not-subset
|
|
107 (let ((set1 charsets)
|
|
108 (set2 (car cell))
|
|
109 obj)
|
|
110 (while set1
|
|
111 (setq obj (car set1))
|
|
112 (or (memq obj set2)
|
|
113 (throw 'not-subset nil)
|
|
114 )
|
|
115 (setq set1 (cdr set1))
|
|
116 )
|
|
117 t))
|
|
118 (throw 'tag (cdr cell))
|
|
119 )
|
|
120 (setq rest (cdr rest))
|
|
121 )))
|
|
122 default-mime-charset)))
|
|
123
|
|
124
|
70
|
125 ;;; @ EMACS 19.29 emulation
|
4
|
126 ;;;
|
|
127
|
86
|
128 (defvar path-separator ":"
|
|
129 "Character used to separate concatenated paths.")
|
4
|
130
|
74
|
131 (defun-maybe buffer-substring-no-properties (beg end)
|
|
132 "Return the text from BEG to END, without text properties, as a string.
|
70
|
133 \[emu.el; EMACS 19.29 emulating function]"
|
74
|
134 (let ((string (buffer-substring beg end)))
|
|
135 (tl:set-text-properties 0 (length string) nil string)
|
|
136 string))
|
|
137
|
|
138 (defun-maybe match-string (num &optional string)
|
|
139 "Return string of text matched by last search.
|
|
140 NUM specifies which parenthesized expression in the last regexp.
|
|
141 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
|
|
142 Zero means the entire text matched by the whole regexp or whole string.
|
|
143 STRING should be given if the last search was by `string-match' on STRING.
|
|
144 \[emu.el; EMACS 19.29 emulating function]"
|
|
145 (if (match-beginning num)
|
|
146 (if string
|
|
147 (substring string (match-beginning num) (match-end num))
|
|
148 (buffer-substring (match-beginning num) (match-end num)))))
|
4
|
149
|
|
150 (or running-emacs-19_29-or-later
|
|
151 running-xemacs
|
|
152 ;; for Emacs 19.28 or earlier
|
|
153 (fboundp 'si:read-string)
|
|
154 (progn
|
|
155 (fset 'si:read-string (symbol-function 'read-string))
|
|
156
|
|
157 (defun read-string (prompt &optional initial-input history)
|
|
158 "Read a string from the minibuffer, prompting with string PROMPT.
|
|
159 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
|
|
160 The third arg HISTORY, is dummy for compatibility. [emu.el]
|
|
161 See `read-from-minibuffer' for details of HISTORY argument."
|
|
162 (si:read-string prompt initial-input)
|
|
163 )
|
|
164 ))
|
|
165
|
74
|
166 ;; This function was imported Emacs 19.30.
|
|
167 (defun-maybe add-to-list (list-var element)
|
|
168 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
|
4
|
169 If you want to use `add-to-list' on a variable that is not defined
|
|
170 until a certain package is loaded, you should put the call to `add-to-list'
|
|
171 into a hook function that will be run only after loading the package.
|
70
|
172 \[emu.el; EMACS 19.30 emulating function]"
|
74
|
173 (or (member element (symbol-value list-var))
|
|
174 (set list-var (cons element (symbol-value list-var)))
|
|
175 ))
|
70
|
176
|
|
177
|
|
178 ;;; @ EMACS 19.30 emulation
|
|
179 ;;;
|
4
|
180
|
|
181 (cond ((fboundp 'insert-file-contents-literally)
|
|
182 )
|
|
183 ((boundp 'file-name-handler-alist)
|
|
184 (defun insert-file-contents-literally
|
|
185 (filename &optional visit beg end replace)
|
|
186 "Like `insert-file-contents', q.v., but only reads in the file.
|
|
187 A buffer may be modified in several ways after reading into the buffer due
|
|
188 to advanced Emacs features, such as file-name-handlers, format decoding,
|
|
189 find-file-hooks, etc.
|
|
190 This function ensures that none of these modifications will take place.
|
70
|
191 \[emu.el; Emacs 19.30 emulating function]"
|
4
|
192 (let (file-name-handler-alist)
|
|
193 (insert-file-contents filename visit beg end replace)
|
|
194 ))
|
|
195 )
|
|
196 (t
|
|
197 (defalias 'insert-file-contents-literally 'insert-file-contents)
|
|
198 ))
|
|
199
|
|
200
|
70
|
201 ;;; @ EMACS 19.31 emulation
|
4
|
202 ;;;
|
|
203
|
74
|
204 (defun-maybe buffer-live-p (object)
|
|
205 "Return non-nil if OBJECT is a buffer which has not been killed.
|
4
|
206 Value is nil if OBJECT is not a buffer or if it has been killed.
|
70
|
207 \[emu.el; EMACS 19.31 emulating function]"
|
74
|
208 (and object
|
|
209 (get-buffer object)
|
|
210 (buffer-name (get-buffer object))
|
|
211 ))
|
4
|
212
|
70
|
213 (or (fboundp 'save-selected-window)
|
|
214 ;; This function was imported Emacs 19.33.
|
|
215 (defmacro save-selected-window (&rest body)
|
|
216 "Execute BODY, then select the window that was selected before BODY.
|
|
217 \[emu.el; EMACS 19.31 emulating function]"
|
|
218 (list 'let
|
|
219 '((save-selected-window-window (selected-window)))
|
|
220 (list 'unwind-protect
|
|
221 (cons 'progn body)
|
|
222 (list 'select-window 'save-selected-window-window))))
|
|
223 )
|
4
|
224
|
|
225
|
|
226 ;;; @ XEmacs emulation
|
|
227 ;;;
|
|
228
|
74
|
229 (defun-maybe functionp (obj)
|
|
230 "Returns t if OBJ is a function, nil otherwise.
|
70
|
231 \[emu.el; XEmacs emulating function]"
|
74
|
232 (or (subrp obj)
|
|
233 (byte-code-function-p obj)
|
|
234 (and (symbolp obj)(fboundp obj))
|
|
235 (and (consp obj)(eq (car obj) 'lambda))
|
|
236 ))
|
|
237
|
4
|
238
|
|
239 ;;; @ for XEmacs 20
|
|
240 ;;;
|
|
241
|
|
242 (or (fboundp 'char-int)
|
|
243 (fset 'char-int (symbol-function 'identity))
|
|
244 )
|
|
245 (or (fboundp 'int-char)
|
|
246 (fset 'int-char (symbol-function 'identity))
|
|
247 )
|
|
248
|
|
249
|
|
250 ;;; @ for text/richtext and text/enriched
|
|
251 ;;;
|
|
252
|
|
253 (cond ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
|
|
254 ;; have enriched.el
|
|
255 (autoload 'richtext-decode "richtext")
|
|
256 (or (assq 'text/richtext format-alist)
|
|
257 (setq format-alist
|
|
258 (cons
|
|
259 (cons 'text/richtext
|
|
260 '("Extended MIME text/richtext format."
|
|
261 "Content-[Tt]ype:[ \t]*text/richtext"
|
|
262 richtext-decode richtext-encode t enriched-mode))
|
|
263 format-alist)))
|
|
264 )
|
|
265 (t
|
|
266 ;; don't have enriched.el
|
|
267 (autoload 'richtext-decode "tinyrich")
|
|
268 (autoload 'enriched-decode "tinyrich")
|
|
269 ))
|
|
270
|
|
271
|
|
272 ;;; @ end
|
|
273 ;;;
|
|
274
|
|
275 (provide 'emu)
|
|
276
|
|
277 ;;; emu.el ends here
|