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