Move MIME charset features and binary access features from
[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-e19)
32 (require 'emu-e20_2)
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-file-contents-as-binary (filename
80                                        &optional visit beg end replace)
81   "Like `insert-file-contents', q.v., but don't code and format conversion.
82 Like `insert-file-contents-literary', but it allows find-file-hooks,
83 automatic uncompression, etc.
84
85 Namely this function ensures that only format decoding and character
86 code conversion will not take place."
87   (let ((flag enable-multibyte-characters)
88         (coding-system-for-read 'binary)
89         format-alist)
90     (insert-file-contents filename visit beg end replace)
91     (setq enable-multibyte-characters flag)
92     ))
93
94 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
95 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
96
97 (defalias 'insert-binary-file-contents-literally
98   'insert-file-contents-literally)
99
100
101 ;;; @ MIME charset
102 ;;;
103
104 (defsubst encode-mime-charset-region (start end charset)
105   "Encode the text between START and END as MIME CHARSET."
106   (let (cs)
107     (if (and enable-multibyte-characters
108              (setq cs (mime-charset-to-coding-system charset)))
109         (encode-coding-region start end cs)
110       )))
111
112 (defsubst decode-mime-charset-region (start end charset)
113   "Decode the text between START and END as MIME CHARSET."
114   (let (cs)
115     (if (and enable-multibyte-characters
116              (setq cs (mime-charset-to-coding-system charset)))
117         (decode-coding-region start end cs)
118       )))
119
120 (defsubst encode-mime-charset-string (string charset)
121   "Encode the STRING as MIME CHARSET."
122   (let (cs)
123     (if (and enable-multibyte-characters
124              (setq cs (mime-charset-to-coding-system charset)))
125         (encode-coding-string string cs)
126       string)))
127
128 (defsubst decode-mime-charset-string (string charset)
129   "Decode the STRING as MIME CHARSET."
130   (let (cs)
131     (if (and enable-multibyte-characters
132              (setq cs (mime-charset-to-coding-system charset)))
133         (decode-coding-string string cs)
134       string)))
135
136
137 (defvar charsets-mime-charset-alist
138   '(((ascii)                                            . us-ascii)
139     ((ascii latin-iso8859-1)                            . iso-8859-1)
140     ((ascii latin-iso8859-2)                            . iso-8859-2)
141     ((ascii latin-iso8859-3)                            . iso-8859-3)
142     ((ascii latin-iso8859-4)                            . iso-8859-4)
143 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
144     ((ascii cyrillic-iso8859-5)                         . koi8-r)
145     ((ascii arabic-iso8859-6)                           . iso-8859-6)
146     ((ascii greek-iso8859-7)                            . iso-8859-7)
147     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
148     ((ascii latin-iso8859-9)                            . iso-8859-9)
149     ((ascii latin-jisx0201
150             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
151     ((ascii korean-ksc5601)                             . euc-kr)
152     ((ascii chinese-gb2312)                             . cn-gb-2312)
153     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
154     ((ascii latin-iso8859-1 greek-iso8859-7
155             latin-jisx0201 japanese-jisx0208-1978
156             chinese-gb2312 japanese-jisx0208
157             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
158     ((ascii latin-iso8859-1 greek-iso8859-7
159             latin-jisx0201 japanese-jisx0208-1978
160             chinese-gb2312 japanese-jisx0208
161             korean-ksc5601 japanese-jisx0212
162             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
163     ((ascii latin-iso8859-1 latin-iso8859-2
164             cyrillic-iso8859-5 greek-iso8859-7
165             latin-jisx0201 japanese-jisx0208-1978
166             chinese-gb2312 japanese-jisx0208
167             korean-ksc5601 japanese-jisx0212
168             chinese-cns11643-1 chinese-cns11643-2
169             chinese-cns11643-3 chinese-cns11643-4
170             chinese-cns11643-5 chinese-cns11643-6
171             chinese-cns11643-7)                         . iso-2022-int-1)
172     ))
173
174
175 ;;; @ character
176 ;;;
177
178 ;;; @@ Mule emulating aliases
179 ;;;
180 ;;; You should not use them.
181
182 (defun char-category (character)
183   "Return string of category mnemonics for CHAR in TABLE.
184 CHAR can be any multilingual character
185 TABLE defaults to the current buffer's category table."
186   (category-set-mnemonics (char-category-set character))
187   )
188
189
190 ;;; @ end
191 ;;;
192
193 (require 'emu-20)
194
195 (provide 'emu-e20)
196
197 ;;; emu-e20.el ends here