Mercurial > emacs
annotate leim/quail/lrt.el @ 18839:1405083241e8
new version
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Thu, 17 Jul 1997 19:37:07 +0000 |
parents | 48e05cca9d7b |
children | 2d94069b1e81 |
rev | line source |
---|---|
18673 | 1 ;;; quail/lrt.el --- Quail package for inputting Lao characters by LRT method |
2 | |
3 ;; Copyright (C) 1997 Electrotechnical Laboratory, JAPAN. | |
4 ;; Licensed to the Free Software Foundation. | |
5 | |
6 ;; Keywords: multilingual, input method, Lao, LRT. | |
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 'lao-util) | |
29 | |
30 ;; LRT (Lao Roman Transcription) input method accepts the following | |
31 ;; key sequence: | |
32 ;; consonant [+ semi-vowel-sign-lo ] + vowel [+ maa-sakod ] [+ tone-mark ] | |
33 | |
34 (eval-and-compile | |
35 | |
36 ;; Upper vowels and tone-marks are put on the letter. | |
37 ;; Semi-vowel-sign-lo and lower vowels are put under the letter. | |
38 (defconst lrt-single-consonant-table | |
39 '(("k" . ?(1!(B) | |
40 ("kh" . ?(1"(B) | |
41 ("qh" . ?(1$(B) | |
42 ("ng" . ?(1'(B) | |
43 ("j" . ?(1((B) | |
44 ("s" . ?(1J(B) | |
45 ("x" . ?(1*(B) | |
46 ("y" . ?(1-(B) | |
47 ("d" . ?(14(B) | |
48 ("t" . ?(15(B) | |
49 ("th" . ?(16(B) | |
50 ("dh" . ?(17(B) | |
51 ("n" . ?(19(B) | |
52 ("b" . ?(1:(B) | |
53 ("p" . ?(1;(B) | |
54 ("hp" . ?(1<(B) | |
55 ("fh" . ?(1=(B) | |
56 ("ph" . ?(1>(B) | |
57 ("f" . ?(1?(B) | |
58 ("m" . ?(1A(B) | |
59 ("gn" . ?(1B(B) | |
60 ("l" . ?(1E(B) | |
61 ("r" . ?(1C(B) | |
62 ("v" . ?(1G(B) | |
63 ("w" . ?(1G(B) | |
64 ("hh" . ?(1K(B) | |
65 ("O" . ?(1M(B) | |
66 ("h" . ?(1N(B) | |
67 ("nh" . ?(1|(B) | |
68 ("mh" . ?(1}(B) | |
69 ("lh" . ?0(1K\1(B) | |
70 )) | |
71 | |
72 ;; Semi-vowel-sign-lo is put under the first letter. | |
73 ;; Lower vowels are put under the last letter. | |
74 ;; Upper vowels and tone-marks are put on the last letter. | |
75 (defconst lrt-double-consonant-table | |
76 '(("ngh" . "(1K'(B") | |
77 ("yh" . "(1K](B") | |
78 ("wh" . "(1KG(B") | |
79 ("hl" . "(1KE(B") | |
80 ("hy" . "(1K-(B") | |
81 ("hn" . "(1K9(B") | |
82 ("hm" . "(1KA(B") | |
83 )) | |
84 | |
85 (defconst lrt-semi-vowel-sign-lo | |
86 '("r" . ?(1\(B)) | |
87 | |
88 (defconst lrt-vowel-table | |
89 '(("a" "(1P(B" (0 ?(1P(B) (0 ?(1Q(B)) | |
90 ("ar" "(1R(B" (0 ?(1R(B)) | |
91 ("i" "(1T(B" (0 ?(1T(B)) | |
92 ("ii" "(1U(B" (0 ?(1U(B)) | |
93 ("eu" "(1V(B" (0 ?(1V(B)) | |
94 ("ur" "(1W(B" (0 ?(1W(B)) | |
95 ("u" "(1X(B" (0 ?(1X(B)) | |
96 ("uu" "(1Y(B" (0 ?(1Y(B)) | |
97 ("e" "(1`(B (1P(B" (?(1`(B 0 ?(1P(B) (?(1`(B 0 ?(1Q(B)) | |
98 ("ee" "(1`(B" (?(1`(B 0)) | |
99 ("ae" "(1a(B (1P(B" (?(1a(B 0 ?(1P(B) (?(1a(B 0 ?(1Q(B)) | |
100 ("aa" "(1a(B" (?(1a(B 0)) | |
101 ("o" "(1b(B (1P(B" (?(1b(B 0 ?(1P(B) (0 ?(1[(B) (?(1-(B ?(1b(B 0 ?(1Q(B) (?(1G(B ?(1b(B 0 ?(1Q(B)) | |
102 ("oo" "(1b(B" (?(1b(B 0)) | |
103 ("oe" "(1`(B (1RP(B" (?(1`(B 0 ?(1R(B ?(1P(B) (0 ?(1Q(B ?(1M(B)) | |
104 ("or" "(1m(B" (0 ?(1m(B) (0 ?(1M(B)) | |
105 ("er" "(1`(B (1T(B" (?(1`(B 0 ?(1T(B)) | |
106 ("ir" "(1`(B (1U(B" (?(1`(B 0 ?(1U(B)) | |
107 ("oua" "(1[GP(B" (0 ?(1[(B ?(1G(B ?(1P(B) (0 ?(1Q(B ?(1G(B)) | |
108 ("ua" "(1[G(B" (0 ?(1[(B ?(1G(B) (0 ?(1G(B)) | |
109 ("ie" "(1`Q]P(B" (?(1`(B 0 ?(1Q(B ?(1](B ?(1P(B) (0 ?(1Q(B ?(1](B)) | |
110 ("ia" "(1`Q](B" (?(1`(B 0 ?(1Q(B ?(1](B) (0 ?(1](B)) | |
111 ("eua" "(1`VM(B" (?(1`(B 0 ?(1V(B ?(1M(B)) | |
112 ("ea" "(1`WM(B" (?(1`(B 0 ?(1W(B ?(1M(B)) | |
113 ("ai" "(1d(B" (?(1d(B 0)) | |
114 ("ei" "(1c(B" (?(1c(B 0)) | |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
115 ("ao" "(1`[R(B" (?(1`(B 0 ?(1[(B ?(1R(B)) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
116 ("arm" "(1S(B" (?(1S(B 0)))) |
18673 | 117 |
118 ;; Maa-sakod is put at the tail. | |
119 (defconst lrt-maa-sakod-table | |
120 '((?k . ?(1!(B) | |
121 (?g . ?(1'(B) | |
122 (?y . ?(1-(B) | |
123 (?d . ?(14(B) | |
124 (?n . ?(19(B) | |
125 (?b . ?(1:(B) | |
126 (?m . ?(1A(B) | |
127 (?v . ?(1G(B) | |
128 (?w . ?(1G(B) | |
129 )) | |
130 | |
131 (defconst lrt-tone-mark-table | |
132 '(("'" . ?(1h(B) | |
133 ("\"" . ?(1i(B) | |
134 ("^" . ?(1j(B) | |
135 ("+" . ?(1k(B) | |
136 ("~" . ?(1l(B))) | |
137 | |
138 ;; Return list of composing patterns for normal (without maa-sakod) | |
139 ;; key sequence and with-maa-sakod key sequence starting with single | |
140 ;; consonant C and optional SEMI-VOWEL. | |
141 (defun lrt-composing-pattern-single-c (c semi-vowel vowel-pattern) | |
142 (let* ((patterns (copy-sequence vowel-pattern)) | |
143 (tail patterns) | |
144 place) | |
145 ;; Embed C and SEMI-VOWEL (if any) at the place of 0. | |
146 (while tail | |
147 ;; At first, make a copy. | |
148 (setcar tail (copy-sequence (car tail))) | |
149 ;; Then, do embedding. | |
150 (setq place (memq 0 (car tail))) | |
151 (setcar place c) | |
152 (if semi-vowel | |
153 (setcdr place (cons semi-vowel (cdr place)))) | |
154 (setq tail (cdr tail))) | |
155 patterns)) | |
156 | |
157 ;; Return list of composing patterns for normal (without maa-sakod) | |
158 ;; key sequence and with-maa-sakod key sequence starting with double | |
159 ;; consonant STR and optional SEMI-VOWEL. | |
160 (defun lrt-composing-pattern-double-c (str semi-vowel vowel-pattern) | |
161 (let* ((patterns (copy-sequence vowel-pattern)) | |
162 (tail patterns) | |
163 (chars (string-to-list str)) | |
164 place) | |
165 ;; Embed C and SEMI-VOWEL (if any) at the place of 0. | |
166 (while tail | |
167 ;; At first, make a copy. | |
168 (setcar tail (copy-sequence (car tail))) | |
169 ;; Then, do embedding. | |
170 (setq place (memq 0 (car tail))) | |
171 (setcar place (car chars)) | |
172 (setcdr place (cons (nth 1 chars) (cdr place))) | |
173 (if semi-vowel | |
174 ;; Embed SEMI-VOWEL in between CHARS. | |
175 (setcdr place (cons semi-vowel (cdr place)))) | |
176 (setq tail (cdr tail))) | |
177 patterns)) | |
178 | |
179 ;; Return a string made of characters in CHAR-LIST while composing | |
180 ;; such characters as vowel-upper, vowel-lower, semi-vowel(lower), | |
181 ;; and tone-mark with the preceding base character. | |
182 (defun lrt-compose-string (char-list) | |
183 ;; Make a copy because the following work alters it. | |
184 (setq char-list (copy-sequence char-list)) | |
185 (let ((i -1) | |
186 (l char-list)) | |
187 (while l | |
188 (if (memq (get-char-code-property (car l) 'phonetic-type) | |
189 '(vowel-upper vowel-lower semivowel-lower tone)) | |
190 (let (composed-char) | |
191 (if (< i 0) | |
192 ;; No preceding base character. | |
193 (error "Invalid CHAR-LIST: %s" char-list)) | |
194 (setq composed-char | |
195 (string-to-char (compose-chars (nth i char-list) (car l)))) | |
196 (setcar (nthcdr i char-list) composed-char) | |
197 (setq l (cdr l)) | |
198 (setcdr (nthcdr i char-list) l)) | |
199 (setq l (cdr l)) | |
200 (setq i (1+ i)))) | |
201 (concat (apply 'vector char-list)))) | |
202 | |
203 (defun lrt-compose-c-s-v (consonant semi-vowel vowel-pattern) | |
204 (let ((pattern-list | |
205 (if (integerp consonant) | |
206 (lrt-composing-pattern-single-c | |
207 consonant semi-vowel vowel-pattern) | |
208 (lrt-composing-pattern-double-c | |
209 consonant semi-vowel vowel-pattern)))) | |
210 (cons (vector (lrt-compose-string (car pattern-list))) | |
211 (cons t pattern-list)))) | |
212 | |
213 ) | |
214 | |
215 (defun lrt-handle-maa-sakod () | |
216 (interactive) | |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
217 (if (or (= (length quail-current-key) 0) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
218 (not quail-current-data)) |
18673 | 219 (quail-self-insert-command) |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
220 (if (not (car quail-current-data)) |
18673 | 221 (progn |
222 (setq quail-current-data nil) | |
223 (setq unread-command-events | |
224 (cons last-command-event unread-command-events)) | |
225 (quail-terminate-translation)) | |
226 (if (not (integerp last-command-event)) | |
227 (error "Bogus calling sequence")) | |
228 (let* ((maa-sakod (cdr (assq last-command-event lrt-maa-sakod-table))) | |
229 (maa-sakod-pattern (append | |
230 (or (cdr (assq maa-sakod | |
231 (nthcdr 3 quail-current-data))) | |
232 (nth 2 quail-current-data) | |
233 (nth 1 quail-current-data)) | |
234 (list maa-sakod)))) | |
235 (quail-delete-region) | |
236 (setq quail-current-str (lrt-compose-string maa-sakod-pattern)) | |
237 (insert quail-current-str) | |
238 (setq quail-current-key " ") | |
239 (quail-show-translations) | |
240 (setq quail-current-data (list nil maa-sakod-pattern)))))) | |
241 | |
242 (defun lrt-handle-tone-mark () | |
243 (interactive) | |
244 (if (= (length quail-current-key) 0) | |
245 (quail-self-insert-command) | |
246 (if (not quail-current-data) | |
247 (progn | |
248 (setq unread-command-events | |
249 (cons last-command-event unread-command-events)) | |
250 (quail-terminate-translation)) | |
251 (if (not (integerp last-command-event)) | |
252 (error "Bogus calling sequence")) | |
253 (let* ((tone-mark (cdr (assoc (char-to-string last-command-event) | |
254 lrt-tone-mark-table))) | |
255 (tone-mark-pattern | |
256 (if (car quail-current-data) | |
257 (copy-sequence (nth 1 quail-current-data)) | |
258 ;; No need of copy because lrt-handle-maa-sakod should | |
259 ;; have already done it. | |
260 (nth 1 quail-current-data))) | |
261 (tail tone-mark-pattern) | |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
262 (double-consonant-tail '(?(1'(B ?(1](B ?(1G(B ?(1E(B ?(1-(B ?(19(B ?(1A(B)) |
18673 | 263 place) |
264 ;; Find a place to embed TONE-MARK. It should be after a | |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
265 ;; single or double consonant and following vowels. |
18673 | 266 (while (and tail (not place)) |
267 (if (and | |
268 (eq (get-char-code-property (car tail) 'phonetic-type) | |
18833
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
269 'consonant) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
270 ;; Skip `(1K(B' if it is the first letter of double consonant. |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
271 (or (/= (car tail) ?(1K(B) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
272 (not (cdr tail)) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
273 (not |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
274 (if (= (car (cdr tail)) ?(1\(B) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
275 (and (cdr (cdr tail)) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
276 (memq (car (cdr (cdr tail))) double-consonant-tail)) |
48e05cca9d7b
(lrt-vowel-table): Change "ow" -> "ao", "am" -> "arm".
Kenichi Handa <handa@m17n.org>
parents:
18673
diff
changeset
|
277 (memq (car (cdr tail)) double-consonant-tail))))) |
18673 | 278 (progn |
279 (setq place tail) | |
280 (setq tail (cdr tail)) | |
281 (while (and tail | |
282 (memq (get-char-code-property (car tail) | |
283 'phonetic-type) | |
284 '(vowel-upper vowel-lower semivowel-lower))) | |
285 (setq place tail tail (cdr tail)))) | |
286 (setq tail (cdr tail)))) | |
287 ;; Embed TONE-MARK. | |
288 (setcdr place (cons tone-mark (cdr place))) | |
289 (quail-delete-region) | |
290 (insert (lrt-compose-string tone-mark-pattern)) | |
291 (setq quail-current-data nil) | |
292 (quail-terminate-translation))))) | |
293 | |
294 (defmacro lrt-generate-quail-map () | |
295 `(quail-install-map | |
296 ',(let ((map (list nil)) | |
297 (semi-vowel-key (car lrt-semi-vowel-sign-lo)) | |
298 (semi-vowel-char (cdr lrt-semi-vowel-sign-lo)) | |
299 l1 e1 l2 e2 pattern key) | |
300 ;; Single consonants. | |
301 (setq l1 lrt-single-consonant-table) | |
302 (while l1 | |
303 (setq e1 (car l1)) | |
304 (quail-defrule-internal (car e1) (cdr e1) map) | |
305 (quail-defrule-internal | |
306 (concat (car e1) semi-vowel-key) | |
307 (compose-string (format "%c%c" (cdr e1) semi-vowel-char)) | |
308 map) | |
309 (setq l2 lrt-vowel-table) | |
310 (while l2 | |
311 (setq e2 (car l2)) | |
312 (setq key (concat (car e1) (car e2)) | |
313 pattern (lrt-compose-c-s-v (cdr e1) nil (nthcdr 2 e2))) | |
314 (quail-defrule-internal key pattern map) | |
315 (quail-defrule-internal | |
316 (concat key " ") | |
317 (vector (concat (aref (car pattern) 0) " ")) map) | |
318 (setq key (concat (car e1) semi-vowel-key (car e2)) | |
319 pattern (lrt-compose-c-s-v (cdr e1) semi-vowel-char | |
320 (nthcdr 2 e2))) | |
321 (quail-defrule-internal key pattern map) | |
322 (quail-defrule-internal | |
323 (concat key " ") | |
324 (vector (concat (aref (car pattern) 0) " ")) map) | |
325 (setq l2 (cdr l2))) | |
326 (setq l1 (cdr l1))) | |
327 | |
328 ;; Double consonants. | |
329 (setq l1 lrt-double-consonant-table) | |
330 (while l1 | |
331 (setq e1 (car l1)) | |
332 (quail-defrule-internal (car e1) (vector (cdr e1)) map) | |
333 (quail-defrule-internal | |
334 (concat (car e1) semi-vowel-key) | |
335 (vector (concat (compose-string | |
336 (format "%c%c" (sref (cdr e1) 0) semi-vowel-char)) | |
337 (substring (cdr e1) (charset-bytes 'lao)))) | |
338 map) | |
339 (setq l2 lrt-vowel-table) | |
340 (while l2 | |
341 (setq e2 (car l2)) | |
342 (setq key (concat (car e1) (car e2)) | |
343 pattern (lrt-compose-c-s-v (cdr e1) nil (nthcdr 2 e2))) | |
344 (quail-defrule-internal key pattern map) | |
345 (quail-defrule-internal | |
346 (concat key " ") | |
347 (vector (concat (aref (car pattern) 0) " ")) map) | |
348 (setq key (concat (car e1) semi-vowel-key (car e2)) | |
349 pattern (lrt-compose-c-s-v (cdr e1) semi-vowel-char | |
350 (nthcdr 2 e2))) | |
351 (quail-defrule-internal key pattern map) | |
352 (quail-defrule-internal | |
353 (concat key " ") | |
354 (vector (concat (aref (car pattern) 0) " ")) map) | |
355 (setq l2 (cdr l2))) | |
356 (setq l1 (cdr l1))) | |
357 | |
358 ;; Vowels. | |
359 (setq l1 lrt-vowel-table) | |
360 (while l1 | |
361 (setq e1 (car l1) l1 (cdr l1)) | |
362 (quail-defrule-internal (car e1) (vector (nth 1 e1)) map)) | |
363 | |
364 ;; Tone-marks. | |
365 (setq l1 lrt-tone-mark-table) | |
366 (while l1 | |
367 (setq e1 (car l1) l1 (cdr l1)) | |
368 (quail-defrule-internal (car e1) (cdr e1) map)) | |
369 | |
370 map))) | |
371 | |
372 (quail-define-package | |
373 "lao-lrt" "Lao" "(1"(BR" t | |
374 "Lao input method using LRT (Lao Roman Transcription)" | |
375 '(("k" . lrt-handle-maa-sakod) | |
376 ("g" . lrt-handle-maa-sakod) | |
377 ("y" . lrt-handle-maa-sakod) | |
378 ("d" . lrt-handle-maa-sakod) | |
379 ("n" . lrt-handle-maa-sakod) | |
380 ("b" . lrt-handle-maa-sakod) | |
381 ("m" . lrt-handle-maa-sakod) | |
382 ("v" . lrt-handle-maa-sakod) | |
383 ("w" . lrt-handle-maa-sakod) | |
384 ("'" . lrt-handle-tone-mark) | |
385 ("\"" . lrt-handle-tone-mark) | |
386 ("^" . lrt-handle-tone-mark) | |
387 ("+" . lrt-handle-tone-mark) | |
388 ("~" . lrt-handle-tone-mark)) | |
389 'forget-last-selection 'deterministic 'kbd-translate 'show-layout) | |
390 | |
391 (lrt-generate-quail-map) |