428
|
1 ;;; chinese.el --- Support for Chinese -*- coding: iso-2022-7bit; -*-
|
|
2
|
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
4 ;; Licensed to the Free Software Foundation.
|
|
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
|
771
|
6 ;; Copyright (C) 2000, 2001 Ben Wing.
|
428
|
7
|
|
8 ;; Keywords: multilingual, Chinese
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free
|
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; For Chinese, three character sets GB2312, BIG5, and CNS11643 are
|
|
30 ;; supported.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
|
34 ;; Syntax of Chinese characters.
|
|
35 (modify-syntax-entry 'chinese-gb2312 "w")
|
|
36 (loop for row in '(33 34 41)
|
|
37 do (modify-syntax-entry `[chinese-gb2312 ,row] "."))
|
|
38 ;;(loop for row from 35 to 40
|
|
39 ;; do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
|
|
40 ;;(loop for row from 42 to 126
|
|
41 ;; do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
|
|
42
|
|
43 (modify-syntax-entry 'chinese-cns11643-1 "w")
|
|
44 (modify-syntax-entry 'chinese-cns11643-2 "w")
|
|
45 (modify-syntax-entry 'chinese-big5-1 "w")
|
|
46 (modify-syntax-entry 'chinese-big5-2 "w")
|
|
47
|
|
48 ;; CNS11643 Plane3 thru Plane7
|
|
49 ;; These represent more and more obscure Chinese characters.
|
|
50 ;; By the time you get to Plane 7, we're talking about characters
|
|
51 ;; that appear once in some ancient manuscript and whose meaning
|
|
52 ;; is unknown.
|
|
53
|
|
54 (flet
|
|
55 ((make-chinese-cns11643-charset
|
|
56 (name plane final)
|
|
57 (make-charset
|
|
58 name (concat "CNS 11643 Plane " plane " (Chinese traditional)")
|
|
59 `(registry
|
|
60 ,(concat "CNS11643[.-]\\(.*[.-]\\)?" plane "$")
|
|
61 dimension 2
|
|
62 chars 94
|
|
63 final ,final
|
|
64 graphic 0))
|
|
65 (modify-syntax-entry name "w")
|
|
66 (modify-category-entry name ?t)
|
|
67 ))
|
|
68 (make-chinese-cns11643-charset 'chinese-cns11643-3 "3" ?I)
|
|
69 (make-chinese-cns11643-charset 'chinese-cns11643-4 "4" ?J)
|
|
70 (make-chinese-cns11643-charset 'chinese-cns11643-5 "5" ?K)
|
|
71 (make-chinese-cns11643-charset 'chinese-cns11643-6 "6" ?L)
|
|
72 (make-chinese-cns11643-charset 'chinese-cns11643-7 "7" ?M)
|
|
73 )
|
|
74
|
|
75 ;; ISO-IR-165 (CCITT Extended GB)
|
|
76 ;; It is based on CCITT Recommendation T.101, includes GB 2312-80 +
|
|
77 ;; GB 8565-88 table A4 + 293 characters.
|
|
78 (make-charset
|
|
79 'chinese-isoir165
|
|
80 "ISO-IR-165 (CCITT Extended GB; Chinese simplified)"
|
|
81 `(registry "isoir165"
|
|
82 dimension 2
|
|
83 chars 94
|
|
84 final ?E
|
|
85 graphic 0))
|
|
86
|
|
87 ;; PinYin-ZhuYin
|
|
88 (make-charset 'sisheng "PinYin-ZhuYin"
|
|
89 '(registry "sisheng_cwnn\\|OMRON_UDC_ZH"
|
|
90 dimension 1
|
|
91 chars 94
|
|
92 final ?0
|
|
93 graphic 0
|
|
94 ))
|
|
95
|
|
96 ;; If you prefer QUAIL to EGG, please modify below as you wish.
|
|
97 ;;(when (and (featurep 'egg) (featurep 'wnn))
|
|
98 ;; (setq wnn-server-type 'cserver)
|
|
99 ;; (load "pinyin")
|
|
100 ;; (setq its:*standard-modes*
|
|
101 ;; (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
|
|
102
|
|
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
104 ;;; Chinese (general)
|
|
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
106
|
|
107 ;; (make-coding-system
|
|
108 ;; 'iso-2022-cn 2 ?C
|
|
109 ;; "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN)"
|
|
110 ;; '(ascii
|
|
111 ;; (nil chinese-gb2312 chinese-cns11643-1)
|
|
112 ;; (nil chinese-cns11643-2)
|
|
113 ;; nil
|
|
114 ;; nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
|
|
115 ;; init-bol)
|
|
116 ;; '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2)
|
|
117 ;; (mime-charset . iso-2022-cn)))
|
|
118
|
|
119 ;; (define-coding-system-alias 'chinese-iso-7bit 'iso-2022-cn)
|
|
120
|
|
121 ;; (make-coding-system
|
|
122 ;; 'iso-2022-cn-ext 2 ?C
|
|
123 ;; "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN-EXT)"
|
|
124 ;; '(ascii
|
|
125 ;; (nil chinese-gb2312 chinese-cns11643-1)
|
|
126 ;; (nil chinese-cns11643-2)
|
|
127 ;; (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
|
|
128 ;; chinese-cns11643-6 chinese-cns11643-7)
|
|
129 ;; nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
|
|
130 ;; init-bol)
|
|
131 ;; '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2
|
|
132 ;; chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
|
|
133 ;; chinese-cns11643-6 chinese-cns11643-7)
|
|
134 ;; (mime-charset . iso-2022-cn-ext)))
|
|
135
|
|
136
|
|
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
138 ;;; Chinese GB2312 (simplified)
|
|
139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
140
|
|
141 ;; (make-coding-system
|
|
142 ;; 'chinese-iso-8bit 2 ?c
|
|
143 ;; "ISO 2022 based EUC encoding for Chinese GB2312 (MIME:CN-GB-2312)"
|
|
144 ;; '(ascii chinese-gb2312 nil nil
|
|
145 ;; nil ascii-eol ascii-cntl nil nil nil nil)
|
|
146 ;; '((safe-charsets ascii chinese-gb2312)
|
|
147 ;; (mime-charset . cn-gb-2312)))
|
|
148
|
|
149 (make-coding-system
|
|
150 'cn-gb-2312 'iso2022
|
771
|
151 "Chinese EUC"
|
428
|
152 '(charset-g0 ascii
|
|
153 charset-g1 chinese-gb2312
|
|
154 charset-g2 sisheng
|
|
155 charset-g3 t
|
|
156 mnemonic "Zh-GB/EUC"
|
771
|
157 documentation
|
|
158 "Chinese EUC (Extended Unix Code), the standard Chinese encoding on Unix.
|
|
159 This follows the same overall EUC principles as Japanese EUC (see the
|
|
160 description under Japanese EUC), but specifies different character sets:
|
|
161
|
|
162 G0: ASCII
|
|
163 G1: Chinese-GB2312
|
|
164 G2: Sisheng (PinYin - ZhuYin)"
|
428
|
165 ))
|
|
166
|
|
167 ;; (define-coding-system-alias 'cn-gb-2312 'chinese-iso-8bit)
|
|
168 ;; (define-coding-system-alias 'euc-china 'chinese-iso-8bit)
|
|
169 ;; (define-coding-system-alias 'euc-cn 'chinese-iso-8bit)
|
|
170
|
|
171 (define-coding-system-alias 'gb2312 'cn-gb-2312)
|
|
172 (define-coding-system-alias 'chinese-euc 'cn-gb-2312)
|
|
173
|
|
174 ;; (make-coding-system
|
|
175 ;; 'chinese-hz 0 ?z
|
|
176 ;; "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
|
|
177 ;; nil
|
|
178 ;; '((safe-charsets ascii chinese-gb2312)
|
|
179 ;; (mime-charset . hz-gb-2312)
|
|
180 ;; (post-read-conversion . post-read-decode-hz)
|
|
181 ;; (pre-write-conversion . pre-write-encode-hz)))
|
|
182 ;; (put 'chinese-hz 'post-read-conversion 'post-read-decode-hz)
|
|
183 ;; (put 'chinese-hz 'pre-write-conversion 'pre-write-encode-hz)
|
|
184
|
|
185 (make-coding-system
|
|
186 'hz-gb-2312 'no-conversion
|
771
|
187 "Hz/ZW (Chinese)"
|
428
|
188 '(mnemonic "Zh-GB/Hz"
|
|
189 eol-type lf
|
|
190 post-read-conversion post-read-decode-hz
|
771
|
191 pre-write-conversion pre-write-encode-hz
|
|
192 documentation "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
|
|
193 ))
|
428
|
194
|
|
195 ;; (define-coding-system-alias 'hz-gb-2312 'chinese-hz)
|
|
196 ;; (define-coding-system-alias 'hz 'chinese-hz)
|
|
197
|
|
198 (define-coding-system-alias 'hz 'hz-gb-2312)
|
|
199
|
|
200 (defun post-read-decode-hz (len)
|
|
201 (let ((pos (point))
|
|
202 (buffer-modified-p (buffer-modified-p))
|
|
203 last-coding-system-used)
|
|
204 (prog1
|
|
205 (decode-hz-region pos (+ pos len))
|
|
206 (set-buffer-modified-p buffer-modified-p))))
|
|
207
|
|
208 (defun pre-write-encode-hz (from to)
|
|
209 (let ((buf (current-buffer)))
|
|
210 (set-buffer (generate-new-buffer " *temp*"))
|
|
211 (if (stringp from)
|
|
212 (insert from)
|
|
213 (insert-buffer-substring buf from to))
|
|
214 (let (last-coding-system-used)
|
|
215 (encode-hz-region 1 (point-max)))
|
|
216 nil))
|
771
|
217
|
428
|
218 (set-language-info-alist
|
|
219 "Chinese-GB" '((setup-function . setup-chinese-gb-environment-internal)
|
|
220 (charset chinese-gb2312 sisheng)
|
|
221 (coding-system cn-gb-2312 iso-2022-7bit hz-gb-2312)
|
|
222 (coding-priority cn-gb-2312 big5 iso-2022-7bit)
|
771
|
223 (cygwin-locale "zh")
|
|
224 (locale "zh_CN.eucCN" "zh_CN.EUC" "zh_CN"
|
|
225 "chinese-s" "zh"
|
|
226 #'(lambda (arg)
|
|
227 (and arg (let ((case-fold-search t))
|
|
228 (string-match "^zh_.*.GB.*" arg)))))
|
|
229 (mswindows-locale ("CHINESE" . "CHINESE_SIMPLIFIED"))
|
|
230 (native-coding-system cn-gb-2312)
|
428
|
231 (input-method . "chinese-py-punct")
|
|
232 (features china-util)
|
|
233 (sample-text . "Chinese ($AVPND(B,$AFUM(;0(B,$A::So(B) $ADc:C(B")
|
771
|
234 (documentation .
|
|
235 "Supports Simplified Chinese, used in mainland China.
|
|
236 Uses the GB2312 character set."))
|
428
|
237 '("Chinese"))
|
|
238
|
|
239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
240 ;; Chinese BIG5 (traditional)
|
|
241 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
242
|
|
243 ;; (make-coding-system
|
|
244 ;; 'chinese-big5 3 ?B "BIG5 8-bit encoding for Chinese (MIME:CN-BIG5)"
|
|
245 ;; nil
|
|
246 ;; '((safe-charsets ascii chinese-big5-1 chinese-big5-2)
|
|
247 ;; (mime-charset . cn-big5)
|
|
248 ;; (charset-origin-alist (chinese-big5-1 "BIG5" encode-big5-char)
|
|
249 ;; (chinese-big5-2 "BIG5" encode-big5-char))))
|
|
250
|
|
251 (make-coding-system
|
|
252 'big5 'big5
|
771
|
253 "Big5"
|
|
254 '(mnemonic "Zh/Big5"
|
|
255 documentation
|
|
256 "A non-modal encoding formed by five large Taiwanese companies
|
|
257 \(hence \"Big5\") to produce a character set and encoding for
|
|
258 traditional Chinese writing. Big5 encodes some 13,000+ characters.
|
|
259 ASCII is encoded as normal, and Chinese characters as two bytes, but
|
|
260 Chinese characters do not exclusively use the high half. The first
|
|
261 byte is in the high half standard position A1-FE, but the second byte
|
|
262 is in either low 40-7E or high A1-FE. Thus Big5 suffers from the
|
|
263 classic \"it might look like a slash, but it's really the second byte
|
|
264 of a Chinese character\"."))
|
428
|
265
|
|
266 ;; (define-coding-system-alias 'big5 'chinese-big5)
|
|
267 ;; (define-coding-system-alias 'cn-big5 'chinese-big5)
|
|
268
|
|
269 (define-coding-system-alias 'cn-big5 'big5)
|
|
270
|
|
271 ;; Big5 font requires special encoding.
|
|
272 (define-ccl-program ccl-encode-big5-font
|
|
273 `(0
|
|
274 ;; In: R0:chinese-big5-1 or chinese-big5-2
|
|
275 ;; R1:position code 1
|
|
276 ;; R2:position code 2
|
|
277 ;; Out: R1:font code point 1
|
|
278 ;; R2:font code point 2
|
|
279 ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
|
|
280 (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
|
|
281 (r1 = ((r2 / 157) + ?\xA1))
|
|
282 (r2 %= 157)
|
|
283 (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
|
|
284 "CCL program to encode a Big5 code to code point of Big5 font.")
|
|
285
|
|
286 ;; (setq font-ccl-encoder-alist
|
|
287 ;; (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
|
|
288
|
444
|
289 (set-charset-ccl-program 'chinese-big5-1 'ccl-encode-big5-font)
|
|
290 (set-charset-ccl-program 'chinese-big5-2 'ccl-encode-big5-font)
|
428
|
291
|
|
292 (set-language-info-alist
|
|
293 "Chinese-BIG5" '((charset chinese-big5-1 chinese-big5-2)
|
|
294 (coding-system big5 iso-2022-7bit)
|
|
295 (coding-priority big5 cn-gb-2312 iso-2022-7bit)
|
771
|
296 (cygwin-locale "zh_TW")
|
|
297 (locale "zh_TW.Big5" "zh_TW.big5" "zh_CN.big5" "zh_TW"
|
|
298 "chinese-t"
|
|
299 #'(lambda (arg)
|
|
300 (and arg (let ((case-fold-search t))
|
|
301 (string-match "^zh_.*.BIG5.*" arg)))))
|
|
302 (mswindows-locale ("CHINESE" . "CHINESE_TRADITIONAL"))
|
|
303 (native-coding-system big5)
|
428
|
304 (input-method . "chinese-py-punct-b5")
|
|
305 (features china-util)
|
|
306 (sample-text . "Cantonese ($(0GnM$(B,$(0N]0*Hd(B) $(0*/=((B, $(0+$)p(B")
|
771
|
307 (documentation .
|
|
308 "Supports Traditional Chinese, used in Taiwan, Hong Kong, and Singapore.
|
|
309 Uses the Chinese Big5 character set."
|
|
310 ))
|
428
|
311 '("Chinese"))
|
|
312
|
|
313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
314 ;; Chinese CNS11643 (traditional)
|
|
315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
316
|
|
317 ;; (set-language-info-alist
|
|
318 ;; "Chinese-CNS" '((charset chinese-cns11643-1 chinese-cns11643-2
|
|
319 ;; chinese-cns11643-3 chinese-cns11643-4
|
|
320 ;; chinese-cns11643-5 chinese-cns11643-6
|
|
321 ;; chinese-cns11643-7)
|
|
322 ;; (coding-system iso-2022-cn)
|
|
323 ;; (coding-priority iso-2022-cn chinese-big5 chinese-iso-8bit)
|
|
324 ;; (features china-util)
|
|
325 ;; (input-method . "chinese-cns-quick")
|
|
326 ;; (documentation . "Support for Chinese CNS character sets."))
|
|
327 ;; '("Chinese"))
|
|
328
|
|
329 ;;; chinese.el ends here
|