update.
[elisp/apel.git] / emu-e20.el
1 ;;; emu-e20.el --- emu API implementation for Emacs 20.1 and 20.2
2
3 ;; Copyright (C) 1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
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 ;;; Commentary:
26
27 ;;    This module requires Emacs 20.1 and 20.2.
28
29 ;;; Code:
30
31 (require 'emu-19)
32
33 (defun fontset-pixel-size (fontset)
34   (let* ((info (fontset-info fontset))
35          (height (aref info 1))
36          )
37     (cond ((> height 0) height)
38           ((string-match "-\\([0-9]+\\)-" fontset)
39            (string-to-number
40             (substring fontset (match-beginning 1)(match-end 1))
41             )
42            )
43           (t 0)
44           )))
45
46
47 ;;; @ character set
48 ;;;
49
50 ;; (defalias 'charset-columns 'charset-width)
51
52 (defun find-non-ascii-charset-string (string)
53   "Return a list of charsets in the STRING except ascii."
54   (delq 'ascii (find-charset-string string))
55   )
56
57 (defun find-non-ascii-charset-region (start end)
58   "Return a list of charsets except ascii
59 in the region between START and END."
60   (delq 'ascii (find-charset-string (buffer-substring start end)))
61   )
62
63
64 ;;; @ coding system
65 ;;;
66
67 (defsubst-maybe find-coding-system (obj)
68   "Return OBJ if it is a coding-system."
69   (if (coding-system-p obj)
70       obj))
71
72 (defalias 'set-process-input-coding-system 'set-process-coding-system)
73
74
75 ;;; @ binary access
76 ;;;
77
78 (defun insert-file-contents-as-binary (filename
79                                        &optional visit beg end replace)
80   "Like `insert-file-contents', q.v., but don't code and format conversion.
81 Like `insert-file-contents-literary', but it allows find-file-hooks,
82 automatic uncompression, etc.
83
84 Namely this function ensures that only format decoding and character
85 code conversion will not take place."
86   (let ((flag enable-multibyte-characters)
87         (coding-system-for-read 'binary)
88         format-alist)
89     (insert-file-contents filename visit beg end replace)
90     (setq enable-multibyte-characters flag)
91     ))
92
93 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
94 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
95
96 (defalias 'insert-binary-file-contents-literally
97   'insert-file-contents-literally)
98
99
100 ;;; @ MIME charset
101 ;;;
102
103 (defsubst encode-mime-charset-region (start end charset)
104   "Encode the text between START and END as MIME CHARSET."
105   (let (cs)
106     (if (and enable-multibyte-characters
107              (setq cs (mime-charset-to-coding-system charset)))
108         (encode-coding-region start end cs)
109       )))
110
111 (defsubst decode-mime-charset-region (start end charset)
112   "Decode the text between START and END as MIME CHARSET."
113   (let (cs)
114     (if (and enable-multibyte-characters
115              (setq cs (mime-charset-to-coding-system charset)))
116         (decode-coding-region start end cs)
117       )))
118
119 (defsubst encode-mime-charset-string (string charset)
120   "Encode the STRING as MIME CHARSET."
121   (let (cs)
122     (if (and enable-multibyte-characters
123              (setq cs (mime-charset-to-coding-system charset)))
124         (encode-coding-string string cs)
125       string)))
126
127 (defsubst decode-mime-charset-string (string charset)
128   "Decode the STRING as MIME CHARSET."
129   (let (cs)
130     (if (and enable-multibyte-characters
131              (setq cs (mime-charset-to-coding-system charset)))
132         (decode-coding-string string cs)
133       string)))
134
135
136 (defvar charsets-mime-charset-alist
137   '(((ascii)                                            . us-ascii)
138     ((ascii latin-iso8859-1)                            . iso-8859-1)
139     ((ascii latin-iso8859-2)                            . iso-8859-2)
140     ((ascii latin-iso8859-3)                            . iso-8859-3)
141     ((ascii latin-iso8859-4)                            . iso-8859-4)
142 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
143     ((ascii cyrillic-iso8859-5)                         . koi8-r)
144     ((ascii arabic-iso8859-6)                           . iso-8859-6)
145     ((ascii greek-iso8859-7)                            . iso-8859-7)
146     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
147     ((ascii latin-iso8859-9)                            . iso-8859-9)
148     ((ascii latin-jisx0201
149             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
150     ((ascii korean-ksc5601)                             . euc-kr)
151     ((ascii chinese-gb2312)                             . cn-gb-2312)
152     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
153     ((ascii latin-iso8859-1 greek-iso8859-7
154             latin-jisx0201 japanese-jisx0208-1978
155             chinese-gb2312 japanese-jisx0208
156             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
157     ((ascii latin-iso8859-1 greek-iso8859-7
158             latin-jisx0201 japanese-jisx0208-1978
159             chinese-gb2312 japanese-jisx0208
160             korean-ksc5601 japanese-jisx0212
161             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
162     ((ascii latin-iso8859-1 latin-iso8859-2
163             cyrillic-iso8859-5 greek-iso8859-7
164             latin-jisx0201 japanese-jisx0208-1978
165             chinese-gb2312 japanese-jisx0208
166             korean-ksc5601 japanese-jisx0212
167             chinese-cns11643-1 chinese-cns11643-2
168             chinese-cns11643-3 chinese-cns11643-4
169             chinese-cns11643-5 chinese-cns11643-6
170             chinese-cns11643-7)                         . iso-2022-int-1)
171     ))
172
173
174 ;;; @ character
175 ;;;
176
177 (defalias 'char-length 'char-bytes)
178
179 (defalias 'char-columns 'char-width)
180
181
182 ;;; @@ Mule emulating aliases
183 ;;;
184 ;;; You should not use them.
185
186 (defun char-category (character)
187   "Return string of category mnemonics for CHAR in TABLE.
188 CHAR can be any multilingual character
189 TABLE defaults to the current buffer's category table."
190   (category-set-mnemonics (char-category-set character))
191   )
192
193
194 ;;; @ string
195 ;;;
196
197 (defalias 'string-columns 'string-width)
198
199 (defalias 'sset 'store-substring)
200
201 (defun string-to-char-list (string)
202   "Return a list of which elements are characters in the STRING."
203   (let* ((len (length string))
204          (i 0)
205          l chr)
206     (while (< i len)
207       (setq chr (sref string i))
208       (setq l (cons chr l))
209       (setq i (+ i (char-bytes chr)))
210       )
211     (nreverse l)
212     ))
213
214 (defalias 'string-to-int-list 'string-to-char-list)
215
216
217 ;;; @ end
218 ;;;
219
220 (require 'emu-20)
221
222 (provide 'emu-e20)
223
224 ;;; emu-e20.el ends here