]> code.delx.au - gnu-emacs/blobdiff - lisp/language/thai-util.el
Assorted cleanups for compiler warnings, doc strings, `array-' prefix
[gnu-emacs] / lisp / language / thai-util.el
index a97fad0ae7c3feaffdfcbf86419e1cb2a98542ac..04b48a6af1332bc14de11b3fa62ea04bb154f6bb 100644 (file)
@@ -1,7 +1,7 @@
 ;;; thai-util.el --- utilities for Thai
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
 
 ;; Keywords: mule, multilingual, thai
 
 
 ;;; Code:
 
+;;;###autoload
+(defun setup-thai-environment ()
+  "Setup multilingual environment (MULE) for Thai."
+  (interactive)
+  (set-language-environment "Thai"))
+
 ;; Setting information of Thai characters.
 
+(defconst thai-category-table (make-category-table))
+(define-category ?c "Thai consonant" thai-category-table)
+(define-category ?v "Thai upper/lower vowel" thai-category-table)
+(define-category ?t "Thai tone" thai-category-table)
+
+;; The general composing rules are as follows:
+;;
+;;                          T
+;;       V        T         V                  T
+;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
+;;                                   v         v
+;;
+;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
+
+(defvar thai-composition-pattern "\\cc\\(\\ct\\|\\cv\\ct?\\)"
+  "Regular expression matching a Thai composite sequence.")
+
 (let ((l '((?\e,T!\e(B consonant "LETTER KO KAI")                                ; 0xA1
           (?\e,T"\e(B consonant "LETTER KHO KHAI")                               ; 0xA2
           (?\e,T#\e(B consonant "LETTER KHO KHUAT")                              ; 0xA3
           ))
       elm)
   (while l
-    (setq elm (car l))
-    (put-char-code-property (car elm) 'phonetic-type (car (cdr elm)))
-    (put-char-code-property (car elm) 'name (nth 2 elm))
-    (setq l (cdr l))))
+    (setq elm (car l) l (cdr l))
+    (let ((char (car elm))
+         (ptype (nth 1 elm)))
+      (put-char-code-property char 'phonetic-type ptype)
+      (cond ((eq ptype 'consonant)
+            (modify-category-entry char ?c thai-category-table))
+           ((memq ptype '(vowel-upper vowel-lower))
+            (modify-category-entry char ?v thai-category-table))
+           ((eq ptype 'tone)
+            (modify-category-entry char ?t thai-category-table)))
+      (put-char-code-property char 'name (nth 2 elm)))))
 
 ;;;###autoload
 (defun thai-compose-region (beg end)
@@ -136,12 +166,21 @@ positions (integers or markers) specifying the region."
   (interactive "r")
   (save-restriction
     (narrow-to-region beg end)
-    (decompose-region (point-min) (point-max))
     (goto-char (point-min))
-    (while (re-search-forward "\\c0\\(\\c2\\|\\c3\\|\\c4\\)+" nil t)
-      (if (aref (char-category-set (char-after (match-beginning 0))) ?t)
-         (compose-region (match-beginning 0) (match-end 0))))))
+    (with-category-table thai-category-table
+      (while (re-search-forward thai-composition-pattern nil t)
+       (compose-region (match-beginning 0) (match-end 0))))))
 
+;;;###autoload
+(defun thai-compose-string (string)
+  "Compose Thai characters in STRING and return the resulting string."
+  (with-category-table thai-category-table
+    (let ((idx 0))
+      (while (setq idx (string-match thai-composition-pattern string idx))
+       (compose-string string idx (match-end 0))
+       (setq idx (match-end 0)))))
+  string)
+      
 ;;;###autoload
 (defun thai-compose-buffer ()
   "Compose Thai characters in the current buffer."
@@ -150,27 +189,25 @@ positions (integers or markers) specifying the region."
 
 ;;;###autoload
 (defun thai-post-read-conversion (len)
-  (save-excursion
-    (save-restriction
-      (let ((buffer-modified-p (buffer-modified-p)))
-       (narrow-to-region (point) (+ (point) len))
-       (thai-compose-region (point-min) (point-max))
-       (set-buffer-modified-p buffer-modified-p)
-       (- (point-max) (point-min))))))
+  (thai-compose-region (point) (+ (point) len))
+  len)
 
 ;;;###autoload
-(defun thai-pre-write-conversion (from to)
-  (let ((old-buf (current-buffer))
-       (work-buf (get-buffer-create " *thai-work*")))
-    (set-buffer work-buf)
-    (erase-buffer)
-    (insert-buffer-substring old-buf from to)
-    (decompose-region (point-min) (point-max))))
+(defun thai-composition-function (from to pattern &optional string)
+  "Compose Thai text in the region FROM and TO.
+The text matches the regular expression PATTERN.
+Optional 4th argument STRING, if non-nil, is a string containing text
+to compose.
+
+The return value is number of composed characters."a
+  (if (< (1+ from) to)
+      (prog1 (- to from)
+       (if string
+           (compose-string from to)
+         (compose-region from to))
+       (- to from))))
 
 ;;
-(provide 'language/thai-util)
+(provide 'thai-util)
 
-;;; Local Variables:
-;;; generated-autoload-file: "../loaddefs.el"
-;;; End:
 ;;; thai-util.el ends here