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