771
|
1 ;;; unicode.el --- Unicode support -*- coding: iso-2022-7bit; -*-
|
|
2
|
778
|
3 ;; Copyright (C) 2001, 2002 Ben Wing.
|
771
|
4
|
|
5 ;; Keywords: multilingual, Unicode
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
|
23
|
|
24 ;;; Synched up with: Not in FSF.
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; Lisp support for Unicode, e.g. initialize the translation tables.
|
|
29
|
|
30 ;;; Code:
|
|
31
|
778
|
32 ; ;; Subsets of Unicode.
|
|
33
|
|
34 ; (make-charset 'mule-unicode-2500-33ff
|
|
35 ; "Unicode characters of the range U+2500..U+33FF."
|
|
36 ; '(dimension
|
|
37 ; 2
|
|
38 ; registry "ISO10646-1"
|
|
39 ; chars 96
|
|
40 ; columns 1
|
|
41 ; direction l2r
|
|
42 ; final ?2
|
|
43 ; graphic 0
|
|
44 ; short-name "Unicode subset 2"
|
|
45 ; long-name "Unicode subset (U+2500..U+33FF)"
|
|
46 ; ))
|
|
47
|
|
48
|
|
49 ; (make-charset 'mule-unicode-e000-ffff
|
|
50 ; "Unicode characters of the range U+E000..U+FFFF."
|
|
51 ; '(dimension
|
|
52 ; 2
|
|
53 ; registry "ISO10646-1"
|
|
54 ; chars 96
|
|
55 ; columns 1
|
|
56 ; direction l2r
|
|
57 ; final ?3
|
|
58 ; graphic 0
|
|
59 ; short-name "Unicode subset 3"
|
|
60 ; long-name "Unicode subset (U+E000+FFFF)"
|
|
61 ; ))
|
|
62
|
|
63
|
|
64 ; (make-charset 'mule-unicode-0100-24ff
|
|
65 ; "Unicode characters of the range U+0100..U+24FF."
|
|
66 ; '(dimension
|
|
67 ; 2
|
|
68 ; registry "ISO10646-1"
|
|
69 ; chars 96
|
|
70 ; columns 1
|
|
71 ; direction l2r
|
|
72 ; final ?1
|
|
73 ; graphic 0
|
|
74 ; short-name "Unicode subset"
|
|
75 ; long-name "Unicode subset (U+0100..U+24FF)"
|
|
76 ; ))
|
|
77
|
|
78
|
771
|
79 ;; NOTE: This takes only a fraction of a second on my Pentium III
|
|
80 ;; 700Mhz even with a totally optimization-disabled XEmacs.
|
|
81 (defun load-unicode-tables ()
|
|
82 "Initialize the Unicode translation tables for all standard charsets."
|
780
|
83 (let ((parse-args
|
|
84 '(("unicode/unicode-consortium"
|
|
85 ("8859-1.TXT" latin-iso8859-1 #xA0 #xFF #x-80)
|
|
86 ;; "8859-10.TXT"
|
|
87 ;; "8859-13.TXT"
|
|
88 ;; "8859-14.TXT"
|
|
89 ("8859-14.TXT" latin-iso8859-14 #xA0 #xFF #x-80)
|
|
90 ("8859-15.TXT" latin-iso8859-15 #xA0 #xFF #x-80)
|
|
91 ("8859-2.TXT" latin-iso8859-2 #xA0 #xFF #x-80)
|
|
92 ("8859-3.TXT" latin-iso8859-3 #xA0 #xFF #x-80)
|
|
93 ("8859-4.TXT" latin-iso8859-4 #xA0 #xFF #x-80)
|
|
94 ("8859-5.TXT" cyrillic-iso8859-5 #xA0 #xFF #x-80)
|
|
95 ("8859-6.TXT" arabic-iso8859-6 #xA0 #xFF #x-80)
|
|
96 ("8859-7.TXT" greek-iso8859-7 #xA0 #xFF #x-80)
|
|
97 ("8859-8.TXT" hebrew-iso8859-8 #xA0 #xFF #x-80)
|
|
98 ("8859-9.TXT" latin-iso8859-9 #xA0 #xFF #x-80)
|
|
99 ;; charset for Big5 does not matter; specifying `big5' will
|
|
100 ;; automatically make the right thing happen
|
|
101 ("BIG5.TXT" chinese-big5-1 nil nil nil big5)
|
|
102 ("CNS11643.TXT" chinese-cns11643-1 #x10000 #x1FFFF #x-10000)
|
|
103 ("CNS11643.TXT" chinese-cns11643-2 #x20000 #x2FFFF #x-20000)
|
|
104 ;; "CP1250.TXT"
|
|
105 ;; "CP1251.TXT"
|
|
106 ;; "CP1252.TXT"
|
|
107 ;; "CP1253.TXT"
|
|
108 ;; "CP1254.TXT"
|
|
109 ;; "CP1255.TXT"
|
|
110 ;; "CP1256.TXT"
|
|
111 ;; "CP1257.TXT"
|
|
112 ;; "CP1258.TXT"
|
|
113 ;; "CP874.TXT"
|
|
114 ;; "CP932.TXT"
|
|
115 ;; "CP936.TXT"
|
|
116 ;; "CP949.TXT"
|
|
117 ;; "CP950.TXT"
|
|
118 ;; "GB12345.TXT"
|
|
119 ("GB2312.TXT" chinese-gb2312)
|
|
120 ;; "HANGUL.TXT"
|
|
121 ("JIS0201.TXT" latin-jisx0201 #x21 #x80)
|
|
122 ("JIS0201.TXT" katakana-jisx0201 #xA0 #xFF #x-80)
|
|
123 ("JIS0208.TXT" japanese-jisx0208 nil nil nil ignore-first-column)
|
|
124 ("JIS0212.TXT" japanese-jisx0212)
|
|
125 ;; "JOHAB.TXT"
|
|
126 ;; "KOI8-R.TXT"
|
|
127 ;; "KSC5601.TXT"
|
|
128 ;; note that KSC5601.TXT as currently distributed is NOT what
|
|
129 ;; it claims to be! see comments in KSX1001.TXT.
|
|
130 ("KSX1001.TXT" korean-ksc5601)
|
|
131 ;; "OLD5601.TXT"
|
|
132 ;; "SHIFTJIS.TXT"
|
|
133 )
|
|
134 ("unicode/mule-ucs"
|
|
135 ;; use these instead of the above ones once we support surrogates
|
|
136 ;;("chinese-cns11643-1.txt" chinese-cns11643-1)
|
|
137 ;;("chinese-cns11643-2.txt" chinese-cns11643-2)
|
|
138 ;;("chinese-cns11643-3.txt" chinese-cns11643-3)
|
|
139 ;;("chinese-cns11643-4.txt" chinese-cns11643-4)
|
|
140 ;;("chinese-cns11643-5.txt" chinese-cns11643-5)
|
|
141 ;;("chinese-cns11643-6.txt" chinese-cns11643-6)
|
|
142 ;;("chinese-cns11643-7.txt" chinese-cns11643-7)
|
|
143 ("chinese-sisheng.txt" chinese-sisheng)
|
|
144 ("ethiopic.txt" ethiopic)
|
|
145 ("indian-is13194.txt" indian-is13194)
|
|
146 ("ipa.txt" ipa)
|
|
147 ("thai-tis620.txt" thai-tis620)
|
|
148 ("tibetan.txt" tibetan)
|
|
149 ("vietnamese-viscii-lower.txt" vietnamese-viscii-lower)
|
|
150 ("vietnamese-viscii-upper.txt" vietnamese-viscii-upper)
|
|
151 )
|
|
152 ("unicode/other"
|
|
153 ("lao.txt" lao)
|
|
154 )
|
771
|
155 )))
|
780
|
156 (mapcar #'(lambda (tables)
|
|
157 (let ((undir
|
|
158 (expand-file-name (car tables) data-directory)))
|
|
159 (mapcar #'(lambda (args)
|
|
160 (apply 'parse-unicode-translation-table
|
|
161 (expand-file-name (car args) undir)
|
|
162 (cdr args)))
|
|
163 (cdr tables))))
|
771
|
164 parse-args)))
|
|
165
|
|
166 (defun init-unicode-at-startup ()
|
|
167 (load-unicode-tables))
|
|
168
|
|
169 (make-coding-system
|
|
170 'utf-16 'unicode
|
|
171 "UTF-16"
|
|
172 '(mnemonic "UTF-16"
|
|
173 documentation
|
|
174 "UTF-16 Unicode encoding -- the standard (almost-) fixed-width
|
|
175 two-byte encoding, with surrogates. It will be fixed-width if all
|
|
176 characters are in the BMP (Basic Multilingual Plane -- first 65536
|
|
177 codepoints). Cannot represent characters with codepoints above
|
|
178 0x10FFFF (a little more than 1,000,000). Unicode and ISO guarantee
|
|
179 never to encode any characters outside this range -- all the rest are
|
|
180 for private, corporate or internal use."
|
|
181 type utf-16))
|
|
182
|
|
183 (make-coding-system
|
|
184 'utf-16-bom 'unicode
|
|
185 "UTF-16 w/BOM"
|
|
186 '(mnemonic "UTF16-BOM"
|
|
187 documentation
|
|
188 "UTF-16 Unicode encoding with byte order mark (BOM) at the beginning.
|
|
189 The BOM is Unicode character U+FEFF -- i.e. the first two bytes are
|
|
190 0xFE and 0xFF, respectively, or reversed in a little-endian
|
|
191 representation. It has been sanctioned by the Unicode Consortium for
|
|
192 use at the beginning of a Unicode stream as a marker of the byte order
|
|
193 of the stream, and commonly appears in Unicode files under Microsoft
|
|
194 Windows, where it also functions as a magic cookie identifying a
|
|
195 Unicode file. The character is called \"ZERO WIDTH NO-BREAK SPACE\"
|
|
196 and is suitable as a byte-order marker because:
|
|
197
|
|
198 -- it has no displayable representation
|
|
199 -- due to its semantics it never normally appears at the beginning
|
|
200 of a stream
|
|
201 -- its reverse U+FFFE is not a legal Unicode character
|
|
202 -- neither byte sequence is at all likely in any other standard
|
|
203 encoding, particularly at the beginning of a stream
|
|
204
|
|
205 This coding system will insert a BOM at the beginning of a stream when
|
|
206 writing and strip it off when reading."
|
|
207 type utf-16
|
|
208 need-bom t))
|
|
209
|
|
210 (make-coding-system
|
|
211 'utf-16-little-endian 'unicode
|
|
212 "UTF-16 Little Endian"
|
|
213 '(mnemonic "UTF16-LE"
|
|
214 documentation
|
|
215 "Little-endian version of UTF-16 Unicode encoding.
|
|
216 See `utf-16' coding system."
|
|
217 type utf-16
|
|
218 little-endian t))
|
|
219
|
|
220 (make-coding-system
|
|
221 'utf-16-little-endian-bom 'unicode
|
|
222 "UTF-16 Little Endian w/BOM"
|
|
223 '(mnemonic "MSW-Unicode"
|
|
224 documentation
|
|
225 "Little-endian version of UTF-16 Unicode encoding, with byte order mark.
|
|
226 Standard encoding for representing Unicode under MS Windows. See
|
|
227 `utf-16-bom' coding system."
|
|
228 type utf-16
|
|
229 little-endian t
|
|
230 need-bom t))
|
|
231
|
|
232 (make-coding-system
|
|
233 'ucs-4 'unicode
|
|
234 "UCS-4"
|
|
235 '(mnemonic "UCS4"
|
|
236 documentation
|
|
237 "UCS-4 Unicode encoding -- fully fixed-width four-byte encoding."
|
|
238 type ucs-4))
|
|
239
|
|
240 (make-coding-system
|
|
241 'ucs-4-little-endian 'unicode
|
|
242 "UCS-4 Little Endian"
|
|
243 '(mnemonic "UCS4-LE"
|
|
244 documentation
|
|
245 "Little-endian version of UCS-4 Unicode encoding. See `ucs-4' coding system."
|
|
246 type ucs-4
|
|
247 little-endian t))
|
|
248
|
|
249 (make-coding-system
|
|
250 'utf-8 'unicode
|
|
251 "UTF-8"
|
|
252 '(mnemonic "UTF8"
|
|
253 documentation
|
|
254 "UTF-8 Unicode encoding -- ASCII-compatible 8-bit variable-width encoding
|
|
255 with the same principles as the Mule-internal encoding:
|
|
256
|
|
257 -- All ASCII characters (codepoints 0 through 127) are represented
|
|
258 by themselves (i.e. using one byte, with the same value as the
|
|
259 ASCII codepoint), and these bytes are disjoint from bytes
|
|
260 representing non-ASCII characters.
|
|
261
|
|
262 This means that any 8-bit clean application can safely process
|
|
263 UTF-8-encoded text as it were ASCII, with no corruption (e.g. a
|
|
264 '/' byte is always a slash character, never the second byte of
|
|
265 some other character, as with Big5, so a pathname encoded in
|
|
266 UTF-8 can safely be split up into components and reassembled
|
|
267 again using standard ASCII processes).
|
|
268
|
|
269 -- Leading bytes and non-leading bytes in the encoding of a
|
|
270 character are disjoint, so moving backwards is easy.
|
|
271
|
|
272 -- Given only the leading byte, you know how many following bytes
|
|
273 are present.
|
|
274 "
|
|
275 type utf-8))
|
|
276
|
|
277 ;; #### UTF-7 is not yet implemented, and it's tricky to do. There's
|
|
278 ;; an implementation in appendix A.1 of the Unicode Standard, Version
|
|
279 ;; 2.0, but I don't know its licensing characteristics.
|
|
280
|
|
281 ; (make-coding-system
|
|
282 ; 'utf-7 'unicode
|
|
283 ; "UTF-7"
|
|
284 ; '(mnemonic "UTF7"
|
|
285 ; documentation
|
|
286 ; "UTF-7 Unicode encoding -- 7-bit-ASCII modal Internet-mail-compatible
|
|
287 ; encoding especially designed for headers, with the following
|
|
288 ; properties:
|
|
289
|
|
290 ; -- Only characters that are considered safe for passing through any mail
|
|
291 ; gateway without damage are used.
|
|
292
|
|
293 ; -- This is a modal encoding, with two states. The first, default
|
|
294 ; state encodes the most common Unicode characters (upper and
|
|
295 ; lowercase letters, digits, and 9 common punctuation marks) as
|
|
296 ; themselves, and the second state, entered using '+' and
|
|
297 ; terminated with '-' or any character disallowed in state 2,
|
|
298 ; encodes any Unicode characters by first converting to UTF-16,
|
|
299 ; most significant byte first, and then to a slightly modified
|
|
300 ; Base64 encoding. (Thus, UTF-7 has the same limitations on the
|
|
301 ; characters it can encode as UTF-16.)
|
|
302
|
|
303 ; -- The modified Base64 encoding deviates from standard Base64 in
|
|
304 ; that it omits the `=' pad character. This is eliminated so as to
|
|
305 ; avoid conflicts with the use of `=' as an escape in the
|
|
306 ; Quoted-Printable encoding and the related Q encoding for headers:
|
|
307 ; With this modification, non-whitespace chars in UTF-7 will be
|
|
308 ; represented in Quoted-Printable and in Q as-is, with no further
|
|
309 ; encoding.
|
|
310
|
|
311 ; For more information, see Appendix A.1 of The Unicode Standard 2.0, or
|
|
312 ; wherever it is in v3.0."
|
|
313 ; type utf-7))
|