1 ;;; quail/thai.el --- Quail package for inputting Thai characters
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
6 ;; Keywords: multilingual, input method, Thai
8 ;; This file is part of GNU Emacs.
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)
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.
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.
32 (defvar thai-keyboard-mapping-alist
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
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" ; 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 "
\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
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.
72 KEYBOARD-TYPE is a symbol, one of kesmanee or pattachote.
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.
79 CONSONANT-MAP-TEMPLATE is a template of a cdr part of a Quail map when
80 a consonant is entered.
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.")
85 (defmacro thai-keyboard-info (keyboard-type)
86 `(assq ,keyboard-type thai-keyboard-mapping-alist))
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.")
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
98 (defvar thai-vowel-upper-lower-alist nil)
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)
107 (setq str (concat str (aref (nth 1 (thai-keyboard-info
108 thai-current-keyboard-type))
111 (cons (string-to-char (compose-string str)) (copy-alist alist))))
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))
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
123 (nth 3 (thai-keyboard-info thai-current-keyboard-type))))
125 ;; Define RULES in Quail map. In addition, create
126 ;; `thai-consonant-alist-KEYBOARD-TYPE' and
127 ;; `thai-vowel-upper-lower-alist-KEYBOARD-TYPE'.
129 ;; The general composing rules are as follows:
133 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
136 ;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
138 (defmacro thai-quail-define-rules (keyboard-type &rest rules)
141 vowel-upper-lower-alist
145 (setq trans (nth 1 rule))
147 (setq trans (car trans)))
148 (setq c-set (char-category-set (string-to-char trans)))
149 (cond ((or (aref c-set ?2)
151 (setq consonant-alist
152 (cons (cons (string-to-char (car rule))
153 'thai-vowel-upper-lower-input)
156 (setq consonant-alist
157 (cons (cons (string-to-char (car rule))
160 vowel-upper-lower-alist
161 (cons (cons (string-to-char (car rule))
163 vowel-upper-lower-alist))))
166 (quail-define-rules ,@rules)
167 (setcar (nthcdr 2 (thai-keyboard-info ,keyboard-type))
169 (setcar (nthcdr 3 (thai-keyboard-info ,keyboard-type))
170 ',vowel-upper-lower-alist))))
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)))))
182 ;; Thai Kesmanee keyboard support.
184 (quail-define-package
185 "thai-kesmanee" "Thai" "
\e,T!!
\e(B>" t
186 "Thai Kesmanee input method with TIS620 keyboard layout
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 nil nil nil nil nil t)
194 (thai-quail-define-rules 'kesmanee
195 ("1" ("
\e,TE
\e(B" . thai-consonant-input))
201 ("4" ("
\e,T@
\e(B" . thai-consonant-input))
203 ("5" ("
\e,T6
\e(B" . thai-consonant-input))
208 ("&" "
\e0
\e,TQi
\e1
\e(B")
209 ("8" ("
\e,T$
\e(B" . thai-consonant-input))
211 ("9" ("
\e,T5
\e(B" . thai-consonant-input))
213 ("0" ("
\e,T(
\e(B" . thai-consonant-input))
215 ("-" ("
\e,T"
\e(B" . thai-consonant-input))
217 ("=" ("
\e,T*
\e(B" . thai-consonant-input))
221 ("`" ("
\e,T#
\e(B" . thai-consonant-input))
222 ("~" ("
\e,T%
\e(B" . thai-consonant-input))
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))
232 ("T" ("
\e,T8
\e(B" . thai-consonant-input))
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))
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))
248 ("a" ("
\e,T?
\e(B" . thai-consonant-input))
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))
257 ("G" ("
\e,T,
\e(B" . thai-consonant-input))
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))
271 ("z" ("
\e,T<
\e(B" . thai-consonant-input))
273 ("x" ("
\e,T;
\e(B" . thai-consonant-input))
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))
283 ("m" ("
\e,T7
\e(B" . thai-consonant-input))
285 ("," ("
\e,TA
\e(B" . thai-consonant-input))
286 ("<" ("
\e,T2
\e(B" . thai-consonant-input))
288 (">" ("
\e,TL
\e(B" . thai-consonant-input))
289 ("/" ("
\e,T=
\e(B" . thai-consonant-input))
294 ;; Thai Pattachote keyboard support.
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 nil nil nil nil nil t)
301 (thai-quail-define-rules 'pattachote
328 ("`" ("
\e,T#
\e(B" . thai-consonant-input))
329 ("~" ("
\e,T%
\e(B" . thai-consonant-input))
333 ("w" ("
\e,T5
\e(B" . thai-consonant-input))
335 ("e" ("
\e,TB
\e(B" . thai-consonant-input))
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))
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))
350 ("P" ("
\e,T2
\e(B" . thai-consonant-input))
353 ("\]" ("
\e,T2
\e(B" . thai-consonant-input))
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))
362 ("f" ("
\e,T!
\e(B" . thai-consonant-input))
363 ("F" ("
\e,T3
\e(B" . thai-consonant-input))
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))
375 (":" ("
\e,T&
\e(B" . thai-consonant-input))
376 ("'" ("
\e,T"
\e(B" . thai-consonant-input))
377 ("\"" ("
\e,T1
\e(B" . thai-consonant-input))
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))
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))
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))
401 ;;; quail/thai.el ends here