123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- (defvar viet-viscii-nonascii-translation-table)
- (defun viet-encode-viscii-char (char)
- "Return VISCII character code of CHAR if appropriate."
- (encode-char char 'viscii))
- (defvar viet-viqr-alist
- '(
- (?,1!(B . "a('")
- (?,1"(B . "a(`") ; 162
- (?,1#(B . "a(.") ; 163
- (?,1$(B . "a") ; 164
- (?,1%(B . "a^`") ; 165
- (?,1&(B . "a") ; 166
- (?,1'(B . "a") ; 167
- (?,1((B . "e~") ; 168
- (?,1)(B . "e.") ; 169
- (?,1*(B . "e") ; 170
- (?,1+(B . "e^`") ; 171
- (?,1,(B . "e") ; 172
- (?,1-(B . "e^~") ; 173
- (?,1.(B . "e") ; 174
- (?,1/(B . "o") ; 175
- (?,10(B . "o^`") ; 176
- (?,11(B . "o") ; 177
- (?,12(B . "o^~") ; 178
- (?,15(B . "o") ; 181
- (?,16(B . "o+`") ; 182
- (?,17(B . "o+?") ; 183
- (?,18(B . "i.") ; 184
- (?,1=(B . "o+") ; 189
- (?,1>(B . "o+'") ; 190
- (?,1F(B . "a(?") ; 198
- (?,1G(B . "a(~") ; 199
- (?,1O(B . "y`") ; 207
- (?,1Q(B . "u+'") ; 209
- (?,1U(B . "a.") ; 213
- (?,1V(B . "y?") ; 214
- (?,1W(B . "u+`") ; 215
- (?,1X(B . "u+?") ; 216
- (?,1[(B . "y~") ; 219
- (?,1\(B . "y.") ; 220
- (?,1^(B . "o+~") ; 222
- (?,1_(B . "u+") ; 223
- (?,1`(B . "a`") ; 224
- (?,1a(B . "a'") ; 225
- (?,1b(B . "a^") ; 226
- (?,1c(B . "a~") ; 227
- (?,1d(B . "a?") ; 228
- (?,1e(B . "a(") ; 229
- (?,1f(B . "u+~") ; 230
- (?,1g(B . "a^~") ; 231
- (?,1h(B . "e`") ; 232
- (?,1i(B . "e'") ; 233
- (?,1j(B . "e^") ; 234
- (?,1k(B . "e?") ; 235
- (?,1l(B . "i`") ; 236
- (?,1m(B . "i'") ; 237
- (?,1n(B . "i~") ; 238
- (?,1o(B . "i?") ; 239
- (?,1p(B . "dd") ; 240
- (?,1q(B . "u+.") ; 241
- (?,1r(B . "o`") ; 242
- (?,1s(B . "o'") ; 243
- (?,1t(B . "o^") ; 244
- (?,1u(B . "o~") ; 245
- (?,1v(B . "o?") ; 246
- (?,1w(B . "o.") ; 247
- (?,1x(B . "u.") ; 248
- (?,1y(B . "u`") ; 249
- (?,1z(B . "u'") ; 250
- (?,1{(B . "u~") ; 251
- (?,1|(B . "u?") ; 252
- (?,1}(B . "y'") ; 253
- (?,1~(B . "o+.") ; 254
- ;; upper case
- (?,2!(B . "A('") ; 161
- (?,2"(B . "A(`")
- (?,2#(B . "A(.")
- (?,2$(B . "A^'")
- (?,2%(B . "A^`")
- (?,2&(B . "A^?")
- (?,2'(B . "A^.")
- (?,2((B . "E~")
- (?,2)(B . "E.")
- (?,2*(B . "E^'")
- (?,2+(B . "E^`")
- (?,2,(B . "E^?")
- (?,2-(B . "E^~")
- (?,2.(B . "E^.")
- (?,2/(B . "O^'")
- (?,20(B . "O^`")
- (?,21(B . "O^?")
- (?,22(B . "O^~")
- (?,25(B . "O^.")
- (?,26(B . "O+`")
- (?,27(B . "O+?")
- (?,28(B . "I.")
- (?,2=(B . "O+")
- (?,2>(B . "O+'")
- (?,2F(B . "A(?")
- (?,2G(B . "A(~")
- (?,2O(B . "Y`")
- (?,2Q(B . "U+'")
- (?,2U(B . "A.")
- (?,2V(B . "Y?")
- (?,2W(B . "U+`")
- (?,2X(B . "U+?")
- (?,2[(B . "Y~")
- (?,2\(B . "Y.")
- (?,2^(B . "O+~")
- (?,2_(B . "U+")
- (?,2`(B . "A`")
- (?,2a(B . "A'")
- (?,2b(B . "A^")
- (?,2c(B . "A~")
- (?,2d(B . "A?")
- (?,2e(B . "A(")
- (?,2f(B . "U+~")
- (?,2g(B . "A^~")
- (?,2h(B . "E`")
- (?,2i(B . "E'")
- (?,2j(B . "E^")
- (?,2k(B . "E?")
- (?,2l(B . "I`")
- (?,2m(B . "I'")
- (?,2n(B . "I~")
- (?,2o(B . "I?")
- (?,2p(B . "DD")
- (?,2p(B . "dD")
- (?,2p(B . "Dd")
- (?,2q(B . "U+.")
- (?,2r(B . "O`")
- (?,2s(B . "O'")
- (?,2t(B . "O^")
- (?,2u(B . "O~")
- (?,2v(B . "O?")
- (?,2w(B . "O.")
- (?,2x(B . "U.")
- (?,2y(B . "U`")
- (?,2z(B . "U'")
- (?,2{(B . "U~")
- (?,2|(B . "U?")
- (?,2}(B . "Y'")
- (?,2~(B . "O+.")
-
- (?\( . "\\(")
- (?^ . "\\^")
- (?+ . "\\+")
- (?' . "\\'")
- (?` . "\\`")
- (?? . "\\?")
- (?~ . "\\~")
- (?. . "\\.")
- (?d . "\\d")
- (?\\ . "\\\\")
- )
- "Alist of Vietnamese characters vs corresponding `VIQR' string.")
- (defconst viqr-regexp
- "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]")
- (defun viet-decode-viqr-region (from to)
- "Convert `VIQR' mnemonics of the current region to Vietnamese characters.
- When called from a program, expects two arguments,
- positions (integers or markers) specifying the stretch of the region."
- (interactive "r")
- (save-restriction
- (narrow-to-region from to)
- (goto-char (point-min))
- (while (re-search-forward viqr-regexp nil t)
- (let* ((viqr (buffer-substring (match-beginning 0) (match-end 0)))
- (ch (car (rassoc viqr viet-viqr-alist))))
- (if ch
- (progn
- (delete-region (match-beginning 0) (match-end 0))
- (insert ch)))))))
- (defun viet-decode-viqr-buffer ()
- "Convert `VIQR' mnemonics of the current buffer to Vietnamese characters."
- (interactive)
- (viet-decode-viqr-region (point-min) (point-max)))
- (defun viet-encode-viqr-region (from to)
- "Convert Vietnamese characters of the current region to `VIQR' mnemonics.
- When called from a program, expects two arguments,
- positions (integers or markers) specifying the stretch of the region."
- (interactive "r")
- (save-restriction
- (narrow-to-region from to)
- (goto-char (point-min))
- (while (re-search-forward "\\cv" nil t)
- (let* ((ch (preceding-char))
- (viqr (cdr (assq ch viet-viqr-alist))))
- (if viqr
- (progn
- (delete-char -1)
- (insert viqr)))))))
- (defun viet-encode-viqr-buffer ()
- "Convert Vietnamese characters of the current buffer to `VIQR' mnemonics."
- (interactive)
- (viet-encode-viqr-region (point-min) (point-max)))
- (defun viqr-post-read-conversion (len)
- (save-excursion
- (save-restriction
- (narrow-to-region (point) (+ (point) len))
- (let ((buffer-modified-p (buffer-modified-p)))
- (viet-decode-viqr-region (point-min) (point-max))
- (set-buffer-modified-p buffer-modified-p)
- (- (point-max) (point-min))))))
- (defun viqr-pre-write-conversion (from to)
- (let ((old-buf (current-buffer)))
- (set-buffer (generate-new-buffer " *temp*"))
- (if (stringp from)
- (insert from)
- (insert-buffer-substring old-buf from to))
- (viet-encode-viqr-region (point-min) (point-max))
-
- nil))
- (provide 'viet-util)
|