]> code.delx.au - gnu-emacs/blobdiff - lisp/language/viet-util.el
Add new maintainer (deego).
[gnu-emacs] / lisp / language / viet-util.el
index cbae104a52344fe73f2006d5c9583e431edeb574..1b72ff07d8bd46aaf2f2b9a8464d91cc2cfbb963 100644 (file)
@@ -1,7 +1,7 @@
-;; viet-util.el --  utilities for Vietnamese
+;;; viet-util.el --- utilities for Vietnamese  -*- coding: iso-2022-7bit; -*-
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
 
 ;; Keywords: mule, multilingual, Vietnamese
 
 
 ;; Vietnamese uses ASCII characters and additional 134 unique
 ;; characters (these are Latin alphabets with various diacritical and
-;; tone marks).  As far as I know, Vietnamese now has 4 different ways
-;; for representing these characters: VISCII, VSCII, VIQR, and
-;; Unicode.  VISCII and VSCII are simple 1-byte code which assigns 134
-;; unique characters in control-code area (0x00..0x1F) and right half
-;; area (0x80..0xFF).  VIQR is a menmonic encoding specification
-;; representing diacritical marks by following ASCII characters.
+;; tone marks).  As far as I know, Vietnamese now has 5 different ways
+;; for representing these characters: VISCII, TCVN-5712, VPS, VIQR,
+;; and Unicode.  VISCII, TCVN-5712 and VPS are simple 1-byte code
+;; which assigns 134 unique characters in control-code area
+;; (0x00..0x1F) and right half area (0x80..0xFF).  VIQR is a menmonic
+;; encoding specification representing diacritical marks by following
+;; ASCII characters.
 
 ;;; Code:
 
+;;;###autoload
+(defun viet-encode-viscii-char (char)
+  "Return VISCII character code of CHAR if appropriate."
+  (aref (char-table-extra-slot viet-viscii-nonascii-translation-table 0)
+       char))
+
 ;; VIQR is a menmonic encoding specification for Vietnamese.
 ;; It represents diacritical marks by ASCII characters as follows:
 ;; ------------+----------+--------
 
 ;;;###autoload
 (defun viet-decode-viqr-region (from to)
-  "Convert `VIQR' mnemonics of the current region to Vietnamese characaters.
+  "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")
@@ -224,7 +231,7 @@ positions (integers or markers) specifying the stretch of the region."
     (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 viet-viqr-alist viqr))))
+            (ch (car (rassoc viqr viet-viqr-alist))))
        (if ch
            (progn
              (delete-region (match-beginning 0) (match-end 0))
@@ -232,13 +239,13 @@ positions (integers or markers) specifying the stretch of the region."
 
 ;;;###autoload
 (defun viet-decode-viqr-buffer ()
-  "Convert `VIQR' mnemonics of the current buffer to Vietnamese characaters."
+  "Convert `VIQR' mnemonics of the current buffer to Vietnamese characters."
   (interactive)
   (viet-decode-viqr-region (point-min) (point-max)))
 
 ;;;###autoload
 (defun viet-encode-viqr-region (from to)
-  "Convert Vietnamese characaters of the current region to `VIQR' mnemonics.
+  "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")
@@ -247,7 +254,7 @@ positions (integers or markers) specifying the stretch of the region."
     (goto-char (point-min))
     (while (re-search-forward "\\cv" nil t)
       (let* ((ch (preceding-char))
-            (viqr (cdr (assoc viet-viqr-alist ch))))
+            (viqr (cdr (assq ch viet-viqr-alist))))
        (if viqr
            (progn
              (delete-char -1)
@@ -255,14 +262,32 @@ positions (integers or markers) specifying the stretch of the region."
 
 ;;;###autoload
 (defun viet-encode-viqr-buffer ()
-  "Convert Vietnamese characaters of the current buffer to `VIQR' mnemonics."
+  "Convert Vietnamese characters of the current buffer to `VIQR' mnemonics."
   (interactive)
   (viet-encode-viqr-region (point-min) (point-max)))
 
+;;;###autoload
+(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))))))
+
+;;;###autoload
+(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))
+    ;; Should return nil as annotations.
+    nil))
+
 ;;;
-(provide 'language/viet-util)
+(provide 'viet-util)
 
-;;; Local Variables:
-;;; generated-autoload-file: "../loaddefs.el"
-;;; End:
 ;;; viet-util.el ends here