cd31b152955ea101f00309b925adcf5ac8516940
[elisp/apel.git] / emu-x20.el
1 ;;; emu-x20.el --- emu API implementation for XEmacs 20 with mule
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1994,1995,1996 MORIOKA Tomohiko
5
6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Version: $Id: emu-x20.el,v 7.35 1996/09/15 08:04:02 morioka Exp $
8 ;; Keywords: emulation, compatibility, Mule, XEmacs
9
10 ;; This file is part of tl (Tiny Library).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with This program; see the file COPYING.  If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'cyrillic)
30 (require 'emu-xemacs)
31
32 (defvar xemacs-beta-version
33   (if (string-match "(beta\\([0-9]+\\))" emacs-version)
34       (string-to-number
35        (substring emacs-version (match-beginning 1)(match-end 1))
36        )))
37
38
39 ;;; @ character set
40 ;;;
41
42 (defalias 'charset-description 'charset-doc-string)
43
44 (defun find-charset-string (string)
45   "Return a list of charsets in the STRING except ascii.
46 \[emu-x20.el; Mule emulating function]"
47   (delq 'ascii (charsets-in-string string))
48   )
49
50 (defun find-charset-region (start end)
51   "Return a list of charsets except ascii
52 in the region between START and END.
53 \[emu-x20.el; Mule emulating function]"
54   (delq 'ascii (charsets-in-region start end))
55   )
56
57 ;;; @@ for Mule emulation
58 ;;;
59
60 (defconst lc-ascii  'ascii)
61 (defconst lc-ltn1   'latin-1)
62 (defconst lc-ltn2   'latin-2)
63 (defconst lc-ltn3   'latin-3)
64 (defconst lc-ltn4   'latin-4)
65 (defconst lc-crl    'cyrillic)
66 (defconst lc-arb    'arabic)
67 (defconst lc-grk    'greek)
68 (defconst lc-hbw    'hebrew)
69 (defconst lc-ltn5   'latin-5)
70 (defconst lc-jp     'japanese)
71 (defconst lc-jp2    'japanese-2)
72 (defconst lc-kr     'korean)
73 (defconst lc-big5-1 'chinese-big5-1)
74 (defconst lc-big5-2 'chinese-big5-2)
75 (defconst lc-cn     'chinese-gb)
76 (defconst lc-cns1   'chinese-cns-1)
77 (defconst lc-cns2   'chinese-cns-2)
78 (defconst lc-cns3   'chinese-cns-3)
79 (defconst lc-cns4   'chinese-cns-4)
80 (defconst lc-cns5   'chinese-cns-5)
81 (defconst lc-cns6   'chinese-cns-6)
82 (defconst lc-cns7   'chinese-cns-7)
83
84
85 ;;; @ coding-system
86 ;;;
87
88 (defconst *noconv* 'noconv)
89 (defconst *ctext*  'ctext)
90 (defconst *hz*     'hz)
91 (defconst *big5*   'big5)
92 (defconst *euc-kr* 'euc-kr)
93 (defconst *koi8*   'koi8)
94
95 (defmacro as-binary-process (&rest body)
96   `(let (selective-display      ; Disable ^M to nl translation.
97          process-input-coding-system
98          process-output-coding-system)
99      ,@body))
100
101
102 ;;; @ MIME charset
103 ;;;
104
105 (defvar charsets-mime-charset-alist
106   '(((ascii)                                            . us-ascii)
107     ((ascii latin-1)                                    . iso-8859-1)
108     ((ascii latin-2)                                    . iso-8859-2)
109     ((ascii latin-3)                                    . iso-8859-3)
110     ((ascii latin-4)                                    . iso-8859-4)
111 ;;; ((ascii cyrillic)                                   . iso-8859-5)
112     ((ascii cyrillic)                                   . koi8-r)
113     ((ascii arabic)                                     . iso-8859-6)
114     ((ascii greek)                                      . iso-8859-7)
115     ((ascii hebrew)                                     . iso-8859-8)
116     ((ascii latin-5)                                    . iso-8859-9)
117     ((ascii japanese-old japanese)                      . iso-2022-jp)
118     ((ascii korean)                                     . euc-kr)
119     ((ascii chinese-big5-1 chinese-big5-2)              . big5)
120     ((ascii japanese-old chinese-gb japanese korean
121             japanese-2 latin-1 greek)                   . iso-2022-jp-2)
122     ((ascii japanese-old chinese-gb japanese korean
123             japanese-2 chinese-cns-1 chinese-cns-2
124             latin-1 greek)                              . iso-2022-int-1)
125     ))
126
127 (defvar default-mime-charset 'iso-2022-int-1)
128
129 (defvar mime-charset-coding-system-alist
130   '((iso-8859-1      . ctext)
131     (gb2312          . euc-china)
132     (koi8-r          . koi8)
133     (iso-2022-jp-2   . iso-2022-ss2-7)
134     (x-iso-2022-jp-2 . iso-2022-ss2-7)
135     (shift_jis       . sjis)
136     (x-shiftjis      . sjis)
137     ))
138
139 (defun mime-charset-to-coding-system (charset)
140   "Return coding-system by MIME charset. [emu-x20.el]"
141   (if (stringp charset)
142       (setq charset (intern (downcase charset)))
143     )
144   (or (cdr (assq charset mime-charset-coding-system-alist))
145       (and (memq charset (coding-system-list)) charset)
146       ))
147
148 (defun detect-mime-charset-region (start end)
149   "Return MIME charset for region between START and END.
150 \[emu-x20.el]"
151   (charsets-to-mime-charset (charsets-in-region start end)))
152
153 (defun encode-mime-charset-region (start end charset)
154   "Encode the text between START and END as MIME CHARSET.
155 \[emu-x20.el]"
156   (let ((cs (mime-charset-to-coding-system charset)))
157     (if cs
158         (encode-coding-region start end cs)
159       )))
160
161 (defun decode-mime-charset-region (start end charset)
162   "Decode the text between START and END as MIME CHARSET.
163 \[emu-x20.el]"
164   (let ((cs (mime-charset-to-coding-system charset)))
165     (if cs
166         (decode-coding-region start end cs)
167       )))
168
169 (defun encode-mime-charset-string (string charset)
170   "Encode the STRING as MIME CHARSET. [emu-x20.el]"
171   (let ((cs (mime-charset-to-coding-system charset)))
172     (if cs
173         (encode-coding-string string cs)
174       string)))
175
176 (defun decode-mime-charset-string (string charset)
177   "Decode the STRING as MIME CHARSET. [emu-x20.el]"
178   (let ((cs (mime-charset-to-coding-system charset)))
179     (if cs
180         (decode-coding-string string cs)
181       string)))
182
183
184 ;;; @ character
185 ;;;
186
187 (defun char-bytes (chr) 1)
188
189 (defun char-length (character)
190   "Return number of elements a CHARACTER occupies in a string or buffer.
191 \[emu-x20.el]"
192   1)
193
194 (defun char-columns (character)
195   "Return number of columns a CHARACTER occupies when displayed.
196 \[emu-x20.el]"
197   (charset-columns (char-charset character))
198   )
199
200 ;;; @@ Mule emulating aliases
201 ;;;
202 ;;; You should not use them.
203
204 (defalias 'char-width 'char-columns)
205
206 (defalias 'char-leading-char 'char-charset)
207
208 (defun char-category (character)
209   "Return string of category mnemonics for CHAR in TABLE.
210 CHAR can be any multilingual character
211 TABLE defaults to the current buffer's category table.
212 \[emu-x20.el; Mule emulating function]"
213   (mapconcat (lambda (chr)
214                (char-to-string (int-char chr))
215                )
216              (char-category-list character)
217              ""))
218
219
220 ;;; @ string
221 ;;;
222
223 (defun string-columns (string)
224   "Return number of columns STRING occupies when displayed.
225 \[emu-x20.el]"
226   (let ((col 0)
227         (len (length string))
228         (i 0))
229     (while (< i len)
230       (setq col (+ col (char-columns (aref string i))))
231       (setq i (1+ i))
232       )
233     col))
234
235 (defalias 'string-width 'string-column)
236
237 (defun string-to-int-list (str)
238   (mapcar #'char-int str)
239   )
240
241 (defalias 'sref 'aref)
242
243 (defun truncate-string (str width &optional start-column)
244   "Truncate STR to fit in WIDTH columns.
245 Optional non-nil arg START-COLUMN specifies the starting column.
246 \[emu-x20.el; Mule 2.3 emulating function]"
247   (or start-column
248       (setq start-column 0))
249   (substring str start-column width)
250   )
251
252
253 ;;; @ end
254 ;;;
255
256 (provide 'emu-x20)
257
258 ;;; emu-x20.el ends here