]> code.delx.au - gnu-emacs/blobdiff - lisp/language/thai-util.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / language / thai-util.el
index 3fda08ee42dd48f0d6b76e1ba552abde618f90a4..be5ce10ad08393cce58674d053dfd9a38b85617c 100644 (file)
@@ -7,7 +7,7 @@
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 ;;   Free Software Foundation, Inc.
 
-;; Keywords: mule, multilingual, thai
+;; Keywords: mule, multilingual, Thai, i18n
 
 ;; This file is part of GNU Emacs.
 
   "\\cc\\(\\cu\\|\\cI\\cU\\|\\cv\\ct?\\)\\|\\cv\\ct\\|\\cI\\cU"
   "Regular expression matching a Thai composite sequence.")
 
-(defun thai-self-insert-command (&optional n)
-  "Insert the Thai character you type.
-The character will be composed with the surrounding Thai character
-if necessary."
-  (interactive "*p")
-  (let ((pos (point))
-       category-set ch)
-    (self-insert-command n)
-    (or thai-auto-composition-mode
-       (thai-auto-composition (1- (point)) (point) 0))))
-
 (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
@@ -163,95 +152,6 @@ if necessary."
           (?\e,T|\e(B invalid nil)                                               ; 0xFC
           (?\e,T}\e(B invalid nil)                                               ; 0xFD
           (?\e,T~\e(B invalid nil)                                               ; 0xFE
-
-          ;; Unicode equivalents
-          (?\e$,1Ba\e(B consonant "LETTER KO KAI")
-          (?\e$,1Bb\e(B consonant "LETTER KHO KHAI")
-          (?\e$,1Bc\e(B consonant "LETTER KHO KHUAT")
-          (?\e$,1Bd\e(B consonant "LETTER KHO KHWAI")
-          (?\e$,1Be\e(B consonant "LETTER KHO KHON")
-          (?\e$,1Bf\e(B consonant "LETTER KHO RAKHANG")
-          (?\e$,1Bg\e(B consonant "LETTER NGO NGU")
-          (?\e$,1Bh\e(B consonant "LETTER CHO CHAN")
-          (?\e$,1Bi\e(B consonant "LETTER CHO CHING")
-          (?\e$,1Bj\e(B consonant "LETTER CHO CHANG")
-          (?\e$,1Bk\e(B consonant "LETTER SO SO")
-          (?\e$,1Bl\e(B consonant "LETTER CHO CHOE")
-          (?\e$,1Bm\e(B consonant "LETTER YO YING")
-          (?\e$,1Bn\e(B consonant "LETTER DO CHADA")
-          (?\e$,1Bo\e(B consonant "LETTER TO PATAK")
-          (?\e$,1Bp\e(B consonant "LETTER THO THAN")
-          (?\e$,1Bq\e(B consonant "LETTER THO NANGMONTHO")
-          (?\e$,1Br\e(B consonant "LETTER THO PHUTHAO")
-          (?\e$,1Bs\e(B consonant "LETTER NO NEN")
-          (?\e$,1Bt\e(B consonant "LETTER DO DEK")
-          (?\e$,1Bu\e(B consonant "LETTER TO TAO")
-          (?\e$,1Bv\e(B consonant "LETTER THO THUNG")
-          (?\e$,1Bw\e(B consonant "LETTER THO THAHAN")
-          (?\e$,1Bx\e(B consonant "LETTER THO THONG")
-          (?\e$,1By\e(B consonant "LETTER NO NU")
-          (?\e$,1Bz\e(B consonant "LETTER BO BAIMAI")
-          (?\e$,1B{\e(B consonant "LETTER PO PLA")
-          (?\e$,1B|\e(B consonant "LETTER PHO PHUNG")
-          (?\e$,1B}\e(B consonant "LETTER FO FA")
-          (?\e$,1B~\e(B consonant "LETTER PHO PHAN")
-          (?\e$,1B\7f\e(B consonant "LETTER FO FAN")
-          (?\e$,1C \e(B consonant "LETTER PHO SAMPHAO")
-          (?\e$,1C!\e(B consonant "LETTER MO MA")
-          (?\e$,1C"\e(B consonant "LETTER YO YAK")
-          (?\e$,1C#\e(B consonant "LETTER RO RUA")
-          (?\e$,1C$\e(B vowel-base "LETTER RU (Pali vowel letter)")
-          (?\e$,1C%\e(B consonant "LETTER LO LING")
-          (?\e$,1C&\e(B vowel-base "LETTER LU (Pali vowel letter)")
-          (?\e$,1C'\e(B consonant "LETTER WO WAEN")
-          (?\e$,1C(\e(B consonant "LETTER SO SALA")
-          (?\e$,1C)\e(B consonant "LETTER SO RUSI")
-          (?\e$,1C*\e(B consonant "LETTER SO SUA")
-          (?\e$,1C+\e(B consonant "LETTER HO HIP")
-          (?\e$,1C,\e(B consonant "LETTER LO CHULA")
-          (?\e$,1C-\e(B consonant "LETTER O ANG")
-          (?\e$,1C.\e(B consonant "LETTER HO NOK HUK")
-          (?\e$,1C/\e(B special "PAI YAN NOI (abbreviation)")
-          (?\e$,1C0\e(B vowel-base "VOWEL SIGN SARA A")
-          (?\e$,1C1\e(B vowel-upper "VOWEL SIGN MAI HAN-AKAT N/S-T")
-          (?\e$,1C2\e(B vowel-base "VOWEL SIGN SARA AA")
-          (?\e$,1C3\e(B vowel-base "VOWEL SIGN SARA AM")
-          (?\e$,1C4\e(B vowel-upper "VOWEL SIGN SARA I N/S-T")
-          (?\e$,1C5\e(B vowel-upper "VOWEL SIGN SARA II N/S-T")
-          (?\e$,1C6\e(B vowel-upper "VOWEL SIGN SARA UE N/S-T")
-          (?\e$,1C7\e(B vowel-upper "VOWEL SIGN SARA UEE N/S-T")
-          (?\e$,1C8\e(B vowel-lower "VOWEL SIGN SARA U N/S-B")
-          (?\e$,1C9\e(B vowel-lower "VOWEL SIGN SARA UU N/S-B")
-          (?\e$,1C:\e(B vowel-lower "VOWEL SIGN PHINTHU N/S-B (Pali virama)")
-          (?\e$,1C?\e(B special "BAHT SIGN (currency symbol)")
-          (?\e$,1C@\e(B vowel-base "VOWEL SIGN SARA E")
-          (?\e$,1CA\e(B vowel-base "VOWEL SIGN SARA AE")
-          (?\e$,1CB\e(B vowel-base "VOWEL SIGN SARA O")
-          (?\e$,1CC\e(B vowel-base "VOWEL SIGN SARA MAI MUAN")
-          (?\e$,1CD\e(B vowel-base "VOWEL SIGN SARA MAI MALAI")
-          (?\e$,1CE\e(B vowel-base "LAK KHANG YAO")
-          (?\e$,1CF\e(B special "MAI YAMOK (repetion)")
-          (?\e$,1CG\e(B sign-upper "VOWEL SIGN MAI TAI KHU N/S-T")
-          (?\e$,1CH\e(B tone "TONE MAI EK N/S-T")
-          (?\e$,1CI\e(B tone "TONE MAI THO N/S-T")
-          (?\e$,1CJ\e(B tone "TONE MAI TRI N/S-T")
-          (?\e$,1CK\e(B tone "TONE MAI CHATTAWA N/S-T")
-          (?\e$,1CL\e(B sign-upper "THANTHAKHAT N/S-T (cancellation mark)")
-          (?\e$,1CM\e(B sign-upper "NIKKHAHIT N/S-T (final nasal)")
-          (?\e$,1CN\e(B sign-upper "YAMAKKAN N/S-T")
-          (?\e$,1CO\e(B special "FONRMAN")
-          (?\e$,1CP\e(B special "DIGIT ZERO")
-          (?\e$,1CQ\e(B special "DIGIT ONE")
-          (?\e$,1CR\e(B special "DIGIT TWO")
-          (?\e$,1CS\e(B special "DIGIT THREE")
-          (?\e$,1CT\e(B special "DIGIT FOUR")
-          (?\e$,1CU\e(B special "DIGIT FIVE")
-          (?\e$,1CV\e(B special "DIGIT SIX")
-          (?\e$,1CW\e(B special "DIGIT SEVEN")
-          (?\e$,1CX\e(B special "DIGIT EIGHT")
-          (?\e$,1CY\e(B special "DIGIT NINE")
-          (?\e$,1CZ\e(B special "ANGKHANKHU (ellipsis)")
-          (?\e$,1C[\e(B special "KHOMUT (beginning of religious texts)")
           ))
       elm)
   (while l
@@ -260,24 +160,20 @@ if necessary."
          (ptype (nth 1 elm)))
       (put-char-code-property char 'phonetic-type ptype)
       (cond ((eq ptype 'consonant)
-            (modify-category-entry char ?c thai-category-table)
-            (global-set-key (vector char) 'thai-self-insert-command))
+            (modify-category-entry char ?c thai-category-table))
            ((memq ptype '(vowel-upper vowel-lower))
             (modify-category-entry char ?v thai-category-table)
-            (if (or (= char ?\e,TT\e(B) (= char ?\e$,1C4\e(B))
+            (if (= char ?\e,TT\e(B)
                 ;; Give category `I' to "SARA I".
-                (modify-category-entry char ?I thai-category-table))
-            (global-set-key (vector char) 'thai-self-insert-command))
+                (modify-category-entry char ?I thai-category-table)))
            ((eq ptype 'tone)
             (modify-category-entry char ?t thai-category-table)
-            (modify-category-entry char ?u thai-category-table)
-            (global-set-key (vector char) 'thai-self-insert-command))
+            (modify-category-entry char ?u thai-category-table))
            ((eq ptype 'sign-upper)
             (modify-category-entry char ?u thai-category-table)
-            (if (or (= char ?\e,Tl\e(B) (= char ?\e$,1CL\e(B))
+            (if (= char ?\e,Tl\e(B)
                 ;; Give category `U' to "THANTHAKHAT".
-                (modify-category-entry char ?U thai-category-table))
-            (global-set-key (vector char) 'thai-self-insert-command)))
+                (modify-category-entry char ?U thai-category-table))))
       (put-char-code-property char 'name (nth 2 elm)))))
 
 (defun thai-compose-syllable (beg end &optional category-set string)
@@ -333,57 +229,20 @@ positions (integers or markers) specifying the region."
   (thai-compose-region (point-min) (point-max)))
 
 ;;;###autoload
-(defun thai-post-read-conversion (len)
-  (thai-compose-region (point) (+ (point) len))
-  len)
-
-;;;###autoload
-(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."
-  (when (and (not thai-auto-composition-mode)
-            (< (1+ from) to))
-    (with-category-table thai-category-table
-      (if string
-         (if (eq (string-match thai-composition-pattern string from) from)
-             (thai-compose-syllable from (match-end 0) nil string))
-       (if (save-excursion
-             (goto-char from)
-             (and (looking-at thai-composition-pattern)
-                  (setq to (match-end 0))))
-           (thai-compose-syllable from to))))))
-
-(defun thai-auto-composition (beg end len)
+(defun thai-composition-function (pos to font-object string)
+  (setq pos (1- pos))
   (with-category-table thai-category-table
-    (let (category-set)
-      (while (and (> beg (point-min))
-                 (setq category-set (char-category-set (char-after (1- beg))))
-                 (or (aref category-set ?v) (aref category-set ?u)))
-         (setq beg (1- beg)))
-      (if (and (> beg (point-min))
-              (aref (char-category-set (char-after (1- beg))) ?c))
-         (setq beg (1- beg)))
-      (while (and (< end (point-max))
-                 (setq category-set (char-category-set (char-after end)))
-                 (or (aref category-set ?v) (aref category-set ?u)))
-       (setq end (1+ end)))
-      (if (< beg end)
-         (thai-compose-region beg end)))))
-
-(put 'thai-auto-composition-mode 'permanent-local t)
-
-;;;###autoload
-(define-minor-mode thai-auto-composition-mode
-  "Minor mode for automatically correct Thai character composition."
-  :group 'mule
-  (cond ((null thai-auto-composition-mode)
-        (remove-hook 'after-change-functions 'thai-auto-composition))
-       (t
-        (add-hook 'after-change-functions 'thai-auto-composition))))
+    (if string
+       (if (and (>= pos 0)
+                (eq (string-match thai-composition-pattern string pos) pos))
+           (prog1 (match-end 0)
+             (thai-compose-syllable pos (match-end 0) nil string)))
+      (if (>= pos (point-min))
+         (progn
+           (goto-char pos)
+           (if (looking-at thai-composition-pattern)
+               (prog1 (match-end 0)
+                 (thai-compose-syllable pos (match-end 0)))))))))
 
 ;; Thai-word-mode requires functions in the feature `thai-word'.
 (require 'thai-word)