(show-paren-mode): Use define-minor-mode.
[bpt/emacs.git] / leim / quail / tibetan.el
dissimilarity index 63%
index b6563d3..83b2fb8 100644 (file)
-;;; quail/tibetan.el -- Quail package for inputting Tibetan characters
-
-;; Copyright (C) 1995 Free Software Foundation, Inc.
-;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
-
-;; Keywords: multilingual, input method, Tibetan
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-;; Author: Toru TOMABECHI, <Toru.Tomabechi@orient.unil.ch>
-
-;; Created: Feb. 17. 1997
-
-;; History:
-;; 1997.03.13 Support for inputting special signs and punctuations added.
-;;            (Only Ext. Wylie input)
-
-;;; Code:
-
-(require 'quail)
-
-;;;
-;;; Functions for making some composite punctuations.
-;;;
-
-(defun tibetan-quail-bzhi-shad (&rest ignore)
-  (quail-delete-region)
-  (quail-delete-overlays)
-  (insert (compose-chars ?\e$(7!>\e(B '(mr . ml) ?\x20 '(mr . ml) ?\e$(7!>\e(B))
-  (throw 'quail-tag nil))
-
-(defun tibetan-quail-nyi-zla (&rest ignore)
-  (quail-delete-region)
-  (quail-delete-overlays)
-  (insert (compose-chars ?\e$(7#R\e(B '(mr . ml) ?\e$(7#S\e(B))
-  (throw 'quail-tag nil))
-
-(defun tibetan-quail-nyi-zla-phur-shad (&rest ignore)
-  (quail-delete-region)
-  (quail-delete-overlays)
-  (insert (compose-chars ?\e$(7#R\e(B '(mr . ml) ?\e$(7#S\e(B '(bc . tl) ?\e$(7!I\e(B))
-  (throw 'quail-tag nil))
-
-(defun tibetan-quail-nyi-zla-double (&rest ignore)
-  (quail-delete-region)
-  (quail-delete-overlays)
-  (insert (compose-chars ?\e$(7#R\e(B '(mr . ml) ?\e$(7#S\e(B '(mr . ml) ?\e$(7#S\e(B))
-  (throw 'quail-tag nil))
-
-(defun tibetan-quail-nyi-zla-triple (&rest ignore)
-  (quail-delete-region)
-  (quail-delete-overlays)
-  (insert (compose-chars ?\e$(7#R\e(B '(mr . ml) ?\e$(7#S\e(B '(mr . ml) ?\e$(7#S\e(B '(mr . ml) ?\e$(7#S\e(B))
-  (throw 'quail-tag nil))
-
-;;;
-;;; Setting-ups for Extended Wylie input.
-;;;
-
-(defun quail-tibetan-input-wylie (key &rest ignore)
-  (let (pc)
-    (quail-delete-region)
-    (quail-delete-overlays)
-    (setq pc (char-before (overlay-start quail-overlay))
-         quail-current-str (tibetan-composition pc key))
-    (if (not (bobp))
-       (progn
-         (delete-char -1)
-         (insert (aref quail-current-str 0))
-         (setq quail-current-str (substring quail-current-str 1))))
-    (move-overlay quail-overlay (point) (point))
-    (insert quail-current-str)
-    (throw 'quail-tag nil)))
-
-
-(quail-define-package "tibetan-wylie" "Tibetan" "TIBw" t
-"Tibetan character input by Extended Wylie key assignment.
-
-    +-------------------------------------+
-    |\e2\e$(7"!`#T\e(B\e1\e$(8!;\e(B k |\e2\e$(7""`#T\e(B\e1\e$(8!;\e(B kh |\e2\e$(7"#`#T\e(B\e1\e$(8!;\e(B g  |\e2\e$(7"$`#T\e(B\e1\e$(8!;\e(B gh |\e2\e$(7"%`#T\e(B\e1\e$(8!;\e(B ng|   \e$(7"S\e(B i          \e$(8!=\e(B        /
-    |\e2\e$(7"&`#T\e(B\e1\e$(8!;\e(B c |\e2\e$(7"'`#T\e(B\e1\e$(8!;\e(B ch |\e2\e$(7"(`#T\e(B\e1\e$(8!;\e(B j  |       |\e$(7"*\e$(8!;\e(B ny|   \e$(7"U\e(B u          \e$(7!>\e(B       //
-    |\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          \e2\e$(7!>P\e(B P\e$(7!>\e(B\e1    ////
-    |\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       ;
-    |\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        $
-    |\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        &
-    |\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          \e2\e$(7#RP#SP#S\e(B\e1   *
-    |\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 :          \e2\e$(7#RP#SP#SP#S\e(B\e1 #
-    |\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   < >
-    +-------------------------------------+   \e$(8!D\e(B  %
-    (The consonant \e$(7"I\e$(8!;\e(B must be typed explicitly.)
-
-  NOT SPECIFIED IN EXT. WYLIE:
-    +--------------------------------------------------------+
-    |\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|\e2\e$(7#RP#S_!I\e(B\e1 = ^|
-    +--------------------------------------------------------+
-    |\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 |
-    +-----------------------------------------------+
-
-  SPECIAL KEYS
-  +     :  Consonant Stacking
-          \(Consonant stacking for ordinary Tibetan is done automatically)
-  -     : No Consonant Stacking
-          \(To suppress automatic stacking for \"g-y\",
-            and to get da-drag in  -r-d, -l-d .)
-  |     : Special signs.
-
-  Tsheg is assigned to SPC. Space is assigned to period '.'.
-"
- nil nil nil)
-
-(quail-define-rules
- ("."    ?\x20)
- ("k"    quail-tibetan-input-wylie)
- ("g"    quail-tibetan-input-wylie)
- ("c"    quail-tibetan-input-wylie)
- ("j"    quail-tibetan-input-wylie)
- ("T"    quail-tibetan-input-wylie)
- ("D"    quail-tibetan-input-wylie)
- ("N"    quail-tibetan-input-wylie)
- ("t"    quail-tibetan-input-wylie)
- ("d"    quail-tibetan-input-wylie)
- ("n"    quail-tibetan-input-wylie)
- ("p"    quail-tibetan-input-wylie)
- ("b"    quail-tibetan-input-wylie)
- ("m"    quail-tibetan-input-wylie)
- ("w"    quail-tibetan-input-wylie)
- ("z"    quail-tibetan-input-wylie)
- ("'"    quail-tibetan-input-wylie)
- ("y"    quail-tibetan-input-wylie)
- ("r"    quail-tibetan-input-wylie)
- ("l"    quail-tibetan-input-wylie)
- ("SH"   quail-tibetan-input-wylie)
- ("s"    quail-tibetan-input-wylie)
- ("h"    quail-tibetan-input-wylie)
- ("H"    quail-tibetan-input-wylie)
- ("A"    quail-tibetan-input-wylie)
- ("+k"   quail-tibetan-input-wylie)
- ("+g"   quail-tibetan-input-wylie)
- ("+c"   quail-tibetan-input-wylie)
- ("+j"   quail-tibetan-input-wylie)
- ("+T"   quail-tibetan-input-wylie)
- ("+D"   quail-tibetan-input-wylie)
- ("+N"   quail-tibetan-input-wylie)
- ("+t"   quail-tibetan-input-wylie)
- ("+d"   quail-tibetan-input-wylie)
- ("+n"   quail-tibetan-input-wylie)
- ("+p"   quail-tibetan-input-wylie)
- ("+b"   quail-tibetan-input-wylie)
- ("+m"   quail-tibetan-input-wylie)
- ("+w"   quail-tibetan-input-wylie)
- ("+z"   quail-tibetan-input-wylie)
- ("+'"   quail-tibetan-input-wylie)
- ("+y"   quail-tibetan-input-wylie)
- ("+r"   quail-tibetan-input-wylie)
- ("+l"   quail-tibetan-input-wylie)
- ("+SH"  quail-tibetan-input-wylie)
- ("+s"   quail-tibetan-input-wylie)
- ("+h"   quail-tibetan-input-wylie)
- ("+H"   quail-tibetan-input-wylie)
- ("+A"   quail-tibetan-input-wylie)
- ("-d"  ?\e$(7"2\e(B)                            ; To avoid default stacking
- ("-y"  ?\e$(7"B\e(B)                            ; Idem.
- ("a"    quail-tibetan-input-wylie)    ; invisible vowel sign
- ("i"    quail-tibetan-input-wylie)
- ("u"    quail-tibetan-input-wylie)
- ("e"    quail-tibetan-input-wylie)
- ("o"    quail-tibetan-input-wylie)
- ("I"    quail-tibetan-input-wylie)
- ("E"    quail-tibetan-input-wylie)
- ("O"    quail-tibetan-input-wylie)
- ("M"    quail-tibetan-input-wylie)
- ("~"    quail-tibetan-input-wylie)
- ("`"    quail-tibetan-input-wylie)
- (","    quail-tibetan-input-wylie)
- ("x"    quail-tibetan-input-wylie)
- ("X"    quail-tibetan-input-wylie)
- ("v"    quail-tibetan-input-wylie)
- ("V"    quail-tibetan-input-wylie)
- ("q"    quail-tibetan-input-wylie)
- ("Q"    quail-tibetan-input-wylie)
- ("_o"    quail-tibetan-input-wylie)
- ("_O"    quail-tibetan-input-wylie)
-;;; ("_/"    quail-tibetan-input-wylie)
- (":"   ?\e$(8"`\e(B)
- (" "   ?\e$(8!;\e(B)
- ("/"   ?\e$(8!=\e(B)
- ("//"  ?\e$(7!>\e(B)
- ("////" tibetan-quail-bzhi-shad)
- ("$"   ?\e$(8!?\e(B)
- ("/\"" ?\e$(8!@\e(B)                            ; Not defined in Ext. Wylie.
- ("&"   ?\e$(8!@\e(B)
- (";"   ?\e$(8!A\e(B)
- ("%"   ?\e$(8!D\e(B)
- ("!"   ?\e$(7!8\e(B)
- ("<"   ?\e$(7!l\e(B)
- (">"   ?\e$(7!m\e(B)
- ("@"   ?\e$(7"f\e(B)
- ("*" tibetan-quail-nyi-zla-double)
- ("#" tibetan-quail-nyi-zla-triple)
- ("^" tibetan-quail-nyi-zla-phur-shad)
- ("0" ?\e$(7!P\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!c\e(B)
- ("-1" ?\e$(7!Z\e(B)
- ("-2" ?\e$(7![\e(B)
- ("-3" ?\e$(7!\\e(B)
- ("-4" ?\e$(7!]\e(B)
- ("-5" ?\e$(7!^\e(B)
- ("-6" ?\e$(7!_\e(B)
- ("-7" ?\e$(7!`\e(B)
- ("-8" ?\e$(7!a\e(B)
- ("-9" ?\e$(7!b\e(B)
- ("|"  "\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")
- )
-
-;;;
-;;; Setting-ups for TibKey input
-;;;
-
-(defconst tibetan-tibkey-to-transcription-alist
-  '(
-    ("`" . "`")                                ; sna ldan
-    ("~" . "~")                                ; sna ldan + nada
-    ("q" . "k")                                ; ka
-    ("Q" ."kSH")                       ; kSHa
-    ("w" . "kh")                       ; kha
-    ("e" . "g")                                ; ga
-    ("r" . "ng")                       ; nga
-    ("t" . "c")                                ; ca
-    ("T" . "I")                                ; gi gu log
-    ("y" . "ch")                       ; cha
-    ("u" . "j")                                ; ja
-    ("i" . "ny")                       ; nya
-    ("o" . "t")                                ; ta
-    ("O" . "T")                                ; Ta
-    ("p" . "th")                       ; tha
-    ("P" . "TH")                       ; THa
-    ("[" . "d")                                ; da 
-    ("{" . "D")                                ; Da
-    ("]" . "n")                                ; na
-    ("}" . "N")                                ; Na
-    ("a" . "p")                                ; pa
-    ("A" . "a")                                ; Vowel a (not used in original TibKey)
-    ("s" . "ph")                       ; pha
-    ("d" . "b")                                ; ba
-    ("f" . "m")                                ; ma
-    ("F" . "M")                                ; anusvara
-    ("g" . "u")                                ; zhabs kyu
-    ("G" . "i")                                ; gi gu
-    ("H" . ",")                                ; viraama
-    ("j" . "o")                                ; naro
-    ("J" . "e")                                ; 'greng bu
-    ("k" . "ts")                       ; tsa
-    ("l" . "tsh")                      ; tsha
-    (";" . "dz")                        ; dza
-    ("'" . "w")                                ; wa
-    ("\"" . "+w")                      ; wa zur
-    ("z" . "zh")                       ; zha
-    ("x" . "z")                                ; za
-    ("c" . "'")                                ; 'a
-    ("C" . "+'")                       ; 'a chung
-    ("v" . "y")                                ; ya
-    ("V" . "+y")                       ; ya btags
-    ("b" . "r")                                ; ra
-    ("B" . "+r")                       ; ra btags
-    ("n" . "l")                                ; la
-    ("N" . "+l")                       ; la btags
-    ("m" . "sh")                       ; sha
-    ("M" . "SH")                       ; SHa
-    ("," . "s")                                ; sa
-    ("." . "h")                                ; ha
-    ("/" . "A")                                ; Aa
-    ;;subjoined
-    ("hq" . "+k")                      ; ka
-    ("hQ" ."+kSH")                     ; kSHa
-    ("hw" . "+kh")                     ; kha
-    ("he" . "+g")                      ; ga
-    ("hr" . "+ng")                     ; nga
-    ("ht" . "+c")                      ; ca
-    ("hy" . "+ch")                     ; cha
-    ("hu" . "+j")                      ; ja
-    ("hi" . "+ny")                     ; nya
-    ("ho" . "+t")                      ; ta
-    ("hO" . "+T")                      ; Ta
-    ("hp" . "+th")                     ; tha
-    ("hP" . "+TH")                     ; THa
-    ("h[" . "+d")                      ; da 
-    ("h{" . "+D")                      ; Da
-    ("h]" . "+n")                      ; na
-    ("h}" . "+N")                      ; Na
-    ("ha" . "+p")                      ; pa 
-    ("hs" . "+ph")                     ; pha
-    ("hd" . "+b")                      ; ba
-    ("hf" . "+m")                      ; ma
-    ("hk" . "+ts")                     ; tsa
-    ("hl" . "+tsh")                    ; tsha
-    ("h;" . "+dz")                      ; dza
-    ("h'" . "+w")                      ; wa
-    ("hz" . "+zh")                     ; zha
-    ("hx" . "+z")                      ; za
-    ("hc" . "+'")                      ; 'a
-    ("hv" . "+y")                      ; ya
-    ("hb" . "+r")                      ; ra
-    ("hn" . "+l")                      ; la
-    ("hm" . "+sh")                     ; sha
-    ("hM" . "+SH")                     ; SHa
-    ("h," . "+s")                      ; sa
-    ("h." . "+h")                      ; ha
-    ("h/" . "+A")                      ; Aa
-    ))
-
-(defun quail-tibetan-input-tibkey (key &rest ignore)
-  (let (trans pc)
-    (setq trans (cdr (assoc key tibetan-tibkey-to-transcription-alist)))
-    (quail-delete-region)
-    (quail-delete-overlays)
-    (setq pc (char-before (overlay-start quail-overlay))
-         quail-current-str (tibetan-composition pc trans))
-    (if (not (bobp))
-       (progn
-         (delete-char -1)
-         (insert (aref quail-current-str 0))
-         (setq quail-current-str (substring quail-current-str 1))))
-    (move-overlay quail-overlay (point) (point))
-    (insert quail-current-str)
-    (throw 'quail-tag nil)))
-
-
-
-(quail-define-package "tibetan-tibkey" "Tibetan" "TIBt" t
-"Tibetan character input by TibKey key assignment.
-
-(This implementation is still incomplete.
- Therefore, the following key assignment is a provisional one.)
-
-  [NOT SHIFTED]
-
-  +-------------------------------------------------------+
-  |`\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|
-  +-------------------------------------------------------+
-     |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|
-     +-----------------------------------------------+
-      |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|
-      +---------------------------------------------+
-         |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|
-         +---------------------------------------+
-  The key 'h' is used for consonant stacking.
-
-  [SHIFTED]
-
-  +----------------------------------------------------------+
-  |~\e$(7"c\e(B|!\e2\e$(7#RP#S\e(B\e1|@\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|
-  +----------------------------------------------------------+
-     |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|
-     +-----------------------------------------------+
-      |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|
-      +-------------------------------------------+
-         |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 |
-         +---------------------------------------+        
-
-  DIFFERENCE FROM THE ORIGINAL TIBKEY:
-
-    1. Vowel 'a' should be typed explicitly by the key 'A'.
-       This is really inconvenient. But to make the coding
-       scheme clear, it is desirable to have an explicite
-       vowel sign for 'a'.
-    2. Tsheg is assigned to SPC key. You can input a space
-       by typing '>'.
-    4. To avoid the default stacking \e$(7$B\e(B and to obtain \e$(7"#"B\e(B,
-       type 'E' instead of 'v' (=\e$(7"B\e(B).
-    3. There are many characters that are not supported in the
-       current implementation (especially special signs). I hope
-       I'll complete in a future revision.
-"
- nil t)
-
-(quail-define-rules
- ("`" quail-tibetan-input-tibkey)      ; sna ldan, not supported yet
- ("~" quail-tibetan-input-tibkey)      ; sna ldan + nada
- ("1" ?\e$(7!Q\e(B)
- ("!" tibetan-quail-nyi-zla)           ; nyi zla long
- ("2" ?\e$(7!R\e(B)
- ("@" ?\e$(7#S\e(B)                              ; nyi zla simple
- ("3" ?\e$(7!S\e(B)
-;;; ("#" )
- ("4" ?\e$(7!T\e(B)
-;;; ("$" )
- ("5" ?\e$(7!U\e(B)
- ("%" ?\e$(8!D\e(B)
- ("6" ?\e$(7!V\e(B)
- ("^" ?\e$(7!1\e(B)
- ("7" ?\e$(7!W\e(B)
- ("8" ?\e$(7!X\e(B)
-;;; ("*" ) ; avagraha, not supported yet
- ("9" ?\e$(7!Y\e(B)
- ("(" ?\e$(7!l\e(B)
- ("0" ?\e$(7!P\e(B)
- (")" ?\e$(7!m\e(B)
-;;; ("-" ) ; enphatic, not yet supported 
-;;; ("_" ) ; id.
-;;; ("=" ) ; special sign, not yet supported
- ("+" ?\e$(8!A\e(B)
- ("\\" ?\e$(8!?\e(B)
- ("|" ?\e$(7!8\e(B)
- ("q" quail-tibetan-input-tibkey)      ; ka
- ("Q" quail-tibetan-input-tibkey)      ; kSHa
- ("w" quail-tibetan-input-tibkey)      ; kha
- ("e" quail-tibetan-input-tibkey)      ; ga
- ("E" ?\e$(7"B\e(B)
- ("r" quail-tibetan-input-tibkey)      ; nga
- ("t" quail-tibetan-input-tibkey)      ; ca
- ("T" quail-tibetan-input-tibkey)      ; gi gu log
- ("y" quail-tibetan-input-tibkey)      ; cha
- ("u" quail-tibetan-input-tibkey)      ; ja
- ("i" quail-tibetan-input-tibkey)      ; nya
- ("I" ?\e$(7"f\e(B)                              ; avagraha
- ("o" quail-tibetan-input-tibkey)      ; ta
- ("O" quail-tibetan-input-tibkey)      ; Ta
- ("p" quail-tibetan-input-tibkey)      ; tha
- ("P" quail-tibetan-input-tibkey)      ; THa
- ("[" quail-tibetan-input-tibkey)      ; da 
- ("{" quail-tibetan-input-tibkey)      ; Da
- ("]" quail-tibetan-input-tibkey)      ; na
- ("}" quail-tibetan-input-tibkey)      ; Na
- ("a" quail-tibetan-input-tibkey)      ; pa 
- ("A" quail-tibetan-input-tibkey)      ; Vowel sign a
- ("s" quail-tibetan-input-tibkey)      ; pha
- ("d" quail-tibetan-input-tibkey)      ; ba
-;;; ("D" ) ; special sign, not supported yet
- ("f" quail-tibetan-input-tibkey)      ; ma
- ("F" quail-tibetan-input-tibkey)      ; anusvara
- ("g" quail-tibetan-input-tibkey)      ; zhabs kyu
- ("G" quail-tibetan-input-tibkey)      ; gi gu
- ("H" quail-tibetan-input-tibkey)      ; viraama
- ("j" quail-tibetan-input-tibkey)      ; naro
- ("J" quail-tibetan-input-tibkey)      ; 'greng bu
- ("k" quail-tibetan-input-tibkey);;tsa
-;;; ("K" ) ; tsadru, not supported yet
- ("l" quail-tibetan-input-tibkey)      ; tsha
- (";" quail-tibetan-input-tibkey)       ; dza
- (":" ?\e$(8"`\e(B)
- ("'" quail-tibetan-input-tibkey)      ; wa
- ("\"" quail-tibetan-input-tibkey)     ; wa zur
- ("z" quail-tibetan-input-tibkey)      ; zha
- ("x" quail-tibetan-input-tibkey)      ; za
- ("c" quail-tibetan-input-tibkey)      ; 'a
- ("C" quail-tibetan-input-tibkey)      ; 'a chung
- ("v" quail-tibetan-input-tibkey)      ; ya
- ("V" quail-tibetan-input-tibkey)      ; ya btags
- ("b" quail-tibetan-input-tibkey)      ; ra
- ("B" quail-tibetan-input-tibkey)      ; ra btags
- ("n" quail-tibetan-input-tibkey)      ; la
- ("N" quail-tibetan-input-tibkey)      ; la btags
- ("m" quail-tibetan-input-tibkey)      ; sha
- ("M" quail-tibetan-input-tibkey)      ; SHa
- ("," quail-tibetan-input-tibkey)      ; sa
- ("." quail-tibetan-input-tibkey)      ; ha
-;;; (">" ?\e$(8!;\e(B) ; to be assigned to SPC
- (">" ?\x20)
- ("/" quail-tibetan-input-tibkey)      ; Aa
- ("?" ?\e$(8!=\e(B)
- ("??" ?\e$(7!>\e(B)
- ("????" tibetan-quail-bzhi-shad)
- (" " ?\e$(8!;\e(B)
- ;;subjoined
- ("hq" quail-tibetan-input-tibkey)     ; ka
- ("hQ" quail-tibetan-input-tibkey)     ; kSHa
- ("hw" quail-tibetan-input-tibkey)     ; kha
- ("he" quail-tibetan-input-tibkey)     ; ga
- ("hr" quail-tibetan-input-tibkey)     ; nga
- ("ht" quail-tibetan-input-tibkey)     ; ca
- ("hy" quail-tibetan-input-tibkey)     ; cha
- ("hu" quail-tibetan-input-tibkey)     ; ja
- ("hi" quail-tibetan-input-tibkey)     ; nya
- ("ho" quail-tibetan-input-tibkey)     ; ta
- ("hO" quail-tibetan-input-tibkey)     ; Ta
- ("hp" quail-tibetan-input-tibkey)     ; tha
- ("hP" quail-tibetan-input-tibkey)     ; THa
- ("h[" quail-tibetan-input-tibkey)     ; da 
- ("h{" quail-tibetan-input-tibkey)     ; Da
- ("h]" quail-tibetan-input-tibkey)     ; na
- ("h}" quail-tibetan-input-tibkey)     ; Na
- ("ha" quail-tibetan-input-tibkey)     ; pa 
- ("hs" quail-tibetan-input-tibkey)     ; pha
- ("hd" quail-tibetan-input-tibkey)     ; ba
- ("hf" quail-tibetan-input-tibkey)     ; ma
- ("hk" quail-tibetan-input-tibkey)     ; tsa
- ("hl" quail-tibetan-input-tibkey)     ; tsha
- ("h;" quail-tibetan-input-tibkey)      ; dza
- ("h'" quail-tibetan-input-tibkey)     ; wa
- ("hz" quail-tibetan-input-tibkey)     ; zha
- ("hx" quail-tibetan-input-tibkey)     ; za
- ("hc" quail-tibetan-input-tibkey)     ; 'a
- ("hv" quail-tibetan-input-tibkey)     ; ya
- ("hb" quail-tibetan-input-tibkey)     ; ra
- ("hn" quail-tibetan-input-tibkey)     ; la
- ("hm" quail-tibetan-input-tibkey)     ; sha
- ("hM" quail-tibetan-input-tibkey)     ; SHa
- ("h," quail-tibetan-input-tibkey)     ; sa
- ("h." quail-tibetan-input-tibkey)     ; ha
- ("h/" quail-tibetan-input-tibkey)     ; Aa
- )
-
-;;; quail/tibetan.el ends here.
-
-
-
+;;; quail/tibetan.el -- Quail package for inputting Tibetan characters
+
+;; Copyright (C) 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+
+;; Keywords: multilingual, input method, Tibetan
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;; Author: Toru TOMABECHI, <Toru.Tomabechi@orient.unil.ch>
+
+;; Created: Feb. 17. 1997
+
+;; History:
+;; 1997.03.13 Support for inputting special signs and punctuations added.
+;;            (Only Ext. Wylie input)
+
+;;; Code:
+
+(require 'quail)
+(require 'tibet-util)
+
+;; Now quail-current-key is set to Tibetan-Roman transcription.  We
+;; set quail-current-str to the corresponding Tibetan string (composed
+;; if necessary).  Both Wylie and TibKey input methods use this
+;; function.
+
+(defun quail-tibetan-update-translation (control-flag)
+  (if (numberp control-flag)
+      ;; Non-composable-character typed.
+      (setq quail-current-str
+           (buffer-substring (overlay-start quail-overlay)
+                             (overlay-end quail-overlay))
+           unread-command-events
+           (string-to-list
+            (substring quail-current-key control-flag)))
+    ;; Special treatment of "-d..." and "-y...".
+    (if (string-match "^-[dy]" quail-current-key)
+       (setq quail-current-key (substring quail-current-key 1)))
+    (let ((str (tibetan-transcription-to-tibetan quail-current-key)))
+      ;; If quail-current-key is for punctuations, it can't be
+      ;; transcribed by tibetan-transcription-to-tibetan, thus STR
+      ;; contains ASCII string now.  In that case, use the current
+      ;; characters set in quail-current-str.
+      (if (> (aref str 0) 255)
+         (setq quail-current-str (tibetan-compose-string str))
+       (or quail-current-str
+           (setq quail-current-str quail-current-key)))))
+  control-flag)
+
+;;; Wylie transcription based input methods.
+
+;; Special alist for `\e$(7"A\e(B'.  It must be treated as a subjoined
+;; consonant if it follows a consonant.
+;; * Removed by Tomabechi 2000/06/10 *
+;; 'a chung must be explicitly typed as a vowel ("fa")
+;; \e$(7"A\e(B is now treated as normal base consonants
+;; (defconst tibetan-wylie-quote-alist '(("'" . ?\e$(7"A\e(B)))
+
+;; Special alist to avoid default stacking.
+(defconst tibetan-wylie-non-stacking-alist
+  '(("-d" . "\e$(7"2\e(B")
+    ("-y" . "\e$(7"B\e(B")))
+
+;; Punctuations are not transcribed.
+
+(defconst tibetan-wylie-punctuation-alist
+   '(("."  . " ")
+     (":"  . "\e$(7"`\e(B")
+     (" "  . "\e$(7!;\e(B")
+     ("/"  . "\e$(7!=\e(B")
+     ("//" . "\e$(7!>\e(B")
+     ("////" . ["\e$(7!>\e(B \e$(7!>\e(B"])
+     ("$"  . "\e$(7!?\e(B")
+     ("/\"" . "\e$(7!@\e(B")                     ; Not defined in Ext. Wylie.
+     ("&"  . "\e$(7!@\e(B")
+     (";"  . "\e$(7!A\e(B")
+     ("%"  . "\e$(7!D\e(B")
+     ("!"  . "\e$(7!8\e(B")
+     ("<"  . "\e$(7!l\e(B")
+     (">"  . "\e$(7!m\e(B")
+     ("@"  . "\e$(7"f\e(B")
+     ("*"  . ["\e$(7!4!5\e(B"])
+     ("#"  . ["\e$(7!4!5!5\e(B"])
+     ("^"  . "\e$(7!6\e(B")
+     ("0" . "\e$(7!P\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!c\e(B")
+     ("-1" . "\e$(7!Z\e(B")
+     ("-2" . "\e$(7![\e(B")
+     ("-3" . "\e$(7!\\e(B")
+     ("-4" . "\e$(7!]\e(B")
+     ("-5" . "\e$(7!^\e(B")
+     ("-6" . "\e$(7!_\e(B")
+     ("-7" . "\e$(7!`\e(B")
+     ("-8" . "\e$(7!a\e(B")
+     ("-9" . "\e$(7!b\e(B")
+     ("|"  . "\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")))
+
+(quail-define-package "tibetan-wylie" "Tibetan" "TIBw" t
+"Tibetan character input by Extended Wylie key assignment.
+
+    +-------------------------------------+
+    |\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        /
+    |\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       //
+    |\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    ////
+    |\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       ;
+    |\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        $
+    |\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        &
+    |\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   *
+    |\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  #
+    |\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   < >
+    +-------------------------------------+   \e$(7!D\e(B  %
+    (The consonant \e$(7"I!;\e(B must be typed explicitly.)
+
+  NOT SPECIFIED IN EXT. WYLIE:
+    +--------------------------------------------------------+
+    |\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 = ^|
+    +--------------------------------------------------------+
+    |\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 |
+    +-----------------------------------------------+
+
+  SPECIAL KEYS
+  +     :  Consonant Stacking
+          \(Consonant stacking for ordinary Tibetan is done automatically)
+  -     : No Consonant Stacking
+          \(To suppress automatic stacking for \"g-y\",
+            and to get da-drag in  -r-d, -l-d .)
+  |     : Special signs.
+
+  Tsheg is assigned to SPC. Space is assigned to period '.'.
+"
+ nil nil nil nil nil nil nil nil
+ 'quail-tibetan-update-translation)
+
+;; Here we build up a Quail map for a Tibtan sequence the whole of
+;; which can be one composition.
+;;
+;; A Tibetan syllable is typically structured as follows:
+;;      [P] C [c+] V [M] [S [s]]
+;;          ^^^^^^^^^^^^
+;; where P:prefix, C:base consonant, c:subjoined consonant,
+;; V:vowel, M:vowel modifier, S:suffix, s:post suffix.
+;; In this pattern, the part indicated by "^^^" can be one composition.
+
+;;; modified by Tomabechi 1999/12/10
+;;; modified by Tomabechi 2000/06/08
+;;;             Allows infinite addition of vowels/modifiers
+;;;             as specified in Unicode v.3
+(quail-install-map
+ (quail-map-from-table
+  '((base-state (tibetan-consonant-transcription-alist . svm-state)
+               (tibetan-precomposed-transcription-alist . svm-state)
+               (tibetan-wylie-non-stacking-alist . svm-state)
+               tibetan-subjoined-transcription-alist
+               tibetan-vowel-transcription-alist
+               tibetan-modifier-transcription-alist
+               tibetan-wylie-punctuation-alist)
+    (svm-state ;;(tibetan-wylie-quote-alist . vm-state)
+               (tibetan-vowel-transcription-alist . vm-state)
+               (tibetan-subjoined-transcription-alist . svm-state)
+               (tibetan-modifier-transcription-alist . m-state))
+    (vm-state (tibetan-vowel-transcription-alist . vm-state)
+             (tibetan-modifier-transcription-alist . m-state))
+    (m-state (tibetan-modifier-transcription-alist . m-state)))))
+
+;;;
+;;; TibKey key alignment based input method
+;;;
+
+(defconst tibetan-tibkey-to-transcription-alist
+  '(;; consonant
+    ("`" . "`")                                ; sna ldan
+    ("~" . "~")                                ; sna ldan + nada
+    ("q" . "k")                                ; ka
+    ("Q" ."kSH")                       ; kSHa
+    ("w" . "kh")                       ; kha
+    ("e" . "g")                                ; ga
+    ("r" . "ng")                       ; nga
+    ("t" . "c")                                ; ca
+    ("T" . "I")                                ; gi gu log
+    ("y" . "ch")                       ; cha
+    ("u" . "j")                                ; ja
+    ("i" . "ny")                       ; nya
+    ("o" . "t")                                ; ta
+    ("O" . "T")                                ; Ta
+    ("p" . "th")                       ; tha
+    ("P" . "TH")                       ; THa
+    ("[" . "d")                                ; da 
+    ("{" . "D")                                ; Da
+    ("]" . "n")                                ; na
+    ("}" . "N")                                ; Na
+    ("a" . "p")                                ; pa
+    ("A" . "a")                                ; Vowel a (not used in original TibKey)
+    ("s" . "ph")                       ; pha
+    ("d" . "b")                                ; ba
+    ("f" . "m")                                ; ma
+    ("F" . "M")                                ; anusvara
+    ("g" . "u")                                ; zhabs kyu
+    ("G" . "i")                                ; gi gu
+    ("H" . ",")                                ; viraama
+    ("j" . "o")                                ; naro
+    ("J" . "e")                                ; 'greng bu
+    ("k" . "ts")                       ; tsa
+    ("l" . "tsh")                      ; tsha
+    (";" . "dz")                        ; dza
+    ("'" . "w")                                ; wa
+    ("\"" . "+w")                      ; wa zur
+    ("z" . "zh")                       ; zha
+    ("x" . "z")                                ; za
+    ("c" . "'")                                ; 'a
+    ("C" . "+'")                       ; 'a chung
+    ("v" . "y")                                ; ya
+    ("V" . "+y")                       ; ya btags
+    ("b" . "r")                                ; ra
+    ("B" . "+r")                       ; ra btags
+    ("n" . "l")                                ; la
+    ("N" . "+l")                       ; la btags
+    ("m" . "sh")                       ; sha
+    ("M" . "SH")                       ; SHa
+    ("," . "s")                                ; sa
+    ("." . "h")                                ; ha
+    ("/" . "A")                                ; Aa
+    ;; subjoined
+    ("hq" . "+k")                      ; ka
+    ("hQ" ."+kSH")                     ; kSHa
+    ("hw" . "+kh")                     ; kha
+    ("he" . "+g")                      ; ga
+    ("hr" . "+ng")                     ; nga
+    ("ht" . "+c")                      ; ca
+    ("hy" . "+ch")                     ; cha
+    ("hu" . "+j")                      ; ja
+    ("hi" . "+ny")                     ; nya
+    ("ho" . "+t")                      ; ta
+    ("hO" . "+T")                      ; Ta
+    ("hp" . "+th")                     ; tha
+    ("hP" . "+TH")                     ; THa
+    ("h[" . "+d")                      ; da 
+    ("h{" . "+D")                      ; Da
+    ("h]" . "+n")                      ; na
+    ("h}" . "+N")                      ; Na
+    ("ha" . "+p")                      ; pa 
+    ("hs" . "+ph")                     ; pha
+    ("hd" . "+b")                      ; ba
+    ("hf" . "+m")                      ; ma
+    ("hk" . "+ts")                     ; tsa
+    ("hl" . "+tsh")                    ; tsha
+    ("h;" . "+dz")                      ; dza
+    ("h'" . "+w")                      ; wa
+    ("hz" . "+zh")                     ; zha
+    ("hx" . "+z")                      ; za
+    ("hc" . "+'")                      ; 'a
+    ("hv" . "+y")                      ; ya
+    ("hb" . "+r")                      ; ra
+    ("hn" . "+l")                      ; la
+    ("hm" . "+sh")                     ; sha
+    ("hM" . "+SH")                     ; SHa
+    ("h," . "+s")                      ; sa
+    ("h." . "+h")                      ; ha
+    ("h/" . "+A")                      ; Aa
+    ;; Special rule for `\e$(7"B\e(B' to avoid stacking.
+    ("E" . "-y")
+    ))
+
+(defconst tibetan-consonant-tibkey-alist nil)
+(defconst tibetan-subjoined-tibkey-alist nil)
+(defconst tibetan-vowel-tibkey-alist nil)
+(defconst tibetan-modifier-tibkey-alist nil)
+(defconst tibetan-non-stacking-tibkey-alist nil)
+
+(let ((type-list '("consonant" "subjoined" "vowel" "modifier" "non-stacking"))
+      (tail tibetan-tibkey-to-transcription-alist)
+      elt)
+  (while tail
+    (setq elt (car tail) tail (cdr tail))
+    (let ((types type-list)
+         type transcription trans-alist tibkey-alist)
+      (while types
+       (setq type (car types) types (cdr types))
+       (setq trans-alist
+             (if (string= type "non-stacking")
+                 'tibetan-wylie-non-stacking-alist
+               (intern (format "tibetan-%s-transcription-alist" type)))
+             transcription
+             (cdr (assoc (cdr elt) (symbol-value trans-alist))))
+       (when transcription
+         (setq tibkey-alist (intern (format "tibetan-%s-tibkey-alist" type)))
+         (set tibkey-alist
+              (cons (cons (car elt) transcription)
+                    (symbol-value tibkey-alist)))))
+      (or tibkey-alist
+         (error "No Tibetan transcription for %s" (cdr elt))))))
+
+(defconst tibetan-punctuation-tibkey-alist
+  '(("1" . "\e$(7!Q\e(B")
+    ("!" . "\e$(7!4\e(B")                ; nyi zla long
+    ("2" . "\e$(7!R\e(B")
+    ("@" . "\e$(7!5\e(B")                        ; nyi zla simple
+    ("3" . "\e$(7!S\e(B")
+;;; ("#" )
+    ("4" . "\e$(7!T\e(B")
+;;; ("$" )
+    ("5" . "\e$(7!U\e(B")
+    ("%" . "\e$(7!D\e(B")
+    ("6" . "\e$(7!V\e(B")
+    ("^" . "\e$(7!1\e(B")
+    ("7" . "\e$(7!W\e(B")
+    ("8" . "\e$(7!X\e(B")
+;;; ("*" ) ; avagraha, not supported yet
+    ("9" . "\e$(7!Y\e(B")
+    ("(" . "\e$(7!l\e(B")
+    ("0" . "\e$(7!P\e(B")
+    (")" . "\e$(7!m\e(B")
+;;; ("-" ) ; enphatic, not yet supported 
+;;; ("_" ) ; id.
+;;; ("=" ) ; special sign, not yet supported
+    ("+" . "\e$(7!A\e(B")
+    ("\\" . "\e$(7!?\e(B")
+    ("|" . "\e$(7!8\e(B")
+    ("I" . "\e$(7"f\e(B")                                ; avagraha
+    (":" . "\e$(7"`\e(B")
+;;; (">" ?\e$(7!;\e(B) ; to be assigned to SPC
+    (">" . " ")
+    ("?" . "\e$(7!=\e(B")
+    ("??" . "\e$(7!>\e(B")
+    ("????" . ["\e$(7!>\e(B \e$(7!>\e(B"])
+    (" " . "\e$(7!;\e(B")
+    ))
+
+;; Convert TibKey string to Tibetan-Roman transcription string.
+;; If there's no proper conversion, return nil.
+(defun quail-tibkey-to-transcription (tibkey)
+  (let ((len (length tibkey))
+       (i 0)
+       (trans-list nil))
+    (while (< i len)
+      (let ((last len)
+           trans)
+       (while (and (not trans) (> last i))
+         (or (setq trans (cdr (assoc (substring tibkey i last)
+                                     tibetan-tibkey-to-transcription-alist)))
+             (setq last (1- last))))
+       (if trans
+           (setq trans-list (cons trans trans-list)
+                 i last)
+         (setq trans-list nil i len))))
+    (apply 'concat (nreverse trans-list))))
+
+(defvar quail-tibkey-characters nil)
+
+(defun quail-tibkey-update-translation (control-flag)
+  (if (integerp control-flag)
+      ;; Non-composable-character typed.
+      (setq quail-current-str
+           (buffer-substring (overlay-start quail-overlay)
+                             (overlay-end quail-overlay))
+           unread-command-events
+           (string-to-list
+            (substring quail-current-key control-flag)))
+    (let ((transcription (quail-tibkey-to-transcription quail-current-key)))
+      (if (> (length transcription) 0)
+         (let ((quail-current-key transcription))
+           (setq control-flag
+                 (quail-tibetan-update-translation control-flag)))
+       (or quail-current-str
+           (setq quail-current-str quail-current-key)))))
+  control-flag)
+
+(quail-define-package "tibetan-tibkey" "Tibetan" "TIBt" t
+"Tibetan character input by TibKey key assignment.
+
+\(This implementation is still incomplete.
+ Therefore, the following key assignment is a provisional one.)
+
+  [NOT SHIFTED]
+
+  +-------------------------------------------------------+
+  |`\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|
+  +-------------------------------------------------------+
+     |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|
+     +-----------------------------------------------+
+      |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|
+      +---------------------------------------------+
+         |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|
+         +---------------------------------------+
+  The key 'h' is used for consonant stacking.
+
+  [SHIFTED]
+
+  +----------------------------------------------------------+
+  |~\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|
+  +----------------------------------------------------------+
+     |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|
+     +-----------------------------------------------+
+      |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|
+      +-------------------------------------------+
+         |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 |
+         +---------------------------------------+        
+
+  DIFFERENCE FROM THE ORIGINAL TIBKEY:
+
+    1. Vowel 'a' should be typed explicitly by the key 'A'.
+       This is really inconvenient. But to make the coding
+       scheme clear, it is desirable to have an explicite
+       vowel sign for 'a'.
+    2. Tsheg is assigned to SPC key. You can input a space
+       by typing '>'.
+    4. To avoid the default stacking \e$(7$B\e(B and to obtain \e$(7"#"B\e(B,
+       type 'E' instead of 'v' (=\e$(7"B\e(B).
+    3. There are many characters that are not supported in the
+       current implementation (especially special signs). I hope
+       I'll complete in a future revision.
+"
+ nil nil nil nil nil nil nil nil
+ 'quail-tibkey-update-translation)
+
+(quail-install-map
+ (quail-map-from-table
+  '((base-state (tibetan-consonant-tibkey-alist . s-state)
+               (tibetan-non-stacking-tibkey-alist . s-state)
+               tibetan-subjoined-tibkey-alist
+               tibetan-vowel-tibkey-alist
+               tibetan-modifier-tibkey-alist
+               tibetan-punctuation-tibkey-alist)
+    (s-state (tibetan-subjoined-tibkey-alist . s-state)
+            (tibetan-vowel-tibkey-alist . m-state))
+    (m-state tibetan-modifier-tibkey-alist))))