(handle-mark): Don't delte the previous
[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   ;; At first, cancel the tone mark if already put.
53   (move T) (select 0)
54   (move M)
55   (cond (V-3
56          ;; Tripple-vowel
57          ;; Put a tone mark on the last vowel if it is ê, or ơ.
58          ;; Otherwise put a tone mark on the second vowel.
59          (cond ((| (= V-1 ?ê) (= V-1 ?ơ) (= V-1 ?Ê) (= V-1 ?Ơ)))
60                (1 (move @-))))
61         (V-2
62          ;; Double-vowel
63          ;; Put a tone mark on the last vowel in the following cases:
64          ;;  * The last vowel is  â, ă, ê, ô, ơ, ư, or ư (i.e. non-ASCII).
65          ;;  * The initial consonant and the first vowel is "gi" or "qu".
66          ;;  * tone-mark-on-last is customized to 1 in such equivocal
67          ;;    cases as "oa", "oe", "oo", and "uy".
68          ;; Otherwise put a tone mark on the first vowel.
69          (cond ((| (> V-1 127)
70                    (& (| (= C ?g) (= C ?G)) (| (= V-2 ?i) (= V-2 ?I)))
71                    (& (| (= C ?q) (= C ?Q)) (| (= V-2 ?u) (= V-2 ?U)))
72                    (& (| tone-mark-on-last (> C-AFTER-V))
73                       (| (& (| (= V-2 ?o) (= V-2 ?O))
74                             (| (= V-1 ?a) (= V-1 ?A) (= V-1 ?e) (= V-1 ?E)
75                                (= V-1 ?o) (= V-1 ?O)))
76                          (& (| (= V-2 ?u) (= V-2 ?U))
77                             (| (= V-1 ?y) (= V-1 ?Y)))))))
78                (1 (move @-)))))
79   (select SELECT)
80   (mark T)
81   (move @>)))
82
83 (map
84  (vowel  ; sfrxj
85   ("a"  ("aáàảãạ")) ("A"  ("AÁÀẢÃẠ"))
86   ("e"  ("eéèẻẽẹ")) ("E"  ("EÉÈẺẼẸ"))
87   ("i"  ("iíìỉĩị")) ("I"  ("IÍÌỈĨỊ"))
88   ("o"  ("oóòỏõọ")) ("O"  ("OÓÒỎÕỌ"))
89   ("u"  ("uúùủũụ")) ("U"  ("UÚÙỦŨỤ"))
90   ("y"  ("yýỳỷỹỵ")) ("Y"  ("YÝỲỶỸỴ"))
91   ("aa" ("âấầẩẫậ")) ("AA" ("ÂẤẦẨẪẬ")) ("Aa" ("ÂẤẦẨẪẬ"))
92   ("aw" ("ăắằẳẵặ")) ("AW" ("ĂẮẰẲẴẶ")) ("Aw" ("ĂẮẰẲẴẶ"))
93   ("ee" ("êếềểễệ")) ("EE" ("ÊẾỀỂỄỆ")) ("Ee" ("ÊẾỀỂỄỆ"))
94   ("oo" ("ôốồổỗộ")) ("OO" ("ÔỐỒỔỖỘ")) ("Oo" ("ÔỐỒỔỖỘ"))
95   ("ow" ("ơớờởỡợ")) ("OW" ("ƠỚỜỞỠỢ")) ("Ow" ("ƠỚỜỞỠỢ"))
96   ("uw" ("ưứừửữự")) ("UW" ("ƯỨỪỬỮỰ")) ("Uw" ("ƯỨỪỬỮỰ"))
97   ("w"  ("ưứừửữự")) ("W"  ("ƯỨỪỬỮỰ"))
98   ("ooo" ("oóòỏõọ") ("oóòỏõọ") (set V-2 V-1) (set V-1 ?o))
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
102  (tone-mark
103   ("z" (set SELECT 0) ?z) ("Z" (set SELECT 0) ?Z)
104   ("s" (set SELECT 1) ?s) ("S" (set SELECT 1) ?S)
105   ("f" (set SELECT 2) ?f) ("F" (set SELECT 2) ?F)
106   ("r" (set SELECT 3) ?r) ("R" (set SELECT 3) ?R)
107   ("x" (set SELECT 4) ?x) ("X" (set SELECT 4) ?X)
108   ("j" (set SELECT 5) ?j) ("J" (set SELECT 5) ?J))
109
110  (consonant-or-tone-mark
111   ("z" ?z) ("s" ?s) ("f" ?f) ("r" ?r) ("x" ?x) ("j" ?j)
112   ("Z" ?Z) ("S" ?S) ("F" ?F) ("R" ?R) ("X" ?X) ("J" ?J))
113
114  (consonant
115   ("b" ?b) ("c" ?c) ("d" ?d) ("g" ?g) ("h" ?h) ("k" ?k) ("l" ?l) ("m" ?m)
116   ("n" ?n) ("p" ?p) ("q" ?q) ("t" ?t) ("v" ?v)
117   ("dd" ?đ)
118   ("B" ?B) ("C" ?C) ("D" ?D) ("G" ?G) ("H" ?H) ("K" ?K) ("L" ?L) ("M" ?M)
119   ("N" ?N) ("P" ?P) ("Q" ?Q) ("T" ?T) ("V" ?V)
120   ("DD" ?Đ) ("Dd" ?Đ))
121
122  (temporary-escape
123   ("aaa" "aa") ("AAA" "AA") ("Aaa" "Aa")
124   ("eee" "ee") ("EEE" "EE") ("Eee" "Ee")
125   ("ddd" "dd") ("DDD" "DD") ("Ddd" "Dd")
126   ("ww" ?w) ("WW" ?W) ("Ww" ?W)
127   ("zz" ?z) ("ZZ" ?Z) ("Zz" ?Z)
128   ("ss" ?s) ("SS" ?S) ("Ss" ?S)
129   ("ff" ?f) ("FF" ?F) ("Ff" ?F)
130   ("rr" ?r) ("RR" ?R) ("Rr" ?R)
131   ("xx" ?x) ("XX" ?X) ("Xx" ?X)
132   ("jj" ?j) ("JJ" ?J) ("Jj" ?J))
133
134  (alphabet
135   ("a" ?a) ("b" ?b) ("c" ?c) ("d" ?d) ("e" ?e) ("f" ?f) ("g" ?g) 
136   ("h" ?h) ("i" ?i) ("j" ?j) ("k" ?k) ("l" ?l) ("m" ?m) ("n" ?n)
137   ("o" ?o) ("p" ?p) ("q" ?q) ("r" ?r) ("s" ?s) ("t" ?t) ("u" ?u)
138   ("v" ?v) ("w" ?w) ("x" ?x) ("y" ?y) ("z" ?z)
139   ("A" ?A) ("B" ?B) ("C" ?C) ("D" ?D) ("E" ?E) ("F" ?F) ("G" ?G) 
140   ("H" ?H) ("I" ?I) ("J" ?J) ("K" ?K) ("L" ?L) ("M" ?M) ("N" ?N)
141   ("O" ?O) ("P" ?P) ("Q" ?Q) ("R" ?R) ("S" ?S) ("T" ?T) ("U" ?U)
142   ("V" ?V) ("W" ?W) ("X" ?X) ("Y" ?Y) ("Z" ?Z))
143
144  (permanent-escape
145   ("\\"))
146
147  (backspace
148   ((BackSpace) (cond (backspace-is-undo (undo))))))
149
150 (state
151  (init
152   ;; Initialize variables.  C is the initial consonant.  V-N is the
153   ;; (N-1)th vowel from the last.  C-AFTER-V is a number of consonants
154   ;; typed after vowel.
155   (t (set C @-1) (set V-1 0) (set V-2 0) (set V-3 0) (set C-AFTER-V 0))
156
157   (consonant (set C @-1))
158   (consonant-or-tone-mark (set C @-1))
159
160   ;; Mark M remembers the preedit position after the last vowel.
161   (vowel (mark M) (set V-2 V-1) (set V-1 @-1) (shift after-v))
162   (temporary-escape (shift temporary-escape))
163   (permanent-escape (shift escape-in-normal-mode)))
164
165  ;; The state shifted to when a vowel is typed.
166  (after-v
167   (consonant (shift after-vc))
168   (vowel (mark M) (set V-3 V-2) (set V-2 V-1) (set V-1 @-1)
169          (move T) (select 0) (handle-mark) (move M))
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 (delete @-) (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: