]> code.delx.au - gnu-emacs/blob - lisp/language/thai-util.el
(thai-category-table): Use
[gnu-emacs] / lisp / language / thai-util.el
1 ;;; thai-util.el --- utilities for Thai
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5
6 ;; Keywords: mule, multilingual, 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 ;;;###autoload
28 (defun setup-thai-environment ()
29 "Setup multilingual environment (MULE) for Thai."
30 (interactive)
31 (set-language-environment "Thai"))
32
33 ;; Setting information of Thai characters.
34
35 (defconst thai-category-table (make-category-table))
36 (define-category ?c "Thai consonant" thai-category-table)
37 (define-category ?v "Thai upper/lower vowel" thai-category-table)
38 (define-category ?t "Thai tone" thai-category-table)
39
40 ;; The general composing rules are as follows:
41 ;;
42 ;; T
43 ;; V T V T
44 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
45 ;; v v
46 ;;
47 ;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
48
49 (defvar thai-composition-pattern "\\cc\\(\\ct\\|\\cv\\ct?\\)"
50 "Regular expression matching a Thai composite sequence.")
51
52 (let ((l '((?\e,T!\e(B consonant "LETTER KO KAI") ; 0xA1
53 (?\e,T"\e(B consonant "LETTER KHO KHAI") ; 0xA2
54 (?\e,T#\e(B consonant "LETTER KHO KHUAT") ; 0xA3
55 (?\e,T$\e(B consonant "LETTER KHO KHWAI") ; 0xA4
56 (?\e,T%\e(B consonant "LETTER KHO KHON") ; 0xA5
57 (?\e,T&\e(B consonant "LETTER KHO RAKHANG") ; 0xA6
58 (?\e,T'\e(B consonant "LETTER NGO NGU") ; 0xA7
59 (?\e,T(\e(B consonant "LETTER CHO CHAN") ; 0xA8
60 (?\e,T)\e(B consonant "LETTER CHO CHING") ; 0xA9
61 (?\e,T*\e(B consonant "LETTER CHO CHANG") ; 0xAA
62 (?\e,T+\e(B consonant "LETTER SO SO") ; 0xAB
63 (?\e,T,\e(B consonant "LETTER CHO CHOE") ; 0xAC
64 (?\e,T-\e(B consonant "LETTER YO YING") ; 0xAD
65 (?\e,T.\e(B consonant "LETTER DO CHADA") ; 0xAE
66 (?\e,T/\e(B consonant "LETTER TO PATAK") ; 0xAF
67 (?\e,T0\e(B consonant "LETTER THO THAN") ; 0xB0
68 (?\e,T1\e(B consonant "LETTER THO NANGMONTHO") ; 0xB1
69 (?\e,T2\e(B consonant "LETTER THO PHUTHAO") ; 0xB2
70 (?\e,T3\e(B consonant "LETTER NO NEN") ; 0xB3
71 (?\e,T4\e(B consonant "LETTER DO DEK") ; 0xB4
72 (?\e,T5\e(B consonant "LETTER TO TAO") ; 0xB5
73 (?\e,T6\e(B consonant "LETTER THO THUNG") ; 0xB6
74 (?\e,T7\e(B consonant "LETTER THO THAHAN") ; 0xB7
75 (?\e,T8\e(B consonant "LETTER THO THONG") ; 0xB8
76 (?\e,T9\e(B consonant "LETTER NO NU") ; 0xB9
77 (?\e,T:\e(B consonant "LETTER BO BAIMAI") ; 0xBA
78 (?\e,T;\e(B consonant "LETTER PO PLA") ; 0xBB
79 (?\e,T<\e(B consonant "LETTER PHO PHUNG") ; 0xBC
80 (?\e,T=\e(B consonant "LETTER FO FA") ; 0xBD
81 (?\e,T>\e(B consonant "LETTER PHO PHAN") ; 0xBE
82 (?\e,T?\e(B consonant "LETTER FO FAN") ; 0xBF
83 (?\e,T@\e(B consonant "LETTER PHO SAMPHAO") ; 0xC0
84 (?\e,TA\e(B consonant "LETTER MO MA") ; 0xC1
85 (?\e,TB\e(B consonant "LETTER YO YAK") ; 0xC2
86 (?\e,TC\e(B consonant "LETTER RO RUA") ; 0xC3
87 (?\e,TD\e(B vowel-base "LETTER RU (Pali vowel letter)") ; 0xC4
88 (?\e,TE\e(B consonant "LETTER LO LING") ; 0xC5
89 (?\e,TF\e(B vowel-base "LETTER LU (Pali vowel letter)") ; 0xC6
90 (?\e,TG\e(B consonant "LETTER WO WAEN") ; 0xC7
91 (?\e,TH\e(B consonant "LETTER SO SALA") ; 0xC8
92 (?\e,TI\e(B consonant "LETTER SO RUSI") ; 0xC9
93 (?\e,TJ\e(B consonant "LETTER SO SUA") ; 0xCA
94 (?\e,TK\e(B consonant "LETTER HO HIP") ; 0xCB
95 (?\e,TL\e(B consonant "LETTER LO CHULA") ; 0xCC
96 (?\e,TM\e(B consonant "LETTER O ANG") ; 0xCD
97 (?\e,TN\e(B consonant "LETTER HO NOK HUK") ; 0xCE
98 (?\e,TO\e(B special "PAI YAN NOI (abbreviation)") ; 0xCF
99 (?\e,TP\e(B vowel-base "VOWEL SIGN SARA A") ; 0xD0
100 (?\e,TQ\e(B vowel-upper "VOWEL SIGN MAI HAN-AKAT N/S-T") ; 0xD1
101 (?\e,TR\e(B vowel-base "VOWEL SIGN SARA AA") ; 0xD2
102 (?\e,TS\e(B vowel-base "VOWEL SIGN SARA AM") ; 0xD3
103 (?\e,TT\e(B vowel-upper "VOWEL SIGN SARA I N/S-T") ; 0xD4
104 (?\e,TU\e(B vowel-upper "VOWEL SIGN SARA II N/S-T") ; 0xD5
105 (?\e,TV\e(B vowel-upper "VOWEL SIGN SARA UE N/S-T") ; 0xD6
106 (?\e,TW\e(B vowel-upper "VOWEL SIGN SARA UEE N/S-T") ; 0xD7
107 (?\e,TX\e(B vowel-lower "VOWEL SIGN SARA U N/S-B") ; 0xD8
108 (?\e,TY\e(B vowel-lower "VOWEL SIGN SARA UU N/S-B") ; 0xD9
109 (?\e,TZ\e(B vowel-lower "VOWEL SIGN PHINTHU N/S-B (Pali virama)") ; 0xDA
110 (?\e,T[\e(B invalid nil) ; 0xDA
111 (?\e,T\\e(B invalid nil) ; 0xDC
112 (?\e,T]\e(B invalid nil) ; 0xDC
113 (?\e,T^\e(B invalid nil) ; 0xDC
114 (?\e,T_\e(B special "BAHT SIGN (currency symbol)") ; 0xDF
115 (?\e,T`\e(B vowel-base "VOWEL SIGN SARA E") ; 0xE0
116 (?\e,Ta\e(B vowel-base "VOWEL SIGN SARA AE") ; 0xE1
117 (?\e,Tb\e(B vowel-base "VOWEL SIGN SARA O") ; 0xE2
118 (?\e,Tc\e(B vowel-base "VOWEL SIGN SARA MAI MUAN") ; 0xE3
119 (?\e,Td\e(B vowel-base "VOWEL SIGN SARA MAI MALAI") ; 0xE4
120 (?\e,Te\e(B vowel-base "LAK KHANG YAO") ; 0xE5
121 (?\e,Tf\e(B special "MAI YAMOK (repetion)") ; 0xE6
122 (?\e,Tg\e(B vowel-upper "VOWEL SIGN MAI TAI KHU N/S-T") ; 0xE7
123 (?\e,Th\e(B tone "TONE MAI EK N/S-T") ; 0xE8
124 (?\e,Ti\e(B tone "TONE MAI THO N/S-T") ; 0xE9
125 (?\e,Tj\e(B tone "TONE MAI TRI N/S-T") ; 0xEA
126 (?\e,Tk\e(B tone "TONE MAI CHATTAWA N/S-T") ; 0xEB
127 (?\e,Tl\e(B tone "THANTHAKHAT N/S-T (cancellation mark)") ; 0xEC
128 (?\e,Tm\e(B tone "NIKKHAHIT N/S-T (final nasal)") ; 0xED
129 (?\e,Tn\e(B vowel-upper "YAMAKKAN N/S-T") ; 0xEE
130 (?\e,To\e(B special "FONRMAN") ; 0xEF
131 (?\e,Tp\e(B special "DIGIT ZERO") ; 0xF0
132 (?\e,Tq\e(B special "DIGIT ONE") ; 0xF1
133 (?\e,Tr\e(B special "DIGIT TWO") ; 0xF2
134 (?\e,Ts\e(B special "DIGIT THREE") ; 0xF3
135 (?\e,Tt\e(B special "DIGIT FOUR") ; 0xF4
136 (?\e,Tu\e(B special "DIGIT FIVE") ; 0xF5
137 (?\e,Tv\e(B special "DIGIT SIX") ; 0xF6
138 (?\e,Tw\e(B special "DIGIT SEVEN") ; 0xF7
139 (?\e,Tx\e(B special "DIGIT EIGHT") ; 0xF8
140 (?\e,Ty\e(B special "DIGIT NINE") ; 0xF9
141 (?\e,Tz\e(B special "ANGKHANKHU (ellipsis)") ; 0xFA
142 (?\e,T{\e(B special "KHOMUT (beginning of religious texts)") ; 0xFB
143 (?\e,T|\e(B invalid nil) ; 0xFC
144 (?\e,T}\e(B invalid nil) ; 0xFD
145 (?\e,T~\e(B invalid nil) ; 0xFE
146 ))
147 elm)
148 (while l
149 (setq elm (car l) l (cdr l))
150 (let ((char (car elm))
151 (ptype (nth 1 elm)))
152 (put-char-code-property char 'phonetic-type ptype)
153 (cond ((eq ptype 'consonant)
154 (modify-category-entry char ?c thai-category-table))
155 ((memq ptype '(vowel-upper vowel-lower))
156 (modify-category-entry char ?v thai-category-table))
157 ((eq ptype 'tone)
158 (modify-category-entry char ?t thai-category-table)))
159 (put-char-code-property char 'name (nth 2 elm)))))
160
161 ;;;###autoload
162 (defun thai-compose-region (beg end)
163 "Compose Thai characters in the region.
164 When called from a program, expects two arguments,
165 positions (integers or markers) specifying the region."
166 (interactive "r")
167 (save-restriction
168 (narrow-to-region beg end)
169 (goto-char (point-min))
170 (with-category-table thai-category-table
171 (while (re-search-forward thai-composition-pattern nil t)
172 (compose-region (match-beginning 0) (match-end 0))))))
173
174 ;;;###autoload
175 (defun thai-compose-string (string)
176 "Compose Thai characters in STRING and return the resulting string."
177 (with-category-table thai-category-table
178 (let ((idx 0))
179 (while (setq idx (string-match thai-composition-pattern string idx))
180 (compose-string string idx (match-end 0))
181 (setq idx (match-end 0)))))
182 string)
183
184 ;;;###autoload
185 (defun thai-compose-buffer ()
186 "Compose Thai characters in the current buffer."
187 (interactive)
188 (thai-compose-region (point-min) (point-max)))
189
190 ;;;###autoload
191 (defun thai-post-read-conversion (len)
192 (thai-compose-region (point) (+ (point) len))
193 len)
194
195 ;;;###autoload
196 (defun thai-composition-function (from to pattern &optional string)
197 "Compose Thai text in the region FROM and TO.
198 The text matches the regular expression PATTERN.
199 Optional 4th argument STRING, if non-nil, is a string containing text
200 to compose.
201
202 The return value is number of composed characters."a
203 (if (< (1+ from) to)
204 (prog1 (- to from)
205 (if string
206 (compose-string from to)
207 (compose-region from to))
208 (- to from))))
209
210 ;;
211 (provide 'thai-util)
212
213 ;;; thai-util.el ends here