(thai-keyboard-mapping-alist): Some entry corrected.
[bpt/emacs.git] / leim / quail / thai.el
1 ;;; quail/thai.el --- Quail package for inputting Thai characters
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5
6 ;; Keywords: multilingual, input method, Thai
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'quail)
28 (require 'thai-util)
29
30 (eval-and-compile
31
32 (defvar thai-keyboard-mapping-alist
33 '((kesmanee
34 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; control codes
35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; control codes
36 0 "#" "\e,TF\e(B" "\e,Tr\e(B" "\e,Ts\e(B" "\e,Tt\e(B" "\e0\e,TQi\e1\e(B" "\e,T'\e(B" ; SPC .. '
37 "\e,Tv\e(B" "\e,Tw\e(B" "\e,Tu\e(B" "\e,Ty\e(B" "\e,TA\e(B" "\e,T"\e(B" "\e,Tc\e(B" "\e,T=\e(B" ; ( .. /
38 "\e,T(\e(B" "\e,TE\e(B" "/" "_" "\e,T@\e(B" "\e,T6\e(B" "\e,TX\e(B" "\e,TV\e(B" ; 0 .. 7
39 "\e,T$\e(B" "\e,T5\e(B" "\e,T+\e(B" "\e,TG\e(B" "\e,T2\e(B" "\e,T*\e(B" "\e,TL\e(B" "\e,TF\e(B" ; 8 .. ?
40 "\e,Tq\e(B" "\e,TD\e(B" "\e,TZ\e(B" "\e,T)\e(B" "\e,T/\e(B" "\e,T.\e(B" "\e,Tb\e(B" "\e,T,\e(B" ; @ .. G
41 "\e,Tg\e(B" "\e,T3\e(B" "\e,Tk\e(B" "\e,TI\e(B" "\e,TH\e(B" "\e,Tn\e(B" "\e,Tl\e(B" "\e,TO\e(B" ; H .. O
42 "\e,T-\e(B" "\e,Tp\e(B" "\e,T1\e(B" "\e,T&\e(B" "\e,T8\e(B" "\e,Tj\e(B" "\e,TN\e(B" "\"" ; P .. W
43 ")" "\e,Tm\e(B" "(" "\e,T:\e(B" "\e,T_\e(B" "\e,TE\e(B" "\e,TY\e(B" "\e,Tx\e(B" ; X .. _
44 "\e,T#\e(B" "\e,T?\e(B" "\e,TT\e(B" "\e,Ta\e(B" "\e,T!\e(B" "\e,TS\e(B" "\e,T4\e(B" "\e,T`\e(B" ; ` .. g
45 "\e,Ti\e(B" "\e,TC\e(B" "\e,Th\e(B" "\e,TR\e(B" "\e,TJ\e(B" "\e,T7\e(B" "\e,TW\e(B" "\e,T9\e(B" ; h .. o
46 "\e,TB\e(B" "\e,Tf\e(B" "\e,T>\e(B" "\e,TK\e(B" "\e,TP\e(B" "\e,TU\e(B" "\e,TM\e(B" "\e,Td\e(B" ; p .. w
47 "\e,T;\e(B" "\e,TQ\e(B" "\e,T<\e(B" "\e,T0\e(B" "\e,To\e(B" "." "\e,T%\e(B" 0] ; x .. DEL
48 nil nil)
49
50 (pattachote
51 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; control codes
52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; control codes
53 0 "+" "\e,T1\e(B" "/" "," "?" "_" "\e,T"\e(B" ; SPC .. '
54 "(" ")" "." "%" "\e,TP\e(B" "\e,Tq\e(B" "\e,T(\e(B" "\e,T>\e(B" ; ( .. /
55 "\e,Tp\e(B" "=" "\e,Tr\e(B" "\e,Ts\e(B" "\e,Tt\e(B" "\e,Tu\e(B" "\e,TY\e(B" "\e,Tw\e(B" ; 0 .. 7
56 "\e,Tx\e(B" "\e,Ty\e(B" "\e,T&\e(B" "\e,Td\e(B" "\e,T?\e(B" "\e,Tv\e(B" "\e,T2\e(B" "\e,TL\e(B" ; 8 .. ?
57 "\"" "\e,Tk\e(B" "\e,TQ\e(B" "\e,T0\e(B" "\e,TS\e(B" "\e,Tf\e(B" "\e,T3\e(B" "\e,Tl\e(B" ; @ .. G
58 "\e,TW\e(B" "\e,T+\e(B" "\e,T<\e(B" "\e,T*\e(B" "\e,Tb\e(B" "\e,TN\e(B" "\e,TH\e(B" "\e,T6\e(B" ; H .. O
59 "\e,T2\e(B" "\e,Tj\e(B" "\e,T-\e(B" "\e,T8\e(B" "\e,TI\e(B" "\e,T=\e(B" "\e,T@\e(B" "\e,TD\e(B" ; P .. W
60 "\e,T.\e(B" "\e,TV\e(B" "\e,T.\e(B" "\e,Tc\e(B" "\e,TZ\e(B" "\e,T2\e(B" "\e,TX\e(B" "-" ; X .. _
61 "\e,T#\e(B" "\e,Ti\e(B" "\e,TT\e(B" "\e,TE\e(B" "\e,T'\e(B" "\e,TB\e(B" "\e,T!\e(B" "\e,TQ\e(B" ; ` .. g
62 "\e,TU\e(B" "\e,TA\e(B" "\e,TR\e(B" "\e,T9\e(B" "\e,T`\e(B" "\e,TJ\e(B" "\e,T$\e(B" "\e,TG\e(B" ; h .. o
63 "\e,Ta\e(B" "\e,Tg\e(B" "\e,TM\e(B" "\e,T7\e(B" "\e,TC\e(B" "\e,T4\e(B" "\e,TK\e(B" "\e,T5\e(B" ; p .. w
64 "\e,T;\e(B" "\e,Th\e(B" "\e,T:\e(B" "\e,TO\e(B" "\e,Tm\e(B" "\e,TF\e(B" "\e,T%\e(B" 0] ; x .. DEL
65 nil nil)
66 )
67 "Alist of Thai keyboard types vs. corresponding mapping tables.
68 Each element is a list of:
69 KEYBOARD-TYPE, ASCII-THAI-TABLE, CONSONANT-MAP-TEMPLATE,
70 and VOWEL-UPPER-LOWER-TEMPLATE.
71
72 KEYBOARD-TYPE is a symbol, one of kesmanee or pattachote.
73
74 ASCII-THAI-TABLE is a vector indexed by an ASCII key code
75 and the value is the one-char string of Thai character
76 assigned at the location of ASCII key on the specific Thai keyboard.
77 The value is 0 if no Thai character is assigned at the location.
78
79 CONSONANT-MAP-TEMPLATE is a template of a cdr part of a Quail map when
80 a consonant is entered.
81
82 VOWEL-UPPER-LOWER-TEMPLATE is a template of a cdr part of a Quail map
83 when a vowel upper or a vowel lower is entered.")
84
85 (defmacro thai-keyboard-info (keyboard-type)
86 `(assq ,keyboard-type thai-keyboard-mapping-alist))
87
88 )
89
90 (defvar thai-current-keyboard-type nil
91 "Thai Keyboard type which Quail is assuming currently.
92 This variable is used in Quail internally only.")
93
94 ;; Template of a cdr part of a Quail map when a consonant is entered.
95 (defvar thai-consonant-alist nil)
96 ;; Template of a cdr part of a Quail map when a vowel upper or a vowel
97 ;; lower is entered.
98 (defvar thai-vowel-upper-lower-alist nil)
99
100 ;; Return a Quail map corresponding to KEY of length LEN.
101 ;; The car part of the map is a translation generated automatically.
102 ;; The cdr part of the map is a copy of ALIST.
103 (defun thai-generate-quail-map (key len alist)
104 (let ((str "")
105 (idx 0))
106 (while (< idx len)
107 (setq str (concat str (aref (nth 1 (thai-keyboard-info
108 thai-current-keyboard-type))
109 (aref key idx)))
110 idx (1+ idx)))
111 (cons (string-to-char (compose-string str)) (copy-alist alist))))
112
113 ;; Return a Quail map corresponding to KEY of length LEN when Thai
114 ;; tone mark is entered.
115 (defun thai-tone-input (key len)
116 (thai-generate-quail-map key len nil))
117
118 ;; Return a Quail map corresponding to KEY of length LEN when Thai
119 ;; vowel upper or vowel lower is entered.
120 (defun thai-vowel-upper-lower-input (key len)
121 (thai-generate-quail-map
122 key len
123 (nth 3 (thai-keyboard-info thai-current-keyboard-type))))
124
125 ;; Define RULES in Quail map. In addition, create
126 ;; `thai-consonant-alist-KEYBOARD-TYPE' and
127 ;; `thai-vowel-upper-lower-alist-KEYBOARD-TYPE'.
128
129 ;; The general composing rules are as follows:
130 ;;
131 ;; T
132 ;; V T V T
133 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
134 ;; v v
135 ;;
136 ;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
137
138 (defmacro thai-quail-define-rules (keyboard-type &rest rules)
139 (let ((l rules)
140 consonant-alist
141 vowel-upper-lower-alist
142 rule trans ch c-set)
143 (while l
144 (setq rule (car l))
145 (setq trans (nth 1 rule))
146 (if (consp trans)
147 (setq trans (car trans)))
148 (setq c-set (char-category-set (string-to-char trans)))
149 (cond ((or (aref c-set ?2)
150 (aref c-set ?3))
151 (setq consonant-alist
152 (cons (cons (string-to-char (car rule))
153 'thai-vowel-upper-lower-input)
154 consonant-alist)))
155 ((aref c-set ?4)
156 (setq consonant-alist
157 (cons (cons (string-to-char (car rule))
158 'thai-tone-input)
159 consonant-alist)
160 vowel-upper-lower-alist
161 (cons (cons (string-to-char (car rule))
162 'thai-tone-input)
163 vowel-upper-lower-alist))))
164 (setq l (cdr l)))
165 `(progn
166 (quail-define-rules ,@rules)
167 (setcar (nthcdr 2 (thai-keyboard-info ,keyboard-type))
168 ',consonant-alist)
169 (setcar (nthcdr 3 (thai-keyboard-info ,keyboard-type))
170 ',vowel-upper-lower-alist))))
171
172 ;; Return an alist which can be a cdr part of a Quail map
173 ;; corresponding to the current key when Thai consonant is entered.
174 (defun thai-consonant-input (key len)
175 (let ((quail-package-name (quail-name)))
176 (setq thai-current-keyboard-type
177 (cond ((string= quail-package-name "thai-pattachote") 'pattachote)
178 ((string= quail-package-name "thai-kesmanee") 'kesmanee)
179 (t (error "Invalid Quail package %s" quail-package-name))))
180 (copy-alist (nth 2 (thai-keyboard-info thai-current-keyboard-type)))))
181 \f
182 ;; Thai Kesmanee keyboard support.
183
184 (quail-define-package
185 "thai-kesmanee" "Thai" "\e,T!!\e(B>" t
186 "Thai Kesmanee input method with TIS620 keyboard layout
187
188 The difference from the ordinal Thai keyboard:
189 '\e,T_\e(B' and '\e,To\e(B' are assigned to '\\' and '|' respectively,
190 '\e,T#\e(B' and '\e,T%\e(B' are assigned to '`' and '~' respectively,
191 Don't know where to assign characters '\e,Tz\e(B' and '\e,T{\e(B'."
192 nil t t nil t)
193
194 (thai-quail-define-rules 'kesmanee
195 ("1" ("\e,TE\e(B" . thai-consonant-input))
196 ("!" "#")
197 ("2" "/")
198 ("@" "\e,Tq\e(B")
199 ("3" "_")
200 ("#" "\e,Tr\e(B")
201 ("4" ("\e,T@\e(B" . thai-consonant-input))
202 ("$" "\e,Ts\e(B")
203 ("5" ("\e,T6\e(B" . thai-consonant-input))
204 ("%" "\e,Tt\e(B")
205 ("6" "\e,TX\e(B")
206 ("^" "\e,TY\e(B")
207 ("7" "\e,TV\e(B")
208 ("&" "\e0\e,TQi\e1\e(B")
209 ("8" ("\e,T$\e(B" . thai-consonant-input))
210 ("*" "\e,Tu\e(B")
211 ("9" ("\e,T5\e(B" . thai-consonant-input))
212 ("\(" "\e,Tv\e(B")
213 ("0" ("\e,T(\e(B" . thai-consonant-input))
214 ("\)" "\e,Tw\e(B")
215 ("-" ("\e,T"\e(B" . thai-consonant-input))
216 ("_" "\e,Tx\e(B")
217 ("=" ("\e,T*\e(B" . thai-consonant-input))
218 ("+" "\e,Ty\e(B")
219 ("\\" "\e,T_\e(B")
220 ("|" "\e,To\e(B")
221 ("`" ("\e,T#\e(B" . thai-consonant-input))
222 ("~" ("\e,T%\e(B" . thai-consonant-input))
223 ("q" "\e,Tf\e(B")
224 ("Q" "\e,Tp\e(B")
225 ("w" "\e,Td\e(B")
226 ("W" "\"")
227 ("e" "\e,TS\e(B")
228 ("E" ("\e,T.\e(B" . thai-consonant-input))
229 ("r" ("\e,T>\e(B" . thai-consonant-input))
230 ("R" ("\e,T1\e(B" . thai-consonant-input))
231 ("t" "\e,TP\e(B")
232 ("T" ("\e,T8\e(B" . thai-consonant-input))
233 ("y" "\e,TQ\e(B")
234 ("Y" "\e,Tm\e(B")
235 ("u" "\e,TU\e(B")
236 ("U" "\e,Tj\e(B")
237 ("i" ("\e,TC\e(B" . thai-consonant-input))
238 ("I" ("\e,T3\e(B" . thai-consonant-input))
239 ("o" ("\e,T9\e(B" . thai-consonant-input))
240 ("O" "\e,TO\e(B")
241 ("p" ("\e,TB\e(B" . thai-consonant-input))
242 ("P" ("\e,T-\e(B" . thai-consonant-input))
243 ("\[" ("\e,T:\e(B" . thai-consonant-input))
244 ("{" ("\e,T0\e(B" . thai-consonant-input))
245 ("\]" ("\e,TE\e(B" . thai-consonant-input))
246 ("}" ",")
247
248 ("a" ("\e,T?\e(B" . thai-consonant-input))
249 ("A" "\e,TD\e(B")
250 ("s" ("\e,TK\e(B" . thai-consonant-input))
251 ("S" ("\e,T&\e(B" . thai-consonant-input))
252 ("d" ("\e,T!\e(B" . thai-consonant-input))
253 ("D" ("\e,T/\e(B" . thai-consonant-input))
254 ("f" ("\e,T4\e(B" . thai-consonant-input))
255 ("F" "\e,Tb\e(B")
256 ("g" "\e,T`\e(B")
257 ("G" ("\e,T,\e(B" . thai-consonant-input))
258 ("h" "\e,Ti\e(B")
259 ("H" "\e,Tg\e(B")
260 ("j" "\e,Th\e(B")
261 ("J" "\e,Tk\e(B")
262 ("k" "\e,TR\e(B")
263 ("K" ("\e,TI\e(B" . thai-consonant-input))
264 ("l" ("\e,TJ\e(B" . thai-consonant-input))
265 ("L" ("\e,TH\e(B" . thai-consonant-input))
266 ("\;" ("\e,TG\e(B" . thai-consonant-input))
267 (":" ("\e,T+\e(B" . thai-consonant-input))
268 ("'" ("\e,T'\e(B" . thai-consonant-input))
269 ("\"" ".")
270
271 ("z" ("\e,T<\e(B" . thai-consonant-input))
272 ("Z" "(")
273 ("x" ("\e,T;\e(B" . thai-consonant-input))
274 ("X" ")")
275 ("c" "\e,Ta\e(B")
276 ("C" ("\e,T)\e(B" . thai-consonant-input))
277 ("v" ("\e,TM\e(B" . thai-consonant-input))
278 ("V" ("\e,TN\e(B" . thai-consonant-input))
279 ("b" "\e,TT\e(B")
280 ("B" "\e,TZ\e(B")
281 ("n" "\e,TW\e(B")
282 ("N" "\e,Tl\e(B")
283 ("m" ("\e,T7\e(B" . thai-consonant-input))
284 ("M" "\e,Tn\e(B")
285 ("," ("\e,TA\e(B" . thai-consonant-input))
286 ("<" ("\e,T2\e(B" . thai-consonant-input))
287 ("." "\e,Tc\e(B")
288 (">" ("\e,TL\e(B" . thai-consonant-input))
289 ("/" ("\e,T=\e(B" . thai-consonant-input))
290 ("?" "\e,TF\e(B")
291 )
292
293 \f
294 ;; Thai Pattachote keyboard support.
295
296 (quail-define-package
297 "thai-pattachote" "Thai" "\e,T!;\e(B>" t
298 "Thai Pattachote input method with TIS620 keyboard layout"
299 nil t t nil t)
300
301 (thai-quail-define-rules 'pattachote
302 ("1" "=")
303 ("!" "+")
304 ("2" "\e,Tr\e(B")
305 ("@" "\"")
306 ("3" "\e,Ts\e(B")
307 ("#" "/")
308 ("4" "\e,Tt\e(B")
309 ("$" ",")
310 ("5" "\e,Tu\e(B")
311 ("%" "?")
312 ("6" "\e,TY\e(B")
313 ("^" "\e,TX\e(B")
314 ("7" "\e,Tw\e(B")
315 ("&" "_")
316 ("8" "\e,Tx\e(B")
317 ("*" ".")
318 ("9" "\e,Ty\e(B")
319 ("(" "(")
320 ("0" "\e,Tp\e(B")
321 (")" ")")
322 ("-" "\e,Tq\e(B")
323 ("_" "-")
324 ("=" "\e,Tv\e(B")
325 ("+" "%")
326 ("\\" "\e,TZ\e(B")
327 ("|" "\e,Tm\e(B")
328 ("`" ("\e,T#\e(B" . thai-consonant-input))
329 ("~" ("\e,T%\e(B" . thai-consonant-input))
330
331 ("q" "\e,Tg\e(B")
332 ("Q" "\e,Tj\e(B")
333 ("w" ("\e,T5\e(B" . thai-consonant-input))
334 ("W" "\e,TD\e(B")
335 ("e" ("\e,TB\e(B" . thai-consonant-input))
336 ("E" "\e,Tf\e(B")
337 ("r" ("\e,TM\e(B" . thai-consonant-input))
338 ("R" ("\e,T-\e(B" . thai-consonant-input))
339 ("t" ("\e,TC\e(B" . thai-consonant-input))
340 ("T" ("\e,TI\e(B" . thai-consonant-input))
341 ("y" "\e,Th\e(B")
342 ("Y" "\e,TV\e(B")
343 ("u" ("\e,T4\e(B" . thai-consonant-input))
344 ("U" ("\e,T=\e(B" . thai-consonant-input))
345 ("i" ("\e,TA\e(B" . thai-consonant-input))
346 ("I" ("\e,T+\e(B" . thai-consonant-input))
347 ("o" ("\e,TG\e(B" . thai-consonant-input))
348 ("O" ("\e,T6\e(B" . thai-consonant-input))
349 ("p" "\e,Ta\e(B")
350 ("P" ("\e,T2\e(B" . thai-consonant-input))
351 ("\[" "\e,Tc\e(B")
352 ("{" "\e,TO\e(B")
353 ("\]" ("\e,T2\e(B" . thai-consonant-input))
354 ("}" "\e,TF\e(B")
355
356 ("a" "\e,Ti\e(B")
357 ("A" "\e,Tk\e(B")
358 ("s" ("\e,T7\e(B" . thai-consonant-input))
359 ("S" ("\e,T8\e(B" . thai-consonant-input))
360 ("d" ("\e,T'\e(B" . thai-consonant-input))
361 ("D" "\e,TS\e(B")
362 ("f" ("\e,T!\e(B" . thai-consonant-input))
363 ("F" ("\e,T3\e(B" . thai-consonant-input))
364 ("g" "\e,TQ\e(B")
365 ("G" "\e,Tl\e(B")
366 ("h" "\e,TU\e(B")
367 ("H" "\e,TW\e(B")
368 ("j" "\e,TR\e(B")
369 ("J" ("\e,T<\e(B" . thai-consonant-input))
370 ("k" ("\e,T9\e(B" . thai-consonant-input))
371 ("K" ("\e,T*\e(B" . thai-consonant-input))
372 ("l" "\e,T`\e(B")
373 ("L" "\e,Tb\e(B")
374 (";" "\e,Td\e(B")
375 (":" ("\e,T&\e(B" . thai-consonant-input))
376 ("'" ("\e,T"\e(B" . thai-consonant-input))
377 ("\"" ("\e,T1\e(B" . thai-consonant-input))
378
379 ("z" ("\e,T:\e(B" . thai-consonant-input))
380 ("Z" ("\e,T.\e(B" . thai-consonant-input))
381 ("x" ("\e,T;\e(B" . thai-consonant-input))
382 ("X" ("\e,T.\e(B" . thai-consonant-input))
383 ("c" ("\e,TE\e(B" . thai-consonant-input))
384 ("C" ("\e,T0\e(B" . thai-consonant-input))
385 ("v" ("\e,TK\e(B" . thai-consonant-input))
386 ("V" ("\e,T@\e(B" . thai-consonant-input))
387 ("b" "\e,TT\e(B")
388 ("B" "\e,TQ\e(B")
389 ("n" ("\e,T$\e(B" . thai-consonant-input))
390 ("N" ("\e,TH\e(B" . thai-consonant-input))
391 ("m" ("\e,TJ\e(B" . thai-consonant-input))
392 ("M" ("\e,TN\e(B" . thai-consonant-input))
393 ("," "\e,TP\e(B")
394 ("<" ("\e,T?\e(B" . thai-consonant-input))
395 ("." ("\e,T(\e(B" . thai-consonant-input))
396 (">" ("\e,T2\e(B" . thai-consonant-input))
397 ("/" ("\e,T>\e(B" . thai-consonant-input))
398 ("?" ("\e,TL\e(B" . thai-consonant-input))
399 )
400
401 ;;; quail/thai.el ends here