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