tibetan.el 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. ;;; tibetan.el --- Quail package for inputting Tibetan characters -*-coding: iso-2022-7bit;-*-
  2. ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. ;; 2006, 2007, 2008, 2009, 2010, 2011
  5. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  6. ;; Registration Number H14PRO021
  7. ;; Keywords: multilingual, input method, Tibetan
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs 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 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;; Author: Toru TOMABECHI, <Toru.Tomabechi@orient.unil.ch>
  20. ;; Created: Feb. 17. 1997
  21. ;; History:
  22. ;; 1997.03.13 Support for inputting special signs and punctuation added.
  23. ;; (Only Ext. Wylie input)
  24. ;;; Commentary:
  25. ;;; Code:
  26. (require 'quail)
  27. (require 'tibet-util)
  28. ;; Now quail-current-key is set to Tibetan-Roman transcription. We
  29. ;; set quail-current-str to the corresponding Tibetan string (composed
  30. ;; if necessary). Both Wylie and TibKey input methods use this
  31. ;; function.
  32. (defun quail-tibetan-update-translation (control-flag)
  33. (if (numberp control-flag)
  34. ;; Non-composable-character typed.
  35. (setq quail-current-str
  36. (buffer-substring (overlay-start quail-overlay)
  37. (overlay-end quail-overlay))
  38. unread-command-events
  39. (string-to-list
  40. (substring quail-current-key control-flag)))
  41. ;; Special treatment of "-d..." and "-y...".
  42. (if (string-match "^-[dy]" quail-current-key)
  43. (setq quail-current-key (substring quail-current-key 1)))
  44. (let ((str (tibetan-transcription-to-tibetan quail-current-key)))
  45. ;; If quail-current-key is for punctuation, it can't be
  46. ;; transcribed by tibetan-transcription-to-tibetan, thus STR
  47. ;; contains ASCII string now. In that case, use the current
  48. ;; characters set in quail-current-str.
  49. (if (> (aref str 0) 255)
  50. (setq quail-current-str (tibetan-compose-string str))
  51. (or quail-current-str
  52. (setq quail-current-str quail-current-key)))))
  53. control-flag)
  54. ;;; Wylie transcription based input methods.
  55. ;; Special alist for `$(7"A(B'. It must be treated as a subjoined
  56. ;; consonant if it follows a consonant.
  57. ;; * Removed by Tomabechi 2000/06/10 *
  58. ;; 'a chung must be explicitly typed as a vowel ("fa")
  59. ;; $(7"A(B is now treated as normal base consonants
  60. ;; (defconst tibetan-wylie-quote-alist '(("'" . ?$(7"A(B)))
  61. ;; Special alist to avoid default stacking.
  62. (defconst tibetan-wylie-non-stacking-alist
  63. '(("-d" . "$(7"2(B")
  64. ("-y" . "$(7"B(B")))
  65. ;; Punctuation characters are not transcribed.
  66. (defconst tibetan-wylie-punctuation-alist
  67. '(("." . " ")
  68. (":" . "$(7"`(B")
  69. (" " . "$(7!;(B")
  70. ("/" . "$(7!=(B")
  71. ("//" . "$(7!>(B")
  72. ("////" . ["$(7!>(B $(7!>(B"])
  73. ("$" . "$(7!?(B")
  74. ("/\"" . "$(7!@(B") ; Not defined in Ext. Wylie.
  75. ("&" . "$(7!@(B")
  76. (";" . "$(7!A(B")
  77. ("%" . "$(7!D(B")
  78. ("!" . "$(7!8(B")
  79. ("<" . "$(7!l(B")
  80. (">" . "$(7!m(B")
  81. ("@" . "$(7"f(B")
  82. ("*" . ["$(7!4!5(B"])
  83. ("#" . ["$(7!4!5!5(B"])
  84. ("^" . "$(7!6(B")
  85. ("0" . "$(7!P(B")
  86. ("1" . "$(7!Q(B")
  87. ("2" . "$(7!R(B")
  88. ("3" . "$(7!S(B")
  89. ("4" . "$(7!T(B")
  90. ("5" . "$(7!U(B")
  91. ("6" . "$(7!V(B")
  92. ("7" . "$(7!W(B")
  93. ("8" . "$(7!X(B")
  94. ("9" . "$(7!Y(B")
  95. ("-0" . "$(7!c(B")
  96. ("-1" . "$(7!Z(B")
  97. ("-2" . "$(7![(B")
  98. ("-3" . "$(7!\(B")
  99. ("-4" . "$(7!](B")
  100. ("-5" . "$(7!^(B")
  101. ("-6" . "$(7!_(B")
  102. ("-7" . "$(7!`(B")
  103. ("-8" . "$(7!a(B")
  104. ("-9" . "$(7!b(B")
  105. ("|" . "$(7!0!1!2!3!7!9!:!B!C!E!F!G!H!I!J!K!L!M!N!O!d!f!h!j!k!n!o#O#P#Q#R#S#T#U#V#W#X#Y#Z#[#\#]#`(B")))
  106. (quail-define-package "tibetan-wylie" "Tibetan" "TIBw" t
  107. "Tibetan character input by Extended Wylie key assignment.
  108. +-------------------------------------+
  109. |$(7"!!;(B k |$(7""!;(B kh |$(7"#!;(B g |$(7"$!;(B gh |$(7"%!;(B ng| $(7"S(B i $(7!=(B /
  110. |$(7"&!;(B c |$(7"'!;(B ch |$(7"(!;(B j | |$(7"*!;(B ny| $(7"U(B u $(7!>(B //
  111. |$(7"+!;(B T |$(7",!;(B TH |$(7"-!;(B D |$(7".!;(B DH |$(7"/!;(B N | $(7"[(B e $(7!>(B $(7!>(B ////
  112. |$(7"0!;(B t |$(7"1!;(B th |$(7"2!;(B d |$(7"3!;(B dh |$(7"4!;(B n | $(7"](B o $(7!A(B ;
  113. |$(7"5!;(B p |$(7"6!;(B ph |$(7"7!;(B b |$(7"8!;(B bh |$(7"9!;(B m | $(7"\(B ai (ee, E) $(7!?(B $
  114. |$(7":!;(B ts|$(7";!;(B tsh|$(7"<!;(B dz |$(7"=!;(B dzh|$(7">!;(B w | $(7"^(B au (oo, O) $(7!@(B &
  115. |$(7"?!;(B zh|$(7"@!;(B z |$(7"A!;(B ' | |$(7"B!;(B y | $(7"a(B I $(7!4!5(B *
  116. |$(7"C!;(B r |$(7"D!;(B l |$(7"E!;(B sh |$(7"F!;(B SH |$(7"G!;(B s | $(7"`(B : $(7!4!5!5(B #
  117. |$(7"H!;(B h |$(7"I!;(B A |$(7"J!;(B kSH| | | $(7"_(B M $(7!l(B $(7!m(B < >
  118. +-------------------------------------+ $(7!D(B %
  119. (The consonant $(7"I!;(B must be typed explicitly.)
  120. NOT SPECIFIED IN EXT. WYLIE:
  121. +--------------------------------------------------------+
  122. |$(7"c(B = ~ |$(7"d(B = ` |$(7"e(B = , |$(7"f(B = @ |$(7!g(B = _o|$(7!e(B = _O|$(7!6(B = ^|
  123. +--------------------------------------------------------+
  124. |$(7"i(B = x |$(7"j(B = X |$(7"g(B = v |$(7"h(B = V |$(7"k(B = q |$(7"l(B = Q |
  125. +-----------------------------------------------+
  126. SPECIAL KEYS
  127. + : Consonant Stacking
  128. \(Consonant stacking for ordinary Tibetan is done automatically)
  129. - : No Consonant Stacking
  130. \(To suppress automatic stacking for \"g-y\",
  131. and to get da-drag in -r-d, -l-d .)
  132. | : Special signs.
  133. Tsheg is assigned to SPC. Space is assigned to period '.'.
  134. "
  135. nil nil nil nil nil nil nil nil
  136. 'quail-tibetan-update-translation)
  137. ;; Here we build up a Quail map for a Tibetan sequence the whole of
  138. ;; which can be one composition.
  139. ;;
  140. ;; A Tibetan syllable is typically structured as follows:
  141. ;; [P] C [c+] V [M] [S [s]]
  142. ;; ^^^^^^^^^^^^
  143. ;; where P:prefix, C:base consonant, c:subjoined consonant,
  144. ;; V:vowel, M:vowel modifier, S:suffix, s:post suffix.
  145. ;; In this pattern, the part indicated by "^^^" can be one composition.
  146. ;;; modified by Tomabechi 1999/12/10
  147. ;;; modified by Tomabechi 2000/06/08
  148. ;;; Allows infinite addition of vowels/modifiers
  149. ;;; as specified in Unicode v.3
  150. (quail-install-map
  151. (quail-map-from-table
  152. '((base-state (tibetan-consonant-transcription-alist . svm-state)
  153. (tibetan-precomposed-transcription-alist . svm-state)
  154. (tibetan-wylie-non-stacking-alist . svm-state)
  155. tibetan-subjoined-transcription-alist
  156. tibetan-vowel-transcription-alist
  157. tibetan-modifier-transcription-alist
  158. tibetan-wylie-punctuation-alist)
  159. (svm-state ;;(tibetan-wylie-quote-alist . vm-state)
  160. (tibetan-vowel-transcription-alist . vm-state)
  161. (tibetan-subjoined-transcription-alist . svm-state)
  162. (tibetan-modifier-transcription-alist . m-state))
  163. (vm-state (tibetan-vowel-transcription-alist . vm-state)
  164. (tibetan-modifier-transcription-alist . m-state))
  165. (m-state (tibetan-modifier-transcription-alist . m-state)))))
  166. ;;;
  167. ;;; TibKey key alignment based input method
  168. ;;;
  169. (defconst tibetan-tibkey-to-transcription-alist
  170. '(;; consonant
  171. ("`" . "`") ; sna ldan
  172. ("~" . "~") ; sna ldan + nada
  173. ("q" . "k") ; ka
  174. ("Q" ."kSH") ; kSHa
  175. ("w" . "kh") ; kha
  176. ("e" . "g") ; ga
  177. ("r" . "ng") ; nga
  178. ("t" . "c") ; ca
  179. ("T" . "I") ; gi gu log
  180. ("y" . "ch") ; cha
  181. ("u" . "j") ; ja
  182. ("i" . "ny") ; nya
  183. ("o" . "t") ; ta
  184. ("O" . "T") ; Ta
  185. ("p" . "th") ; tha
  186. ("P" . "TH") ; THa
  187. ("[" . "d") ; da
  188. ("{" . "D") ; Da
  189. ("]" . "n") ; na
  190. ("}" . "N") ; Na
  191. ("a" . "p") ; pa
  192. ("A" . "a") ; Vowel a (not used in original TibKey)
  193. ("s" . "ph") ; pha
  194. ("d" . "b") ; ba
  195. ("f" . "m") ; ma
  196. ("F" . "M") ; anusvara
  197. ("g" . "u") ; zhabs kyu
  198. ("G" . "i") ; gi gu
  199. ("H" . ",") ; virama
  200. ("j" . "o") ; naro
  201. ("J" . "e") ; 'greng bu
  202. ("k" . "ts") ; tsa
  203. ("l" . "tsh") ; tsha
  204. (";" . "dz") ; dza
  205. ("'" . "w") ; wa
  206. ("\"" . "+w") ; wa zur
  207. ("z" . "zh") ; zha
  208. ("x" . "z") ; za
  209. ("c" . "'") ; 'a
  210. ("C" . "+'") ; 'a chung
  211. ("v" . "y") ; ya
  212. ("V" . "+y") ; ya btags
  213. ("b" . "r") ; ra
  214. ("B" . "+r") ; ra btags
  215. ("n" . "l") ; la
  216. ("N" . "+l") ; la btags
  217. ("m" . "sh") ; sha
  218. ("M" . "SH") ; SHa
  219. ("," . "s") ; sa
  220. ("." . "h") ; ha
  221. ("/" . "A") ; Aa
  222. ;; subjoined
  223. ("hq" . "+k") ; ka
  224. ("hQ" ."+kSH") ; kSHa
  225. ("hw" . "+kh") ; kha
  226. ("he" . "+g") ; ga
  227. ("hr" . "+ng") ; nga
  228. ("ht" . "+c") ; ca
  229. ("hy" . "+ch") ; cha
  230. ("hu" . "+j") ; ja
  231. ("hi" . "+ny") ; nya
  232. ("ho" . "+t") ; ta
  233. ("hO" . "+T") ; Ta
  234. ("hp" . "+th") ; tha
  235. ("hP" . "+TH") ; THa
  236. ("h[" . "+d") ; da
  237. ("h{" . "+D") ; Da
  238. ("h]" . "+n") ; na
  239. ("h}" . "+N") ; Na
  240. ("ha" . "+p") ; pa
  241. ("hs" . "+ph") ; pha
  242. ("hd" . "+b") ; ba
  243. ("hf" . "+m") ; ma
  244. ("hk" . "+ts") ; tsa
  245. ("hl" . "+tsh") ; tsha
  246. ("h;" . "+dz") ; dza
  247. ("h'" . "+w") ; wa
  248. ("hz" . "+zh") ; zha
  249. ("hx" . "+z") ; za
  250. ("hc" . "+'") ; 'a
  251. ("hv" . "+y") ; ya
  252. ("hb" . "+r") ; ra
  253. ("hn" . "+l") ; la
  254. ("hm" . "+sh") ; sha
  255. ("hM" . "+SH") ; SHa
  256. ("h," . "+s") ; sa
  257. ("h." . "+h") ; ha
  258. ("h/" . "+A") ; Aa
  259. ;; Special rule for `$(7"B(B' to avoid stacking.
  260. ("E" . "-y")
  261. ))
  262. (defconst tibetan-consonant-tibkey-alist nil)
  263. (defconst tibetan-subjoined-tibkey-alist nil)
  264. (defconst tibetan-vowel-tibkey-alist nil)
  265. (defconst tibetan-modifier-tibkey-alist nil)
  266. (defconst tibetan-non-stacking-tibkey-alist nil)
  267. (let ((type-list '("consonant" "subjoined" "vowel" "modifier" "non-stacking"))
  268. (tail tibetan-tibkey-to-transcription-alist)
  269. elt)
  270. (while tail
  271. (setq elt (car tail) tail (cdr tail))
  272. (let ((types type-list)
  273. type transcription trans-alist tibkey-alist)
  274. (while types
  275. (setq type (car types) types (cdr types))
  276. (setq trans-alist
  277. (if (string= type "non-stacking")
  278. 'tibetan-wylie-non-stacking-alist
  279. (intern (format "tibetan-%s-transcription-alist" type)))
  280. transcription
  281. (cdr (assoc (cdr elt) (symbol-value trans-alist))))
  282. (when transcription
  283. (setq tibkey-alist (intern (format "tibetan-%s-tibkey-alist" type)))
  284. (set tibkey-alist
  285. (cons (cons (car elt) transcription)
  286. (symbol-value tibkey-alist)))))
  287. (or tibkey-alist
  288. (error "No Tibetan transcription for %s" (cdr elt))))))
  289. (defconst tibetan-punctuation-tibkey-alist
  290. '(("1" . "$(7!Q(B")
  291. ("!" . "$(7!4(B") ; nyi zla long
  292. ("2" . "$(7!R(B")
  293. ("@" . "$(7!5(B") ; nyi zla simple
  294. ("3" . "$(7!S(B")
  295. ;;; ("#" )
  296. ("4" . "$(7!T(B")
  297. ;;; ("$" )
  298. ("5" . "$(7!U(B")
  299. ("%" . "$(7!D(B")
  300. ("6" . "$(7!V(B")
  301. ("^" . "$(7!1(B")
  302. ("7" . "$(7!W(B")
  303. ("8" . "$(7!X(B")
  304. ;;; ("*" ) ; avagraha, not supported yet
  305. ("9" . "$(7!Y(B")
  306. ("(" . "$(7!l(B")
  307. ("0" . "$(7!P(B")
  308. (")" . "$(7!m(B")
  309. ;;; ("-" ) ; emphatic, not yet supported
  310. ;;; ("_" ) ; id.
  311. ;;; ("=" ) ; special sign, not yet supported
  312. ("+" . "$(7!A(B")
  313. ("\\" . "$(7!?(B")
  314. ("|" . "$(7!8(B")
  315. ("I" . "$(7"f(B") ; avagraha
  316. (":" . "$(7"`(B")
  317. ;;; (">" ?$(7!;(B) ; to be assigned to SPC
  318. (">" . " ")
  319. ("?" . "$(7!=(B")
  320. ("??" . "$(7!>(B")
  321. ("????" . ["$(7!>(B $(7!>(B"])
  322. (" " . "$(7!;(B")
  323. ))
  324. ;; Convert TibKey string to Tibetan-Roman transcription string.
  325. ;; If there's no proper conversion, return nil.
  326. (defun quail-tibkey-to-transcription (tibkey)
  327. (let ((len (length tibkey))
  328. (i 0)
  329. (trans-list nil))
  330. (while (< i len)
  331. (let ((last len)
  332. trans)
  333. (while (and (not trans) (> last i))
  334. (or (setq trans (cdr (assoc (substring tibkey i last)
  335. tibetan-tibkey-to-transcription-alist)))
  336. (setq last (1- last))))
  337. (if trans
  338. (setq trans-list (cons trans trans-list)
  339. i last)
  340. (setq trans-list nil i len))))
  341. (apply 'concat (nreverse trans-list))))
  342. (defvar quail-tibkey-characters nil)
  343. (defun quail-tibkey-update-translation (control-flag)
  344. (if (integerp control-flag)
  345. ;; Non-composable-character typed.
  346. (setq quail-current-str
  347. (buffer-substring (overlay-start quail-overlay)
  348. (overlay-end quail-overlay))
  349. unread-command-events
  350. (string-to-list
  351. (substring quail-current-key control-flag)))
  352. (let ((transcription (quail-tibkey-to-transcription quail-current-key)))
  353. (if (> (length transcription) 0)
  354. (let ((quail-current-key transcription))
  355. (setq control-flag
  356. (quail-tibetan-update-translation control-flag)))
  357. (or quail-current-str
  358. (setq quail-current-str quail-current-key)))))
  359. control-flag)
  360. (quail-define-package "tibetan-tibkey" "Tibetan" "TIBt" t
  361. "Tibetan character input by TibKey key assignment.
  362. \(This implementation is still incomplete.
  363. Therefore, the following key assignment is a provisional one.)
  364. [NOT SHIFTED]
  365. +-------------------------------------------------------+
  366. |`$(7"d(B|1$(7!Q(B|2$(7!R(B|3$(7!S(B|4$(7!T(B|5$(7!U(B|6$(7!V(B|7$(7!W(B|8$(7!X(B|9$(7!Y(B|0$(7!P(B|- |= |\\$(7!8(B|
  367. +-------------------------------------------------------+
  368. |q$(7"!(B|w$(7""(B|e$(7"#(B|r$(7"%(B|t$(7"&(B|y$(7"'(B|u$(7"((B|i$(7"*(B|o$(7"0(B|p$(7"1(B|[$(7"2(B|]$(7"4(B|
  369. +-----------------------------------------------+
  370. |a$(7"5(B| s$(7"6(B| d$(7"7(B|f$(7"9(B|g$(7"U(B|h |j$(7"](B|k$(7":(B|l$(7";(B|;$(7"<(B|'$(7">(B|
  371. +---------------------------------------------+
  372. |z$(7"?(B|x$(7"@(B|c$(7"A(B|v$(7"B(B|b$(7"C(B|n$(7"D(B|m$(7"E(B|,$(7"G(B|.$(7"H(B|/$(7"I(B|
  373. +---------------------------------------+
  374. The key 'h' is used for consonant stacking.
  375. [SHIFTED]
  376. +----------------------------------------------------------+
  377. |~$(7"c(B|!$(7!4(B|@$(7!5(B|# |$ |%$(7!D(B |^$(7!1(B|& |* |($(7!l(B|)$(7!m(B|_ |+$(7!A(B| |$(7!8(B|
  378. +----------------------------------------------------------+
  379. |Q$(7"J(B|W |E |R |T$(7"a(B|Y |U |I$(7"f(B|O$(7"+(B|P$(7",(B|{$(7"-(B|}$(7"/(B|
  380. +-----------------------------------------------+
  381. |A |S |D |F$(7"_(B|G$(7"S(B|H$(7"e(B|J$(7"[(B|K |L |:$(7"`(B|\"$(7#>(B|
  382. +-------------------------------------------+
  383. |Z |X |C$(7"R(B|V$(7#B(B|B$(7#C(B|N$(7#D(B|M$(7"F(B|< |> |?$(7!=(B |
  384. +---------------------------------------+
  385. DIFFERENCE FROM THE ORIGINAL TIBKEY:
  386. 1. Vowel 'a' should be typed explicitly by the key 'A'.
  387. This is really inconvenient. But to make the coding
  388. scheme clear, it is desirable to have an explicit
  389. vowel sign for 'a'.
  390. 2. Tsheg is assigned to SPC key. You can input a space
  391. by typing '>'.
  392. 4. To avoid the default stacking $(7$B(B and to obtain $(7"#"B(B,
  393. type 'E' instead of 'v' (=$(7"B(B).
  394. 3. There are many characters that are not supported in the
  395. current implementation (especially special signs). I hope
  396. I'll complete in a future revision.
  397. "
  398. nil nil nil nil nil nil nil nil
  399. 'quail-tibkey-update-translation)
  400. (quail-install-map
  401. (quail-map-from-table
  402. '((base-state (tibetan-consonant-tibkey-alist . s-state)
  403. (tibetan-non-stacking-tibkey-alist . s-state)
  404. tibetan-subjoined-tibkey-alist
  405. tibetan-vowel-tibkey-alist
  406. tibetan-modifier-tibkey-alist
  407. tibetan-punctuation-tibkey-alist)
  408. (s-state (tibetan-subjoined-tibkey-alist . s-state)
  409. (tibetan-vowel-tibkey-alist . m-state))
  410. (m-state tibetan-modifier-tibkey-alist))))
  411. ;;; tibetan.el ends here