Mercurial > emacs
annotate lisp/language/viet-util.el @ 109633:ce2dcd6fda75
Fix emacs -Q -f server-start & emacsclient -t on GNU/Linux.
* src/term.c (dissociate_if_controlling_tty): Use USG5 instead of
USG. This is equivalent to defined (USG) && !defined (BSD_PGRPS),
which is what was there before BSD_PGRPS was removed.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Thu, 05 Aug 2010 15:20:09 -0700 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
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 |
106815 | 3 ;; Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
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, |
106815 | 6 ;; 2005, 2006, 2007, 2008, 2009, 2010 |
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 | |
94665
55b7f25d920a
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
17 ;; GNU Emacs is free software: you can redistribute it and/or modify |
17052 | 18 ;; it under the terms of the GNU General Public License as published by |
94665
55b7f25d920a
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
19 ;; the Free Software Foundation, either version 3 of the License, or |
55b7f25d920a
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
20 ;; (at your option) any later version. |
17052 | 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 | |
94665
55b7f25d920a
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
17052 | 29 |
30 ;;; Commentary: | |
31 | |
32 ;; Vietnamese uses ASCII characters and additional 134 unique | |
33 ;; characters (these are Latin alphabets with various diacritical and | |
44963 | 34 ;; tone marks). As far as I know, Vietnamese now has 5 different ways |
35 ;; for representing these characters: VISCII, TCVN-5712, VPS, VIQR, | |
36 ;; and Unicode. VISCII, TCVN-5712 and VPS are simple 1-byte code | |
37 ;; which assigns 134 unique characters in control-code area | |
38 ;; (0x00..0x1F) and right half area (0x80..0xFF). VIQR is a menmonic | |
39 ;; encoding specification representing diacritical marks by following | |
40 ;; ASCII characters. | |
17052 | 41 |
42 ;;; Code: | |
43 | |
62619
fee0933da7fe
(viet-viscii-nonascii-translation-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
62396
diff
changeset
|
44 (defvar viet-viscii-nonascii-translation-table) |
fee0933da7fe
(viet-viscii-nonascii-translation-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
62396
diff
changeset
|
45 |
18970
5bbc07f4c61e
(setup-vietnamese-environment): Add autoload cookie.
Kenichi Handa <handa@m17n.org>
parents:
18552
diff
changeset
|
46 ;;;###autoload |
22880
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
47 (defun viet-encode-viscii-char (char) |
125bb37b2e27
(viet-encode-viscii-char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
48 "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
|
49 (encode-char char 'viscii)) |
22880
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 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
299 ;; arch-tag: 082a4d3b-168f-45b4-b3e1-82bfa1b5a194 |
17052 | 300 ;;; viet-util.el ends here |