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