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