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