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