summaryrefslogtreecommitdiff
path: root/leim/quail/thai.el
blob: 2824036243ef6f0b4ea354ea11eca40482e0f546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
;;; quail/thai.el --- Quail package for inputting Thai characters

;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
;; Licensed to the Free Software Foundation.

;; Keywords: multilingual, input method, Thai

;; 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, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Code:

(require 'quail)
(require 'thai-util)

(eval-and-compile

(defvar thai-keyboard-mapping-alist
  '((kesmanee
     [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	; control codes
      0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	; control codes
      0 "#" ",TF(B" ",Tr(B" ",Ts(B" ",Tt(B" "0,TQi1(B" ",T'(B"	; SPC .. '
      ",Tv(B" ",Tw(B" ",Tu(B" ",Ty(B" ",TA(B" ",T"(B" ",Tc(B" ",T=(B"	; ( .. /
      ",T((B" ",TE(B" "/" "_" ",T@(B" ",T6(B" ",TX(B" ",TV(B"	; 0 .. 7
      ",T$(B" ",T5(B" ",T+(B" ",TG(B" ",T2(B" ",T*(B" ",TL(B" ",TF(B"	; 8 .. ?
      ",Tq(B" ",TD(B" ",TZ(B" ",T)(B" ",T/(B" ",T.(B" ",Tb(B" ",T,(B"	; @ .. G
      ",Tg(B" ",T3(B" ",Tk(B" ",TI(B" ",TH(B" ",Tn(B" ",Tl(B" ",TO(B"	; H .. O
      ",T-(B" ",Tp(B" ",T1(B" ",T&(B" ",T8(B" ",Tj(B" ",TN(B" "\""	; P .. W
      ")" ",Tm(B" "(" ",T:(B" ",T_(B" ",TE(B" ",TY(B" ",Tx(B"	; X .. _
      ",T#(B" ",T?(B" ",TT(B" ",Ta(B" ",T!(B" ",TS(B" ",T4(B" ",T`(B"	; ` .. g
      ",Ti(B" ",TC(B" ",Th(B" ",TR(B" ",TJ(B" ",T7(B" ",TW(B" ",T9(B"	; h .. o
      ",TB(B" ",Tf(B" ",T>(B" ",TK(B" ",TP(B" ",TU(B" ",TM(B" ",Td(B"	; p .. w
      ",T;(B" ",TQ(B" ",T<(B" ",T0(B" ",To(B" "." ",T%(B" 0]	; x .. DEL
     nil nil)

    (pattachote
     [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	; control codes
      0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	; control codes
      0 "+" ",T1(B" "/" "," "?" "_" ",T"(B"	; SPC .. '
      "(" ")" "." "%" ",TP(B" ",Tq(B" ",T((B" ",T>(B"	; ( .. /
      ",Tp(B" "=" ",Tr(B" ",Ts(B" ",Tt(B" ",Tu(B" ",TY(B" ",Tw(B"	; 0 .. 7
      ",Tx(B" ",Ty(B" ",T&(B" ",Td(B" ",T?(B" ",Tv(B" ",T2(B" ",TL(B"	; 8 .. ?
      "\"" ",Tk(B" ",TQ(B" ",T0(B" ",TS(B" ",Tf(B" ",T3(B" ",Tl(B"	; @ .. G
      ",TW(B" ",T+(B" ",T<(B" ",T*(B" ",Tb(B" ",TN(B" ",TH(B" ",T6(B"	; H .. O
      ",T2(B" ",Tj(B" ",T-(B" ",T8(B" ",TI(B" ",T=(B" ",T@(B" ",TD(B"	; P .. W
      ",T.(B" ",TV(B" ",T.(B" ",Tc(B" ",TZ(B" ",T2(B" ",TX(B" "-"	; X .. _
      ",T#(B" ",Ti(B" ",TT(B" ",TE(B" ",T'(B" ",TB(B" ",T!(B" ",TQ(B"	; ` .. g
      ",TU(B" ",TA(B" ",TR(B" ",T9(B" ",T`(B" ",TJ(B" ",T$(B" ",TG(B"	; h .. o
      ",Ta(B" ",Tg(B" ",TM(B" ",T7(B" ",TC(B" ",T4(B" ",TK(B" ",T5(B"	; p .. w
      ",T;(B" ",Th(B" ",T:(B" ",TO(B" ",Tm(B" ",TF(B" ",T%(B" 0]	; x .. DEL
     nil nil)
    )
  "Alist of Thai keyboard types vs. corresponding mapping tables.
Each element is a list of:
  KEYBOARD-TYPE, ASCII-THAI-TABLE, CONSONANT-MAP-TEMPLATE,
  and VOWEL-UPPER-LOWER-TEMPLATE.

KEYBOARD-TYPE is a symbol, one of kesmanee or pattachote.

ASCII-THAI-TABLE is a vector indexed by an ASCII key code
and the value is the one-char string of Thai character
assigned at the location of ASCII key on the specific Thai keyboard.
The value is 0 if no Thai character is assigned at the location.

CONSONANT-MAP-TEMPLATE is a template of a cdr part of a Quail map when
a consonant is entered.

VOWEL-UPPER-LOWER-TEMPLATE is a template of a cdr part of a Quail map
when a vowel upper or a vowel lower is entered.")

(defmacro thai-keyboard-info (keyboard-type)
  `(assq ,keyboard-type thai-keyboard-mapping-alist))

)

(defvar thai-current-keyboard-type nil
  "Thai Keyboard type which Quail is assuming currently.
This variable is used in Quail internally only.")

;; Template of a cdr part of a Quail map when a consonant is entered.
(defvar thai-consonant-alist nil)
;; Template of a cdr part of a Quail map when a vowel upper or a vowel
;; lower is entered.
(defvar thai-vowel-upper-lower-alist nil)

;; Return a Quail map corresponding to KEY of length LEN.
;; The car part of the map is a translation generated automatically.
;; The cdr part of the map is a copy of ALIST.
(defun thai-generate-quail-map (key len alist)
  (let ((str "")
	(idx 0))
    (while (< idx len)
      (setq str (concat str (aref (nth 1 (thai-keyboard-info
					  thai-current-keyboard-type))
				  (aref key idx)))
	    idx (1+ idx)))
    (cons (string-to-char (compose-string str)) (copy-alist alist))))

;; Return a Quail map corresponding to KEY of length LEN when Thai
;; tone mark is entered.
(defun thai-tone-input (key len)
  (thai-generate-quail-map key len nil))

;; Return a Quail map corresponding to KEY of length LEN when Thai
;; vowel upper or vowel lower is entered.
(defun thai-vowel-upper-lower-input (key len)
  (thai-generate-quail-map
   key len
   (nth 3 (thai-keyboard-info thai-current-keyboard-type))))

;; Define RULES in Quail map.  In addition, create
;; `thai-consonant-alist-KEYBOARD-TYPE' and
;; `thai-vowel-upper-lower-alist-KEYBOARD-TYPE'.

;; The general composing rules are as follows:
;;
;;                          T
;;       V        T         V                  T
;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
;;                                   v         v
;;
;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.

(defmacro thai-quail-define-rules (keyboard-type &rest rules)
  (let ((l rules)
	consonant-alist
	vowel-upper-lower-alist
	rule trans ch c-set)
    (while l
      (setq rule (car l))
      (setq trans (nth 1 rule))
      (if (consp trans)
	  (setq trans (car trans)))
      (setq c-set (char-category-set (string-to-char trans)))
      (cond ((or (aref c-set ?2)
		 (aref c-set ?3))
	     (setq consonant-alist
		   (cons (cons (string-to-char (car rule))
			       'thai-vowel-upper-lower-input)
			 consonant-alist)))
	    ((aref c-set ?4)
	     (setq consonant-alist
		   (cons (cons (string-to-char (car rule))
			       'thai-tone-input)
			 consonant-alist)
		   vowel-upper-lower-alist
		   (cons (cons (string-to-char (car rule))
			       'thai-tone-input)
			 vowel-upper-lower-alist))))
      (setq l (cdr l)))
    `(progn
	  (quail-define-rules ,@rules)
	  (setcar (nthcdr 2 (thai-keyboard-info ,keyboard-type))
		  ',consonant-alist)
	  (setcar (nthcdr 3 (thai-keyboard-info ,keyboard-type))
		  ',vowel-upper-lower-alist))))

;; Return an alist which can be a cdr part of a Quail map
;; corresponding to the current key when Thai consonant is entered.
(defun thai-consonant-input (key len)
  (let ((quail-package-name (quail-name)))
    (setq thai-current-keyboard-type
	  (cond ((string= quail-package-name "thai-pattachote") 'pattachote)
		((string= quail-package-name "thai-kesmanee") 'kesmanee)
		(t (error "Invalid Quail package %s" quail-package-name))))
    (copy-alist (nth 2 (thai-keyboard-info thai-current-keyboard-type)))))

;; Thai Kesmanee keyboard support.

(quail-define-package
 "thai-kesmanee" "Thai" ",T!!(B>" t
 "Thai Kesmanee input method with TIS620 keyboard layout

The difference from the ordinal Thai keyboard:
    ',T_(B' and ',To(B' are assigned to '\\' and '|' respectively,
    ',T#(B' and ',T%(B' are assigned to '`' and '~' respectively,
    Don't know where to assign characters ',Tz(B' and ',T{(B'."
 nil t t nil t nil nil nil nil nil t)

(thai-quail-define-rules 'kesmanee
 ("1" (",TE(B" . thai-consonant-input))
 ("!" "#")
 ("2" "/")
 ("@" ",Tq(B")
 ("3" "_")
 ("#" ",Tr(B")
 ("4" (",T@(B" . thai-consonant-input))
 ("$" ",Ts(B")
 ("5" (",T6(B" . thai-consonant-input))
 ("%" ",Tt(B")
 ("6" ",TX(B")
 ("^" ",TY(B")
 ("7" ",TV(B")
 ("&" "0,TQi1(B")
 ("8" (",T$(B" . thai-consonant-input))
 ("*" ",Tu(B")
 ("9" (",T5(B" . thai-consonant-input))
 ("\(" ",Tv(B")
 ("0" (",T((B" . thai-consonant-input))
 ("\)" ",Tw(B")
 ("-" (",T"(B" . thai-consonant-input))
 ("_" ",Tx(B")
 ("=" (",T*(B" . thai-consonant-input))
 ("+" ",Ty(B")
 ("\\" ",T_(B")
 ("|" ",To(B")
 ("`" (",T#(B" . thai-consonant-input))
 ("~" (",T%(B" . thai-consonant-input))
 ("q" ",Tf(B")
 ("Q" ",Tp(B")
 ("w" ",Td(B")
 ("W" "\"")
 ("e" ",TS(B")
 ("E" (",T.(B" . thai-consonant-input))
 ("r" (",T>(B" . thai-consonant-input))
 ("R" (",T1(B" . thai-consonant-input))
 ("t" ",TP(B")
 ("T" (",T8(B" . thai-consonant-input))
 ("y" ",TQ(B")
 ("Y" ",Tm(B")
 ("u" ",TU(B")
 ("U" ",Tj(B")
 ("i" (",TC(B" . thai-consonant-input))
 ("I" (",T3(B" . thai-consonant-input))
 ("o" (",T9(B" . thai-consonant-input))
 ("O" ",TO(B")
 ("p" (",TB(B" . thai-consonant-input))
 ("P" (",T-(B" . thai-consonant-input))
 ("\[" (",T:(B" . thai-consonant-input))
 ("{" (",T0(B" . thai-consonant-input))
 ("\]" (",TE(B" . thai-consonant-input))
 ("}" ",")

 ("a" (",T?(B" . thai-consonant-input))
 ("A" ",TD(B")
 ("s" (",TK(B" . thai-consonant-input))
 ("S" (",T&(B" . thai-consonant-input))
 ("d" (",T!(B" . thai-consonant-input))
 ("D" (",T/(B" . thai-consonant-input))
 ("f" (",T4(B" . thai-consonant-input))
 ("F" ",Tb(B")
 ("g" ",T`(B")
 ("G" (",T,(B" . thai-consonant-input))
 ("h" ",Ti(B")
 ("H" ",Tg(B")
 ("j" ",Th(B")
 ("J" ",Tk(B")
 ("k" ",TR(B")
 ("K" (",TI(B" . thai-consonant-input))
 ("l" (",TJ(B" . thai-consonant-input))
 ("L" (",TH(B" . thai-consonant-input))
 ("\;" (",TG(B" . thai-consonant-input))
 (":" (",T+(B" . thai-consonant-input))
 ("'" (",T'(B" . thai-consonant-input))
 ("\"" ".")

 ("z" (",T<(B" . thai-consonant-input))
 ("Z" "(")
 ("x" (",T;(B" . thai-consonant-input))
 ("X" ")")
 ("c" ",Ta(B")
 ("C" (",T)(B" . thai-consonant-input))
 ("v" (",TM(B" . thai-consonant-input))
 ("V" (",TN(B" . thai-consonant-input))
 ("b" ",TT(B")
 ("B" ",TZ(B")
 ("n" ",TW(B")
 ("N" ",Tl(B")
 ("m" (",T7(B" . thai-consonant-input))
 ("M" ",Tn(B")
 ("," (",TA(B" . thai-consonant-input))
 ("<" (",T2(B" . thai-consonant-input))
 ("." ",Tc(B")
 (">" (",TL(B" . thai-consonant-input))
 ("/" (",T=(B" . thai-consonant-input))
 ("?" ",TF(B")
 )


;; Thai Pattachote keyboard support.

(quail-define-package
 "thai-pattachote" "Thai" ",T!;(B>" t
 "Thai Pattachote input method with TIS620 keyboard layout"
 nil t t nil t nil nil nil nil nil t)

(thai-quail-define-rules 'pattachote
 ("1" "=")
 ("!" "+")
 ("2" ",Tr(B")
 ("@" "\"")
 ("3" ",Ts(B")
 ("#" "/")
 ("4" ",Tt(B")
 ("$" ",")
 ("5" ",Tu(B")
 ("%" "?")
 ("6" ",TY(B")
 ("^" ",TX(B")
 ("7" ",Tw(B")
 ("&" "_")
 ("8" ",Tx(B")
 ("*" ".")
 ("9" ",Ty(B")
 ("(" "(")
 ("0" ",Tp(B")
 (")" ")")
 ("-" ",Tq(B")
 ("_" "-")
 ("=" ",Tv(B")
 ("+" "%")
 ("\\" ",TZ(B")
 ("|" ",Tm(B")
 ("`" (",T#(B" . thai-consonant-input))
 ("~" (",T%(B" . thai-consonant-input))

 ("q" ",Tg(B")
 ("Q" ",Tj(B")
 ("w" (",T5(B" . thai-consonant-input))
 ("W" ",TD(B")
 ("e" (",TB(B" . thai-consonant-input))
 ("E" ",Tf(B")
 ("r" (",TM(B" . thai-consonant-input))
 ("R" (",T-(B" . thai-consonant-input))
 ("t" (",TC(B" . thai-consonant-input))
 ("T" (",TI(B" . thai-consonant-input))
 ("y" ",Th(B")
 ("Y" ",TV(B")
 ("u" (",T4(B" . thai-consonant-input))
 ("U" (",T=(B" . thai-consonant-input))
 ("i" (",TA(B" . thai-consonant-input))
 ("I" (",T+(B" . thai-consonant-input))
 ("o" (",TG(B" . thai-consonant-input))
 ("O" (",T6(B" . thai-consonant-input))
 ("p" ",Ta(B")
 ("P" (",T2(B" . thai-consonant-input))
 ("\[" ",Tc(B")
 ("{" ",TO(B")
 ("\]" (",T2(B" . thai-consonant-input))
 ("}" ",TF(B")

 ("a" ",Ti(B")
 ("A" ",Tk(B")
 ("s" (",T7(B" . thai-consonant-input))
 ("S" (",T8(B" . thai-consonant-input))
 ("d" (",T'(B" . thai-consonant-input))
 ("D" ",TS(B")
 ("f" (",T!(B" . thai-consonant-input))
 ("F" (",T3(B" . thai-consonant-input))
 ("g" ",TQ(B")
 ("G" ",Tl(B")
 ("h" ",TU(B")
 ("H" ",TW(B")
 ("j" ",TR(B")
 ("J" (",T<(B" . thai-consonant-input))
 ("k" (",T9(B" . thai-consonant-input))
 ("K" (",T*(B" . thai-consonant-input))
 ("l" ",T`(B")
 ("L" ",Tb(B")
 (";" ",Td(B")
 (":" (",T&(B" . thai-consonant-input))
 ("'" (",T"(B" . thai-consonant-input))
 ("\"" (",T1(B" . thai-consonant-input))

 ("z" (",T:(B" . thai-consonant-input))
 ("Z" (",T.(B" . thai-consonant-input))
 ("x" (",T;(B" . thai-consonant-input))
 ("X" (",T.(B" . thai-consonant-input))
 ("c" (",TE(B" . thai-consonant-input))
 ("C" (",T0(B" . thai-consonant-input))
 ("v" (",TK(B" . thai-consonant-input))
 ("V" (",T@(B" . thai-consonant-input))
 ("b" ",TT(B")
 ("B" ",TQ(B")
 ("n" (",T$(B" . thai-consonant-input))
 ("N" (",TH(B" . thai-consonant-input))
 ("m" (",TJ(B" . thai-consonant-input))
 ("M" (",TN(B" . thai-consonant-input))
 ("," ",TP(B")
 ("<" (",T?(B" . thai-consonant-input))
 ("." (",T((B" . thai-consonant-input))
 (">" (",T2(B" . thai-consonant-input))
 ("/" (",T>(B" . thai-consonant-input))
 ("?" (",TL(B" . thai-consonant-input))
 )

;;; quail/thai.el ends here