sisheng.el 7.5 KB

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