Mercurial > emacs
annotate lisp/language/viet-util.el @ 17405:1c2363f760ef
Add defgroup's; change use defcustom for user vars.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 12 Apr 1997 01:50:50 +0000 |
parents | a3ca5e15c82a |
children | 081f940a8d1f |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17171
diff
changeset
|
1 ;;; viet-util.el --- utilities for Vietnamese |
17052 | 2 |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
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 | |
38 ;; VIQR is a menmonic encoding specification for Vietnamese. | |
39 ;; It represents diacritical marks by ASCII characters as follows: | |
40 ;; ------------+----------+-------- | |
41 ;; mark | mnemonic | example | |
42 ;; ------------+----------+--------- | |
43 ;; breve | ( | a( -> ,1e(B | |
44 ;; circumflex | ^ | a^ -> ,1b(B | |
45 ;; horn | + | o+ -> ,1=(B | |
46 ;; ------------+----------+--------- | |
47 ;; acute | ' | a' -> ,1a(B | |
48 ;; grave | ` | a` -> ,1`(B | |
49 ;; hook above | ? | a? -> ,1d(B | |
50 ;; tilde | ~ | a~ -> ,1c(B | |
51 ;; dot below | . | a. -> ,1U(B | |
52 ;; ------------+----------+--------- | |
53 ;; d bar | dd | dd -> ,1p(B | |
54 ;; ------------+----------+--------- | |
55 | |
56 (defvar viet-viqr-alist | |
57 '(;; lowercase | |
58 (?,1!(B . "a('") ; 161 | |
59 (?,1"(B . "a(`") ; 162 | |
60 (?,1#(B . "a(.") ; 163 | |
61 (?,1$(B . "a^'") ; 164 | |
62 (?,1%(B . "a^`") ; 165 | |
63 (?,1&(B . "a^?") ; 166 | |
64 (?,1'(B . "a^.") ; 167 | |
65 (?,1((B . "e~") ; 168 | |
66 (?,1)(B . "e.") ; 169 | |
67 (?,1*(B . "e^'") ; 170 | |
68 (?,1+(B . "e^`") ; 171 | |
69 (?,1,(B . "e^?") ; 172 | |
70 (?,1-(B . "e^~") ; 173 | |
71 (?,1.(B . "e^.") ; 174 | |
72 (?,1/(B . "o^'") ; 175 | |
73 (?,10(B . "o^`") ; 176 | |
74 (?,11(B . "o^?") ; 177 | |
75 (?,12(B . "o^~") ; 178 | |
76 (?,15(B . "o^.") ; 181 | |
77 (?,16(B . "o+`") ; 182 | |
78 (?,17(B . "o+?") ; 183 | |
79 (?,18(B . "i.") ; 184 | |
80 (?,1=(B . "o+") ; 189 | |
81 (?,1>(B . "o+'") ; 190 | |
82 (?,1F(B . "a(?") ; 198 | |
83 (?,1G(B . "a(~") ; 199 | |
84 (?,1O(B . "y`") ; 207 | |
85 (?,1Q(B . "u+'") ; 209 | |
86 (?,1U(B . "a.") ; 213 | |
87 (?,1V(B . "y?") ; 214 | |
88 (?,1W(B . "u+`") ; 215 | |
89 (?,1X(B . "u+?") ; 216 | |
90 (?,1[(B . "y~") ; 219 | |
91 (?,1\(B . "y.") ; 220 | |
92 (?,1^(B . "o+~") ; 222 | |
93 (?,1_(B . "u+") ; 223 | |
94 (?,1`(B . "a`") ; 224 | |
95 (?,1a(B . "a'") ; 225 | |
96 (?,1b(B . "a^") ; 226 | |
97 (?,1c(B . "a~") ; 227 | |
98 (?,1d(B . "a?") ; 228 | |
99 (?,1e(B . "a(") ; 229 | |
100 (?,1f(B . "u+~") ; 230 | |
101 (?,1g(B . "a^~") ; 231 | |
102 (?,1h(B . "e`") ; 232 | |
103 (?,1i(B . "e'") ; 233 | |
104 (?,1j(B . "e^") ; 234 | |
105 (?,1k(B . "e?") ; 235 | |
106 (?,1l(B . "i`") ; 236 | |
107 (?,1m(B . "i'") ; 237 | |
108 (?,1n(B . "i~") ; 238 | |
109 (?,1o(B . "i?") ; 239 | |
110 (?,1p(B . "dd") ; 240 | |
111 (?,1q(B . "u+.") ; 241 | |
112 (?,1r(B . "o`") ; 242 | |
113 (?,1s(B . "o'") ; 243 | |
114 (?,1t(B . "o^") ; 244 | |
115 (?,1u(B . "o~") ; 245 | |
116 (?,1v(B . "o?") ; 246 | |
117 (?,1w(B . "o.") ; 247 | |
118 (?,1x(B . "u.") ; 248 | |
119 (?,1y(B . "u`") ; 249 | |
120 (?,1z(B . "u'") ; 250 | |
121 (?,1{(B . "u~") ; 251 | |
122 (?,1|(B . "u?") ; 252 | |
123 (?,1}(B . "y'") ; 253 | |
124 (?,1~(B . "o+.") ; 254 | |
125 | |
126 ;; upper case | |
127 (?,2!(B . "A('") ; 161 | |
128 (?,2"(B . "A(`") ; 162 | |
129 (?,2#(B . "A(.") ; 163 | |
130 (?,2$(B . "A^'") ; 164 | |
131 (?,2%(B . "A^`") ; 165 | |
132 (?,2&(B . "A^?") ; 166 | |
133 (?,2'(B . "A^.") ; 167 | |
134 (?,2((B . "E~") ; 168 | |
135 (?,2)(B . "E.") ; 169 | |
136 (?,2*(B . "E^'") ; 170 | |
137 (?,2+(B . "E^`") ; 171 | |
138 (?,2,(B . "E^?") ; 172 | |
139 (?,2-(B . "E^~") ; 173 | |
140 (?,2.(B . "E^.") ; 174 | |
141 (?,2/(B . "O^'") ; 175 | |
142 (?,20(B . "O^`") ; 176 | |
143 (?,21(B . "O^?") ; 177 | |
144 (?,22(B . "O^~") ; 178 | |
145 (?,25(B . "O^.") ; 181 | |
146 (?,26(B . "O+`") ; 182 | |
147 (?,27(B . "O+?") ; 183 | |
148 (?,28(B . "I.") ; 184 | |
149 (?,2=(B . "O+") ; 189 | |
150 (?,2>(B . "O+'") ; 190 | |
151 (?,2F(B . "A(?") ; 198 | |
152 (?,2G(B . "A(~") ; 199 | |
153 (?,2O(B . "Y`") ; 207 | |
154 (?,2Q(B . "U+'") ; 209 | |
155 (?,2U(B . "A.") ; 213 | |
156 (?,2V(B . "Y?") ; 214 | |
157 (?,2W(B . "U+`") ; 215 | |
158 (?,2X(B . "U+?") ; 216 | |
159 (?,2[(B . "Y~") ; 219 | |
160 (?,2\(B . "Y.") ; 220 | |
161 (?,2^(B . "O+~") ; 222 | |
162 (?,2_(B . "U+") ; 223 | |
163 (?,2`(B . "A`") ; 224 | |
164 (?,2a(B . "A'") ; 225 | |
165 (?,2b(B . "A^") ; 226 | |
166 (?,2c(B . "A~") ; 227 | |
167 (?,2d(B . "A?") ; 228 | |
168 (?,2e(B . "A(") ; 229 | |
169 (?,2f(B . "U+~") ; 230 | |
170 (?,2g(B . "A^~") ; 231 | |
171 (?,2h(B . "E`") ; 232 | |
172 (?,2i(B . "E'") ; 233 | |
173 (?,2j(B . "E^") ; 234 | |
174 (?,2k(B . "E?") ; 235 | |
175 (?,2l(B . "I`") ; 236 | |
176 (?,2m(B . "I'") ; 237 | |
177 (?,2n(B . "I~") ; 238 | |
178 (?,2o(B . "I?") ; 239 | |
179 (?,2p(B . "DD") ; 240 | |
180 (?,2p(B . "dD") ; 240 | |
181 (?,2p(B . "Dd") ; 240 | |
182 (?,2q(B . "U+.") ; 241 | |
183 (?,2r(B . "O`") ; 242 | |
184 (?,2s(B . "O'") ; 243 | |
185 (?,2t(B . "O^") ; 244 | |
186 (?,2u(B . "O~") ; 245 | |
187 (?,2v(B . "O?") ; 246 | |
188 (?,2w(B . "O.") ; 247 | |
189 (?,2x(B . "U.") ; 248 | |
190 (?,2y(B . "U`") ; 249 | |
191 (?,2z(B . "U'") ; 250 | |
192 (?,2{(B . "U~") ; 251 | |
193 (?,2|(B . "U?") ; 252 | |
194 (?,2}(B . "Y'") ; 253 | |
195 (?,2~(B . "O+.") ; 254 | |
196 | |
197 ;; escape from composition | |
198 (?\( . "\\(") ; breve (left parenthesis) | |
199 (?^ . "\\^") ; circumflex (caret) | |
200 (?+ . "\\+") ; horn (plus sign) | |
201 (?' . "\\'") ; acute (apostrophe) | |
202 (?` . "\\`") ; grave (backquote) | |
203 (?? . "\\?") ; hook above (question mark) | |
204 (?~ . "\\~") ; tilde (tilde) | |
205 (?. . "\\.") ; dot below (period) | |
206 (?d . "\\d") ; d-bar (d) | |
207 (?\\ . "\\\\") ; literal backslash | |
208 ) | |
209 "Alist of Vietnamese characters vs corresponding `VIQR' string.") | |
210 | |
211 ;; Regular expression matching single Vietnamese character represented | |
212 ;; by VIQR. | |
213 (defconst viqr-regexp | |
214 "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]") | |
215 | |
216 ;;;###autoload | |
217 (defun viet-decode-viqr-region (from to) | |
218 "Convert `VIQR' mnemonics of the current region to Vietnamese characaters. | |
219 When called from a program, expects two arguments, | |
220 positions (integers or markers) specifying the stretch of the region." | |
221 (interactive "r") | |
222 (save-restriction | |
223 (narrow-to-region from to) | |
224 (goto-char (point-min)) | |
225 (while (re-search-forward viqr-regexp nil t) | |
226 (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
|
227 (ch (car (rassoc viqr viet-viqr-alist)))) |
17052 | 228 (if ch |
229 (progn | |
230 (delete-region (match-beginning 0) (match-end 0)) | |
231 (insert ch))))))) | |
232 | |
233 ;;;###autoload | |
234 (defun viet-decode-viqr-buffer () | |
235 "Convert `VIQR' mnemonics of the current buffer to Vietnamese characaters." | |
236 (interactive) | |
237 (viet-decode-viqr-region (point-min) (point-max))) | |
238 | |
239 ;;;###autoload | |
240 (defun viet-encode-viqr-region (from to) | |
241 "Convert Vietnamese characaters of the current region to `VIQR' mnemonics. | |
242 When called from a program, expects two arguments, | |
243 positions (integers or markers) specifying the stretch of the region." | |
244 (interactive "r") | |
245 (save-restriction | |
246 (narrow-to-region from to) | |
247 (goto-char (point-min)) | |
248 (while (re-search-forward "\\cv" nil t) | |
249 (let* ((ch (preceding-char)) | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
250 (viqr (cdr (assq ch viet-viqr-alist)))) |
17052 | 251 (if viqr |
252 (progn | |
253 (delete-char -1) | |
254 (insert viqr))))))) | |
255 | |
256 ;;;###autoload | |
257 (defun viet-encode-viqr-buffer () | |
258 "Convert Vietnamese characaters of the current buffer to `VIQR' mnemonics." | |
259 (interactive) | |
260 (viet-encode-viqr-region (point-min) (point-max))) | |
261 | |
17171
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
262 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
263 (defun viqr-post-read-conversion (len) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
264 (save-excursion |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
265 (save-restriction |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
266 (narrow-to-region (point) (+ (point) len)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
267 (let ((buffer-modified-p (buffer-modified-p))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
268 (viet-decode-viqr-region (point-min) (point-max)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
269 (set-buffer-modified-p buffer-modified-p) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
270 (- (point-max) (point-min)))))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
271 |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
272 ;;;###autoload |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
273 (defun viqr-pre-write-conversion (from to) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
274 (let ((old-buf (current-buffer)) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
275 (work-buf (get-buffer-create " *viet-work*"))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
276 (set-buffer work-buf) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
277 (erase-buffer) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
278 (insert-buffer-substring old-buf from to) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
279 (viet-encode-viqr-region (point-min) (point-max)))) |
6f95d429f32d
(viet-decode-viqr-region): Supply correct
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
280 |
17052 | 281 ;;; |
282 (provide 'language/viet-util) | |
283 | |
284 ;;; Local Variables: | |
285 ;;; generated-autoload-file: "../loaddefs.el" | |
286 ;;; End: | |
287 ;;; viet-util.el ends here |