(set-buffer-multibyte): Use `defun-maybe' instead of `defmacro-maybe'.
[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., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, 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        ;; for tm-7.106
57        (defalias 'tl:make-overlay 'make-overlay)
58        (defalias 'tl:overlay-put 'overlay-put)
59        (defalias 'tl:overlay-buffer 'overlay-buffer)
60        
61        (make-obsolete 'tl:make-overlay 'make-overlay)
62        (make-obsolete 'tl:overlay-put 'overlay-put)
63        (make-obsolete 'tl:overlay-buffer 'overlay-buffer)
64        
65        ;; mouse
66        (defvar mouse-button-1 [mouse-1])
67        (defvar mouse-button-2 [mouse-2])
68        (defvar mouse-button-3 [down-mouse-3])
69        )
70       (t
71        ;; mouse
72        (defvar mouse-button-1 nil)
73        (defvar mouse-button-2 nil)
74        (defvar mouse-button-3 nil)
75        ))
76
77 (require 'poem)
78 (require 'mcharset)
79
80 (cond ((featurep 'mule)
81        (cond ((featurep 'xemacs) ; for XEmacs with MULE
82               ;; old Mule emulating aliases
83
84               ;;(defalias 'char-leading-char 'char-charset)
85
86               (defun char-category (character)
87                 "Return string of category mnemonics for CHAR in TABLE.
88 CHAR can be any multilingual character
89 TABLE defaults to the current buffer's category table."
90                 (mapconcat (lambda (chr)
91                              (char-to-string (int-char chr)))
92                            (char-category-list character)
93                            ""))
94               )
95              ((>= emacs-major-version 20) ; for Emacs 20
96               (defalias 'insert-binary-file-contents-literally
97                 'insert-file-contents-literally)
98               
99               ;; old Mule emulating aliases
100               (defun char-category (character)
101                 "Return string of category mnemonics for CHAR in TABLE.
102 CHAR can be any multilingual character
103 TABLE defaults to the current buffer's category table."
104                 (category-set-mnemonics (char-category-set character)))
105               )
106              (t ; for MULE 1.* and 2.*
107               (require 'emu-mule)
108               ))
109        )
110       ((boundp 'NEMACS)
111        ;; for NEmacs and NEpoch
112
113        ;; old MULE emulation
114        (defconst *noconv*    0)
115        (defconst *sjis*      1)
116        (defconst *junet*     2)
117        (defconst *ctext*     2)
118        (defconst *internal*  3)
119        (defconst *euc-japan* 3)
120        
121        (defun code-convert-string (str ic oc)
122          "Convert code in STRING from SOURCE code to TARGET code,
123 On successful converion, returns the result string,
124 else returns nil. [emu-nemacs.el; Mule emulating function]"
125          (if (not (eq ic oc))
126              (convert-string-kanji-code str ic oc)
127            str))
128        
129        (defun code-convert-region (beg end ic oc)
130          "Convert code of the text between BEGIN and END from SOURCE
131 to TARGET. On successful conversion returns t,
132 else returns nil. [emu-nemacs.el; Mule emulating function]"
133          (if (/= ic oc)
134              (save-excursion
135                (save-restriction
136                  (narrow-to-region beg end)
137                  (convert-region-kanji-code beg end ic oc)))
138            ))
139        )
140       (t
141        ;; for Emacs 19 and XEmacs without MULE
142        
143        ;; old MULE emulation
144        (defconst *internal* nil)
145        (defconst *ctext* nil)
146        (defconst *noconv* nil)
147        
148        (defun code-convert-string (str ic oc)
149          "Convert code in STRING from SOURCE code to TARGET code,
150 On successful converion, returns the result string,
151 else returns nil. [emu-latin1.el; old MULE emulating function]"
152          str)
153
154        (defun code-convert-region (beg end ic oc)
155          "Convert code of the text between BEGIN and END from SOURCE
156 to TARGET. On successful conversion returns t,
157 else returns nil. [emu-latin1.el; old MULE emulating function]"
158          t)
159        ))
160
161
162 ;;; @ Mule emulating aliases
163 ;;;
164 ;;; You should not use it.
165
166 (or (boundp '*noconv*)
167     (defconst *noconv* 'binary
168       "Coding-system for binary.
169 This constant is defined to emulate old MULE anything older than MULE 2.3.
170 It is obsolete, so don't use it."))
171
172
173 ;;; @ without code-conversion
174 ;;;
175
176 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
177 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
178
179 (defun-maybe insert-binary-file-contents-literally (filename
180                                                     &optional visit
181                                                     beg end replace)
182   "Like `insert-file-contents-literally', q.v., but don't code conversion.
183 A buffer may be modified in several ways after reading into the buffer due
184 to advanced Emacs features, such as file-name-handlers, format decoding,
185 find-file-hooks, etc.
186   This function ensures that none of these modifications will take place.
187 \[emu-nemacs.el]"
188   (as-binary-input-file
189    ;; Returns list absolute file name and length of data inserted.
190    (insert-file-contents-literally filename visit beg end replace)))
191
192
193 ;;; @ for text/richtext and text/enriched
194 ;;;
195
196 (cond ((fboundp 'richtext-decode)
197        ;; have richtext.el
198        )
199       ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
200        ;; have enriched.el
201        (autoload 'richtext-decode "richtext")
202        (or (assq 'text/richtext format-alist)
203            (setq format-alist
204                  (cons
205                   (cons 'text/richtext
206                         '("Extended MIME text/richtext format."
207                           "Content-[Tt]ype:[ \t]*text/richtext"
208                           richtext-decode richtext-encode t enriched-mode))
209                   format-alist)))
210        )
211       (t
212        ;; don't have enriched.el
213        (autoload 'richtext-decode "tinyrich")
214        (autoload 'enriched-decode "tinyrich")
215        ))
216
217
218 ;;; @ end
219 ;;;
220
221 (provide 'emu)
222
223 ;;; emu.el ends here