18673
|
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 "#" ",TF(B" ",Tr(B" ",Ts(B" ",Tt(B" "0,TQi1(B" ",T'(B" ; SPC .. '
|
|
37 ",Tv(B" ",Tw(B" ",Tu(B" ",Ty(B" ",TA(B" ",T"(B" ",Tc(B" ",T=(B" ; ( .. /
|
|
38 ",T((B" ",TE(B" "/" "_" ",T@(B" ",T6(B" ",TX(B" ",TV(B" ; 0 .. 7
|
|
39 ",T$(B" ",T5(B" ",T+(B" ",TG(B" ",T2(B" ",T*(B" ",TL(B" ",TF(B" ; 8 .. ?
|
|
40 ",Tq(B" ",TD(B" ",TZ(B" ",T)(B" ",T/(B" ",T.(B" ",Tb(B" ",T,(B" ; @ .. G
|
|
41 ",Tg(B" ",T3(B" ",Tk(B" ",TI(B" ",TH(B" ",Tn(B" ",Tl(B" ",TO(B" ; H .. O
|
|
42 ",T-(B" ",Tp(B" ",T1(B" ",T&(B" ",T8(B" ",Tj(B" ",TN(B" "\"" ; P .. W
|
|
43 ")" ",Tm(B" "(" ",T:(B" ",T_(B" ",TE(B" ",TY(B" ",Tx(B" ; X .. _
|
|
44 ",T#(B" ",T?(B" ",TT(B" ",Ta(B" ",T!(B" ",TS(B" ",T4(B" ",T`(B" ; ` .. g
|
|
45 ",Ti(B" ",TC(B" ",Th(B" ",TR(B" ",TJ(B" ",T7(B" ",TW(B" ",T9(B" ; h .. o
|
|
46 ",TB(B" ",Tf(B" ",T>(B" ",TK(B" ",TP(B" ",TU(B" ",TM(B" ",Td(B" ; p .. w
|
|
47 ",T;(B" ",TQ(B" ",T<(B" ",T0(B" ",To(B" "." ",T%(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 "+" ",T1(B" "/" "," "?" "_" ",T"(B" ; SPC .. '
|
|
54 "(" ")" "." "%" ",TP(B" ",Tq(B" ",T((B" ",T>(B" ; ( .. /
|
|
55 ",Tp(B" "=" ",Tr(B" ",Ts(B" ",Tt(B" ",Tu(B" ",TY(B" ",Tw(B" ; 0 .. 7
|
|
56 ",Tx(B" ",Ty(B" ",T&(B" ",Td(B" ",T?(B" ",Tv(B" ",T2(B" ",TL(B" ; 8 .. ?
|
|
57 "\"" ",Tk(B" ",TQ(B" ",T0(B" 0 ",Tf(B" ",T3(B" ",Tl(B" ; @ .. G
|
|
58 ",TW(B" ",T+(B" ",T<(B" ",T*(B" ",Tb(B" ",TN(B" ",TH(B" ",T6(B" ; H .. O
|
|
59 ",T2(B" ",Tj(B" ",T-(B" ",TS(B" ",TI(B" ",T=(B" ",T@(B" ",T8(B" ; P .. W
|
|
60 ",T.(B" ",TV(B" ",T.(B" ",Tc(B" ",TZ(B" ",T2(B" ",TX(B" "-" ; X .. _
|
|
61 ",T#(B" ",Ti(B" ",TT(B" ",TE(B" 0 ",TB(B" ",T!(B" ",TQ(B" ; ` .. g
|
|
62 ",TU(B" ",TA(B" ",TR(B" ",T9(B" ",T`(B" ",TJ(B" ",T$(B" ",TG(B" ; h .. o
|
|
63 ",Ta(B" ",Tg(B" ",TM(B" ",T'(B" ",TC(B" ",T4(B" ",TK(B" ",T7(B" ; p .. w
|
|
64 ",T;(B" ",Th(B" ",T:(B" ",TO(B" ",Tm(B" ",TF(B" ",T%(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 (t (string= quail-package-name "thai-kesmanee") 'kesmanee)))
|
|
179 (copy-alist (nth 2 (thai-keyboard-info thai-current-keyboard-type)))))
|
|
180
|
|
181 ;; Thai Kesmanee keyboard support.
|
|
182
|
|
183 (quail-define-package
|
|
184 "thai-kesmanee" "Thai" ",T!!(B>" t
|
|
185 "Thai Kesmanee input method with TIS620 keyboard layout
|
|
186
|
|
187 The difference from the ordinal Thai keyboard:
|
|
188 ',T_(B' and ',To(B' are assigned to '\\' and '|' respectively,
|
|
189 ',T#(B' and ',T%(B' are assigned to '`' and '~' respectively,
|
|
190 Don't know where to assign characters ',Tz(B' and ',T{(B'."
|
|
191 nil t t nil t)
|
|
192
|
|
193 (thai-quail-define-rules 'kesmanee
|
|
194 ("1" (",TE(B" . thai-consonant-input))
|
|
195 ("!" "#")
|
|
196 ("2" "/")
|
|
197 ("@" ",Tq(B")
|
|
198 ("3" "_")
|
|
199 ("#" ",Tr(B")
|
|
200 ("4" (",T@(B" . thai-consonant-input))
|
|
201 ("$" ",Ts(B")
|
|
202 ("5" (",T6(B" . thai-consonant-input))
|
|
203 ("%" ",Tt(B")
|
|
204 ("6" ",TX(B")
|
|
205 ("^" ",TY(B")
|
|
206 ("7" ",TV(B")
|
|
207 ("&" "0,TQi1(B")
|
|
208 ("8" (",T$(B" . thai-consonant-input))
|
|
209 ("*" ",Tu(B")
|
|
210 ("9" (",T5(B" . thai-consonant-input))
|
|
211 ("\(" ",Tv(B")
|
|
212 ("0" (",T((B" . thai-consonant-input))
|
|
213 ("\)" ",Tw(B")
|
|
214 ("-" (",T"(B" . thai-consonant-input))
|
|
215 ("_" ",Tx(B")
|
|
216 ("=" (",T*(B" . thai-consonant-input))
|
|
217 ("+" ",Ty(B")
|
|
218 ("\\" ",T_(B")
|
|
219 ("|" ",To(B")
|
|
220 ("`" (",T#(B" . thai-consonant-input))
|
|
221 ("~" (",T%(B" . thai-consonant-input))
|
|
222 ("q" ",Tf(B")
|
|
223 ("Q" ",Tp(B")
|
|
224 ("w" ",Td(B")
|
|
225 ("W" "\"")
|
|
226 ("e" ",TS(B")
|
|
227 ("E" (",T.(B" . thai-consonant-input))
|
|
228 ("r" (",T>(B" . thai-consonant-input))
|
|
229 ("R" (",T1(B" . thai-consonant-input))
|
|
230 ("t" ",TP(B")
|
|
231 ("T" (",T8(B" . thai-consonant-input))
|
|
232 ("y" ",TQ(B")
|
|
233 ("Y" ",Tm(B")
|
|
234 ("u" ",TU(B")
|
|
235 ("U" ",Tj(B")
|
|
236 ("i" (",TC(B" . thai-consonant-input))
|
|
237 ("I" (",T3(B" . thai-consonant-input))
|
|
238 ("o" (",T9(B" . thai-consonant-input))
|
|
239 ("O" ",TO(B")
|
|
240 ("p" (",TB(B" . thai-consonant-input))
|
|
241 ("P" (",T-(B" . thai-consonant-input))
|
|
242 ("\[" (",T:(B" . thai-consonant-input))
|
|
243 ("{" (",T0(B" . thai-consonant-input))
|
|
244 ("\]" (",TE(B" . thai-consonant-input))
|
|
245 ("}" ",")
|
|
246
|
|
247 ("a" (",T?(B" . thai-consonant-input))
|
|
248 ("A" ",TD(B")
|
|
249 ("s" (",TK(B" . thai-consonant-input))
|
|
250 ("S" (",T&(B" . thai-consonant-input))
|
|
251 ("d" (",T!(B" . thai-consonant-input))
|
|
252 ("D" (",T/(B" . thai-consonant-input))
|
|
253 ("f" (",T4(B" . thai-consonant-input))
|
|
254 ("F" ",Tb(B")
|
|
255 ("g" ",T`(B")
|
|
256 ("G" (",T,(B" . thai-consonant-input))
|
|
257 ("h" ",Ti(B")
|
|
258 ("H" ",Tg(B")
|
|
259 ("j" ",Th(B")
|
|
260 ("J" ",Tk(B")
|
|
261 ("k" ",TR(B")
|
|
262 ("K" (",TI(B" . thai-consonant-input))
|
|
263 ("l" (",TJ(B" . thai-consonant-input))
|
|
264 ("L" (",TH(B" . thai-consonant-input))
|
|
265 ("\;" (",TG(B" . thai-consonant-input))
|
|
266 (":" (",T+(B" . thai-consonant-input))
|
|
267 ("'" (",T'(B" . thai-consonant-input))
|
|
268 ("\"" ".")
|
|
269
|
|
270 ("z" (",T<(B" . thai-consonant-input))
|
|
271 ("Z" "(")
|
|
272 ("x" (",T;(B" . thai-consonant-input))
|
|
273 ("X" ")")
|
|
274 ("c" ",Ta(B")
|
|
275 ("C" (",T)(B" . thai-consonant-input))
|
|
276 ("v" (",TM(B" . thai-consonant-input))
|
|
277 ("V" (",TN(B" . thai-consonant-input))
|
|
278 ("b" ",TT(B")
|
|
279 ("B" ",TZ(B")
|
|
280 ("n" ",TW(B")
|
|
281 ("N" ",Tl(B")
|
|
282 ("m" (",T7(B" . thai-consonant-input))
|
|
283 ("M" ",Tn(B")
|
|
284 ("," (",TA(B" . thai-consonant-input))
|
|
285 ("<" (",T2(B" . thai-consonant-input))
|
|
286 ("." ",Tc(B")
|
|
287 (">" (",TL(B" . thai-consonant-input))
|
|
288 ("/" (",T=(B" . thai-consonant-input))
|
|
289 ("?" ",TF(B")
|
|
290 )
|
|
291
|
|
292
|
|
293 ;; Thai Pattachote keyboard support.
|
|
294
|
|
295 (quail-define-package
|
|
296 "thai-pattachote" "Thai" ",T!;(B>" t
|
|
297 "Thai Pattachote input method with TIS620 keyboard layout"
|
|
298 nil t t nil t)
|
|
299
|
|
300 (thai-quail-define-rules 'pattachote
|
|
301 ("1" "=")
|
|
302 ("!" "+")
|
|
303 ("2" ",Tr(B")
|
|
304 ("@" "\"")
|
|
305 ("3" ",Ts(B")
|
|
306 ("#" "/")
|
|
307 ("4" ",Tt(B")
|
|
308 ("$" ",")
|
|
309 ("5" ",Tu(B")
|
|
310 ("%" "?")
|
|
311 ("6" ",TY(B")
|
|
312 ("^" ",TX(B")
|
|
313 ("7" ",Tw(B")
|
|
314 ("&" "_")
|
|
315 ("8" ",Tx(B")
|
|
316 ("*" ".")
|
|
317 ("9" ",Ty(B")
|
|
318 ("(" "(")
|
|
319 ("0" ",Tp(B")
|
|
320 (")" ")")
|
|
321 ("-" ",Tq(B")
|
|
322 ("_" "-")
|
|
323 ("=" ",Tv(B")
|
|
324 ("+" "%")
|
|
325 ("\\" ",TZ(B")
|
|
326 ("|" ",Tm(B")
|
|
327 ("`" (",T#(B" . thai-consonant-input))
|
|
328 ("~" (",T%(B" . thai-consonant-input))
|
|
329
|
|
330 ("q" ",Tg(B")
|
|
331 ("Q" ",Tj(B")
|
|
332 ("w" (",T5(B" . thai-consonant-input))
|
|
333 ("W" ",TD(B")
|
|
334 ("e" (",TB(B" . thai-consonant-input))
|
|
335 ("E" ",Tf(B")
|
|
336 ("r" (",TM(B" . thai-consonant-input))
|
|
337 ("R" (",T-(B" . thai-consonant-input))
|
|
338 ("t" (",TC(B" . thai-consonant-input))
|
|
339 ("T" (",TI(B" . thai-consonant-input))
|
|
340 ("y" ",Th(B")
|
|
341 ("Y" ",TV(B")
|
|
342 ("u" (",T4(B" . thai-consonant-input))
|
|
343 ("U" (",T=(B" . thai-consonant-input))
|
|
344 ("i" (",TA(B" . thai-consonant-input))
|
|
345 ("I" (",T+(B" . thai-consonant-input))
|
|
346 ("o" (",TG(B" . thai-consonant-input))
|
|
347 ("O" (",T6(B" . thai-consonant-input))
|
|
348 ("p" ",Ta(B")
|
|
349 ("P" (",T2(B" . thai-consonant-input))
|
|
350 ("\[" ",Tc(B")
|
|
351 ("{" ",TO(B")
|
|
352 ("\]" (",T2(B" . thai-consonant-input))
|
|
353 ("}" ",TF(B")
|
|
354
|
|
355 ("a" ",Ti(B")
|
|
356 ("A" ",Tk(B")
|
|
357 ("s" (",T7(B" . thai-consonant-input))
|
|
358 ("S" (",T8(B" . thai-consonant-input))
|
|
359 ("d" (",T'(B" . thai-consonant-input))
|
|
360 ("D" ",TS(B")
|
|
361 ("f" (",T!(B" . thai-consonant-input))
|
|
362 ("F" (",T3(B" . thai-consonant-input))
|
|
363 ("g" ",TQ(B")
|
|
364 ("G" ",Tl(B")
|
|
365 ("h" ",TU(B")
|
|
366 ("H" ",TW(B")
|
|
367 ("j" ",TR(B")
|
|
368 ("J" (",T<(B" . thai-consonant-input))
|
|
369 ("k" (",T9(B" . thai-consonant-input))
|
|
370 ("K" (",T*(B" . thai-consonant-input))
|
|
371 ("l" ",T`(B")
|
|
372 ("L" ",Tb(B")
|
|
373 (";" ",Td(B")
|
|
374 (":" (",T&(B" . thai-consonant-input))
|
|
375 ("'" (",T"(B" . thai-consonant-input))
|
|
376 ("\"" (",T1(B" . thai-consonant-input))
|
|
377
|
|
378 ("z" (",T:(B" . thai-consonant-input))
|
|
379 ("Z" (",T.(B" . thai-consonant-input))
|
|
380 ("x" (",T;(B" . thai-consonant-input))
|
|
381 ("X" (",T.(B" . thai-consonant-input))
|
|
382 ("c" (",TE(B" . thai-consonant-input))
|
|
383 ("C" (",T0(B" . thai-consonant-input))
|
|
384 ("v" (",TK(B" . thai-consonant-input))
|
|
385 ("V" (",T@(B" . thai-consonant-input))
|
|
386 ("b" ",TT(B")
|
|
387 ("B" ",TQ(B")
|
|
388 ("n" (",T$(B" . thai-consonant-input))
|
|
389 ("N" (",TH(B" . thai-consonant-input))
|
|
390 ("m" (",TJ(B" . thai-consonant-input))
|
|
391 ("M" (",TN(B" . thai-consonant-input))
|
|
392 ("," ",TP(B")
|
|
393 ("<" (",T?(B" . thai-consonant-input))
|
|
394 ("." (",T((B" . thai-consonant-input))
|
|
395 (">" (",T2(B" . thai-consonant-input))
|
|
396 ("/" (",T>(B" . thai-consonant-input))
|
|
397 ("?" (",TL(B" . thai-consonant-input))
|
|
398 )
|
|
399
|
|
400 ;;; quail/thai.el ends here
|