tm 7.95.
[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.40 1996/10/19 14:35:37 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 GNU XEmacs; see the file COPYING.  If not, write to the
24 ;; 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 (defalias 'find-charset-string 'charsets-in-string)
45 (defalias 'find-charset-region 'charsets-in-region)
46
47 (defun find-non-ascii-charset-string (string)
48   "Return a list of charsets in the STRING except ascii.
49 \[emu-x20.el; Mule emulating function]"
50   (delq 'ascii (charsets-in-string string))
51   )
52
53 (defun find-non-ascii-charset-region (start end)
54   "Return a list of charsets except ascii
55 in the region between START and END.
56 \[emu-x20.el; Mule emulating function]"
57   (delq 'ascii (charsets-in-region start end))
58   )
59
60 ;;; @@ for Mule emulation
61 ;;;
62
63 (defconst lc-ascii  'ascii)
64 (defconst lc-ltn1   'latin-1)
65 (defconst lc-ltn2   'latin-2)
66 (defconst lc-ltn3   'latin-3)
67 (defconst lc-ltn4   'latin-4)
68 (defconst lc-crl    'cyrillic)
69 (defconst lc-arb    'arabic)
70 (defconst lc-grk    'greek)
71 (defconst lc-hbw    'hebrew)
72 (defconst lc-ltn5   'latin-5)
73 (defconst lc-jp     'japanese)
74 (defconst lc-jp2    'japanese-2)
75 (defconst lc-kr     'korean)
76 (defconst lc-big5-1 'chinese-big5-1)
77 (defconst lc-big5-2 'chinese-big5-2)
78 (defconst lc-cn     'chinese-gb)
79 (defconst lc-cns1   'chinese-cns-1)
80 (defconst lc-cns2   'chinese-cns-2)
81 (defconst lc-cns3   'chinese-cns-3)
82 (defconst lc-cns4   'chinese-cns-4)
83 (defconst lc-cns5   'chinese-cns-5)
84 (defconst lc-cns6   'chinese-cns-6)
85 (defconst lc-cns7   'chinese-cns-7)
86
87
88 ;;; @ coding-system
89 ;;;
90
91 (defconst *noconv* 'noconv)
92 (defconst *ctext*  'ctext)
93 (defconst *hz*     'hz)
94 (defconst *big5*   'big5)
95 (defconst *euc-kr* 'euc-kr)
96 (defconst *koi8*   'koi8)
97
98 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
99
100 (defmacro as-binary-process (&rest body)
101   `(let (selective-display      ; Disable ^M to nl translation.
102          process-input-coding-system
103          process-output-coding-system)
104      ,@body))
105
106 (defmacro as-binary-input-file (&rest body)
107   `(let ((file-coding-system-for-read 'noconv))
108      ,@body))
109
110
111 ;;; @ MIME charset
112 ;;;
113
114 (defvar charsets-mime-charset-alist
115   '(((ascii)                                            . us-ascii)
116     ((ascii latin-1)                                    . iso-8859-1)
117     ((ascii latin-2)                                    . iso-8859-2)
118     ((ascii latin-3)                                    . iso-8859-3)
119     ((ascii latin-4)                                    . iso-8859-4)
120 ;;; ((ascii cyrillic)                                   . iso-8859-5)
121     ((ascii cyrillic)                                   . koi8-r)
122     ((ascii arabic)                                     . iso-8859-6)
123     ((ascii greek)                                      . iso-8859-7)
124     ((ascii hebrew)                                     . iso-8859-8)
125     ((ascii latin-5)                                    . iso-8859-9)
126     ((ascii japanese-old japanese)                      . iso-2022-jp)
127     ((ascii korean)                                     . euc-kr)
128     ((ascii chinese-big5-1 chinese-big5-2)              . big5)
129     ((ascii japanese-old chinese-gb japanese korean
130             japanese-2 latin-1 greek)                   . iso-2022-jp-2)
131     ((ascii japanese-old chinese-gb japanese korean
132             japanese-2 chinese-cns-1 chinese-cns-2
133             latin-1 greek)                              . iso-2022-int-1)
134     ))
135
136 (defvar default-mime-charset 'iso-2022-int-1)
137
138 (defvar mime-charset-coding-system-alist
139   '((iso-8859-1      . ctext)
140     (gb2312          . euc-china)
141     (koi8-r          . koi8)
142     (iso-2022-jp-2   . iso-2022-ss2-7)
143     (x-iso-2022-jp-2 . iso-2022-ss2-7)
144     (shift_jis       . sjis)
145     (x-shiftjis      . sjis)
146     ))
147
148 (defun mime-charset-to-coding-system (charset)
149   "Return coding-system by MIME charset. [emu-x20.el]"
150   (if (stringp charset)
151       (setq charset (intern (downcase charset)))
152     )
153   (or (cdr (assq charset mime-charset-coding-system-alist))
154       (and (memq charset (coding-system-list)) charset)
155       ))
156
157 (defun detect-mime-charset-region (start end)
158   "Return MIME charset for region between START and END.
159 \[emu-x20.el]"
160   (charsets-to-mime-charset (charsets-in-region start end)))
161
162 (defun encode-mime-charset-region (start end charset)
163   "Encode the text between START and END as MIME CHARSET.
164 \[emu-x20.el]"
165   (let ((cs (mime-charset-to-coding-system charset)))
166     (if cs
167         (encode-coding-region start end cs)
168       )))
169
170 (defun decode-mime-charset-region (start end charset)
171   "Decode the text between START and END as MIME CHARSET.
172 \[emu-x20.el]"
173   (let ((cs (mime-charset-to-coding-system charset)))
174     (if cs
175         (decode-coding-region start end cs)
176       )))
177
178 (defun encode-mime-charset-string (string charset)
179   "Encode the STRING as MIME CHARSET. [emu-x20.el]"
180   (let ((cs (mime-charset-to-coding-system charset)))
181     (if cs
182         (encode-coding-string string cs)
183       string)))
184
185 (defun decode-mime-charset-string (string charset)
186   "Decode the STRING as MIME CHARSET. [emu-x20.el]"
187   (let ((cs (mime-charset-to-coding-system charset)))
188     (if cs
189         (decode-coding-string string cs)
190       string)))
191
192
193 ;;; @ character
194 ;;;
195
196 (defun char-bytes (chr) 1)
197
198 (defun char-length (character)
199   "Return number of elements a CHARACTER occupies in a string or buffer.
200 \[emu-x20.el]"
201   1)
202
203 (defun char-columns (character)
204   "Return number of columns a CHARACTER occupies when displayed.
205 \[emu-x20.el]"
206   (charset-columns (char-charset character))
207   )
208
209 ;;; @@ Mule emulating aliases
210 ;;;
211 ;;; You should not use them.
212
213 (defalias 'char-width 'char-columns)
214
215 (defalias 'char-leading-char 'char-charset)
216
217 (defun char-category (character)
218   "Return string of category mnemonics for CHAR in TABLE.
219 CHAR can be any multilingual character
220 TABLE defaults to the current buffer's category table.
221 \[emu-x20.el; Mule emulating function]"
222   (mapconcat (lambda (chr)
223                (char-to-string (int-char chr))
224                )
225              (char-category-list character)
226              ""))
227
228
229 ;;; @ string
230 ;;;
231
232 (defun string-columns (string)
233   "Return number of columns STRING occupies when displayed.
234 \[emu-x20.el]"
235   (let ((col 0)
236         (len (length string))
237         (i 0))
238     (while (< i len)
239       (setq col (+ col (char-columns (aref string i))))
240       (setq i (1+ i))
241       )
242     col))
243
244 (defalias 'string-width 'string-columns)
245
246 (defun string-to-int-list (str)
247   (mapcar #'char-int str)
248   )
249
250 (defalias 'sref 'aref)
251
252 (defun truncate-string (str width &optional start-column)
253   "Truncate STR to fit in WIDTH columns.
254 Optional non-nil arg START-COLUMN specifies the starting column.
255 \[emu-x20.el; Mule 2.3 emulating function]"
256   (or start-column
257       (setq start-column 0))
258   (substring str start-column width)
259   )
260
261
262 ;;; @ end
263 ;;;
264
265 (provide 'emu-x20)
266
267 ;;; emu-x20.el ends here