tm 7.105.2.
[elisp/apel.git] / emu-e20.el
1 ;;; emu-e20.el --- emu API implementation for Emacs/mule (19.34.91-delta)
2
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-e20.el,v 7.13 1997/03/10 05:36:04 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 ;;; Code:
27
28 ;;; @ version specific features
29 ;;;
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 \[emu-e20.el; Mule emulating function]"
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 \[emu-e20.el; Mule emulating function]"
62   (delq 'ascii (find-charset-string (buffer-substring start end)))
63   )
64
65
66 ;;; @ coding system
67 ;;;
68
69 (defconst *noconv* 'no-conversion)
70
71 (defmacro as-binary-process (&rest body)
72   `(let (selective-display      ; Disable ^M to nl translation.
73          ;; for Emacs/mule
74          (coding-system-for-read  'no-conversion)
75          (coding-system-for-write 'no-conversion)
76          )
77      ,@ body))
78
79 (defmacro as-binary-input-file (&rest body)
80   `(let ((coding-system-for-read 'no-conversion))
81      ,@body))
82
83 (defmacro as-binary-output-file (&rest body)
84   `(let ((coding-system-for-write 'no-conversion))
85      ,@body))
86
87 (defalias 'set-process-input-coding-system 'set-process-coding-system)
88
89
90 ;;; @ binary access
91 ;;;
92
93 (defun insert-binary-file-contents-literally
94   (filename &optional visit beg end replace)
95   "Like `insert-file-contents-literally', q.v., but don't code conversion.
96 A buffer may be modified in several ways after reading into the buffer due
97 to advanced Emacs features, such as file-name-handlers, format decoding,
98 find-file-hooks, etc.
99   This function ensures that none of these modifications will take place."
100   (let ((coding-system-for-read 'no-conversion))
101     (insert-file-contents-literally filename visit beg end replace)
102     ))
103
104
105 ;;; @ MIME charset
106 ;;;
107
108 (defvar charsets-mime-charset-alist
109   '(((ascii)                                            . us-ascii)
110     ((ascii latin-iso8859-1)                            . iso-8859-1)
111     ((ascii latin-iso8859-2)                            . iso-8859-2)
112     ((ascii latin-iso8859-3)                            . iso-8859-3)
113     ((ascii latin-iso8859-4)                            . iso-8859-4)
114 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
115     ((ascii cyrillic-iso8859-5)                         . koi8-r)
116     ((ascii arabic-iso8859-6)                           . iso-8859-6)
117     ((ascii greek-iso8859-7)                            . iso-8859-7)
118     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
119     ((ascii latin-iso8859-9)                            . iso-8859-9)
120     ((ascii latin-jisx0201
121             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
122     ((ascii korean-ksc5601)                             . euc-kr)
123     ((ascii chinese-gb2312)                             . cn-gb-2312)
124     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
125     ((ascii latin-iso8859-1 greek-iso8859-7
126             latin-jisx0201 japanese-jisx0208-1978
127             chinese-gb2312 japanese-jisx0208
128             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
129     ((ascii latin-iso8859-1 greek-iso8859-7
130             latin-jisx0201 japanese-jisx0208-1978
131             chinese-gb2312 japanese-jisx0208
132             korean-ksc5601 japanese-jisx0212
133             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
134     ((ascii latin-iso8859-1 latin-iso8859-2
135             cyrillic-iso8859-5 greek-iso8859-7
136             latin-jisx0201 japanese-jisx0208-1978
137             chinese-gb2312 japanese-jisx0208
138             korean-ksc5601 japanese-jisx0212
139             chinese-cns11643-1 chinese-cns11643-2
140             chinese-cns11643-3 chinese-cns11643-4
141             chinese-cns11643-5 chinese-cns11643-6
142             chinese-cns11643-7)                         . iso-2022-int-1)
143     ))
144
145 (defvar default-mime-charset 'x-ctext)
146
147 (defvar mime-charset-coding-system-alist
148   '((x-ctext            . ctext)
149     (gb2312             . cn-gb-2312)
150     (iso-2022-jp-2      . iso-2022-ss2-7)
151     ))
152
153 (defun mime-charset-to-coding-system (charset &optional lbt)
154   (if (stringp charset)
155       (setq charset (intern (downcase charset)))
156     )
157   (let ((cs
158          (or (cdr (assq charset mime-charset-coding-system-alist))
159              (and (coding-system-p charset) charset)
160              )))
161     (if lbt
162         (intern (concat (symbol-name cs) "-" (symbol-name lbt)))
163       cs)))
164
165 (defun detect-mime-charset-region (start end)
166   "Return MIME charset for region between START and END. [emu-e20.el]"
167   (charsets-to-mime-charset
168    (find-charset-string (buffer-substring start end))
169    ))
170
171 (defun encode-mime-charset-region (start end charset)
172   "Encode the text between START and END as MIME CHARSET. [emu-e20.el]"
173   (let ((cs (mime-charset-to-coding-system charset)))
174     (if cs
175         (encode-coding-region start end cs)
176       )))
177
178 (defun decode-mime-charset-region (start end charset)
179   "Decode the text between START and END as MIME CHARSET. [emu-e20.el]"
180   (let ((cs (mime-charset-to-coding-system charset)))
181     (if cs
182         (decode-coding-region start end cs)
183       )))
184
185 (defun encode-mime-charset-string (string charset)
186   "Encode the STRING as MIME CHARSET. [emu-e20.el]"
187   (let ((cs (mime-charset-to-coding-system charset)))
188     (if cs
189         (encode-coding-string string cs)
190       string)))
191
192 (defun decode-mime-charset-string (string charset)
193   "Decode the STRING as MIME CHARSET. [emu-e20.el]"
194   (let ((cs (mime-charset-to-coding-system charset)))
195     (if cs
196         (decode-coding-string string cs)
197       string)))
198
199
200 ;;; @ character
201 ;;;
202
203 (defalias 'char-length 'char-bytes)
204
205 (defalias 'char-columns 'char-width)
206
207
208 ;;; @@ Mule emulating aliases
209 ;;;
210 ;;; You should not use them.
211
212 (defalias 'make-character 'make-char)
213
214 (defun char-category (character)
215   "Return string of category mnemonics for CHAR in TABLE.
216 CHAR can be any multilingual character
217 TABLE defaults to the current buffer's category table.
218 \[emu-e20.el; Mule emulating function]"
219   (category-set-mnemonics (char-category-set character))
220   )
221
222
223 ;;; @ string
224 ;;;
225
226 (defalias 'string-columns 'string-width)
227
228 (defalias 'sset 'store-substring)
229
230 (defun string-to-char-list (string)
231   "Return a list of which elements are characters in the STRING.
232 \[emu-e20.el; Mule 2.3 emulating function]"
233   (let* ((len (length string))
234          (i 0)
235          l chr)
236     (while (< i len)
237       (setq chr (sref string i))
238       (setq l (cons chr l))
239       (setq i (+ i (char-bytes chr)))
240       )
241     (nreverse l)
242     ))
243
244 (defalias 'string-to-int-list 'string-to-char-list)
245
246
247 ;;; @ end
248 ;;;
249
250 (provide 'emu-e20)
251
252 ;;; emu-e20.el ends here