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