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