comparison lisp/tl/emu-x20.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents
children 54cc21c15cbb
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
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 1.1.1.1 1996/12/18 22:43:38 steve 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-jisx0208)
74 (defconst lc-jp2 'japanese-jisx0212)
75 (defconst lc-kr 'korean-ksc5601)
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-cns11643-1)
80 (defconst lc-cns2 'chinese-cns11643-2)
81 (defconst lc-cns3 'chinese-cns11643-3)
82 (defconst lc-cns4 'chinese-cns11643-4)
83 (defconst lc-cns5 'chinese-cns11643-5)
84 (defconst lc-cns6 'chinese-cns11643-6)
85 (defconst lc-cns7 'chinese-cns11643-7)
86
87
88 ;;; @ coding-system
89 ;;;
90
91 (defconst *noconv* 'no-conversion)
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 'no-conversion))
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-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
127 ((ascii korean-ksc5601) . euc-kr)
128 ((ascii chinese-big5-1 chinese-big5-2) . big5)
129 ((ascii japanese-jisx0208-1978 chinese-gb
130 japanese-jisx0208 korean-ksc5601
131 japanese-jisx0212 latin-1 greek) . iso-2022-jp-2)
132 ((ascii japanese-jisx0208-1978 chinese-gb japanese-jisx0208 korean-ksc5601
133 japanese-jisx0212 chinese-cns11643-1 chinese-cns11643-2
134 latin-1 greek) . iso-2022-int-1)
135 ))
136
137 (defvar default-mime-charset 'iso-2022-int-1)
138
139 (defvar mime-charset-coding-system-alist
140 '((iso-8859-1 . ctext)
141 (gb2312 . euc-china)
142 (koi8-r . koi8)
143 (iso-2022-jp-2 . iso-2022-ss2-7)
144 (x-iso-2022-jp-2 . iso-2022-ss2-7)
145 (shift_jis . sjis)
146 (x-shiftjis . sjis)
147 ))
148
149 (defun mime-charset-to-coding-system (charset)
150 "Return coding-system by MIME charset. [emu-x20.el]"
151 (if (stringp charset)
152 (setq charset (intern (downcase charset)))
153 )
154 (or (cdr (assq charset mime-charset-coding-system-alist))
155 (and (memq charset (coding-system-list)) charset)
156 ))
157
158 (defun detect-mime-charset-region (start end)
159 "Return MIME charset for region between START and END.
160 \[emu-x20.el]"
161 (charsets-to-mime-charset (charsets-in-region start end)))
162
163 (defun encode-mime-charset-region (start end charset)
164 "Encode the text between START and END as MIME CHARSET.
165 \[emu-x20.el]"
166 (let ((cs (mime-charset-to-coding-system charset)))
167 (if cs
168 (encode-coding-region start end cs)
169 )))
170
171 (defun decode-mime-charset-region (start end charset)
172 "Decode the text between START and END as MIME CHARSET.
173 \[emu-x20.el]"
174 (let ((cs (mime-charset-to-coding-system charset)))
175 (if cs
176 (decode-coding-region start end cs)
177 )))
178
179 (defun encode-mime-charset-string (string charset)
180 "Encode the STRING as MIME CHARSET. [emu-x20.el]"
181 (let ((cs (mime-charset-to-coding-system charset)))
182 (if cs
183 (encode-coding-string string cs)
184 string)))
185
186 (defun decode-mime-charset-string (string charset)
187 "Decode the STRING as MIME CHARSET. [emu-x20.el]"
188 (let ((cs (mime-charset-to-coding-system charset)))
189 (if cs
190 (decode-coding-string string cs)
191 string)))
192
193
194 ;;; @ character
195 ;;;
196
197 (defun char-bytes (chr) 1)
198
199 (defun char-length (character)
200 "Return number of elements a CHARACTER occupies in a string or buffer.
201 \[emu-x20.el]"
202 1)
203
204 (defun char-columns (character)
205 "Return number of columns a CHARACTER occupies when displayed.
206 \[emu-x20.el]"
207 (charset-columns (char-charset character))
208 )
209
210 ;;; @@ Mule emulating aliases
211 ;;;
212 ;;; You should not use them.
213
214 (defalias 'char-width 'char-columns)
215
216 (defalias 'char-leading-char 'char-charset)
217
218 (defun char-category (character)
219 "Return string of category mnemonics for CHAR in TABLE.
220 CHAR can be any multilingual character
221 TABLE defaults to the current buffer's category table.
222 \[emu-x20.el; Mule emulating function]"
223 (mapconcat (lambda (chr)
224 (char-to-string (int-char chr))
225 )
226 (char-category-list character)
227 ""))
228
229
230 ;;; @ string
231 ;;;
232
233 (defun string-columns (string)
234 "Return number of columns STRING occupies when displayed.
235 \[emu-x20.el]"
236 (let ((col 0)
237 (len (length string))
238 (i 0))
239 (while (< i len)
240 (setq col (+ col (char-columns (aref string i))))
241 (setq i (1+ i))
242 )
243 col))
244
245 (defalias 'string-width 'string-columns)
246
247 (defun string-to-int-list (str)
248 (mapcar #'char-int str)
249 )
250
251 (defalias 'sref 'aref)
252
253 (defun truncate-string (str width &optional start-column)
254 "Truncate STR to fit in WIDTH columns.
255 Optional non-nil arg START-COLUMN specifies the starting column.
256 \[emu-x20.el; Mule 2.3 emulating function]"
257 (or start-column
258 (setq start-column 0))
259 (substring str start-column width)
260 )
261
262
263 ;;; @ end
264 ;;;
265
266 (provide 'emu-x20)
267
268 ;;; emu-x20.el ends here