159
|
1 ;;; chinese.el --- Support for Chinese
|
|
2
|
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
197
|
4 ;; Licensed to the Free Software Foundation.
|
159
|
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
|
|
6
|
|
7 ;; Keywords: multilingual, Chinese
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; For Chinese, three character sets GB2312, BIG5, and CNS11643 are
|
|
29 ;; supported.
|
|
30
|
|
31 ;;; Code:
|
|
32
|
|
33 ;; Syntax of Chinese characters.
|
|
34 (modify-syntax-entry 'chinese-gb2312 "w")
|
|
35 (loop for row in '(33 34 41)
|
|
36 do (modify-syntax-entry `[chinese-gb2312 ,row] "."))
|
|
37 ;;(loop for row from 35 to 40
|
|
38 ;; do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
|
|
39 ;;(loop for row from 42 to 126
|
|
40 ;; do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
|
|
41
|
|
42 (modify-syntax-entry 'chinese-cns11643-1 "w")
|
|
43 (modify-syntax-entry 'chinese-cns11643-2 "w")
|
|
44 (modify-syntax-entry 'chinese-big5-1 "w")
|
|
45 (modify-syntax-entry 'chinese-big5-2 "w")
|
|
46
|
|
47 ;; CNS11643 Plane3 thru Plane7
|
|
48 ;; These represent more and more obscure Chinese characters.
|
|
49 ;; By the time you get to Plane 7, we're talking about characters
|
|
50 ;; that appear once in some ancient manuscript and whose meaning
|
|
51 ;; is unknown.
|
|
52
|
|
53 (flet
|
|
54 ((make-chinese-cns11643-charset
|
|
55 (name plane final)
|
|
56 (make-charset
|
167
|
57 name (concat "CNS 11643 Plane " plane " (Chinese traditional)")
|
159
|
58 `(registry
|
|
59 ,(concat "CNS11643[.-]\\(.*[.-]\\)?" plane "$")
|
|
60 dimension 2
|
|
61 chars 94
|
|
62 final ,final
|
|
63 graphic 0))
|
|
64 (modify-syntax-entry name "w")
|
|
65 (modify-category-entry name ?t)
|
|
66 ))
|
|
67 (make-chinese-cns11643-charset 'chinese-cns11643-3 "3" ?I)
|
|
68 (make-chinese-cns11643-charset 'chinese-cns11643-4 "4" ?J)
|
|
69 (make-chinese-cns11643-charset 'chinese-cns11643-5 "5" ?K)
|
|
70 (make-chinese-cns11643-charset 'chinese-cns11643-6 "6" ?L)
|
|
71 (make-chinese-cns11643-charset 'chinese-cns11643-7 "7" ?M)
|
|
72 )
|
|
73
|
167
|
74 ;; ISO-IR-165 (CCITT Extended GB)
|
|
75 ;; It is based on CCITT Recommendation T.101, includes GB 2312-80 +
|
|
76 ;; GB 8565-88 table A4 + 293 characters.
|
|
77 (make-charset
|
|
78 'chinese-isoir165
|
|
79 "ISO-IR-165 (CCITT Extended GB; Chinese simplified)"
|
|
80 `(registry "isoir165"
|
|
81 dimension 2
|
|
82 chars 94
|
|
83 final ?E
|
|
84 graphic 0))
|
|
85
|
159
|
86 ;; PinYin-ZhuYin
|
|
87 (make-charset 'sisheng "PinYin-ZhuYin"
|
|
88 '(registry "sisheng_cwnn\\|OMRON_UDC_ZH"
|
|
89 dimension 1
|
|
90 chars 94
|
|
91 final ?0
|
|
92 graphic 0
|
|
93 ))
|
|
94
|
|
95 ;; If you prefer QUAIL to EGG, please modify below as you wish.
|
|
96 ;;(when (and (featurep 'egg) (featurep 'wnn))
|
|
97 ;; (setq wnn-server-type 'cserver)
|
|
98 ;; (load "its/pinyin")
|
|
99 ;; (setq its:*standard-modes*
|
|
100 ;; (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
|
|
101
|
|
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
103 ;;; Chinese (general)
|
|
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
105
|
|
106 ;; (make-coding-system
|
197
|
107 ;; 'chinese-iso-7bit 2 ?C
|
|
108 ;; "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN)"
|
159
|
109 ;; '(ascii
|
|
110 ;; (nil chinese-gb2312 chinese-cns11643-1)
|
|
111 ;; (nil chinese-cns11643-2)
|
|
112 ;; (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
|
|
113 ;; chinese-cns11643-6 chinese-cns11643-7)
|
|
114 ;; nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
|
|
115 ;; init-bol))
|
|
116
|
197
|
117 ;; (define-coding-system-alias 'iso-2022-cn 'chinese-iso-7bit)
|
|
118 ;; (define-coding-system-alias 'iso-2022-cn-ext 'chinese-iso-7bit)
|
|
119
|
|
120 ;; (define-prefix-command 'describe-chinese-environment-map)
|
|
121 ;; (define-key-after describe-language-environment-map [Chinese]
|
|
122 ;; '("Chinese" . describe-chinese-environment-map)
|
|
123 ;; t)
|
159
|
124
|
197
|
125 ;; (define-prefix-command 'setup-chinese-environment-map)
|
|
126 ;; (define-key-after setup-language-environment-map [Chinese]
|
|
127 ;; '("Chinese" . setup-chinese-environment-map)
|
|
128 ;; t)
|
159
|
129
|
197
|
130 ;; (defun describe-chinese-support ()
|
|
131 ;; "Describe how Emacs supports Chinese."
|
|
132 ;; (interactive)
|
|
133 ;; (with-output-to-temp-buffer "*Help*"
|
|
134 ;; (princ (get-language-info "Chinese" 'documentation))
|
|
135 ;; (princ "\n")))
|
|
136
|
159
|
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
138 ;;; Chinese GB2312 (simplified)
|
|
139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
140
|
|
141 ;; (make-coding-system
|
197
|
142 ;; 'chinese-iso-8bit 2 ?c
|
|
143 ;; "ISO 2022 based EUC encoding for Chinese GB2312 (MIME:CN-GB-2312)"
|
159
|
144 ;; '((ascii t) chinese-gb2312 chinese-sisheng nil
|
|
145 ;; nil ascii-eol ascii-cntl nil nil single-shift nil))
|
|
146
|
|
147 (make-coding-system
|
|
148 'cn-gb-2312 'iso2022
|
|
149 "Coding-system of Chinese EUC (Extended Unix Code)."
|
|
150 '(charset-g0 ascii
|
|
151 charset-g1 chinese-gb2312
|
|
152 charset-g2 sisheng
|
|
153 charset-g3 t
|
|
154 mnemonic "Zh-GB/EUC"
|
|
155 ))
|
|
156
|
197
|
157 ;; (define-coding-system-alias 'cn-gb-2312 'chinese-iso-8bit)
|
|
158 ;; (define-coding-system-alias 'euc-china 'chinese-iso-8bit)
|
159
|
159
|
|
160 (copy-coding-system 'cn-gb-2312 'gb2312)
|
|
161 (copy-coding-system 'cn-gb-2312 'chinese-euc)
|
|
162
|
|
163 ;; (make-coding-system
|
197
|
164 ;; 'chinese-hz 0 ?z
|
|
165 ;; "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
|
159
|
166 ;; nil)
|
197
|
167 ;; (put 'chinese-hz 'post-read-conversion 'post-read-decode-hz)
|
|
168 ;; (put 'chinese-hz 'pre-write-conversion 'pre-write-encode-hz)
|
159
|
169
|
|
170 (make-coding-system
|
|
171 'hz-gb-2312 'no-conversion
|
|
172 "Coding-system of Hz/ZW used for Chinese."
|
|
173 '(mnemonic "Zh-GB/Hz"
|
|
174 eol-type lf
|
|
175 post-read-conversion post-read-decode-hz
|
|
176 pre-write-conversion pre-write-encode-hz))
|
|
177
|
197
|
178 ;; (define-coding-system-alias 'hz-gb-2312 'chinese-hz)
|
|
179 ;; (define-coding-system-alias 'hz 'chinese-hz)
|
159
|
180
|
|
181 (copy-coding-system 'hz-gb-2312 'hz)
|
|
182 (copy-coding-system 'hz-gb-2312 'chinese-hz)
|
|
183
|
|
184 (defun post-read-decode-hz (len)
|
|
185 (let ((pos (point)))
|
|
186 (decode-hz-region pos (+ pos len))))
|
|
187
|
|
188 (defun pre-write-encode-hz (from to)
|
|
189 (let ((buf (current-buffer))
|
|
190 (work (get-buffer-create " *pre-write-encoding-work*")))
|
|
191 (set-buffer work)
|
|
192 (erase-buffer)
|
|
193 (if (stringp from)
|
|
194 (insert from)
|
|
195 (insert-buffer-substring buf from to))
|
|
196 (encode-hz-region 1 (point-max))
|
|
197 nil))
|
|
198
|
197
|
199 ;; (defun setup-chinese-gb-environment ()
|
|
200 ;; "Setup multilingual environment (MULE) for Chinese GB2312 users."
|
|
201 ;; (interactive)
|
|
202 ;; (setq primary-language "Chinese-GB")
|
|
203 ;;
|
|
204 ;; (setq coding-category-iso-8-2 'cn-gb-2312)
|
|
205 ;; (setq coding-category-iso-else 'iso-2022-cn)
|
|
206 ;; (setq coding-category-big5 'cn-big5)
|
|
207 ;;
|
|
208 ;; (set-coding-priority
|
|
209 ;; '(coding-category-iso-7
|
|
210 ;; coding-category-iso-else
|
|
211 ;; coding-category-iso-8-2
|
|
212 ;; coding-category-big5
|
|
213 ;; coding-category-iso-8-1
|
|
214 ;; coding-category-internal
|
|
215 ;; ))
|
|
216 ;;
|
|
217 ;; (setq-default buffer-file-coding-system 'cn-gb-2312)
|
|
218 ;; (set-terminal-coding-system 'cn-gb-2312)
|
|
219 ;; (set-keyboard-coding-system 'cn-gb-2312)
|
|
220 ;;
|
|
221 ;; (setq default-input-method '("Chinese-GB" . "quail-py"))
|
|
222 ;; )
|
159
|
223
|
197
|
224 ;; (defun describe-chinese-gb-support ()
|
|
225 ;; "Describe how Emacs supports Chinese for GB2312 users."
|
|
226 ;; (interactive)
|
|
227 ;; (describe-language-support-internal "Chinese-GB"))
|
|
228
|
159
|
229 (set-language-info-alist
|
197
|
230 "Chinese-GB" '((setup-function . (setup-chinese-gb-environment
|
|
231 . setup-chinese-environment-map))
|
159
|
232 (charset . (chinese-gb2312 chinese-sisheng))
|
197
|
233 (coding-system
|
|
234 . (cn-gb-2312 iso-2022-7bit hz-gb-2312))
|
159
|
235 (sample-text . "Chinese ($AVPND(B,$AFUM(;0(B,$A::So(B) $ADc:C(B")
|
197
|
236 (documentation . ("Support for Chinese GB2312 character set."
|
|
237 . describe-chinese-environment-map))
|
|
238 ))
|
159
|
239
|
|
240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
241 ;; Chinese BIG5 (traditional)
|
|
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
243
|
|
244 ;; (make-coding-system
|
197
|
245 ;; 'chinese-big5 3 ?B "BIG5 8-bit encoding for Chinese (MIME:CN-BIG5)")
|
159
|
246
|
|
247 (make-coding-system
|
|
248 'big5 'big5
|
|
249 "Coding-system of BIG5."
|
|
250 '(mnemonic "Zh/Big5"))
|
|
251
|
197
|
252 ;; (define-coding-system-alias 'big5 'chinese-big5)
|
|
253 ;; (define-coding-system-alias 'cn-big5 'chinese-big5)
|
|
254
|
159
|
255 (copy-coding-system 'big5 'cn-big5)
|
|
256 (copy-coding-system 'big5 'chinese-big5)
|
|
257
|
|
258 ;; Big5 font requires special encoding.
|
|
259 ;; (define-ccl-program ccl-encode-big5-font
|
|
260 ;; `(0
|
|
261 ;; ;; In: R0:chinese-big5-1 or chinese-big5-2
|
|
262 ;; ;; R1:position code 1
|
|
263 ;; ;; R2:position code 2
|
|
264 ;; ;; Out: R1:font code point 1
|
|
265 ;; ;; R2:font code point 2
|
|
266 ;; ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
|
|
267 ;; (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
|
|
268 ;; (r1 = ((r2 / 157) + ?\xA1))
|
|
269 ;; (r2 %= 157)
|
|
270 ;; (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
|
|
271 ;; "CCL program to encode a Big5 code to code point of Big5 font.")
|
|
272
|
|
273 ;; (setq font-ccl-encoder-alist
|
|
274 ;; (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
|
|
275
|
|
276 (define-ccl-program ccl-encode-big5-1-font
|
|
277 '(((r1 = ((((r0 - #x21) * 94) + r1) - #x21))
|
|
278 (r0 = ((r1 / 157) + #xA1))
|
|
279 (r1 %= 157)
|
|
280 (if (r1 < #x3F) (r1 += #x40) (r1 += #x62))))
|
|
281 "CCL program to encode a Big5 code (level1) to code point of Big5 font.")
|
|
282
|
|
283 ;; 6280 is the number of characters that got shoved into `chinese-big5-1'.
|
|
284 (define-ccl-program ccl-encode-big5-2-font
|
|
285 '(((r1 = (((((r0 - #x21) * 94) + r1) - #x21) + 6280))
|
|
286 (r0 = ((r1 / 157) + #xA1))
|
|
287 (r1 %= 157)
|
|
288 (if (r1 < #x3F) (r1 += #x40) (r1 += #x62))))
|
|
289 "CCL program to encode a Big5 code (level2) to code point of Big5 font.")
|
|
290
|
|
291 (set-charset-ccl-program 'chinese-big5-1 ccl-encode-big5-1-font)
|
|
292 (set-charset-ccl-program 'chinese-big5-2 ccl-encode-big5-2-font)
|
|
293
|
197
|
294 ;; (defun setup-chinese-big5-environment ()
|
|
295 ;; "Setup multilingual environment (MULE) for Chinese Big5 users."
|
|
296 ;; (interactive)
|
|
297 ;; (setq primary-language "Chinese-BIG5")
|
|
298 ;;
|
|
299 ;; (setq coding-category-big5 'cn-big5)
|
|
300 ;; (setq coding-category-iso-else 'iso-2022-cn)
|
|
301 ;; (setq coding-category-iso-8-2 'cn-gb-2312)
|
|
302 ;;
|
|
303 ;; (set-coding-priority
|
|
304 ;; '(coding-category-iso-7
|
|
305 ;; coding-category-iso-else
|
|
306 ;; coding-category-big5
|
|
307 ;; coding-category-iso-8-2))
|
|
308 ;;
|
|
309 ;; (setq-default buffer-file-coding-system 'cn-big5)
|
|
310 ;; (set-terminal-coding-system 'cn-big5)
|
|
311 ;; (set-keyboard-coding-system 'cn-big5)
|
|
312 ;;
|
|
313 ;; (setq default-input-method '("Chinese-BIG5" . "quail-py-b5"))
|
|
314 ;; )
|
159
|
315
|
197
|
316 ;; (defun describe-chinese-big5-support ()
|
|
317 ;; "Describe how Emacs supports Chinese for Big5 users."
|
|
318 ;; (interactive)
|
|
319 ;; (describe-language-support-internal "Chinese-BIG5"))
|
159
|
320
|
|
321 (set-language-info-alist
|
197
|
322 "Chinese-BIG5" '((setup-function . (setup-chinese-big5-environment
|
|
323 . setup-chinese-environment-map))
|
159
|
324 (charset . (chinese-big5-1 chinese-big5-2))
|
197
|
325 (coding-system . (big5 iso-2022-7bit))
|
159
|
326 (sample-text . "Cantonese ($(0GnM$(B,$(0N]0*Hd(B) $(0*/=((B, $(0+$)p(B")
|
197
|
327 (documentation . ("Support for Chinese Big5 character set."
|
|
328 . describe-chinese-environment-map))
|
|
329 ))
|
159
|
330
|
|
331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
332 ;; Chinese CNS11643 (traditional)
|
|
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
334
|
197
|
335 ;; (defun setup-chinese-cns-environment ()
|
|
336 ;; "Setup multilingual environment (MULE) for Chinese CNS11643 family users."
|
|
337 ;; (interactive)
|
|
338 ;; (setq primary-language "Chinese-CNS")
|
|
339 ;;
|
|
340 ;; (setq coding-category-iso-else 'iso-2022-cn)
|
|
341 ;; (setq coding-category-big5 'cn-big5)
|
|
342 ;; (setq coding-category-iso-8-2 'cn-gb-2312)
|
|
343 ;;
|
|
344 ;; (set-coding-priority
|
|
345 ;; '(coding-category-iso-7
|
|
346 ;; coding-category-iso-else
|
|
347 ;; coding-category-iso-8-2
|
|
348 ;; coding-category-big5))
|
|
349 ;;
|
|
350 ;; (setq-default buffer-file-coding-system 'iso-2022-cn)
|
|
351 ;; (set-terminal-coding-system 'iso-2022-cn)
|
|
352 ;; (set-keyboard-coding-system 'iso-2022-cn)
|
|
353 ;;
|
|
354 ;; (setq default-input-method '("Chinese-CNS" . "quail-py-cns"))
|
|
355 ;; )
|
159
|
356
|
197
|
357 ;; (defun describe-chinese-cns-support ()
|
|
358 ;; "Describe how Emacs supports Chinese for CNS11643 family users."
|
|
359 ;; (interactive)
|
|
360 ;; (describe-language-support-internal "Chinese-CNS"))
|
159
|
361
|
|
362 (set-language-info-alist
|
197
|
363 "Chinese-CNS" '((setup-function . (setup-chinese-cns-environment
|
|
364 . setup-chinese-environment-map))
|
159
|
365 (charset . (chinese-cns11643-1 chinese-cns11643-2
|
|
366 chinese-cns11643-3 chinese-cns11643-4
|
|
367 chinese-cns11643-5 chinese-cns11643-6
|
|
368 chinese-cns11643-7))
|
197
|
369 (coding-system . (iso-2022-7bit))
|
|
370 (documentation . ("Support for Chinese CNS character sets."
|
|
371 . describe-chinese-environment-map))
|
|
372 ))
|
159
|
373
|
|
374 ;;; for XEmacs (will be obsoleted)
|
|
375
|
|
376 (define-language-environment 'chinese
|
|
377 "Chinese (includes GB, Big5, and CNS)"
|
|
378 (lambda ()
|
|
379 (require 'chinese)
|
|
380 (set-coding-category-system 'iso-8-2 'cn-gb-2312)
|
|
381 (set-coding-priority-list '(iso-8-2 big5 iso-8-designate))
|
|
382 (set-pathname-coding-system 'cn-gb-2312)
|
|
383 (set-default-buffer-file-coding-system 'cn-gb-2312) ; GB encoding
|
|
384 (setq terminal-coding-system 'cn-gb-2312)
|
|
385 (setq keyboard-coding-system 'cn-gb-2312)
|
|
386 (add-hook 'comint-exec-hook
|
|
387 (lambda ()
|
|
388 (let ((proc (get-buffer-process (current-buffer))))
|
|
389 (set-process-input-coding-system proc 'cn-gb-2312)
|
|
390 (set-process-output-coding-system proc 'cn-gb-2312))))
|
|
391 (set-buffer-file-coding-system-for-read 'automatic-conversion)
|
|
392 (set-default-buffer-file-coding-system 'cn-gb-2312)
|
|
393 (setq keyboard-coding-system 'cn-gb-2312)
|
|
394 (setq terminal-coding-system 'cn-gb-2312)
|
|
395 (when (eq 'x (device-type (selected-device)))
|
|
396 (x-use-halfwidth-roman-font 'chinese-gb2312 "gb1988"))))
|
|
397 ;; (when (featurep 'egg)
|
|
398 ;; (setq-default its:*current-map* (its:get-mode-map "PinYin")))
|
|
399 ;; (setq-default quail-current-package (assoc "py" quail-package-alist))))
|
|
400 ;; ))
|
|
401
|
|
402 (set-coding-category-system 'big5 'big5)
|
|
403
|
|
404 ;;; chinese.el ends here
|