tm 7.71.
[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.27 1996/07/11 09:02:01 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 '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*   nil)
94
95 (defvar code-converter-is-broken
96   (and xemacs-beta-version (<= xemacs-beta-version 26)))
97
98 (if code-converter-is-broken
99 (progn
100 ;;;
101 (defun decode-coding-region (start end coding-system &optional buffer)
102   "Decode the text between START and END which is encoded in CODING-SYSTEM.
103 \[emu-x20.el; XEmacs 20 emulating function]"
104   (save-excursion
105     (if buffer
106         (set-buffer buffer)
107       )
108     (save-restriction
109       (narrow-to-region start end)
110       (let ((process-output-coding-system 'noconv)
111             (process-input-coding-system coding-system))
112         (call-process-region start end "cat" t t nil)
113         ))))
114
115 (defun encode-coding-region (start end coding-system &optional buffer)
116   "Encode the text between START and END which is encoded in CODING-SYSTEM.
117 \[emu-x20.el; XEmacs 20 emulating function]"
118   (save-excursion
119     (if buffer
120         (set-buffer buffer)
121       )
122     (save-restriction
123       (narrow-to-region start end)
124       (let ((process-output-coding-system coding-system)
125             (process-input-coding-system 'noconv))
126         (call-process-region start end "cat" t t nil)
127         ))))
128 ;;;
129 ))
130
131 (defalias 'character-encode-string 'encode-coding-string)
132 (defalias 'character-decode-string 'decode-coding-string)
133 (defalias 'character-encode-region 'encode-coding-region)
134 (defalias 'character-decode-region 'decode-coding-region)
135
136 (defmacro as-binary-process (&rest body)
137   `(let (selective-display      ; Disable ^M to nl translation.
138          process-input-coding-system
139          process-output-coding-system)
140      ,@body))
141
142
143 ;;; @ MIME charset
144 ;;;
145
146 (defvar charsets-mime-charset-alist
147   '(((ascii)                                            . us-ascii)
148     ((ascii latin-1)                                    . iso-8859-1)
149     ((ascii latin-2)                                    . iso-8859-2)
150     ((ascii latin-3)                                    . iso-8859-3)
151     ((ascii latin-4)                                    . iso-8859-4)
152 ;;; ((ascii cyrillic)                                   . iso-8859-5)
153     ((ascii cyrillic)                                   . koi8-r)
154     ((ascii arabic)                                     . iso-8859-6)
155     ((ascii greek)                                      . iso-8859-7)
156     ((ascii hebrew)                                     . iso-8859-8)
157     ((ascii latin-5)                                    . iso-8859-9)
158     ((ascii japanese-old japanese)                      . iso-2022-jp)
159     ((ascii korean)                                     . euc-kr)
160     ((ascii chinese-big5-1 chinese-big5-2)              . big5)
161     ((ascii japanese-old chinese-gb japanese korean
162             japanese-2 latin-1 greek)                   . iso-2022-jp-2)
163     ((ascii japanese-old chinese-gb japanese korean
164             japanese-2 chinese-cns-1 chinese-cns-2
165             latin-1 greek)                              . iso-2022-int-1)
166     ))
167
168 (defvar default-mime-charset 'iso-2022-int-1)
169
170 (defvar mime-charset-coding-system-alist
171   '((iso-8859-1      . ctext)
172     (gb2312          . euc-china)
173     (koi8-r          . koi8)
174     (iso-2022-jp-2   . iso-2022-ss2-7)
175     (x-iso-2022-jp-2 . iso-2022-ss2-7)
176     (shift_jis       . sjis)
177     (x-shiftjis      . sjis)
178     ))
179
180 (defun mime-charset-to-coding-system (charset)
181   "Return coding-system by MIME charset. [emu-x20.el]"
182   (if (stringp charset)
183       (setq charset (intern (downcase charset)))
184     )
185   (or (cdr (assq charset mime-charset-coding-system-alist))
186       (and (memq charset (coding-system-list)) charset)
187       ))
188
189 (defun detect-mime-charset-region (start end)
190   "Return MIME charset for region between START and END.
191 \[emu-x20.el]"
192   (charsets-to-mime-charset (charsets-in-region start end)))
193
194 (defun encode-mime-charset-region (start end charset)
195   "Encode the text between START and END which is
196 encoded in MIME CHARSET. [emu-x20.el]"
197   (let ((cs (mime-charset-to-coding-system charset)))
198     (if cs
199         (encode-coding-region start end cs)
200       )))
201
202 (defun encode-mime-charset-string (string charset)
203   "Encode the STRING which is encoded in MIME CHARSET. [emu-x20.el]"
204   (let ((cs (mime-charset-to-coding-system charset)))
205     (if cs
206         (encode-coding-string string cs)
207       string)))
208
209
210 ;;; @ character
211 ;;;
212
213 (defun char-bytes (chr) 1)
214
215 (defun char-length (character)
216   "Return number of elements a CHARACTER occupies in a string or buffer.
217 \[emu-x20.el]"
218   1)
219
220 (defun char-columns (character)
221   "Return number of columns a CHARACTER occupies when displayed.
222 \[emu-x20.el]"
223   (charset-columns (char-charset character))
224   )
225
226 ;;; @@ Mule emulating aliases
227 ;;;
228 ;;; You should not use them.
229
230 (defalias 'char-width 'char-columns)
231
232 (defalias 'char-leading-char 'char-charset)
233
234 (defun char-category (character)
235   "Return string of category mnemonics for CHAR in TABLE.
236 CHAR can be any multilingual character
237 TABLE defaults to the current buffer's category table.
238 \[emu-x20.el; Mule emulating function]"
239   (mapconcat (lambda (chr)
240                (char-to-string (int-char chr))
241                )
242              (char-category-list character)
243              ""))
244
245
246 ;;; @ string
247 ;;;
248
249 (defun string-columns (string)
250   "Return number of columns STRING occupies when displayed.
251 \[emu-x20.el]"
252   (let ((col 0)
253         (len (length string))
254         (i 0))
255     (while (< i len)
256       (setq col (+ col (char-columns (aref string i))))
257       (setq i (1+ i))
258       )
259     col))
260
261 (defalias 'string-width 'string-column)
262
263 (defun string-to-int-list (str)
264   (mapcar #'char-int str)
265   )
266
267 (defalias 'sref 'aref)
268
269 (defun truncate-string (str width &optional start-column)
270   "Truncate STR to fit in WIDTH columns.
271 Optional non-nil arg START-COLUMN specifies the starting column.
272 \[emu-x20.el; Mule 2.3 emulating function]"
273   (or start-column
274       (setq start-column 0))
275   (substring str start-column width)
276   )
277
278
279 ;;; @ end
280 ;;;
281
282 (provide 'emu-x20)
283
284 ;;; emu-x20.el ends here