1 ;;; sisheng.el --- sisheng input method for Chinese pinyin transliteration
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Werner LEMBERG <wl@gnu.org>
7 ;; Keywords: multilingual, input method, Chinese, pinyin, sisheng
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (defconst sisheng-regexp
33 ;; First element is the key,
34 ;; second element is the vowel used for the input sequence,
35 ;; last four elements are the resulting tones.
37 (defconst sisheng-vowel-table
38 '(("ā" "a" "ā" "á" "ǎ" "à")
39 ("ē" "e" "ē" "é" "ě" "è")
40 ("ī" "i" "ī" "í" "ǐ" "ì")
41 ("ō" "o" "ō" "ó" "ǒ" "ò")
42 ("ū" "u" "ū" "ú" "ǔ" "ù")
43 ("ǖ" "v" "ǖ" "ǘ" "ǚ" "ǜ")
44 ("üē" "ve" "üē" "üé" "üě" "üè")))
47 ;; All possible syllables in Mandarin Chinese, presented in the first
48 ;; tone. Note that make-sisheng-rules always constructs rules for all
49 ;; four tones even if some of those tones aren't used in Mandarin.
51 (defconst sisheng-syllable-table
52 '("ā" "āi" "ān" "āng" "āo"
54 "bā" "bāi" "bān" "bāng" "bāo"
56 "bī" "biān" "biāo" "biē" "bīn" "bīng"
60 "cā" "cāi" "cān" "cāng" "cāo"
64 "cū" "cuān" "cuī" "cūn" "cuō"
66 "chā" "chāi" "chān" "chāng" "chāo"
70 "chū" "chuā" "chuāi" "chuān" "chuāng" "chuī" "chūn" "chuō"
72 "dā" "dāi" "dān" "dāng" "dāo"
73 "dē" "dēi" "dēn" "dēng"
74 "dī" "diān" "diāo" "diē" "dīng" "diū"
76 "dū" "duān" "duī" "dūn" "duō"
78 "ē" "ēi" "ēn" "ēng" "ēr"
86 "gā" "gāi" "gān" "gāng" "gāo"
87 "gē" "gēi" "gēn" "gēng"
89 "gū" "guā" "guāi" "guān" "guāng" "guī" "gūn" "guō"
91 "hā" "hāi" "hān" "hāng" "hāo"
92 "hē" "hēi" "hēn" "hēng"
94 "hū" "huā" "huāi" "huān" "huāng" "huī" "hūn" "huō"
96 "jī" "jiā" "jiān" "jiāng" "jiāo" "jiē" "jīn" "jīng" "jiōng" "jiū"
97 "jū" "juān" "juē" "jūn"
99 "kā" "kāi" "kān" "kāng" "kāo"
100 "kē" "kēi" "kēn" "kēng"
102 "kū" "kuā" "kuāi" "kuān" "kuāng" "kuī" "kūn" "kuō"
104 "lā" "lāi" "lān" "lāng" "lāo"
106 "lī" "liā" "liān" "liāng" "liāo" "liē" "līn" "līng" "liū"
108 "lū" "luān" "lūn" "luō"
111 "mā" "māi" "mān" "māng" "māo"
112 "mē" "mēi" "mēn" "mēng"
113 "mī" "miān" "miāo" "miē" "mīn" "mīng" "miū"
117 "nā" "nāi" "nān" "nāng" "nāo"
118 "nē" "nēi" "nēn" "nēng"
119 "nī" "niān" "niāng" "niāo" "niē" "nīn" "nīng" "niū"
126 "pā" "pāi" "pān" "pāng" "pāo"
128 "pī" "piān" "piāo" "piē" "pīn" "pīng"
132 "qī" "qiā" "qiān" "qiāng" "qiāo" "qiē" "qīn" "qīng" "qiōng" "qiū"
133 "qū" "quān" "quē" "qūn"
139 "rū" "ruā" "ruān" "ruī" "rūn" "ruō"
141 "sā" "sāi" "sān" "sāng" "sāo"
145 "sū" "suān" "suī" "sūn" "suō"
147 "shā" "shāi" "shān" "shāng" "shāo"
148 "shē" "shēi" "shēn" "shēng"
151 "shū" "shuā" "shuāi" "shuān" "shuāng" "shuī" "shūn" "shuō"
153 "tā" "tāi" "tān" "tāng" "tāo"
155 "tī" "tiān" "tiāo" "tiē" "tīng"
157 "tū" "tuān" "tuī" "tūn" "tuō"
159 "wā" "wāi" "wān" "wāng"
164 "xī" "xiā" "xiān" "xiāng" "xiāo" "xiē" "xīn" "xīng" "xiōng" "xiū"
165 "xū" "xuān" "xuē" "xūn"
167 "yā" "yān" "yāng" "yāo"
171 "yū" "yuān" "yuē" "yūn"
173 "zā" "zāi" "zān" "zāng" "zāo"
174 "zē" "zēi" "zēn" "zēng"
177 "zū" "zuān" "zuī" "zūn" "zuō"
179 "zhā" "zhāi" "zhān" "zhāng" "zhāo"
180 "zhē" "zhēi" "zhēn" "zhēng"
183 "zhū" "zhuā" "zhuāi" "zhuān" "zhuāng" "zhuī" "zhūn" "zhuō"))
185 ;; This function converts e.g.
191 ;; (("zhuo4" ["zhuò"])
192 ;; ("zhuo3" ["zhuǒ"])
193 ;; ("zhuo2" ["zhuó"])
194 ;; ("zhuo1" ["zhuō"]))
196 (defun quail-make-sisheng-rules (syllable)
197 (let ((case-fold-search t
)
206 (string-match sisheng-regexp syllable
)
207 (setq vowel-match
(downcase (match-string 0 syllable
)))
209 (cdr (assoc-string vowel-match sisheng-vowel-table
)))
210 (setq input-vowel
(car vowel-list
))
211 (setq base-key
(replace-match input-vowel nil nil syllable
))
213 (setq key
(concat base-key
(number-to-string i
)))
214 (setq value
(vector (replace-match (nth i vowel-list
) nil nil syllable
)))
215 (push (list key value
) key-value-list
)
219 ;; Set up sisheng input method.
221 (quail-define-package
222 "chinese-sisheng" ; name
226 "Sìshēng input method for pīnyīn transliteration of Chinese.
228 Examples: shuang1 -> shuāng
232 Use the fifth (unstressed) tone for syllables containing `ü'
237 nil
; translation-keys
238 t
; forget-last-selection
242 nil
; create-decode-map
243 nil
; maximum-shortest
245 nil
; update-translation-function
246 nil
; conversion-keys
250 ;; Call quail-make-sisheng-rules for all syllables in sisheng-syllable-table.
252 (let ((case-table-save (current-case-table))
254 (set-case-table (standard-case-table))
255 (dolist (syllable sisheng-syllable-table
)
257 (append (quail-make-sisheng-rules syllable
)
260 (dolist (syllable sisheng-syllable-table
)
262 (append (quail-make-sisheng-rules (upcase-initials syllable
))
265 (dolist (syllable sisheng-syllable-table
)
267 (append (quail-make-sisheng-rules (upcase syllable
))
270 (eval `(quail-define-rules
287 (set-case-table case-table-save
))
293 ;; arch-tag: 1fa6ba5f-6747-44bc-bf12-30628ad3e8ad
294 ;;; sisheng.el ends here