(Download): Renamed from "Anonymous FTP"; modify for
[elisp/apel.git] / emu.el
1 ;;; emu.el --- Emulation module for each Emacs variants
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Nemacs, MULE, Emacs/mule, XEmacs
7
8 ;; This file is part of emu.
9
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.
14
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.
19
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Code:
26
27 (require 'poe)
28
29 (defvar running-emacs-18 (<= emacs-major-version 18))
30 (defvar running-xemacs (featurep 'xemacs))
31
32 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
33                                        (not running-xemacs) (featurep 'mule)))
34 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
35
36 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
37 (defvar running-emacs-19_29-or-later
38   (or (and running-emacs-19 (>= emacs-minor-version 29))
39       (and (not running-xemacs)(>= emacs-major-version 20))))
40
41 (defvar running-xemacs-19 (and running-xemacs
42                                (= emacs-major-version 19)))
43 (defvar running-xemacs-20-or-later (and running-xemacs
44                                         (>= emacs-major-version 20)))
45 (defvar running-xemacs-19_14-or-later
46   (or (and running-xemacs-19 (>= emacs-minor-version 14))
47       running-xemacs-20-or-later))
48
49 (cond (running-xemacs
50        ;; for XEmacs
51        (defvar mouse-button-1 'button1)
52        (defvar mouse-button-2 'button2)
53        (defvar mouse-button-3 'button3)
54        )
55       ((>= emacs-major-version 19)
56        ;; mouse
57        (defvar mouse-button-1 [mouse-1])
58        (defvar mouse-button-2 [mouse-2])
59        (defvar mouse-button-3 [down-mouse-3])
60        )
61       (t
62        ;; mouse
63        (defvar mouse-button-1 nil)
64        (defvar mouse-button-2 nil)
65        (defvar mouse-button-3 nil)
66        ))
67
68 ;; for tm-7.106
69 (unless (fboundp 'tl:make-overlay)
70   (defalias 'tl:make-overlay 'make-overlay)
71   (make-obsolete 'tl:make-overlay 'make-overlay)
72   )
73 (unless (fboundp 'tl:overlay-put)
74   (defalias 'tl:overlay-put 'overlay-put)
75   (make-obsolete 'tl:overlay-put 'overlay-put)
76   )
77 (unless (fboundp 'tl:overlay-buffer)
78   (defalias 'tl:overlay-buffer 'overlay-buffer)
79   (make-obsolete 'tl:overlay-buffer 'overlay-buffer)
80   )
81
82 (require 'poem)
83 (require 'mcharset)
84 (require 'invisible)
85
86 (defsubst char-list-to-string (char-list)
87   "Convert list of character CHAR-LIST to string."
88   (apply (function string) char-list))
89
90 (cond ((featurep 'mule)
91        (cond ((featurep 'xemacs) ; for XEmacs with MULE
92               ;; old Mule emulating aliases
93
94               ;;(defalias 'char-leading-char 'char-charset)
95
96               (defun char-category (character)
97                 "Return string of category mnemonics for CHAR in TABLE.
98 CHAR can be any multilingual character
99 TABLE defaults to the current buffer's category table."
100                 (mapconcat (lambda (chr)
101                              (if (integerp chr)
102                                  (char-to-string (int-char chr))
103                                (char-to-string chr)))
104                            ;; `char-category-list' returns a list of
105                            ;; characters in XEmacs 21.2.25 and later,
106                            ;; otherwise integers.
107                            (char-category-list character)
108                            ""))
109               )
110              ((>= emacs-major-version 20) ; for Emacs 20
111               (defalias 'insert-binary-file-contents-literally
112                 'insert-file-contents-literally)
113               
114               ;; old Mule emulating aliases
115               (defun char-category (character)
116                 "Return string of category mnemonics for CHAR in TABLE.
117 CHAR can be any multilingual character
118 TABLE defaults to the current buffer's category table."
119                 (category-set-mnemonics (char-category-set character)))
120               )
121              (t ; for MULE 1.* and 2.*
122               (require 'emu-mule)
123               ))
124        )
125       ((boundp 'NEMACS)
126        ;; for Nemacs and Nepoch
127
128        ;; old MULE emulation
129        (defconst *noconv*    0)
130        (defconst *sjis*      1)
131        (defconst *junet*     2)
132        (defconst *ctext*     2)
133        (defconst *internal*  3)
134        (defconst *euc-japan* 3)
135        
136        (defun code-convert-string (str ic oc)
137          "Convert code in STRING from SOURCE code to TARGET code,
138 On successful conversion, returns the result string,
139 else returns nil."
140          (if (not (eq ic oc))
141              (convert-string-kanji-code str ic oc)
142            str))
143        
144        (defun code-convert-region (beg end ic oc)
145          "Convert code of the text between BEGIN and END from SOURCE
146 to TARGET. On successful conversion returns t,
147 else returns nil."
148          (if (/= ic oc)
149              (save-excursion
150                (save-restriction
151                  (narrow-to-region beg end)
152                  (convert-region-kanji-code beg end ic oc)))
153            ))
154        )
155       (t
156        ;; for Emacs 19 and XEmacs without MULE
157        
158        ;; old MULE emulation
159        (defconst *internal* nil)
160        (defconst *ctext* nil)
161        (defconst *noconv* nil)
162        
163        (defun code-convert-string (str ic oc)
164          "Convert code in STRING from SOURCE code to TARGET code,
165 On successful conversion, returns the result string,
166 else returns nil. [emu-latin1.el; old MULE emulating function]"
167          str)
168
169        (defun code-convert-region (beg end ic oc)
170          "Convert code of the text between BEGIN and END from SOURCE
171 to TARGET. On successful conversion returns t,
172 else returns nil. [emu-latin1.el; old MULE emulating function]"
173          t)
174        ))
175
176
177 ;;; @ Mule emulating aliases
178 ;;;
179 ;;; You should not use it.
180
181 (or (boundp '*noconv*)
182     (defconst *noconv* 'binary
183       "Coding-system for binary.
184 This constant is defined to emulate old MULE anything older than MULE 2.3.
185 It is obsolete, so don't use it."))
186
187
188 ;;; @ without code-conversion
189 ;;;
190
191 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
192 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
193
194 (defun-maybe insert-binary-file-contents-literally (filename
195                                                     &optional visit
196                                                     beg end replace)
197   "Like `insert-file-contents-literally', q.v., but don't code conversion.
198 A buffer may be modified in several ways after reading into the buffer due
199 to advanced Emacs features, such as file-name-handlers, format decoding,
200 find-file-hooks, etc.
201   This function ensures that none of these modifications will take place."
202   (as-binary-input-file
203    ;; Returns list absolute file name and length of data inserted.
204    (insert-file-contents-literally filename visit beg end replace)))
205
206
207 ;;; @ for text/richtext and text/enriched
208 ;;;
209
210 (cond ((fboundp 'richtext-decode)
211        ;; have richtext.el
212        )
213       ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
214        ;; have enriched.el
215        (autoload 'richtext-decode "richtext")
216        (or (assq 'text/richtext format-alist)
217            (setq format-alist
218                  (cons
219                   (cons 'text/richtext
220                         '("Extended MIME text/richtext format."
221                           "Content-[Tt]ype:[ \t]*text/richtext"
222                           richtext-decode richtext-encode t enriched-mode))
223                   format-alist)))
224        )
225       (t
226        ;; don't have enriched.el
227        (autoload 'richtext-decode "tinyrich")
228        (autoload 'enriched-decode "tinyrich")
229        ))
230
231 (if (or (and (eq emacs-major-version 19)
232              (>= emacs-minor-version (if (featurep 'xemacs) 14 29)))
233         (and (eq emacs-major-version 20)
234              (< emacs-minor-version (if (featurep 'xemacs) 3 1))))
235     (eval-after-load "enriched"
236       '(if (fboundp 'si:enriched-encode)
237            nil
238          (fset 'si:enriched-encode (symbol-function 'enriched-encode))
239          (defun enriched-encode (from to &optional orig-buf)
240            (let* ((si:enriched-initial-annotation enriched-initial-annotation)
241                   (enriched-initial-annotation
242                    (if (stringp si:enriched-initial-annotation)
243                        si:enriched-initial-annotation
244                      (function
245                       (lambda ()
246                         (save-excursion
247                           ;; Eval this in the buffer we are annotating.  This
248                           ;; fixes a bug which was saving incorrect File-Width
249                           ;; information, since we were looking at local
250                           ;; variables in the wrong buffer.
251                           (if orig-buf (set-buffer orig-buf))
252                           (funcall si:enriched-initial-annotation)))))))
253              (si::enriched-encode from to))))))
254
255
256 ;;; @ end
257 ;;;
258
259 (require 'product)
260 (product-provide (provide 'emu) (require 'apel-ver))
261
262 ;;; emu.el ends here