Mercurial > emacs
annotate lisp/language/viet-util.el @ 92761:e3d7d040b34d
*** empty log message ***
author | Tassilo Horn <tassilo@member.fsf.org> |
---|---|
date | Wed, 12 Mar 2008 14:59:10 +0000 |
parents | 606f2d163a64 |
children | 1e3a407766b9 |
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 |
79711 | 3 ;; Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
74544 | 4 ;; Free Software Foundation, Inc. |
74605
6ee41fdd69ff
Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents:
74544
diff
changeset
|
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
79711 | 6 ;; 2005, 2006, 2007, 2008 |
62396 | 7 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
8 ;; Registration Number H14PRO021 | |
89483 | 9 ;; Copyright (C) 2003 |
10 ;; National Institute of Advanced Industrial Science and Technology (AIST) | |
11 ;; Registration Number H13PRO009 | |
17052 | 12 |
13 ;; Keywords: mule, multilingual, Vietnamese | |
14 | |
15 ;; This file is part of GNU Emacs. | |
16 | |
17 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
18 ;; it under the terms of the GNU General Public License as published by | |
78309
0938de05f510
Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents:
78300
diff
changeset
|
19 ;; the Free Software Foundation; either version 3, or (at your option) |
17052 | 20 ;; any later version. |
21 | |
22 ;; GNU Emacs is distributed in the hope that it will be useful, | |
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 ;; GNU General Public License for more details. | |
26 | |
27 ;; You should have received a copy of the GNU General Public License | |
17071 | 28 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
30 ;; Boston, MA 02110-1301, USA. | |
17052 | 31 |
32 ;;; Commentary: | |
33 | |
34 ;; Vietnamese uses ASCII characters and additional 134 unique | |
35 ;; characters (these are Latin alphabets with various diacritical and | |
44963 | 36 ;; tone marks). As far as I know, Vietnamese now has 5 different ways |
37 ;; for representing these characters: VISCII, TCVN-5712, VPS, VIQR, | |
38 ;; and Unicode. VISCII, TCVN-5712 and VPS are simple 1-byte code | |
39 ;; which assigns 134 unique characters in control-code area | |
40 ;; (0x00..0x1F) and right half area (0x80..0xFF). VIQR is a menmonic | |
41 ;; encoding specification representing diacritical marks by following | |
42 ;; ASCII characters. | |
17052 | 43 |
44 ;;; Code: | |
45 | |
62619
fee0933da7fe
(viet-viscii-nonascii-translation-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
62396
diff
changeset
|
46 (defvar viet-viscii-nonascii-translation-table) |
fee0933da7fe
(viet-viscii-nonascii-translation-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
62396
diff
changeset
|
47 |
18970
5bbc07f4c61e
(setup-vietnamese-environment): Add autoload cookie.
Kenichi Handa <handa@m17n.org>
parents:
18552
diff
changeset
|
48 ;;;###autoload |
22880
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
49 (defun viet-encode-viscii-char (char) |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
50 "Return VISCII character code of CHAR if appropriate." |
88992
88f65b224d62
(viet-encode-viscii-char): Use encode-char.
Dave Love <fx@gnu.org>
parents:
38414
diff
changeset
|
51 (encode-char char 'viscii)) |
22880
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
52 |
17052 | 53 ;; VIQR is a menmonic encoding specification for Vietnamese. |
54 ;; It represents diacritical marks by ASCII characters as follows: | |
55 ;; ------------+----------+-------- | |
56 ;; mark | mnemonic | example | |
57 ;; ------------+----------+--------- | |
58 ;; breve | ( | a( -> ,1e(B | |
59 ;; circumflex | ^ | a^ -> ,1b(B | |
60 ;; horn | + | o+ -> ,1=(B | |
61 ;; ------------+----------+--------- | |
62 ;; acute | ' | a' -> ,1a(B | |
63 ;; grave | ` | a` -> ,1`(B | |
64 ;; hook above | ? | a? -> ,1d(B | |
65 ;; tilde | ~ | a~ -> ,1c(B | |
66 ;; dot below | . | a. -> ,1U(B | |
67 ;; ------------+----------+--------- | |
68 ;; d bar | dd | dd -> ,1p(B | |
69 ;; ------------+----------+--------- | |
70 | |
71 (defvar viet-viqr-alist | |
72 '(;; lowercase | |
73 (?,1!(B . "a('") ; 161 | |
74 (?,1"(B . "a(`") ; 162 | |
75 (?,1#(B . "a(.") ; 163 | |
76 (?,1$(B . "a^'") ; 164 | |
77 (?,1%(B . "a^`") ; 165 | |
78 (?,1&(B . "a^?") ; 166 | |
79 (?,1'(B . "a^.") ; 167 | |
80 (?,1((B . "e~") ; 168 | |
81 (?,1)(B . "e.") ; 169 | |
82 (?,1*(B . "e^'") ; 170 | |
83 (?,1+(B . "e^`") ; 171 | |
84 (?,1,(B . "e^?") ; 172 | |
85 (?,1-(B . "e^~") ; 173 | |
86 (?,1.(B . "e^.") ; 174 | |
87 (?,1/(B . "o^'") ; 175 | |
88 (?,10(B . "o^`") ; 176 | |
89 (?,11(B . "o^?") ; 177 | |
90 (?,12(B . "o^~") ; 178 | |
91 (?,15(B . "o^.") ; 181 | |
92 (?,16(B . "o+`") ; 182 | |
93 (?,17(B . "o+?") ; 183 | |
94 (?,18(B . "i.") ; 184 | |
95 (?,1=(B . "o+") ; 189 | |
96 (?,1>(B . "o+'") ; 190 | |
97 (?,1F(B . "a(?") ; 198 | |
98 (?,1G(B . "a(~") ; 199 | |
99 (?,1O(B . "y`") ; 207 | |
100 (?,1Q(B . "u+'") ; 209 | |
101 (?,1U(B . "a.") ; 213 | |
102 (?,1V(B . "y?") ; 214 | |
103 (?,1W(B . "u+`") ; 215 | |
104 (?,1X(B . "u+?") ; 216 | |
105 (?,1[(B . "y~") ; 219 | |
106 (?,1\(B . "y.") ; 220 | |
107 (?,1^(B . "o+~") ; 222 | |
108 (?,1_(B . "u+") ; 223 | |
109 (?,1`(B . "a`") ; 224 | |
110 (?,1a(B . "a'") ; 225 | |
111 (?,1b(B . "a^") ; 226 | |
112 (?,1c(B . "a~") ; 227 | |
113 (?,1d(B . "a?") ; 228 | |
114 (?,1e(B . "a(") ; 229 | |
115 (?,1f(B . "u+~") ; 230 | |
116 (?,1g(B . "a^~") ; 231 | |
117 (?,1h(B . "e`") ; 232 | |
118 (?,1i(B . "e'") ; 233 | |
119 (?,1j(B . "e^") ; 234 | |
120 (?,1k(B . "e?") ; 235 | |
121 (?,1l(B . "i`") ; 236 | |
122 (?,1m(B . "i'") ; 237 | |
123 (?,1n(B . "i~") ; 238 | |
124 (?,1o(B . "i?") ; 239 | |
125 (?,1p(B . "dd") ; 240 | |
126 (?,1q(B . "u+.") ; 241 | |
127 (?,1r(B . "o`") ; 242 | |
128 (?,1s(B . "o'") ; 243 | |
129 (?,1t(B . "o^") ; 244 | |
130 (?,1u(B . "o~") ; 245 | |
131 (?,1v(B . "o?") ; 246 | |
132 (?,1w(B . "o.") ; 247 | |
133 (?,1x(B . "u.") ; 248 | |
134 (?,1y(B . "u`") ; 249 | |
135 (?,1z(B . "u'") ; 250 | |
136 (?,1{(B . "u~") ; 251 | |
137 (?,1|(B . "u?") ; 252 | |
138 (?,1}(B . "y'") ; 253 | |
139 (?,1~(B . "o+.") ; 254 | |
140 | |
141 ;; upper case | |
142 (?,2!(B . "A('") ; 161 | |
143 (?,2"(B . "A(`") ; 162 | |
144 (?,2#(B . "A(.") ; 163 | |
145 (?,2$(B . "A^'") ; 164 | |
146 (?,2%(B . "A^`") ; 165 | |
147 (?,2&(B . "A^?") ; 166 | |
148 (?,2'(B . "A^.") ; 167 | |
149 (?,2((B . "E~") ; 168 | |
150 (?,2)(B . "E.") ; 169 | |
151 (?,2*(B . "E^'") ; 170 | |
152 (?,2+(B . "E^`") ; 171 | |
153 (?,2,(B . "E^?") ; 172 | |
154 (?,2-(B . "E^~") ; 173 | |
155 (?,2.(B . "E^.") ; 174 | |
156 (?,2/(B . "O^'") ; 175 | |
157 (?,20(B . "O^`") ; 176 | |
158 (?,21(B . "O^?") ; 177 | |
159 (?,22(B . "O^~") ; 178 | |
160 (?,25(B . "O^.") ; 181 | |
161 (?,26(B . "O+`") ; 182 | |
162 (?,27(B . "O+?") ; 183 | |
163 (?,28(B . "I.") ; 184 | |
164 (?,2=(B . "O+") ; 189 | |
165 (?,2>(B . "O+'") ; 190 | |
166 (?,2F(B . "A(?") ; 198 | |
167 (?,2G(B . "A(~") ; 199 | |
168 (?,2O(B . "Y`") ; 207 | |
169 (?,2Q(B . "U+'") ; 209 | |
170 (?,2U(B . "A.") ; 213 | |
171 (?,2V(B . "Y?") ; 214 | |
172 (?,2W(B . "U+`") ; 215 | |
173 (?,2X(B . "U+?") ; 216 | |
174 (?,2[(B . "Y~") ; 219 | |
175 (?,2\(B . "Y.") ; 220 | |
176 (?,2^(B . "O+~") ; 222 | |
177 (?,2_(B . "U+") ; 223 | |
178 (?,2`(B . "A`") ; 224 | |
179 (?,2a(B . "A'") ; 225 | |
180 (?,2b(B . "A^") ; 226 | |
181 (?,2c(B . "A~") ; 227 | |
182 (?,2d(B . "A?") ; 228 | |
183 (?,2e(B . "A(") ; 229 | |
184 (?,2f(B . "U+~") ; 230 | |
185 (?,2g(B . "A^~") ; 231 | |
186 (?,2h(B . "E`") ; 232 | |
187 (?,2i(B . "E'") ; 233 | |
188 (?,2j(B . "E^") ; 234 | |
189 (?,2k(B . "E?") ; 235 | |
190 (?,2l(B . "I`") ; 236 | |
191 (?,2m(B . "I'") ; 237 | |
192 (?,2n(B . "I~") ; 238 | |
193 (?,2o(B . "I?") ; 239 | |
194 (?,2p(B . "DD") ; 240 | |
195 (?,2p(B . "dD") ; 240 | |
196 (?,2p(B . "Dd") ; 240 | |
197 (?,2q(B . "U+.") ; 241 | |
198 (?,2r(B . "O`") ; 242 | |
199 (?,2s(B . "O'") ; 243 | |
200 (?,2t(B . "O^") ; 244 | |
201 (?,2u(B . "O~") ; 245 | |
202 (?,2v(B . "O?") ; 246 | |
203 (?,2w(B . "O.") ; 247 | |
204 (?,2x(B . "U.") ; 248 | |
205 (?,2y(B . "U`") ; 249 | |
206 (?,2z(B . "U'") ; 250 | |
207 (?,2{(B . "U~") ; 251 | |
208 (?,2|(B . "U?") ; 252 | |
209 (?,2}(B . "Y'") ; 253 | |
210 (?,2~(B . "O+.") ; 254 | |
211 | |
212 ;; escape from composition | |
213 (?\( . "\\(") ; breve (left parenthesis) | |
214 (?^ . "\\^") ; circumflex (caret) | |
215 (?+ . "\\+") ; horn (plus sign) | |
216 (?' . "\\'") ; acute (apostrophe) | |
217 (?` . "\\`") ; grave (backquote) | |
218 (?? . "\\?") ; hook above (question mark) | |
219 (?~ . "\\~") ; tilde (tilde) | |
220 (?. . "\\.") ; dot below (period) | |
221 (?d . "\\d") ; d-bar (d) | |
222 (?\\ . "\\\\") ; literal backslash | |
223 ) | |
224 "Alist of Vietnamese characters vs corresponding `VIQR' string.") | |
225 | |
226 ;; Regular expression matching single Vietnamese character represented | |
227 ;; by VIQR. | |
228 (defconst viqr-regexp | |
229 "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]") | |
230 | |
231 ;;;###autoload | |
232 (defun viet-decode-viqr-region (from to) | |
49122
1a51889893d0
* language/ethio-util.el (ethio-gemination)
John Paul Wallington <jpw@pobox.com>
parents:
44963
diff
changeset
|
233 "Convert `VIQR' mnemonics of the current region to Vietnamese characters. |
17052 | 234 When called from a program, expects two arguments, |
235 positions (integers or markers) specifying the stretch of the region." | |
236 (interactive "r") | |
237 (save-restriction | |
238 (narrow-to-region from to) | |
239 (goto-char (point-min)) | |
240 (while (re-search-forward viqr-regexp nil t) | |
241 (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
|
242 (ch (car (rassoc viqr viet-viqr-alist)))) |
17052 | 243 (if ch |
244 (progn | |
245 (delete-region (match-beginning 0) (match-end 0)) | |
246 (insert ch))))))) | |
247 | |
248 ;;;###autoload | |
249 (defun viet-decode-viqr-buffer () | |
49122
1a51889893d0
* language/ethio-util.el (ethio-gemination)
John Paul Wallington <jpw@pobox.com>
parents:
44963
diff
changeset
|
250 "Convert `VIQR' mnemonics of the current buffer to Vietnamese characters." |
17052 | 251 (interactive) |
252 (viet-decode-viqr-region (point-min) (point-max))) | |
253 | |
254 ;;;###autoload | |
255 (defun viet-encode-viqr-region (from to) | |
49122
1a51889893d0
* language/ethio-util.el (ethio-gemination)
John Paul Wallington <jpw@pobox.com>
parents:
44963
diff
changeset
|
256 "Convert Vietnamese characters of the current region to `VIQR' mnemonics. |
17052 | 257 When called from a program, expects two arguments, |
258 positions (integers or markers) specifying the stretch of the region." | |
259 (interactive "r") | |
260 (save-restriction | |
261 (narrow-to-region from to) | |
262 (goto-char (point-min)) | |
263 (while (re-search-forward "\\cv" nil t) | |
264 (let* ((ch (preceding-char)) | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
265 (viqr (cdr (assq ch viet-viqr-alist)))) |
17052 | 266 (if viqr |
267 (progn | |
268 (delete-char -1) | |
269 (insert viqr))))))) | |
270 | |
271 ;;;###autoload | |
272 (defun viet-encode-viqr-buffer () | |
49122
1a51889893d0
* language/ethio-util.el (ethio-gemination)
John Paul Wallington <jpw@pobox.com>
parents:
44963
diff
changeset
|
273 "Convert Vietnamese characters of the current buffer to `VIQR' mnemonics." |
17052 | 274 (interactive) |
275 (viet-encode-viqr-region (point-min) (point-max))) | |
276 | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
277 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
278 (defun viqr-post-read-conversion (len) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
279 (save-excursion |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
280 (save-restriction |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
281 (narrow-to-region (point) (+ (point) len)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
282 (let ((buffer-modified-p (buffer-modified-p))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
283 (viet-decode-viqr-region (point-min) (point-max)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
284 (set-buffer-modified-p buffer-modified-p) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
285 (- (point-max) (point-min)))))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
286 |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
287 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
288 (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
|
289 (let ((old-buf (current-buffer))) |
23544
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
290 (set-buffer (generate-new-buffer " *temp*")) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
291 (if (stringp from) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
292 (insert from) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
293 (insert-buffer-substring old-buf from to)) |
e54fbf58812f
(viqr-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23521
diff
changeset
|
294 (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
|
295 ;; Should return nil as annotations. |
081f940a8d1f
(viqr-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
296 nil)) |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
297 |
17052 | 298 ;;; |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
299 (provide 'viet-util) |
17052 | 300 |
52401 | 301 ;;; arch-tag: 082a4d3b-168f-45b4-b3e1-82bfa1b5a194 |
17052 | 302 ;;; viet-util.el ends here |