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