0616f08822e3c7492970f594107fb4774a60c514
[m17n/m17n-db.git] / MIM / vi-telex.mim
1 ;; vi-telex.mim -- Input method for Vietnames with TELEX key sequence
2 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007
3 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
4 ;;   Registration Number H15PRO112
5
6 ;; This file is part of the m17n database; a sub-part of the m17n
7 ;; library.
8
9 ;; The m17n library is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU Lesser General Public License
11 ;; as published by the Free Software Foundation; either version 2.1 of
12 ;; the License, or (at your option) any later version.
13
14 ;; The m17n library is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; Lesser General Public License for more details.
18
19 ;; You should have received a copy of the GNU Lesser General Public
20 ;; License along with the m17n library; if not, write to the Free
21 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 (input-method vi telex)
25
26 (description "Vietnames input method using the TELEX key sequence.
27 Typing Backslash ('\\') toggles the normal mode and English mode.
28 The following variables are customizable:
29   tone-mark-on-last: control tone mark position in equivocal cases
30   backspace-is-undo: control the action of Backspace key (delete or undo)")
31
32 (title "Ắ")
33
34 (variable
35  (tone-mark-on-last
36   "Flag to control tone mark position in equivocal cases.
37 If this variable is 0 (the default), put tone mark on the first vowel
38 in such equivocal cases as \"oa\", \"oe\", \"uy\".
39 Otherwise, put tone mark on the last vowel."
40   0 0 1)
41
42  (backspace-is-undo
43   "Flag to control the action of Backspace key (delete or undo).
44 If this variable is 0 (the default), Backspace key deletes the previous
45 character (e.g. \"q u a i s BS\" => \"quá\").
46 If the value is 1, Backspace key undoes the previous key
47 \(e.g. \"q u a i s BS\" => \"quai\")."
48   0 0 1))
49
50 (macro
51  (handle-mark
52   (delete @-)
53   ;; At first, cancel the tone mark if already put.
54   (move T) (select 0)
55   (move M)
56   (cond (V-3
57          ;; Tripple-vowel
58          ;; Put a tone mark on the last vowel if it is ê, or ơ.
59          ;; Otherwise put a tone mark on the second vowel.
60          (cond ((| (= V-1 ?ê) (= V-1 ?ơ) (= V-1 ?Ê) (= V-1 ?Ơ)))
61                (1 (move @-))))
62         (V-2
63          ;; Double-vowel
64          ;; Put a tone mark on the last vowel in the following cases:
65          ;;  * The last vowel is  â, ă, ê, ô, ơ, ư, or ư (i.e. non-ASCII).
66          ;;  * The initial consonant and the first vowel is "gi" or "qu".
67          ;;  * tone-mark-on-last is customized to 1 in such equivocal
68          ;;    cases as "oa", "oe", "oo", and "uy".
69          ;; Otherwise put a tone mark on the first vowel.
70          (cond ((| (> V-1 127)
71                    (& (| (= C ?g) (= C ?G)) (| (= V-2 ?i) (= V-2 ?I)))
72                    (& (| (= C ?q) (= C ?Q)) (| (= V-2 ?u) (= V-2 ?U)))
73                    (& (| tone-mark-on-last C-AFTER-V)
74                       (| (& (| (= V-2 ?o) (= V-2 ?O))
75                             (| (= V-1 ?a) (= V-1 ?A) (= V-1 ?e) (= V-1 ?E)
76                                (= V-1 ?o) (= V-1 ?O)))
77                          (& (| (= V-2 ?u) (= V-2 ?U))
78                             (| (= V-1 ?y) (= V-1 ?Y)))))))
79                (1 (move @-)))))
80   (select SELECT)
81   (mark T)
82   (move @>)))
83
84 (map
85  (vowel  ; sfrxj
86   ("a"  ("aáàảãạ")) ("A"  ("AÁÀẢÃẠ"))
87   ("e"  ("eéèẻẽẹ")) ("E"  ("EÉÈẺẼẸ"))
88   ("i"  ("iíìỉĩị")) ("I"  ("IÍÌỈĨỊ"))
89   ("o"  ("oóòỏõọ")) ("O"  ("OÓÒỎÕỌ"))
90   ("u"  ("uúùủũụ")) ("U"  ("UÚÙỦŨỤ"))
91   ("y"  ("yýỳỷỹỵ")) ("Y"  ("YÝỲỶỸỴ"))
92   ("aa" ("âấầẩẫậ")) ("AA" ("ÂẤẦẨẪẬ")) ("Aa" ("ÂẤẦẨẪẬ"))
93   ("aw" ("ăắằẳẵặ")) ("AW" ("ĂẮẰẲẴẶ")) ("Aw" ("ĂẮẰẲẴẶ"))
94   ("ee" ("êếềểễệ")) ("EE" ("ÊẾỀỂỄỆ")) ("Ee" ("ÊẾỀỂỄỆ"))
95   ("oo" ("ôốồổỗộ")) ("OO" ("ÔỐỒỔỖỘ")) ("Oo" ("ÔỐỒỔỖỘ"))
96   ("ow" ("ơớờởỡợ")) ("OW" ("ƠỚỜỞỠỢ")) ("Ow" ("ƠỚỜỞỠỢ"))
97   ("uw" ("ưứừửữự")) ("UW" ("ƯỨỪỬỮỰ")) ("Uw" ("ƯỨỪỬỮỰ"))
98   ("w"  ("ưứừửữự")) ("W"  ("ƯỨỪỬỮỰ"))
99   ("ooo" ("oóòỏõọ") ("oóòỏõọ") (set V-2 V-1) (set V-1 ?o))
100   ("OOO" ("OÓÒỎÕỌ") ("OÓÒỎÕỌ") (set V-2 V-1) (set V-1 ?O))
101   ("Ooo" ("OÓÒỎÕỌ") ("oóòỏõọ") (set V-2 V-1) (set V-1 ?O)))
102
103  (tone-mark
104   ("z" (set SELECT 0) ?z) ("Z" (set SELECT 0) ?Z)
105   ("s" (set SELECT 1) ?s) ("S" (set SELECT 1) ?S)
106   ("f" (set SELECT 2) ?f) ("F" (set SELECT 2) ?F)
107   ("r" (set SELECT 3) ?r) ("R" (set SELECT 3) ?R)
108   ("x" (set SELECT 4) ?x) ("X" (set SELECT 4) ?X)
109   ("j" (set SELECT 5) ?j) ("J" (set SELECT 5) ?J))
110
111  (consonant-or-tone-mark
112   ("z" ?z) ("s" ?s) ("f" ?f) ("r" ?r) ("x" ?x) ("j" ?j)
113   ("Z" ?Z) ("S" ?S) ("F" ?F) ("R" ?R) ("X" ?X) ("J" ?J))
114
115  (consonant
116   ("b" ?b) ("c" ?c) ("d" ?d) ("g" ?g) ("h" ?h) ("k" ?k) ("l" ?l) ("m" ?m)
117   ("n" ?n) ("p" ?p) ("q" ?q) ("t" ?t) ("v" ?v)
118   ("dd" ?đ)
119   ("B" ?B) ("C" ?C) ("D" ?D) ("G" ?G) ("H" ?H) ("K" ?K) ("L" ?L) ("M" ?M)
120   ("N" ?N) ("P" ?P) ("Q" ?Q) ("T" ?T) ("V" ?V)
121   ("DD" ?Đ) ("Dd" ?Đ))
122
123  (temporary-escape
124   ("aaa" "aa") ("AAA" "AA") ("Aaa" "Aa")
125   ("eee" "ee") ("EEE" "EE") ("Eee" "Ee")
126   ("ddd" "dd") ("DDD" "DD") ("Ddd" "Dd")
127   ("ww" ?w) ("WW" ?W) ("Ww" ?W)
128   ("zz" ?z) ("ZZ" ?Z) ("Zz" ?Z)
129   ("ss" ?s) ("SS" ?S) ("Ss" ?S)
130   ("ff" ?f) ("FF" ?F) ("Ff" ?F)
131   ("rr" ?r) ("RR" ?R) ("Rr" ?R)
132   ("xx" ?x) ("XX" ?X) ("Xx" ?X)
133   ("jj" ?j) ("JJ" ?J) ("Jj" ?J))
134
135  (alphabet
136   ("a" ?a) ("b" ?b) ("c" ?c) ("d" ?d) ("e" ?e) ("f" ?f) ("g" ?g) 
137   ("h" ?h) ("i" ?i) ("j" ?j) ("k" ?k) ("l" ?l) ("m" ?m) ("n" ?n)
138   ("o" ?o) ("p" ?p) ("q" ?q) ("r" ?r) ("s" ?s) ("t" ?t) ("u" ?u)
139   ("v" ?v) ("w" ?w) ("x" ?x) ("y" ?y) ("z" ?z)
140   ("A" ?A) ("B" ?B) ("C" ?C) ("D" ?D) ("E" ?E) ("F" ?F) ("G" ?G) 
141   ("H" ?H) ("I" ?I) ("J" ?J) ("K" ?K) ("L" ?L) ("M" ?M) ("N" ?N)
142   ("O" ?O) ("P" ?P) ("Q" ?Q) ("R" ?R) ("S" ?S) ("T" ?T) ("U" ?U)
143   ("V" ?V) ("W" ?W) ("X" ?X) ("Y" ?Y) ("Z" ?Z))
144
145  (permanent-escape
146   ("\\"))
147
148  (backspace
149   ((BackSpace) (cond (backspace-is-undo (undo))))))
150
151 (state
152  (init
153   ;; Initialize variables.  C is the initial consonant.  V-N is the
154   ;; (N-1)th vowel from the last.  C-AFTER-V is a number of consonants
155   ;; typed after vowel.
156   (t (set C @-1) (set V-1 0) (set V-2 0) (set V-3 0) (set C-AFTER-V 0))
157
158   (consonant (set C @-1))
159   (consonant-or-tone-mark (set C @-1))
160
161   ;; Mark M remembers the preedit position after the last vowel.
162   (vowel (mark M) (set V-2 V-1) (set V-1 @-1) (shift after-v))
163   (temporary-escape (shift temporary-escape))
164   (permanent-escape (shift escape-in-normal-mode)))
165
166  ;; The state shifted to when a vowel is typed.
167  (after-v
168   (consonant (shift after-vc))
169   (vowel (mark M) (set V-3 V-2) (set V-2 V-1) (set V-1 @-1))
170   (consonant-or-tone-mark (delete @-) (pushback 1) (shift after-t))
171   (backspace (delete @-)
172              (cond (V-3 (set V-1 V-2) (set V-2 V-3) (set V-3 0))
173                    (V-2 (set V-1 V-2) (set V-2 0))
174                    (1 (shift init)))))
175
176  ;; The state shifted to when a consonant is typed after a vowel.
177  (after-vc
178   (t (set C-AFTER-V 1))
179   (consonant (add C-AFTER-V 1))
180   (consonant-or-tone-mark (delete @-) (pushback 1) (shift after-t))
181   (backspace (delete @-)
182              (sub C-AFTER-V 1)
183              (cond ((= C-AFTER-V 0) (shift after-v)))))
184
185  ;; The state shifted to when a tone-mark is typed.
186  (after-t
187   (t (set CURRENT-SELECT -1))
188   (tone-mark (cond ((= CURRENT-SELECT SELECT) (move T) (select 0) (move @>)
189                     (shift temporary-escape))
190                    (1 (handle-mark) (set CURRENT-SELECT SELECT))))
191   (nil (cond (C-AFTER-V (shift after-vc))
192              (1 (shift after-v)))))
193
194  (temporary-escape
195   "en"
196   (t (commit))
197   (alphabet (commit)))
198
199  (escape-in-normal-mode
200   "EN"
201   (permanent-escape (insert "\\") (shift init))
202   ;; Any other key force shifting to permanent-escape.
203   (nil (shift permanent-escape)))
204
205  (permanent-escape
206   "EN"
207   (t (set ESCAPE 1))
208   (permanent-escape (shift escape-in-permanent-escape))
209   ;; Unhandle any characters.
210   (nil (unhandle)))
211
212  (escape-in-permanent-escape
213   "Ắ"
214   (permanent-escape (insert "\\") (commit) (shift permanent-escape))
215   ;; Any other key force shifting to init
216   ))
217
218 ;; Local Variables:
219 ;; coding: utf-8
220 ;; mode: emacs-lisp
221 ;; End: