Mercurial > emacs
annotate lisp/language/viet-util.el @ 41196:f8661b5a0670
("French"): New language environment.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 17 Nov 2001 14:37:32 +0000 |
parents | 67b464da13ec |
children | 189dc6f5e0a6 88f65b224d62 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36683
diff
changeset
|
1 ;;; viet-util.el --- utilities for Vietnamese -*- coding: iso-2022-7bit; -*- |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18309
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 5 |
6 ;; Keywords: mule, multilingual, Vietnamese | |
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 | |
17071 | 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. | |
17052 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; Vietnamese uses ASCII characters and additional 134 unique | |
28 ;; characters (these are Latin alphabets with various diacritical and | |
29 ;; tone marks). As far as I know, Vietnamese now has 4 different ways | |
30 ;; for representing these characters: VISCII, VSCII, VIQR, and | |
31 ;; Unicode. VISCII and VSCII are simple 1-byte code which assigns 134 | |
32 ;; unique characters in control-code area (0x00..0x1F) and right half | |
33 ;; area (0x80..0xFF). VIQR is a menmonic encoding specification | |
34 ;; representing diacritical marks by following ASCII characters. | |
35 | |
36 ;;; Code: | |
37 | |
18970
5bbc07f4c61e
(setup-vietnamese-environment): Add autoload cookie.
Kenichi Handa <handa@m17n.org>
parents:
18552
diff
changeset
|
38 ;;;###autoload |
22880
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
39 (defun viet-encode-viscii-char (char) |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
40 "Return VISCII character code of CHAR if appropriate." |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
41 (aref (char-table-extra-slot viet-viscii-nonascii-translation-table 0) |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
42 char)) |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
43 |
17052 | 44 ;; VIQR is a menmonic encoding specification for Vietnamese. |
45 ;; It represents diacritical marks by ASCII characters as follows: | |
46 ;; ------------+----------+-------- | |
47 ;; mark | mnemonic | example | |
48 ;; ------------+----------+--------- | |
49 ;; breve | ( | a( -> ,1e(B | |
50 ;; circumflex | ^ | a^ -> ,1b(B | |
51 ;; horn | + | o+ -> ,1=(B | |
52 ;; ------------+----------+--------- | |
53 ;; acute | ' | a' -> ,1a(B | |
54 ;; grave | ` | a` -> ,1`(B | |
55 ;; hook above | ? | a? -> ,1d(B | |
56 ;; tilde | ~ | a~ -> ,1c(B | |
57 ;; dot below | . | a. -> ,1U(B | |
58 ;; ------------+----------+--------- | |
59 ;; d bar | dd | dd -> ,1p(B | |
60 ;; ------------+----------+--------- | |
61 | |
62 (defvar viet-viqr-alist | |
63 '(;; lowercase | |
64 (?,1!(B . "a('") ; 161 | |
65 (?,1"(B . "a(`") ; 162 | |
66 (?,1#(B . "a(.") ; 163 | |
67 (?,1$(B . "a^'") ; 164 | |
68 (?,1%(B . "a^`") ; 165 | |
69 (?,1&(B . "a^?") ; 166 | |
70 (?,1'(B . "a^.") ; 167 | |
71 (?,1((B . "e~") ; 168 | |
72 (?,1)(B . "e.") ; 169 | |
73 (?,1*(B . "e^'") ; 170 | |
74 (?,1+(B . "e^`") ; 171 | |
75 (?,1,(B . "e^?") ; 172 | |
76 (?,1-(B . "e^~") ; 173 | |
77 (?,1.(B . "e^.") ; 174 | |
78 (?,1/(B . "o^'") ; 175 | |
79 (?,10(B . "o^`") ; 176 | |
80 (?,11(B . "o^?") ; 177 | |
81 (?,12(B . "o^~") ; 178 | |
82 (?,15(B . "o^.") ; 181 | |
83 (?,16(B . "o+`") ; 182 | |
84 (?,17(B . "o+?") ; 183 | |
85 (?,18(B . "i.") ; 184 | |
86 (?,1=(B . "o+") ; 189 | |
87 (?,1>(B . "o+'") ; 190 | |
88 (?,1F(B . "a(?") ; 198 | |
89 (?,1G(B . "a(~") ; 199 | |
90 (?,1O(B . "y`") ; 207 | |
91 (?,1Q(B . "u+'") ; 209 | |
92 (?,1U(B . "a.") ; 213 | |
93 (?,1V(B . "y?") ; 214 | |
94 (?,1W(B . "u+`") ; 215 | |
95 (?,1X(B . "u+?") ; 216 | |
96 (?,1[(B . "y~") ; 219 | |
97 (?,1\(B . "y.") ; 220 | |
98 (?,1^(B . "o+~") ; 222 | |
99 (?,1_(B . "u+") ; 223 | |
100 (?,1`(B . "a`") ; 224 | |
101 (?,1a(B . "a'") ; 225 | |
102 (?,1b(B . "a^") ; 226 | |
103 (?,1c(B . "a~") ; 227 | |
104 (?,1d(B . "a?") ; 228 | |
105 (?,1e(B . "a(") ; 229 | |
106 (?,1f(B . "u+~") ; 230 | |
107 (?,1g(B . "a^~") ; 231 | |
108 (?,1h(B . "e`") ; 232 | |
109 (?,1i(B . "e'") ; 233 | |
110 (?,1j(B . "e^") ; 234 | |
111 (?,1k(B . "e?") ; 235 | |
112 (?,1l(B . "i`") ; 236 | |
113 (?,1m(B . "i'") ; 237 | |
114 (?,1n(B . "i~") ; 238 | |
115 (?,1o(B . "i?") ; 239 | |
116 (?,1p(B . "dd") ; 240 | |
117 (?,1q(B . "u+.") ; 241 | |
118 (?,1r(B . "o`") ; 242 | |
119 (?,1s(B . "o'") ; 243 | |
120 (?,1t(B . "o^") ; 244 | |
121 (?,1u(B . "o~") ; 245 | |
122 (?,1v(B . "o?") ; 246 | |
123 (?,1w(B . "o.") ; 247 | |
124 (?,1x(B . "u.") ; 248 | |
125 (?,1y(B . "u`") ; 249 | |
126 (?,1z(B . "u'") ; 250 | |
127 (?,1{(B . "u~") ; 251 | |
128 (?,1|(B . "u?") ; 252 | |
129 (?,1}(B . "y'") ; 253 | |
130 (?,1~(B . "o+.") ; 254 | |
131 | |
132 ;; upper case | |
133 (?,2!(B . "A('") ; 161 | |
134 (?,2"(B . "A(`") ; 162 | |
135 (?,2#(B . "A(.") ; 163 | |
136 (?,2$(B . "A^'") ; 164 | |
137 (?,2%(B . "A^`") ; 165 | |
138 (?,2&(B . "A^?") ; 166 | |
139 (?,2'(B . "A^.") ; 167 | |
140 (?,2((B . "E~") ; 168 | |
141 (?,2)(B . "E.") ; 169 | |
142 (?,2*(B . "E^'") ; 170 | |
143 (?,2+(B . "E^`") ; 171 | |
144 (?,2,(B . "E^?") ; 172 | |
145 (?,2-(B . "E^~") ; 173 | |
146 (?,2.(B . "E^.") ; 174 | |
147 (?,2/(B . "O^'") ; 175 | |
148 (?,20(B . "O^`") ; 176 | |
149 (?,21(B . "O^?") ; 177 | |
150 (?,22(B . "O^~") ; 178 | |
151 (?,25(B . "O^.") ; 181 | |
152 (?,26(B . "O+`") ; 182 | |
153 (?,27(B . "O+?") ; 183 | |
154 (?,28(B . "I.") ; 184 | |
155 (?,2=(B . "O+") ; 189 | |
156 (?,2>(B . "O+'") ; 190 | |
157 (?,2F(B . "A(?") ; 198 | |
158 (?,2G(B . "A(~") ; 199 | |
159 (?,2O(B . "Y`") ; 207 | |
160 (?,2Q(B . "U+'") ; 209 | |
161 (?,2U(B . "A.") ; 213 | |
162 (?,2V(B . "Y?") ; 214 | |
163 (?,2W(B . "U+`") ; 215 | |
164 (?,2X(B . "U+?") ; 216 | |
165 (?,2[(B . "Y~") ; 219 | |
166 (?,2\(B . "Y.") ; 220 | |
167 (?,2^(B . "O+~") ; 222 | |
168 (?,2_(B . "U+") ; 223 | |
169 (?,2`(B . "A`") ; 224 | |
170 (?,2a(B . "A'") ; 225 | |
171 (?,2b(B . "A^") ; 226 | |
172 (?,2c(B . "A~") ; 227 | |
173 (?,2d(B . "A?") ; 228 | |
174 (?,2e(B . "A(") ; 229 | |
175 (?,2f(B . "U+~") ; 230 | |
176 (?,2g(B . "A^~") ; 231 | |
177 (?,2h(B . "E`") ; 232 | |
178 (?,2i(B . "E'") ; 233 | |
179 (?,2j(B . "E^") ; 234 | |
180 (?,2k(B . "E?") ; 235 | |
181 (?,2l(B . "I`") ; 236 | |
182 (?,2m(B . "I'") ; 237 | |
183 (?,2n(B . "I~") ; 238 | |
184 (?,2o(B . "I?") ; 239 | |
185 (?,2p(B . "DD") ; 240 | |
186 (?,2p(B . "dD") ; 240 | |
187 (?,2p(B . "Dd") ; 240 | |
188 (?,2q(B . "U+.") ; 241 | |
189 (?,2r(B . "O`") ; 242 | |
190 (?,2s(B . "O'") ; 243 | |
191 (?,2t(B . "O^") ; 244 | |
192 (?,2u(B . "O~") ; 245 | |
193 (?,2v(B . "O?") ; 246 | |
194 (?,2w(B . "O.") ; 247 | |
195 (?,2x(B . "U.") ; 248 | |
196 (?,2y(B . "U`") ; 249 | |
197 (?,2z(B . "U'") ; 250 | |
198 (?,2{(B . "U~") ; 251 | |
199 (?,2|(B . "U?") ; 252 | |
200 (?,2}(B . "Y'") ; 253 | |
201 (?,2~(B . "O+.") ; 254 | |
202 | |
203 ;; escape from composition | |
204 (?\( . "\\(") ; breve (left parenthesis) | |
205 (?^ . "\\^") ; circumflex (caret) | |
206 (?+ . "\\+") ; horn (plus sign) | |
207 (?' . "\\'") ; acute (apostrophe) | |
208 (?` . "\\`") ; grave (backquote) | |
209 (?? . "\\?") ; hook above (question mark) | |
210 (?~ . "\\~") ; tilde (tilde) | |
211 (?. . "\\.") ; dot below (period) | |
212 (?d . "\\d") ; d-bar (d) | |
213 (?\\ . "\\\\") ; literal backslash | |
214 ) | |
215 "Alist of Vietnamese characters vs corresponding `VIQR' string.") | |
216 | |
217 ;; Regular expression matching single Vietnamese character represented | |
218 ;; by VIQR. | |
219 (defconst viqr-regexp | |
220 "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]") | |
221 | |
222 ;;;###autoload | |
223 (defun viet-decode-viqr-region (from to) | |
224 "Convert `VIQR' mnemonics of the current region to Vietnamese characaters. | |
225 When called from a program, expects two arguments, | |
226 positions (integers or markers) specifying the stretch of the region." | |
227 (interactive "r") | |
228 (save-restriction | |
229 (narrow-to-region from to) | |
230 (goto-char (point-min)) | |
231 (while (re-search-forward viqr-regexp nil t) | |
232 (let* ((viqr (buffer-substring (match-beginning 0) (match-end 0))) | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
233 (ch (car (rassoc viqr viet-viqr-alist)))) |
17052 | 234 (if ch |
235 (progn | |
236 (delete-region (match-beginning 0) (match-end 0)) | |
237 (insert ch))))))) | |
238 | |
239 ;;;###autoload | |
240 (defun viet-decode-viqr-buffer () | |
241 "Convert `VIQR' mnemonics of the current buffer to Vietnamese characaters." | |
242 (interactive) | |
243 (viet-decode-viqr-region (point-min) (point-max))) | |
244 | |
245 ;;;###autoload | |
246 (defun viet-encode-viqr-region (from to) | |
247 "Convert Vietnamese characaters of the current region to `VIQR' mnemonics. | |
248 When called from a program, expects two arguments, | |
249 positions (integers or markers) specifying the stretch of the region." | |
250 (interactive "r") | |
251 (save-restriction | |
252 (narrow-to-region from to) | |
253 (goto-char (point-min)) | |
254 (while (re-search-forward "\\cv" nil t) | |
255 (let* ((ch (preceding-char)) | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
256 (viqr (cdr (assq ch viet-viqr-alist)))) |
17052 | 257 (if viqr |
258 (progn | |
259 (delete-char -1) | |
260 (insert viqr))))))) | |
261 | |
262 ;;;###autoload | |
263 (defun viet-encode-viqr-buffer () | |
264 "Convert Vietnamese characaters of the current buffer to `VIQR' mnemonics." | |
265 (interactive) | |
266 (viet-encode-viqr-region (point-min) (point-max))) | |
267 | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
268 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
269 (defun viqr-post-read-conversion (len) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
270 (save-excursion |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
271 (save-restriction |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
272 (narrow-to-region (point) (+ (point) len)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
273 (let ((buffer-modified-p (buffer-modified-p))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
274 (viet-decode-viqr-region (point-min) (point-max)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
275 (set-buffer-modified-p buffer-modified-p) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
276 (- (point-max) (point-min)))))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
277 |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
278 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
279 (defun viqr-pre-write-conversion (from to) |
23521
616acf65d243
(viqr-pre-write-conversion): Use with-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
280 (let ((old-buf (current-buffer))) |
23544
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
281 (set-buffer (generate-new-buffer " *temp*")) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
282 (if (stringp from) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
283 (insert from) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
284 (insert-buffer-substring old-buf from to)) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
285 (viet-encode-viqr-region (point-min) (point-max)) |
17777
081f940a8d1f
(viqr-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
286 ;; Should return nil as annotations. |
081f940a8d1f
(viqr-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
287 nil)) |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
288 |
17052 | 289 ;;; |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
290 (provide 'viet-util) |
17052 | 291 |
292 ;;; viet-util.el ends here |