comparison lisp/language/chinese.el @ 159:3bb7ccffb0c0 r20-3b6

Import from CVS: tag r20-3b6
author cvs
date Mon, 13 Aug 2007 09:41:43 +0200
parents
children 85ec50267440
comparison
equal deleted inserted replaced
158:558dfa75ffb3 159:3bb7ccffb0c0
1 ;;; chinese.el --- Support for Chinese
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
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
57 name (concat "Chinese CNS Plane " plane)
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
74 ;; PinYin-ZhuYin
75 (make-charset 'sisheng "PinYin-ZhuYin"
76 '(registry "sisheng_cwnn\\|OMRON_UDC_ZH"
77 dimension 1
78 chars 94
79 final ?0
80 graphic 0
81 ))
82
83 ;; If you prefer QUAIL to EGG, please modify below as you wish.
84 ;;(when (and (featurep 'egg) (featurep 'wnn))
85 ;; (setq wnn-server-type 'cserver)
86 ;; (load "its/pinyin")
87 ;; (setq its:*standard-modes*
88 ;; (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
89
90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
91 ;;; Chinese (general)
92 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
93
94 ;; (make-coding-system
95 ;; 'iso-2022-cn 2 ?C
96 ;; "Coding system ISO-2022-CN for Chinese (GB and CNS character sets)."
97 ;; '(ascii
98 ;; (nil chinese-gb2312 chinese-cns11643-1)
99 ;; (nil chinese-cns11643-2)
100 ;; (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
101 ;; chinese-cns11643-6 chinese-cns11643-7)
102 ;; nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
103 ;; init-bol))
104
105 ;; (define-coding-system-alias 'iso-2022-cn 'iso-2022-cn-ext)
106
107 (defun describe-chinese-support ()
108 "Describe how Emacs supports Chinese."
109 (interactive)
110 (with-output-to-temp-buffer "*Help*"
111 (princ (get-language-info "Chinese" 'documentation))
112 (princ "\n")))
113
114 (set-language-info-alist
115 "Chinese" '((describe-function . describe-chinese-support)
116 (documentation . "\
117 Emacs provides the following three kinds of Chinese support:
118 Chinese-GB: for users of the charset GB2312
119 Chinese-BIG5: for users of the charset Big5
120 Chinese-CNS: for users of the charset CNS11643 family
121 Please specify one of them to get more information.")
122 ))
123
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 ;;; Chinese GB2312 (simplified)
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127
128 ;; (make-coding-system
129 ;; 'cn-gb-2312 2 ?C
130 ;; "Coding-system of Chinese EUC (so called GB Encoding)."
131 ;; '((ascii t) chinese-gb2312 chinese-sisheng nil
132 ;; nil ascii-eol ascii-cntl nil nil single-shift nil))
133
134 (make-coding-system
135 'cn-gb-2312 'iso2022
136 "Coding-system of Chinese EUC (Extended Unix Code)."
137 '(charset-g0 ascii
138 charset-g1 chinese-gb2312
139 charset-g2 sisheng
140 charset-g3 t
141 mnemonic "Zh-GB/EUC"
142 ))
143
144 ;;(define-coding-system-alias 'cn-gb-2312 'euc-china)
145
146 (copy-coding-system 'cn-gb-2312 'gb2312)
147 (copy-coding-system 'cn-gb-2312 'chinese-euc)
148
149 ;; (make-coding-system
150 ;; 'hz-gb-2312 0 ?z
151 ;; "Codins-system of Hz/ZW used for Chinese (GB)."
152 ;; nil)
153 ;; (put 'hz-gb-2312 'post-read-conversion 'post-read-decode-hz)
154 ;; (put 'hz-gb-2312 'pre-write-conversion 'pre-write-encode-hz)
155
156 (make-coding-system
157 'hz-gb-2312 'no-conversion
158 "Coding-system of Hz/ZW used for Chinese."
159 '(mnemonic "Zh-GB/Hz"
160 eol-type lf
161 post-read-conversion post-read-decode-hz
162 pre-write-conversion pre-write-encode-hz))
163
164 ;; (define-coding-system-alias 'hz-gb-2312 'hz)
165
166 (copy-coding-system 'hz-gb-2312 'hz)
167 (copy-coding-system 'hz-gb-2312 'chinese-hz)
168
169 (defun post-read-decode-hz (len)
170 (let ((pos (point)))
171 (decode-hz-region pos (+ pos len))))
172
173 (defun pre-write-encode-hz (from to)
174 (let ((buf (current-buffer))
175 (work (get-buffer-create " *pre-write-encoding-work*")))
176 (set-buffer work)
177 (erase-buffer)
178 (if (stringp from)
179 (insert from)
180 (insert-buffer-substring buf from to))
181 (encode-hz-region 1 (point-max))
182 nil))
183
184 (register-input-method
185 "Chinese-GB" '("quail-ccdospy" quail-use-package "quail/ccdospy"))
186 (register-input-method
187 "Chinese-GB" '("quail-ctlau" quail-use-package "quail/ctlau"))
188 (register-input-method
189 "Chinese-GB" '("quail-punct" quail-use-package "quail/punct"))
190 (register-input-method
191 "Chinese-GB" '("quail-qj" quail-use-package "quail/qj"))
192 (register-input-method
193 "Chinese-GB" '("quail-sw" quail-use-package "quail/sw"))
194 (register-input-method
195 "Chinese-GB" '("quail-ziranma" quail-use-package "quail/ziranma"))
196 (register-input-method
197 "Chinese-GB" '("quail-tonepy" quail-use-package "quail/tonepy"))
198 (register-input-method
199 "Chinese-GB" '("quail-py" quail-use-package "quail/py"))
200
201 (defun setup-chinese-gb-environment ()
202 "Setup multilingual environment (MULE) for Chinese GB2312 users."
203 (interactive)
204 (setq primary-language "Chinese-GB")
205
206 (setq coding-category-iso-8-2 'cn-gb-2312)
207 (setq coding-category-iso-else 'iso-2022-cn)
208 (setq coding-category-big5 'cn-big5)
209
210 (set-coding-priority
211 '(coding-category-iso-7
212 coding-category-iso-else
213 coding-category-iso-8-2
214 coding-category-big5
215 coding-category-iso-8-1
216 coding-category-internal
217 ))
218
219 (setq-default buffer-file-coding-system 'cn-gb-2312)
220 (set-terminal-coding-system 'cn-gb-2312)
221 (set-keyboard-coding-system 'cn-gb-2312)
222
223 (setq default-input-method '("Chinese-GB" . "quail-py"))
224 )
225
226 (defun describe-chinese-gb-support ()
227 "Describe how Emacs supports Chinese for GB2312 users."
228 (interactive)
229 (describe-language-support-internal "Chinese-GB"))
230
231 (set-language-info-alist
232 "Chinese-GB" '((setup-function . setup-chinese-gb-environment)
233 (describe-function . describe-chinese-gb-support)
234 (charset . (chinese-gb2312 chinese-sisheng))
235 (coding-system . (cn-gb-2312 hz-gb-2312 iso-2022-cn))
236 (sample-text . "Chinese ($AVPND(B,$AFUM(;0(B,$A::So(B) $ADc:C(B")
237 (documentation . nil)))
238
239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
240 ;; Chinese BIG5 (traditional)
241 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
242
243 ;; (make-coding-system
244 ;; 'big5 3 ?B
245 ;; "Coding-system of BIG5.")
246
247 ;;(define-coding-system-alias 'big5 'cn-big5)
248
249 (make-coding-system
250 'big5 'big5
251 "Coding-system of BIG5."
252 '(mnemonic "Zh/Big5"))
253
254 (copy-coding-system 'big5 'cn-big5)
255 (copy-coding-system 'big5 'chinese-big5)
256
257 ;; Big5 font requires special encoding.
258 ;; (define-ccl-program ccl-encode-big5-font
259 ;; `(0
260 ;; ;; In: R0:chinese-big5-1 or chinese-big5-2
261 ;; ;; R1:position code 1
262 ;; ;; R2:position code 2
263 ;; ;; Out: R1:font code point 1
264 ;; ;; R2:font code point 2
265 ;; ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
266 ;; (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
267 ;; (r1 = ((r2 / 157) + ?\xA1))
268 ;; (r2 %= 157)
269 ;; (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
270 ;; "CCL program to encode a Big5 code to code point of Big5 font.")
271
272 ;; (setq font-ccl-encoder-alist
273 ;; (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
274
275 (define-ccl-program ccl-encode-big5-1-font
276 '(((r1 = ((((r0 - #x21) * 94) + r1) - #x21))
277 (r0 = ((r1 / 157) + #xA1))
278 (r1 %= 157)
279 (if (r1 < #x3F) (r1 += #x40) (r1 += #x62))))
280 "CCL program to encode a Big5 code (level1) to code point of Big5 font.")
281
282 ;; 6280 is the number of characters that got shoved into `chinese-big5-1'.
283 (define-ccl-program ccl-encode-big5-2-font
284 '(((r1 = (((((r0 - #x21) * 94) + r1) - #x21) + 6280))
285 (r0 = ((r1 / 157) + #xA1))
286 (r1 %= 157)
287 (if (r1 < #x3F) (r1 += #x40) (r1 += #x62))))
288 "CCL program to encode a Big5 code (level2) to code point of Big5 font.")
289
290 (set-charset-ccl-program 'chinese-big5-1 ccl-encode-big5-1-font)
291 (set-charset-ccl-program 'chinese-big5-2 ccl-encode-big5-2-font)
292
293 (register-input-method
294 "Chinese-BIG5" '("quail-qj-b5" quail-use-package "quail/qj-b5"))
295 (register-input-method
296 "Chinese-BIG5" '("quail-zozy" quail-use-package "quail/zozy"))
297 (register-input-method
298 "Chinese-BIG5" '("quail-tsangchi-b5" quail-use-package "quail/tsangchi-b5"))
299 (register-input-method
300 "Chinese-BIG5" '("quail-py-b5" quail-use-package "quail/py-b5"))
301 (register-input-method
302 "Chinese-BIG5" '("quail-quick-b5" quail-use-package "quail/quick-bt"))
303 (register-input-method
304 "Chinese-BIG5" '("quail-etzy" quail-use-package "quail/etzy"))
305 (register-input-method
306 "Chinese-BIG5" '("quail-ecdict" quail-use-package "quail/ecdict"))
307 (register-input-method
308 "Chinese-BIG5" '("quail-ctlaub" quail-use-package "quail/ctlaub"))
309 (register-input-method
310 "Chinese-BIG5" '("quail-array30" quail-use-package "quail/array30"))
311 (register-input-method
312 "Chinese-BIG5" '("quail-4corner" quail-use-package "quail/4corner"))
313
314 (defun setup-chinese-big5-environment ()
315 "Setup multilingual environment (MULE) for Chinese Big5 users."
316 (interactive)
317 (setq primary-language "Chinese-BIG5")
318
319 (setq coding-category-big5 'cn-big5)
320 (setq coding-category-iso-else 'iso-2022-cn)
321 (setq coding-category-iso-8-2 'cn-gb-2312)
322
323 (set-coding-priority
324 '(coding-category-iso-7
325 coding-category-iso-else
326 coding-category-big5
327 coding-category-iso-8-2))
328
329 (setq-default buffer-file-coding-system 'cn-big5)
330 (set-terminal-coding-system 'cn-big5)
331 (set-keyboard-coding-system 'cn-big5)
332
333 (setq default-input-method '("Chinese-BIG5" . "quail-py-b5"))
334 )
335
336 (defun describe-chinese-big5-support ()
337 "Describe how Emacs supports Chinese for Big5 users."
338 (interactive)
339 (describe-language-support-internal "Chinese-BIG5"))
340
341 (set-language-info-alist
342 "Chinese-BIG5" '((setup-function . setup-chinese-big5-environment)
343 (describe-function . describe-chinese-big5-support)
344 (charset . (chinese-big5-1 chinese-big5-2))
345 (coding-system . (cn-big5 iso-2022-cn))
346 (sample-text . "Cantonese ($(0GnM$(B,$(0N]0*Hd(B) $(0*/=((B, $(0+$)p(B")
347 (documentation . nil)))
348
349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 ;; Chinese CNS11643 (traditional)
351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
352
353 (register-input-method
354 "Chinese-CNS" '("quail-quick-cns" quail-use-package "quail/quick-cns"))
355 (register-input-method
356 "Chinese-CNS" '("quail-tsangchi-cns" quail-use-package "quail/tsangchi-cns"))
357
358 (defun setup-chinese-cns-environment ()
359 "Setup multilingual environment (MULE) for Chinese CNS11643 family users."
360 (interactive)
361 (setq primary-language "Chinese-CNS")
362
363 (setq coding-category-iso-else 'iso-2022-cn)
364 (setq coding-category-big5 'cn-big5)
365 (setq coding-category-iso-8-2 'cn-gb-2312)
366
367 (set-coding-priority
368 '(coding-category-iso-7
369 coding-category-iso-else
370 coding-category-iso-8-2
371 coding-category-big5))
372
373 (setq-default buffer-file-coding-system 'iso-2022-cn)
374 (set-terminal-coding-system 'iso-2022-cn)
375 (set-keyboard-coding-system 'iso-2022-cn)
376
377 (setq default-input-method '("Chinese-CNS" . "quail-py-cns"))
378 )
379
380 (defun describe-chinese-cns-support ()
381 "Describe how Emacs supports Chinese for CNS11643 family users."
382 (interactive)
383 (describe-language-support-internal "Chinese-CNS"))
384
385 (set-language-info-alist
386 "Chinese-CNS" '((setup-function . setup-chinese-cns-environment)
387 (describe-function . describe-chinese-cns-support)
388 (charset . (chinese-cns11643-1 chinese-cns11643-2
389 chinese-cns11643-3 chinese-cns11643-4
390 chinese-cns11643-5 chinese-cns11643-6
391 chinese-cns11643-7))
392 (coding-system . (iso-2022-cn))
393 (documentation . nil)))
394
395
396 ;;; for XEmacs (will be obsoleted)
397
398 (define-language-environment 'chinese
399 "Chinese (includes GB, Big5, and CNS)"
400 (lambda ()
401 (require 'chinese)
402 (set-coding-category-system 'iso-8-2 'cn-gb-2312)
403 (set-coding-priority-list '(iso-8-2 big5 iso-8-designate))
404 (set-pathname-coding-system 'cn-gb-2312)
405 (set-default-buffer-file-coding-system 'cn-gb-2312) ; GB encoding
406 (setq terminal-coding-system 'cn-gb-2312)
407 (setq keyboard-coding-system 'cn-gb-2312)
408 (add-hook 'comint-exec-hook
409 (lambda ()
410 (let ((proc (get-buffer-process (current-buffer))))
411 (set-process-input-coding-system proc 'cn-gb-2312)
412 (set-process-output-coding-system proc 'cn-gb-2312))))
413 (set-buffer-file-coding-system-for-read 'automatic-conversion)
414 (set-default-buffer-file-coding-system 'cn-gb-2312)
415 (setq keyboard-coding-system 'cn-gb-2312)
416 (setq terminal-coding-system 'cn-gb-2312)
417 (when (eq 'x (device-type (selected-device)))
418 (x-use-halfwidth-roman-font 'chinese-gb2312 "gb1988"))))
419 ;; (when (featurep 'egg)
420 ;; (setq-default its:*current-map* (its:get-mode-map "PinYin")))
421 ;; (setq-default quail-current-package (assoc "py" quail-package-alist))))
422 ;; ))
423
424 (set-coding-category-system 'big5 'big5)
425
426 ;;; chinese.el ends here