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