(find-buffer-file-type-coding-system):
[bpt/emacs.git] / leim / quail / thai.el
CommitLineData
24b31c88
KH
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" 0 "\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,TS\e(B" "\e,TI\e(B" "\e,T=\e(B" "\e,T@\e(B" "\e,T8\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" 0 "\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,T'\e(B" "\e,TC\e(B" "\e,T4\e(B" "\e,TK\e(B" "\e,T7\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.
68Each element is a list of:
69 KEYBOARD-TYPE, ASCII-THAI-TABLE, CONSONANT-MAP-TEMPLATE,
70 and VOWEL-UPPER-LOWER-TEMPLATE.
71
72KEYBOARD-TYPE is a symbol, one of kesmanee or pattachote.
73
74ASCII-THAI-TABLE is a vector indexed by an ASCII key code
75and the value is the one-char string of Thai character
76assigned at the location of ASCII key on the specific Thai keyboard.
77The value is 0 if no Thai character is assigned at the location.
78
79CONSONANT-MAP-TEMPLATE is a template of a cdr part of a Quail map when
80a consonant is entered.
81
82VOWEL-UPPER-LOWER-TEMPLATE is a template of a cdr part of a Quail map
83when 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.
92This 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\f
181;; Thai Kesmanee keyboard support.
182
183(quail-define-package
184 "thai-kesmanee" "Thai" "\e,T!!\e(B>" t
185 "Thai Kesmanee input method with TIS620 keyboard layout
186
187The difference from the ordinal Thai keyboard:
188 '\e,T_\e(B' and '\e,To\e(B' are assigned to '\\' and '|' respectively,
189 '\e,T#\e(B' and '\e,T%\e(B' are assigned to '`' and '~' respectively,
190 Don't know where to assign characters '\e,Tz\e(B' and '\e,T{\e(B'."
191 nil t t nil t)
192
193(thai-quail-define-rules 'kesmanee
194 ("1" ("\e,TE\e(B" . thai-consonant-input))
195 ("!" "#")
196 ("2" "/")
197 ("@" "\e,Tq\e(B")
198 ("3" "_")
199 ("#" "\e,Tr\e(B")
200 ("4" ("\e,T@\e(B" . thai-consonant-input))
201 ("$" "\e,Ts\e(B")
202 ("5" ("\e,T6\e(B" . thai-consonant-input))
203 ("%" "\e,Tt\e(B")
204 ("6" "\e,TX\e(B")
205 ("^" "\e,TY\e(B")
206 ("7" "\e,TV\e(B")
207 ("&" "\e0\e,TQi\e1\e(B")
208 ("8" ("\e,T$\e(B" . thai-consonant-input))
209 ("*" "\e,Tu\e(B")
210 ("9" ("\e,T5\e(B" . thai-consonant-input))
211 ("\(" "\e,Tv\e(B")
212 ("0" ("\e,T(\e(B" . thai-consonant-input))
213 ("\)" "\e,Tw\e(B")
214 ("-" ("\e,T"\e(B" . thai-consonant-input))
215 ("_" "\e,Tx\e(B")
216 ("=" ("\e,T*\e(B" . thai-consonant-input))
217 ("+" "\e,Ty\e(B")
218 ("\\" "\e,T_\e(B")
219 ("|" "\e,To\e(B")
220 ("`" ("\e,T#\e(B" . thai-consonant-input))
221 ("~" ("\e,T%\e(B" . thai-consonant-input))
222 ("q" "\e,Tf\e(B")
223 ("Q" "\e,Tp\e(B")
224 ("w" "\e,Td\e(B")
225 ("W" "\"")
226 ("e" "\e,TS\e(B")
227 ("E" ("\e,T.\e(B" . thai-consonant-input))
228 ("r" ("\e,T>\e(B" . thai-consonant-input))
229 ("R" ("\e,T1\e(B" . thai-consonant-input))
230 ("t" "\e,TP\e(B")
231 ("T" ("\e,T8\e(B" . thai-consonant-input))
232 ("y" "\e,TQ\e(B")
233 ("Y" "\e,Tm\e(B")
234 ("u" "\e,TU\e(B")
235 ("U" "\e,Tj\e(B")
236 ("i" ("\e,TC\e(B" . thai-consonant-input))
237 ("I" ("\e,T3\e(B" . thai-consonant-input))
238 ("o" ("\e,T9\e(B" . thai-consonant-input))
239 ("O" "\e,TO\e(B")
240 ("p" ("\e,TB\e(B" . thai-consonant-input))
241 ("P" ("\e,T-\e(B" . thai-consonant-input))
242 ("\[" ("\e,T:\e(B" . thai-consonant-input))
243 ("{" ("\e,T0\e(B" . thai-consonant-input))
244 ("\]" ("\e,TE\e(B" . thai-consonant-input))
245 ("}" ",")
246
247 ("a" ("\e,T?\e(B" . thai-consonant-input))
248 ("A" "\e,TD\e(B")
249 ("s" ("\e,TK\e(B" . thai-consonant-input))
250 ("S" ("\e,T&\e(B" . thai-consonant-input))
251 ("d" ("\e,T!\e(B" . thai-consonant-input))
252 ("D" ("\e,T/\e(B" . thai-consonant-input))
253 ("f" ("\e,T4\e(B" . thai-consonant-input))
254 ("F" "\e,Tb\e(B")
255 ("g" "\e,T`\e(B")
256 ("G" ("\e,T,\e(B" . thai-consonant-input))
257 ("h" "\e,Ti\e(B")
258 ("H" "\e,Tg\e(B")
259 ("j" "\e,Th\e(B")
260 ("J" "\e,Tk\e(B")
261 ("k" "\e,TR\e(B")
262 ("K" ("\e,TI\e(B" . thai-consonant-input))
263 ("l" ("\e,TJ\e(B" . thai-consonant-input))
264 ("L" ("\e,TH\e(B" . thai-consonant-input))
265 ("\;" ("\e,TG\e(B" . thai-consonant-input))
266 (":" ("\e,T+\e(B" . thai-consonant-input))
267 ("'" ("\e,T'\e(B" . thai-consonant-input))
268 ("\"" ".")
269
270 ("z" ("\e,T<\e(B" . thai-consonant-input))
271 ("Z" "(")
272 ("x" ("\e,T;\e(B" . thai-consonant-input))
273 ("X" ")")
274 ("c" "\e,Ta\e(B")
275 ("C" ("\e,T)\e(B" . thai-consonant-input))
276 ("v" ("\e,TM\e(B" . thai-consonant-input))
277 ("V" ("\e,TN\e(B" . thai-consonant-input))
278 ("b" "\e,TT\e(B")
279 ("B" "\e,TZ\e(B")
280 ("n" "\e,TW\e(B")
281 ("N" "\e,Tl\e(B")
282 ("m" ("\e,T7\e(B" . thai-consonant-input))
283 ("M" "\e,Tn\e(B")
284 ("," ("\e,TA\e(B" . thai-consonant-input))
285 ("<" ("\e,T2\e(B" . thai-consonant-input))
286 ("." "\e,Tc\e(B")
287 (">" ("\e,TL\e(B" . thai-consonant-input))
288 ("/" ("\e,T=\e(B" . thai-consonant-input))
289 ("?" "\e,TF\e(B")
290 )
291
292\f
293;; Thai Pattachote keyboard support.
294
295(quail-define-package
296 "thai-pattachote" "Thai" "\e,T!;\e(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" "\e,Tr\e(B")
304 ("@" "\"")
305 ("3" "\e,Ts\e(B")
306 ("#" "/")
307 ("4" "\e,Tt\e(B")
308 ("$" ",")
309 ("5" "\e,Tu\e(B")
310 ("%" "?")
311 ("6" "\e,TY\e(B")
312 ("^" "\e,TX\e(B")
313 ("7" "\e,Tw\e(B")
314 ("&" "_")
315 ("8" "\e,Tx\e(B")
316 ("*" ".")
317 ("9" "\e,Ty\e(B")
318 ("(" "(")
319 ("0" "\e,Tp\e(B")
320 (")" ")")
321 ("-" "\e,Tq\e(B")
322 ("_" "-")
323 ("=" "\e,Tv\e(B")
324 ("+" "%")
325 ("\\" "\e,TZ\e(B")
326 ("|" "\e,Tm\e(B")
327 ("`" ("\e,T#\e(B" . thai-consonant-input))
328 ("~" ("\e,T%\e(B" . thai-consonant-input))
329
330 ("q" "\e,Tg\e(B")
331 ("Q" "\e,Tj\e(B")
332 ("w" ("\e,T5\e(B" . thai-consonant-input))
333 ("W" "\e,TD\e(B")
334 ("e" ("\e,TB\e(B" . thai-consonant-input))
335 ("E" "\e,Tf\e(B")
336 ("r" ("\e,TM\e(B" . thai-consonant-input))
337 ("R" ("\e,T-\e(B" . thai-consonant-input))
338 ("t" ("\e,TC\e(B" . thai-consonant-input))
339 ("T" ("\e,TI\e(B" . thai-consonant-input))
340 ("y" "\e,Th\e(B")
341 ("Y" "\e,TV\e(B")
342 ("u" ("\e,T4\e(B" . thai-consonant-input))
343 ("U" ("\e,T=\e(B" . thai-consonant-input))
344 ("i" ("\e,TA\e(B" . thai-consonant-input))
345 ("I" ("\e,T+\e(B" . thai-consonant-input))
346 ("o" ("\e,TG\e(B" . thai-consonant-input))
347 ("O" ("\e,T6\e(B" . thai-consonant-input))
348 ("p" "\e,Ta\e(B")
349 ("P" ("\e,T2\e(B" . thai-consonant-input))
350 ("\[" "\e,Tc\e(B")
351 ("{" "\e,TO\e(B")
352 ("\]" ("\e,T2\e(B" . thai-consonant-input))
353 ("}" "\e,TF\e(B")
354
355 ("a" "\e,Ti\e(B")
356 ("A" "\e,Tk\e(B")
357 ("s" ("\e,T7\e(B" . thai-consonant-input))
358 ("S" ("\e,T8\e(B" . thai-consonant-input))
359 ("d" ("\e,T'\e(B" . thai-consonant-input))
360 ("D" "\e,TS\e(B")
361 ("f" ("\e,T!\e(B" . thai-consonant-input))
362 ("F" ("\e,T3\e(B" . thai-consonant-input))
363 ("g" "\e,TQ\e(B")
364 ("G" "\e,Tl\e(B")
365 ("h" "\e,TU\e(B")
366 ("H" "\e,TW\e(B")
367 ("j" "\e,TR\e(B")
368 ("J" ("\e,T<\e(B" . thai-consonant-input))
369 ("k" ("\e,T9\e(B" . thai-consonant-input))
370 ("K" ("\e,T*\e(B" . thai-consonant-input))
371 ("l" "\e,T`\e(B")
372 ("L" "\e,Tb\e(B")
373 (";" "\e,Td\e(B")
374 (":" ("\e,T&\e(B" . thai-consonant-input))
375 ("'" ("\e,T"\e(B" . thai-consonant-input))
376 ("\"" ("\e,T1\e(B" . thai-consonant-input))
377
378 ("z" ("\e,T:\e(B" . thai-consonant-input))
379 ("Z" ("\e,T.\e(B" . thai-consonant-input))
380 ("x" ("\e,T;\e(B" . thai-consonant-input))
381 ("X" ("\e,T.\e(B" . thai-consonant-input))
382 ("c" ("\e,TE\e(B" . thai-consonant-input))
383 ("C" ("\e,T0\e(B" . thai-consonant-input))
384 ("v" ("\e,TK\e(B" . thai-consonant-input))
385 ("V" ("\e,T@\e(B" . thai-consonant-input))
386 ("b" "\e,TT\e(B")
387 ("B" "\e,TQ\e(B")
388 ("n" ("\e,T$\e(B" . thai-consonant-input))
389 ("N" ("\e,TH\e(B" . thai-consonant-input))
390 ("m" ("\e,TJ\e(B" . thai-consonant-input))
391 ("M" ("\e,TN\e(B" . thai-consonant-input))
392 ("," "\e,TP\e(B")
393 ("<" ("\e,T?\e(B" . thai-consonant-input))
394 ("." ("\e,T(\e(B" . thai-consonant-input))
395 (">" ("\e,T2\e(B" . thai-consonant-input))
396 ("/" ("\e,T>\e(B" . thai-consonant-input))
397 ("?" ("\e,TL\e(B" . thai-consonant-input))
398 )
399
400;;; quail/thai.el ends here