]> code.delx.au - gnu-emacs/blob - lisp/language/chinese.el
aa3ddcf4d88022302e7dcf3e64b2a60dd28679bc
[gnu-emacs] / lisp / language / chinese.el
1 ;;; chinese.el --- Support for Chinese
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
5
6 ;; Keywords: multilingual, Chinese
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; For Chinese, three character sets GB2312, BIG5, and CNS11643 are
28 ;; supported.
29
30 ;;; Code:
31
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;;; Chinese (general)
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35
36 (make-coding-system
37 'iso-2022-cn 2 ?C
38 "Coding system ISO-2022-CN for Chinese (GB and CNS character sets)."
39 '(ascii
40 (nil chinese-gb2312 chinese-cns11643-1)
41 (nil chinese-cns11643-2)
42 (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
43 chinese-cns11643-6 chinese-cns11643-7)
44 nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
45 init-bol))
46
47 (define-coding-system-alias 'iso-2022-cn 'iso-2022-cn-ext)
48
49 (set-language-info
50 "Chinese" 'documentation
51 "Emacs provides three kinds of Chinese support: Chinese-GB,
52 Chinese-BIG5, and Chinese-CNS. Please specify one of them to get more
53 information.")
54
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 ;;; Chinese GB2312 (simplified)
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
59 (make-coding-system
60 'cn-gb-2312 2 ?C
61 "Coding-system of Chinese EUC (so called GB Encoding)."
62 '((ascii t) chinese-gb2312 chinese-sisheng nil
63 nil ascii-eol ascii-cntl nil nil single-shift nil))
64
65 (define-coding-system-alias 'cn-gb-2312 'euc-china)
66
67 (make-coding-system
68 'hz-gb-2312 0 ?z
69 "Codins-system of Hz/ZW used for Chinese (GB)."
70 nil)
71 (put 'hz-gb-2312 'post-read-conversion 'post-read-decode-hz)
72 (put 'hz-gb-2312 'pre-write-conversion 'pre-write-encode-hz)
73
74 (define-coding-system-alias 'hz-gb-2312 'hz)
75
76 (defun post-read-decode-hz (len)
77 (let ((pos (point)))
78 (decode-hz-region pos (+ pos len))))
79
80 (defun pre-write-encode-hz (from to)
81 (let ((buf (current-buffer))
82 (work (get-buffer-create " *pre-write-encoding-work*")))
83 (set-buffer work)
84 (widen)
85 (erase-buffer)
86 (insert-buffer-substring buf from to)
87 (encode-hz-region 1 (point-max))
88 nil))
89
90 (register-input-method
91 "Chinese-GB" '("cxterm-gb" encoded-kbd-select-terminal cn-gb-2312))
92 (register-input-method
93 "Chinese-GB" '("quail-ccdospy" quail-use-package "quail/ccdospy"))
94 (register-input-method
95 "Chinese-GB" '("quail-ctlau" quail-use-package "quail/ctlau"))
96 (register-input-method
97 "Chinese-GB" '("quail-punct" quail-use-package "quail/punct"))
98 (register-input-method
99 "Chinese-GB" '("quail-qj" quail-use-package "quail/qj"))
100 (register-input-method
101 "Chinese-GB" '("quail-sw" quail-use-package "quail/sw"))
102 (register-input-method
103 "Chinese-GB" '("quail-ziranma" quail-use-package "quail/ziranma"))
104 (register-input-method
105 "Chinese-GB" '("quail-tonepy" quail-use-package "quail/tonepy"))
106 (register-input-method
107 "Chinese-GB" '("quail-py" quail-use-package "quail/py"))
108
109 (defun setup-chinese-gb-environment ()
110 (setq primary-language "Chinese-GB")
111
112 (setq coding-category-iso-8-2 'cn-gb-2312)
113 (setq coding-category-iso-else 'iso-2022-cn)
114 (setq coding-category-big5 'cn-big5)
115
116 (set-coding-priority
117 '(coding-category-iso-7
118 coding-category-iso-else
119 coding-category-iso-8-2
120 coding-category-big5
121 coding-category-iso-8-1
122 coding-category-internal
123 ))
124
125 (setq-default buffer-file-coding-system 'cn-gb-2312)
126 (set-terminal-coding-system 'cn-gb-2312)
127 (set-keyboard-coding-system 'cn-gb-2312)
128
129 (setq default-input-method '("Chinese-GB" . "quail-py"))
130 )
131
132 (set-language-info-alist
133 "Chinese-GB" '((documentation . t)
134 (setup-function . setup-chinese-gb-environment)
135 (charset . (chinese-gb2312 chinese-sisheng))
136 (coding-system . (cn-gb-2312 hz-gb-2312 iso-2022-cn))
137 (documentation . t)
138 (sample-text . "Chinese (\e$AVPND\e(B,\e$AFUM(;0\e(B,\e$A::So\e(B) \e$ADc:C\e(B")))
139
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;; Chinese BIG5 (traditional)
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143
144 (make-coding-system
145 'big5 3 ?B
146 "Coding-system of BIG5.")
147
148 (define-coding-system-alias 'big5 'cn-big5)
149
150 ;; Big5 font requires special encoding.
151 (define-ccl-program ccl-encode-big5-font
152 `(0
153 ;; In: R0:chinese-big5-1 or chinese-big5-2
154 ;; R1:position code 1
155 ;; R2:position code 2
156 ;; Out: R1:font code point 1
157 ;; R2:font code point 2
158 ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
159 (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
160 (r1 = ((r2 / 157) + ?\xA1))
161 (r2 %= 157)
162 (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
163 "CCL program to encode a Big5 code to code point of Big5 font.")
164
165 (setq font-ccl-encoder-alist
166 (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
167
168 (register-input-method
169 "Chinese-BIG5" '("cxterm-big5" encoded-kbd-select-terminal big5))
170 (register-input-method
171 "Chinese-BIG5" '("quail-qj-b5" quail-use-package "quail/qj-b5"))
172 (register-input-method
173 "Chinese-BIG5" '("quail-zozy" quail-use-package "quail/zozy"))
174 (register-input-method
175 "Chinese-BIG5" '("quail-tsangchi-b5" quail-use-package "quail/tsangchi-b5"))
176 (register-input-method
177 "Chinese-BIG5" '("quail-py-b5" quail-use-package "quail/py-b5"))
178 (register-input-method
179 "Chinese-BIG5" '("quail-quick-b5" quail-use-package "quail/quick-bt"))
180 (register-input-method
181 "Chinese-BIG5" '("quail-etzy" quail-use-package "quail/etzy"))
182 (register-input-method
183 "Chinese-BIG5" '("quail-ecdict" quail-use-package "quail/ecdict"))
184 (register-input-method
185 "Chinese-BIG5" '("quail-ctlaub" quail-use-package "quail/ctlaub"))
186 (register-input-method
187 "Chinese-BIG5" '("quail-array30" quail-use-package "quail/array30"))
188 (register-input-method
189 "Chinese-BIG5" '("quail-4corner" quail-use-package "quail/4corner"))
190
191 (defun setup-chinese-big5-environment ()
192 (setq primary-language "Chinese-BIG5")
193
194 (setq coding-category-big5 'cn-big5)
195 (setq coding-category-iso-else 'iso-2022-cn)
196 (setq coding-category-iso-8-2 'cn-gb-2312)
197
198 (set-coding-priority
199 '(coding-category-iso-7
200 coding-category-iso-else
201 coding-category-big5
202 coding-category-iso-8-2))
203
204 (setq-default buffer-file-coding-system 'cn-big5)
205 (set-terminal-coding-system 'cn-big5)
206 (set-keyboard-coding-system 'cn-big5)
207
208 (setq default-input-method '("Chinese-BIG5" . "quail-py-b5"))
209 )
210
211 (set-language-info-alist
212 "Chinese-BIG5" '((setup-function . setup-chinese-big5-environment)
213 (charset . (chinese-big5-1 chinese-big5-2))
214 (coding-system . (cn-big5 iso-2022-cn))
215 (documentation . t)
216 (sample-text . "Cantonese (\e$(0GnM$\e(B,\e$(0N]0*Hd\e(B) \e$(0*/=(\e(B, \e$(0+$)p\e(B")))
217
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219 ;; Chinese CNS11643 (traditional)
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
221
222 (register-input-method
223 "Chinese-CNS" '("quail-quick-cns" quail-use-package "quail/quick-cns"))
224 (register-input-method
225 "Chinese-CNS" '("quail-tsangchi-cns" quail-use-package "quail/tsangchi-cns"))
226
227 (defun setup-chinese-cns-environment ()
228 (setq primary-language "Chinese-CNS")
229
230 (setq coding-category-iso-else 'iso-2022-cn)
231 (setq coding-category-big5 'cn-big5)
232 (setq coding-category-iso-8-2 'cn-gb-2312)
233
234 (set-coding-priority
235 '(coding-category-iso-7
236 coding-category-iso-else
237 coding-category-iso-8-2
238 coding-category-big5))
239
240 (setq-default buffer-file-coding-system 'iso-2022-cn)
241 (set-terminal-coding-system 'iso-2022-cn)
242 (set-keyboard-coding-system 'iso-2022-cn)
243
244 (setq default-input-method '("Chinese-CNS" . "quail-py-cns"))
245 )
246
247 (set-language-info-alist
248 "Chinese-CNS" '((setup-function . setup-chinese-cns-environment)
249 (charset . (chinese-cns11643-1 chinese-cns11643-2
250 chinese-cns11643-3 chinese-cns11643-4
251 chinese-cns11643-5 chinese-cns11643-6
252 chinese-cns11643-7))
253 (coding-system . (iso-2022-cn))
254 (documentation . t)))
255
256 ;;; chinese.el ends here