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