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