Commit | Line | Data |
---|---|---|
ba1d5dcd KH |
1 | ;;; sisheng.el --- sisheng input method for Chinese pinyin transliteration |
2 | ||
3 | ;; Copyright (C) 2004 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: Werner LEMBERG <wl@gnu.org> | |
6 | ||
7 | ;; Keywords: multilingual, input method, Chinese, pinyin, sisheng | |
8 | ||
9 | ;; This program is free software; you can redistribute it and/or modify | |
10 | ;; it under the terms of the GNU General Public License as published by | |
11 | ;; the Free Software Foundation; either version 2, or (at your option) | |
12 | ;; any later version. | |
13 | ||
14 | ;; This program is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
20 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | ||
23 | ;;; Commentary: | |
24 | ||
25 | ;;; Code: | |
26 | ||
27 | (require 'quail) | |
28 | ||
29 | (defconst sisheng-regexp | |
30 | "[āēīōūǖ]\\|üē") | |
31 | ||
32 | ;; First element is the key, | |
33 | ;; second element is the vowel used for the input sequence, | |
34 | ;; last four elements are the resulting tones. | |
35 | ;; | |
36 | (defconst sisheng-vowel-table | |
37 | '(("ā" "a" "ā" "á" "ǎ" "à") | |
38 | ("ē" "e" "ē" "é" "ě" "è") | |
39 | ("ī" "i" "ī" "í" "ǐ" "ì") | |
40 | ("ō" "o" "ō" "ó" "ǒ" "ò") | |
41 | ("ū" "u" "ū" "ú" "ǔ" "ù") | |
42 | ("ǖ" "v" "ǖ" "ǘ" "ǚ" "ǜ") | |
43 | ("üē" "ve" "üē" "üé" "üě" "üè"))) | |
44 | ||
45 | ||
46 | ;; All possible syllables in Mandarin Chinese, presented in the first | |
47 | ;; tone. Note that make-sisheng-rules always constructs rules for all | |
48 | ;; four tones even if some of those tones aren't used in Mandarin. | |
49 | ;; | |
50 | (defconst sisheng-syllable-table | |
51 | '("ā" "āi" "ān" "āng" "āo" | |
52 | ||
53 | "bā" "bāi" "bān" "bāng" "bāo" | |
54 | "bēi" "bēn" "bēng" | |
55 | "bī" "biān" "biāo" "biē" "bīn" "bīng" | |
56 | "bō" | |
57 | "bū" | |
58 | ||
59 | "cā" "cāi" "cān" "cāng" "cāo" | |
60 | "cē" "cēn" "cēng" | |
61 | "cī" | |
62 | "cōng" "cōu" | |
63 | "cū" "cuān" "cuī" "cūn" "cuō" | |
64 | ||
65 | "chā" "chāi" "chān" "chāng" "chāo" | |
66 | "chē" "chēn" "chēng" | |
67 | "chī" | |
68 | "chōng" "chōu" | |
69 | "chū" "chuā" "chuāi" "chuān" "chuāng" "chuī" "chūn" "chuō" | |
70 | ||
71 | "dā" "dāi" "dān" "dāng" "dāo" | |
72 | "dē" "dēi" "dēn" "dēng" | |
73 | "dī" "diān" "diāo" "diē" "dīng" "diū" | |
74 | "dōng" "dōu" | |
75 | "dū" "duān" "duī" "dūn" "duō" | |
76 | ||
77 | "ē" "ēi" "ēn" "ēng" "ēr" | |
78 | ||
79 | "fā" "fān" "fāng" | |
80 | "fēi" "fēn" "fēng" | |
81 | "fiāo" | |
82 | "fō" "fōu" | |
83 | "fū" | |
84 | ||
85 | "gā" "gāi" "gān" "gāng" "gāo" | |
86 | "gē" "gēi" "gēn" "gēng" | |
87 | "gōng" "gōu" | |
88 | "gū" "guā" "guāi" "guān" "guāng" "guī" "gūn" "guō" | |
89 | ||
90 | "hā" "hāi" "hān" "hāng" "hāo" | |
91 | "hē" "hēi" "hēn" "hēng" | |
92 | "hōng" "hōu" | |
93 | "hū" "huā" "huāi" "huān" "huāng" "huī" "hūn" "huō" | |
94 | ||
95 | "jī" "jiā" "jiān" "jiāng" "jiāo" "jiē" "jīn" "jīng" "jiōng" "jiū" | |
96 | "jū" "juān" "juē" "jūn" | |
97 | ||
98 | "kā" "kāi" "kān" "kāng" "kāo" | |
99 | "kē" "kēi" "kēn" "kēng" | |
100 | "kōng" "kōu" | |
101 | "kū" "kuā" "kuāi" "kuān" "kuāng" "kuī" "kūn" "kuō" | |
102 | ||
103 | "lā" "lāi" "lān" "lāng" "lāo" | |
104 | "lē" "lēi" "lēng" | |
105 | "lī" "liā" "liān" "liāng" "liāo" "liē" "līn" "līng" "liū" | |
106 | "lōng" "lōu" | |
107 | "lū" "luān" "lūn" "luō" | |
108 | "lǖ" "lüē" | |
109 | ||
110 | "mā" "māi" "mān" "māng" "māo" | |
111 | "mē" "mēi" "mēn" "mēng" | |
112 | "mī" "miān" "miāo" "miē" "mīn" "mīng" "miū" | |
113 | "mō" "mōu" | |
114 | "mū" | |
115 | ||
116 | "nā" "nāi" "nān" "nāng" "nāo" | |
117 | "nē" "nēi" "nēn" "nēng" | |
118 | "nī" "niān" "niāng" "niāo" "niē" "nīn" "nīng" "niū" | |
119 | "nōng" "nōu" | |
120 | "nū" "nuān" "nuō" | |
121 | "nǖ" "nüē" | |
122 | ||
123 | "ō" "ōu" | |
124 | ||
125 | "pā" "pāi" "pān" "pāng" "pāo" | |
126 | "pēi" "pēn" "pēng" | |
127 | "pī" "piān" "piāo" "piē" "pīn" "pīng" | |
128 | "pō" "pōu" | |
129 | "pū" | |
130 | ||
131 | "qī" "qiā" "qiān" "qiāng" "qiāo" "qiē" "qīn" "qīng" "qiōng" "qiū" | |
132 | "qū" "quān" "quē" "qūn" | |
133 | ||
134 | "rān" "rāng" "rāo" | |
135 | "rē" "rēn" "rēng" | |
136 | "rī" | |
137 | "rōng" "rōu" | |
138 | "rū" "ruā" "ruān" "ruī" "rūn" "ruō" | |
139 | ||
140 | "sā" "sāi" "sān" "sāng" "sāo" | |
141 | "sē" "sēn" "sēng" | |
142 | "sī" | |
143 | "sōng" "sōu" | |
144 | "sū" "suān" "suī" "sūn" "suō" | |
145 | ||
146 | "shā" "shāi" "shān" "shāng" "shāo" | |
147 | "shē" "shēi" "shēn" "shēng" | |
148 | "shī" | |
149 | "shōu" | |
150 | "shū" "shuā" "shuāi" "shuān" "shuāng" "shuī" "shūn" "shuō" | |
151 | ||
152 | "tā" "tāi" "tān" "tāng" "tāo" | |
153 | "tē" "tēi" "tēng" | |
154 | "tī" "tiān" "tiāo" "tiē" "tīng" | |
155 | "tōng" "tōu" | |
156 | "tū" "tuān" "tuī" "tūn" "tuō" | |
157 | ||
158 | "wā" "wāi" "wān" "wāng" | |
159 | "wēi" "wēn" "wēng" | |
160 | "wō" | |
161 | "wū" | |
162 | ||
163 | "xī" "xiā" "xiān" "xiāng" "xiāo" "xiē" "xīn" "xīng" "xiōng" "xiū" | |
164 | "xū" "xuān" "xuē" "xūn" | |
165 | ||
166 | "yā" "yān" "yāng" "yāo" | |
167 | "yē" | |
168 | "yī" "yīn" "yīng" | |
169 | "yō" "yōng" "yōu" | |
170 | "yū" "yuān" "yuē" "yūn" | |
171 | ||
172 | "zā" "zāi" "zān" "zāng" "zāo" | |
173 | "zē" "zēi" "zēn" "zēng" | |
174 | "zī" | |
175 | "zōng" "zōu" | |
176 | "zū" "zuān" "zuī" "zūn" "zuō" | |
177 | ||
178 | "zhā" "zhāi" "zhān" "zhāng" "zhāo" | |
179 | "zhē" "zhēi" "zhēn" "zhēng" | |
180 | "zhī" | |
181 | "zhōng" "zhōu" | |
182 | "zhū" "zhuā" "zhuāi" "zhuān" "zhuāng" "zhuī" "zhūn" "zhuō")) | |
183 | ||
184 | ;; This function converts e.g. | |
185 | ;; | |
186 | ;; "zhuō" | |
187 | ;; | |
188 | ;; into | |
189 | ;; | |
190 | ;; (("zhuo4" ["zhuò"]) | |
191 | ;; ("zhuo3" ["zhuǒ"]) | |
192 | ;; ("zhuo2" ["zhuó"]) | |
193 | ;; ("zhuo1" ["zhuō"])) | |
194 | ;; | |
195 | (defun quail-make-sisheng-rules (syllable) | |
196 | (let ((case-fold-search t) | |
197 | vowel-match | |
198 | vowel-list | |
199 | input-vowel | |
200 | base-key | |
201 | key | |
202 | value | |
203 | key-value-list | |
204 | (i 1)) | |
205 | (string-match sisheng-regexp syllable) | |
206 | (setq vowel-match (downcase (match-string 0 syllable))) | |
207 | (setq vowel-list | |
208 | (cdr (assoc-string vowel-match sisheng-vowel-table))) | |
209 | (setq input-vowel (car vowel-list)) | |
210 | (setq base-key (replace-match input-vowel nil nil syllable)) | |
211 | (while (<= i 4) | |
212 | (setq key (concat base-key (number-to-string i))) | |
213 | (setq value (vector (replace-match (nth i vowel-list) nil nil syllable))) | |
214 | (push (list key value) key-value-list) | |
215 | (setq i (1+ i))) | |
216 | key-value-list)) | |
217 | ||
218 | ;; Set up sisheng input method. | |
219 | ;; | |
220 | (quail-define-package | |
221 | "chinese-sisheng" ; name | |
222 | "Chinese" ; language | |
223 | "ǚ" ; title | |
224 | t ; guidance | |
225 | "Sìshēng input method for pīnyīn transliteration of Chinese. | |
226 | ||
227 | Examples: shuang1 -> shuāng | |
228 | Lv3 -> Lǚ | |
229 | AN4 -> ÀN | |
230 | ||
231 | Use the fifth (unstressed) tone for syllables containing `ü' | |
232 | without a tone mark. | |
233 | ||
234 | Example: nve5 -> nüe | |
235 | " ; docstring | |
236 | nil ; translation-keys | |
237 | t ; forget-last-selection | |
238 | nil ; deterministic | |
239 | nil ; kbd-translate | |
240 | nil ; show-layout | |
241 | nil ; create-decode-map | |
242 | nil ; maximum-shortest | |
243 | nil ; overlay-plist | |
244 | nil ; update-translation-function | |
245 | nil ; conversion-keys | |
246 | t ; simple | |
247 | ) | |
248 | ||
249 | ;; Call quail-make-sisheng-rules for all syllables in sisheng-syllable-table. | |
250 | ;; | |
251 | (let ((case-table-save (current-case-table)) | |
252 | sisheng-list) | |
253 | (set-case-table (standard-case-table)) | |
254 | (dolist (syllable sisheng-syllable-table) | |
255 | (setq sisheng-list | |
256 | (append (quail-make-sisheng-rules syllable) | |
257 | sisheng-list))) | |
258 | ||
259 | (dolist (syllable sisheng-syllable-table) | |
260 | (setq sisheng-list | |
261 | (append (quail-make-sisheng-rules (upcase-initials syllable)) | |
262 | sisheng-list))) | |
263 | ||
264 | (dolist (syllable sisheng-syllable-table) | |
265 | (setq sisheng-list | |
266 | (append (quail-make-sisheng-rules (upcase syllable)) | |
267 | sisheng-list))) | |
268 | ||
269 | (eval `(quail-define-rules | |
270 | ,@sisheng-list | |
271 | ||
272 | ("lv5" ["lü"]) | |
273 | ("lve5" ["lüe"]) | |
274 | ("nv5" ["nü"]) | |
275 | ("nve5" ["nüe"]) | |
276 | ||
277 | ("Lv5" ["Lü"]) | |
278 | ("Lve5" ["Lüe"]) | |
279 | ("Nv5" ["Nü"]) | |
280 | ("Nve5" ["Nüe"]) | |
281 | ||
282 | ("LV5" ["LÜ"]) | |
283 | ("LVE5" ["LÜE"]) | |
284 | ("NV5" ["NÜ"]) | |
285 | ("NVE5" ["NÜE"]))) | |
286 | (set-case-table case-table-save)) | |
287 | ||
288 | ;; Local Variables: | |
289 | ;; coding: utf-8 | |
290 | ;; End: |