Mercurial > emacs
annotate lisp/language/indian.el @ 17422:4042e903985b
Add defgroup's; use defcustom for user vars.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 12 Apr 1997 19:25:28 +0000 |
parents | f438ebf1c679 |
children | 550afdbb31d8 |
rev | line source |
---|---|
17052 | 1 ;;; indian.el --- Support for Indian Languages |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp> | |
6 | |
7 ;; Keywords: multilingual, Indian | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
17314
f438ebf1c679
Fix FSF address in comment.
Kenichi Handa <handa@m17n.org>
parents:
17300
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
f438ebf1c679
Fix FSF address in comment.
Kenichi Handa <handa@m17n.org>
parents:
17300
diff
changeset
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
f438ebf1c679
Fix FSF address in comment.
Kenichi Handa <handa@m17n.org>
parents:
17300
diff
changeset
|
24 ;; Boston, MA 02111-1307, USA. |
17052 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; History: | |
29 ;; 1996.10.18 written by KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp> | |
30 | |
31 ;; For Indian, the character set IS 13194 is supported. | |
32 ;; | |
33 ;; IS 13194 does not specifically assign glyphs for each characters. | |
34 ;; Following code is not specific to each Indian language. | |
35 ;; | |
36 ;; Eventually, this code will support generic information about | |
37 ;; following scripts. | |
38 ;; | |
39 ;; Devanagari | |
40 ;; Bengali | |
41 ;; Gurmukhi | |
42 ;; Gujarati | |
43 ;; Oriya | |
44 ;; Tamil | |
45 ;; Telgu | |
46 ;; Kannada | |
47 ;; Malayalam | |
48 ;; | |
49 ;; In this file, charsets other than charset-ascii and charset-indian-is13194 | |
50 ;; should not be used except in the comment. | |
51 | |
52 ;;; Code: | |
53 | |
54 ;; Followings are what you see when you refer to the Emacs | |
55 ;; representations of IS 13194 charcters. However, this is merely | |
56 ;; tentative apperance, and you must convert them by | |
57 ;; indian-to-xxxxxx(specific script) function to use them. | |
58 ;; Devanagari is not an exception of this rule. | |
59 | |
60 ;; 0xa0 //(5!"#$%&'()*+,-./(B | |
61 ;; 0xb0 (50123456789:;<=>?(B | |
62 ;; 0xc0 (5@ABCDEFGHIJKLMNO(B | |
63 ;; 0xd0 (5PQRSTUVWXYZ[\]^_(B | |
64 ;; 0xe0 (5`abcdefghijklmno(B | |
65 ;; 0xf0 (5pqrstuvwxyz{|}~(B// | |
66 | |
67 ;; Note - In IS 13194, several symbols are obtained by special | |
68 ;; combination of several characters and Nukta sign. | |
69 ;; | |
70 ;; Sanskrit Vowel R -> (5*(B + (5i(B | |
71 ;; Sanskrit Vowel L -> (5&(B + (5i(B | |
72 ;; Sanskrit Vowel LL -> (5'(B + (5i(B | |
73 ;; Sanskrit Avagrah -> (5j(B + (5i(B | |
74 ;; OM -> (5!(B + (5i(B | |
75 ;; | |
76 ;; Note - IS 13194 defines ATR(0xEF) and EXT(0xF0), but they are | |
77 ;; not used in Emacs. | |
78 ;; | |
79 ;; Note - the above characters DO NOT represent any script. For | |
80 ;; example, if you want to obtain Devanagari character, you must do | |
81 ;; something like the following. | |
82 ;; | |
83 ;; (char-to-string (indian-to-devanagari ?(5$(B)) | |
84 ;; "$(5!$(B" | |
85 | |
86 (let ((deflist | |
87 '(;; chars syntax category | |
88 ("(5!"#(B" "w" ?7) ; vowel-modifying diacritical mark | |
89 ; chandrabindu, anuswar, visarga | |
90 ("(5$(B-(52(B" "w" ?5) ; independent vowel | |
91 ("(53(B-(5X(B" "w" ?0) ; consonant | |
92 ("(5Z(B-(5g(B" "w" ?8) ; matra | |
93 ("(5q(B-(5z(B" "w" ?6) ; digit | |
94 )) | |
95 elm chars len syntax category to ch i) | |
96 (while deflist | |
97 (setq elm (car deflist)) | |
98 (setq chars (car elm) | |
99 len (length chars) | |
100 syntax (nth 1 elm) | |
101 category (nth 2 elm) | |
102 i 0) | |
103 (while (< i len) | |
104 (if (= (aref chars i) ?-) | |
105 (setq i (1+ i) | |
106 to (sref chars i)) | |
107 (setq ch (sref chars i) | |
108 to ch)) | |
109 (while (<= ch to) | |
110 (modify-syntax-entry ch syntax) | |
111 (modify-category-entry ch category) | |
112 (setq ch (1+ ch))) | |
113 (setq i (+ i (char-bytes to)))) | |
114 (setq deflist (cdr deflist)))) | |
115 | |
116 | |
117 ;;; ITRANS | |
118 ;; | |
119 ;; ITRANS is one of the most popular method to exchange indian scripts | |
120 ;; electronically. Here is the table to convert between ITRANS code and | |
121 ;; IS 13194 code. | |
122 | |
123 (defvar indian-itrans-consonant-alist | |
124 '( | |
125 ("k" . "(53(B") | |
126 ("kh" . "(54(B") | |
127 ("g" . "(55(B") | |
128 ("gh" . "(56(B") | |
129 ("N^" . "(57(B") | |
130 ("ch" . "(58(B") | |
131 ("chh" . "(59(B") | |
132 ("j" . "(5:(B") | |
133 ("jh" . "(5;(B") | |
134 ("JN" . "(5<(B") | |
135 ("T" . "(5=(B") | |
136 ("Th" . "(5>(B") | |
137 ("D" . "(5?(B") | |
138 ("Dh" . "(5@(B") | |
139 ("N" . "(5A(B") | |
140 ("t" . "(5B(B") | |
141 ("th" . "(5C(B") | |
142 ("d" . "(5D(B") | |
143 ("dh" . "(5E(B") | |
144 ("n" . "(5F(B") | |
145 ("nh" . "(5G(B") ; For transcription of non-Devanagari Languages. | |
146 ("p" . "(5H(B") | |
147 ("ph" . "(5I(B") | |
148 ("b" . "(5J(B") | |
149 ("bh" . "(5K(B") | |
150 ("m" . "(5L(B") | |
151 ("y" . "(5M(B") | |
152 ("yh" . "(5N(B") ; For transcription of non-Devanagari Languages. | |
153 ("r" . "(5O(B") | |
154 ("rh" . "(5P(B") ; For transcription of non-Devanagari Languages. | |
155 ("l" . "(5Q(B") | |
156 ("v" . "(5T(B") | |
157 ("sh" . "(5U(B") | |
158 ("shh" . "(5V(B") | |
159 ("s" . "(5W(B") | |
160 ("h" . "(5X(B") | |
161 ("ld" . "(5R(B") | |
162 ("L" . "(5R(B") | |
163 ("ksh" . "$(5!3!h!V(B") | |
164 ("GY" . "***GY***") ; Must check out later. | |
165 ;; special consonants | |
166 ("q" . "(53i(B") | |
167 ("K" . "(54i(B") | |
168 ("G" . "(55i(B") | |
169 ("z" . "(5:i(B") | |
170 ("f" . "(5Ii(B") | |
171 (".D" . "(5?i(B") | |
172 (".Dh" . "(5@i(B") | |
173 )) | |
174 | |
175 (defvar indian-itrans-vowel-sign-alist | |
176 '( | |
177 ;; Special treatment unique to IS 13194 Transliteration | |
178 ("" . "(5h(B") | |
179 ("a" . "") | |
180 ;; Matra (Vowel Sign) | |
181 ("aa" . "(5Z(B") | |
182 ("A" . "(5Z(B") | |
183 ("i" . "(5[(B") | |
184 ("ii" . "(5\(B") | |
185 ("I" . "(5\(B") | |
186 ("u" . "(5](B") | |
187 ("uu" . "(5^(B") | |
188 ("U" . "(5^(B") | |
189 ("R^i" . "(5_(B") ; These must be checked out later. | |
190 ("R^I" . "(5_i(B") | |
191 ("L^i" . "(5[i(B") | |
192 ("L^I" . "(5\i(B") | |
193 ("E" . "(5`(B") ; For transcription of non-Devanangri Languages. | |
194 ("e" . "(5a(B") | |
195 ("ai" . "(5b(B") | |
196 ;; ("e.c" . "(5c(B") ; Tentatively suppressed. | |
197 ("O" . "(5d(B") ; For transcription of non-Devanagari Languages. | |
198 ("o" . "(5e(B") | |
199 ("au" . "(5f(B") | |
200 ;; ("o.c" . "(5g(B") ; Tentatively suppressed. | |
201 )) | |
202 | |
203 ;; | |
204 ;; Independent vowels and other signs. | |
205 ;; | |
206 | |
207 (defvar indian-itrans-other-letters-alist | |
208 '( | |
209 ("a" . "(5$(B") | |
210 ("aa" . "(5%(B") | |
211 ("A" . "(5%(B") | |
212 ("i" . "(5&(B") | |
213 ("ii" . "(5'(B") | |
214 ("I" . "(5'(B") | |
215 ("u" . "(5((B") | |
216 ("uu" . "(5)(B") | |
217 ("U" . "(5)(B") | |
218 ("R^i" . "(5*(B") | |
219 ("R^I" . "(5*i(B") | |
220 ("L^i" . "(5&i(B") | |
221 ("L^I" . "(5'i(B") | |
222 ("E" . "(5+(B") ; For transcription of non-Devanagari Languages. | |
223 ("e" . "(5,(B") | |
224 ("ai" . "(5-(B") | |
225 ;; ("e.c" . "(5.(B") ; Candra E | |
226 ("O" . "(5/(B") ; For transcription of non-Devanagari Languages. | |
227 ("o" . "(50(B") | |
228 ("au" . "(51(B") | |
229 ;; ("o.c" . "(52(B") ; Candra O | |
230 ("M" . "(5$(B") | |
231 ("H" . "(5#(B") | |
232 ("AUM" . "(5!i(B") | |
233 ("OM" . "(5!i(B") | |
234 (".r" . "(5Oh(B") | |
235 (".n" . "(5"(B") | |
236 (".N" . "(5!(B") | |
237 (".h" . "(5h(B") ; Halant | |
238 (".." . "(5j(B") | |
239 (".a" . "(5ji(B") ; Avagrah | |
240 ("0" . "(5q(B") | |
241 ("1" . "(5r(B") | |
242 ("2" . "(5s(B") | |
243 ("3" . "(5t(B") | |
244 ("4" . "(5u(B") | |
245 ("5" . "(5v(B") | |
246 ("6" . "(5w(B") | |
247 ("7" . "(5x(B") | |
248 ("8" . "(5y(B") | |
249 ("9" . "(5z(B") | |
250 )) | |
251 | |
252 ;; Regular expression matching single Indian character represented | |
253 ;; by ITRANS. | |
254 | |
255 (defvar indian-itrans-regexp | |
256 (let ((consonant "\\([cs]hh?\\)\\|[kgjTDnpbyr]h?\\|\\(N\\^?\\)\\|\\(jN\\)\\|[mvqKGzfs]\\|\\(ld?\\)\\|\\(ksh\\)\\|\\(GY\\)\\|\\(\\.Dh?\\)") | |
257 (vowel "\\(a[aiu]\\)\\|\\(ii\\)\\|\\(uu\\)\\|\\([RL]\\^[iI]\\)\\|[AIEOeoaiu]") | |
258 (misc "[MH0-9]\\|\\(AUM\\)\\|\\(OM\\)\\|\\(\\.[rnNh\\.a]\\)") | |
259 (lpre "\\(") (rpre "\\)") (orre "\\|")) | |
260 (concat lpre misc rpre orre | |
261 lpre lpre consonant rpre "?" lpre vowel rpre rpre orre | |
262 lpre consonant rpre ))) | |
263 | |
264 ;; | |
265 ;; Regular expression matching single ITRANS unit for IS 13194 characters. | |
266 ;; | |
267 | |
268 (defvar itrans-indian-regexp | |
269 (let ((vowel "[(5$(B-(52(B]") | |
270 (consonant "[(53(B-(5X(B]") | |
17300
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
271 (matra "[(5Z(B-(5g(B]") |
17052 | 272 (misc "[(5q(B-(5z(B]") |
273 (lpre "\\(") (rpre "\\)") (orre "\\|")) | |
17300
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
274 (concat misc orre |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
275 lpre consonant matra "?" rpre orre |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
276 vowel))) |
17052 | 277 |
278 ;; | |
279 ;; IS13194 - ITRANS conversion table for string matching above regexp. | |
280 ;; | |
281 | |
282 (defvar indian-itrans-alist | |
283 (let ((cl indian-itrans-consonant-alist) | |
284 (ml indian-itrans-other-letters-alist) rules) | |
285 (while cl | |
286 (let ((vl indian-itrans-vowel-sign-alist)) | |
287 (while vl | |
288 (setq rules | |
289 (cons (cons (concat (car (car cl)) (car (car vl))) | |
290 (concat (cdr (car cl)) (cdr (car vl)))) | |
291 rules)) | |
292 (setq vl (cdr vl)))) | |
293 (setq cl (cdr cl))) | |
294 (while ml | |
295 (setq rules (cons (cons (car (car ml)) | |
296 (cdr (car ml))) | |
297 rules)) | |
298 (setq ml (cdr ml))) | |
299 rules)) | |
300 | |
301 ;; | |
302 ;; Utility program to convert from ITRANS to IS 13194 in specified region. | |
303 ;; | |
304 | |
305 (defun indian-decode-itrans-region (from to) | |
306 "Convert `ITRANS' mnemonics of the current region to Indian characters. | |
307 When called from a program, expects two arguments, | |
308 positions (integers or markers) specifying the stretch of the region." | |
309 (interactive "r") | |
310 (save-restriction | |
311 (narrow-to-region from to) | |
312 (goto-char (point-min)) | |
313 (while (re-search-forward indian-itrans-regexp nil t) | |
314 (let* ((itrans (buffer-substring (match-beginning 0) (match-end 0))) | |
315 (ch (cdr (assoc itrans indian-itrans-alist)))) | |
316 (if ch | |
317 (progn | |
318 (delete-region (match-beginning 0) (match-end 0)) | |
319 (insert ch))))) | |
320 (goto-char (point-min)) | |
321 (while (re-search-forward "\\((5h(B\\)[^\\c0]" nil t) | |
322 (delete-region (match-beginning 1) (match-end 1))))) | |
323 | |
324 ;; | |
325 ;; Utility program to convert from IS 13194 to ITRANS in specified region. | |
326 ;; | |
327 | |
17300
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
328 (defun indian-encode-itrans-region (from to) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
329 "Convert indian region to ITRANS mnemonics." |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
330 (interactive "r") |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
331 (save-restriction |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
332 (narrow-to-region from to) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
333 (goto-char (point-min)) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
334 (while (re-search-forward itrans-indian-regexp nil t) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
335 (let* ((indian (buffer-substring (match-beginning 0) (match-end 0))) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
336 (ch (car (rassoc indian indian-itrans-alist)))) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
337 (if ch |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
338 (progn |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
339 (delete-region (match-beginning 0) (match-end 0)) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
340 (insert ch))))) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
341 (goto-char (point-min)))) |
01d528c5dd18
Handle more Devanagari characters correctly.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
342 |
17052 | 343 ;;; indian.el ends here |