]> code.delx.au - gnu-emacs/blobdiff - leim/quail/lrt.el
Merge from emacs--rel--22
[gnu-emacs] / leim / quail / lrt.el
index b3521c9fb39f1485761a47ca254db4b6a3dbd84d..5eeec0b8ab3a6c19d57e9c36d9c73d8b471e7e21 100644 (file)
@@ -1,7 +1,11 @@
-;;; quail/lrt.el --- Quail package for inputting Lao characters by LRT method
+;;; lrt.el --- Quail package for inputting Lao characters by LRT method  -*-coding: iso-2022-7bit;-*-
 
-;; Copyright (C) 1997 Electrotechnical Laboratory, JAPAN.
-;; Licensed to the Free Software Foundation.
+;; Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;;   Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+;;   2006, 2007
+;;   National Institute of Advanced Industrial Science and Technology (AIST)
+;;   Registration Number H14PRO021
 
 ;; Keywords: multilingual, input method, Lao, LRT.
 
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
 
 ;;; Code:
 
 ;; key sequence:
 ;;     consonant [+ semi-vowel-sign-lo ] + vowel [+ maa-sakod ] [+ tone-mark ]
 
-(eval-and-compile
-
-;; Upper vowels and tone-marks are put on the letter.
-;; Semi-vowel-sign-lo and lower vowels are put under the letter.
-(defconst lrt-single-consonant-table
-  `(("k" . ?\e(1!\e(B)
-    ("kh" . ?\e(1"\e(B)
-    ("qh" . ?\e(1$\e(B)
-    ("ng" . ?\e(1'\e(B)
-    ("j" . ?\e(1(\e(B)
-    ("s" . ?\e(1J\e(B)
-    ("x" . ?\e(1*\e(B)
-    ("y" . ?\e(1-\e(B)
-    ("d" . ?\e(14\e(B)
-    ("t" . ?\e(15\e(B)
-    ("th" . ?\e(16\e(B)
-    ("dh" . ?\e(17\e(B)
-    ("n" . ?\e(19\e(B)
-    ("b" . ?\e(1:\e(B)
-    ("p" . ?\e(1;\e(B)
-    ("hp" . ?\e(1<\e(B)
-    ("fh" . ?\e(1=\e(B)
-    ("ph" . ?\e(1>\e(B)
-    ("f" . ?\e(1?\e(B)
-    ("m" . ?\e(1A\e(B)
-    ("gn" . ?\e(1B\e(B)
-    ("l" . ?\e(1E\e(B)
-    ("r" . ?\e(1C\e(B)
-    ("v" . ?\e(1G\e(B)
-    ("w" . ?\e(1G\e(B)
-    ("hh" . ?\e(1K\e(B)
-    ("O" . ?\e(1M\e(B)
-    ("h" . ?\e(1N\e(B)
-    ("nh" . ?\e(1|\e(B)
-    ("mh" . ?\e(1}\e(B)
-    ("lh" . "\e0\e(1K\\e(B\e1")
-    ))
-
-;; Semi-vowel-sign-lo is put under the first letter.
-;; Lower vowels are put under the last letter.
-;; Upper vowels and tone-marks are put on the last letter.
-(defconst lrt-double-consonant-table
-  '(("ngh" . "\e(1K'\e(B")
-    ("yh" . "\e(1K]\e(B")
-    ("wh" . "\e(1KG\e(B")
-    ("hl" . "\e(1KE\e(B")
-    ("hy" . "\e(1K-\e(B")         
-    ("hn" . "\e(1K9\e(B")
-    ("hm" . "\e(1KA\e(B")
-    ))
-
-(defconst lrt-semi-vowel-sign-lo
-  '("r" . ?\e(1\\e(B))
-
-(defconst lrt-vowel-table
-  '(("a" "\e(1P\e(B" (0 ?\e(1P\e(B) (0 ?\e(1Q\e(B))
-    ("ar" "\e(1R\e(B" (0 ?\e(1R\e(B))
-    ("i" "\e(1T\e(B" (0 ?\e(1T\e(B))
-    ("ii" "\e(1U\e(B" (0 ?\e(1U\e(B))
-    ("eu" "\e(1V\e(B" (0 ?\e(1V\e(B))
-    ("ur" "\e(1W\e(B" (0 ?\e(1W\e(B))
-    ("u" "\e(1X\e(B" (0 ?\e(1X\e(B))
-    ("uu" "\e(1Y\e(B" (0 ?\e(1Y\e(B))
-    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e(B))
-    ("eaa" "\e(1`WM\e(B" (?\e(1`\e(B 0 ?\e(1W\e(B ?\e(1M\e(B))
-    ("ai" "\e(1d\e(B" (?\e(1d\e(B 0))
-    ("ei" "\e(1c\e(B" (?\e(1c\e(B 0))
-    ("ao" "\e(1`[R\e(B" (?\e(1`\e(B 0 ?\e(1[\e(B ?\e(1R\e(B))
-    ("aM" "\e(1S\e(B" (0 ?\e(1S\e(B))))
-
-;; Maa-sakod is put at the tail.
-(defconst lrt-maa-sakod-table
-  '((?k . ?\e(1!\e(B)
-    (?g . ?\e(1'\e(B)
-    (?y . ?\e(1-\e(B)
-    (?d . ?\e(14\e(B)
-    (?n . ?\e(19\e(B)
-    (?b . ?\e(1:\e(B)
-    (?m . ?\e(1A\e(B)
-    (?v . ?\e(1G\e(B)
-    (?w . ?\e(1G\e(B)
-    ))
-
-(defconst lrt-tone-mark-table
-  '(("'" . ?\e(1h\e(B)
-    ("\"" . ?\e(1i\e(B)
-    ("^" . ?\e(1j\e(B)
-    ("+" . ?\e(1k\e(B)
-    ("~" . ?\e(1l\e(B)))
-
-;; Return list of composing patterns for normal (without maa-sakod)
-;; key sequence and with-maa-sakod key sequence starting with single
-;; consonant C and optional SEMI-VOWEL.
-(defun lrt-composing-pattern-single-c (c semi-vowel vowel-pattern)
-  (let* ((patterns (copy-sequence vowel-pattern))
-        (tail patterns)
-        place)
-    ;; Embed C and SEMI-VOWEL (if any) at the place of 0.
-    (while tail
-      ;; At first, make a copy.
-      (setcar tail (copy-sequence (car tail)))
-      ;; Then, do embedding.
-      (setq place (memq 0 (car tail)))
-      (setcar place c)
-      (if semi-vowel
-         (setcdr place (cons semi-vowel (cdr place))))
-      (setq tail (cdr tail)))
-    patterns))
-
-;; Return list of composing patterns for normal (without maa-sakod)
-;; key sequence and with-maa-sakod key sequence starting with double
-;; consonant STR and optional SEMI-VOWEL.
-(defun lrt-composing-pattern-double-c (str semi-vowel vowel-pattern)
-  (let* ((patterns (copy-sequence vowel-pattern))
-        (tail patterns)
-        (chars (string-to-list
-                (if (= (length str) 1)
-                    (decompose-string str)
-                  str)))
-        place)
-    ;; Embed C and SEMI-VOWEL (if any) at the place of 0.
-    (while tail
-      ;; At first, make a copy.
-      (setcar tail (copy-sequence (car tail)))
-      ;; Then, do embedding.
-      (setq place (memq 0 (car tail)))
-      (setcar place (car chars))
-      (setcdr place (cons (nth 1 chars) (cdr place)))
-      (if semi-vowel
-         ;; Embed SEMI-VOWEL in between CHARS.
-         (setcdr place (cons semi-vowel (cdr place))))
-      (setq tail (cdr tail)))
-    patterns))
-
-;; Return a string made of characters in CHAR-LIST while composing
-;; such characters as vowel-upper, vowel-lower, semi-vowel(lower),
-;; and tone-mark with the preceding base character.
-(defun lrt-compose-string (char-list)
-  ;; Make a copy because the following work alters it.
-  (setq char-list (copy-sequence char-list))
-  (let ((i -1)
-       (l char-list))
-    (while l
-      (if (memq (get-char-code-property (car l) 'phonetic-type)
-               '(vowel-upper vowel-lower semivowel-lower tone))
-         (let (composed-char)
-           (if (< i 0)
-               ;; No preceding base character.
-               (error "Invalid CHAR-LIST: %s" char-list))
-           (setq composed-char
-                 (string-to-char (compose-chars (nth i char-list) (car l))))
-           (setcar (nthcdr i char-list) composed-char)
-           (setq l (cdr l))
-           (setcdr (nthcdr i char-list) l))
-       (setq l (cdr l))
-       (setq i (1+ i))))
-    (concat (apply 'vector char-list))))
-
-(defun lrt-compose-c-s-v (consonant semi-vowel vowel-pattern)
-  (let ((pattern-list
-        (if (integerp consonant)
-            (lrt-composing-pattern-single-c
-             consonant semi-vowel vowel-pattern)
-          (lrt-composing-pattern-double-c
-           consonant semi-vowel vowel-pattern))))
-    (cons (vector (lrt-compose-string (car pattern-list)))
-         (cons t pattern-list))))
-
-)
-
-(defun lrt-handle-maa-sakod ()
-  (interactive)
-  (if (or (= (length quail-current-key) 0)
-         (not quail-current-data))
-      (quail-self-insert-command)
-    (if (not (car quail-current-data))
-       (progn
-         (setq quail-current-data nil)
-         (setq unread-command-events
-               (cons last-command-event unread-command-events))
-         (quail-terminate-translation))
-      (if (not (integerp last-command-event))
-         (error "Bogus calling sequence"))
-      (let* ((maa-sakod (cdr (assq last-command-event lrt-maa-sakod-table)))
-            (maa-sakod-pattern (append
-                                (or (cdr (assq maa-sakod
-                                               (nthcdr 3 quail-current-data)))
-                                    (nth 2 quail-current-data)
-                                    (nth 1 quail-current-data))
-                                (list maa-sakod))))
-       (quail-delete-region)
-       (setq quail-current-str (lrt-compose-string maa-sakod-pattern))
-       (insert quail-current-str)
-       (quail-show-translations)
-       (setq quail-current-data (list nil maa-sakod-pattern))))))
+(defun quail-lao-update-translation (control-flag)
+  (if (integerp control-flag)
+      ;; Non-composable character typed.
+      (setq quail-current-str
+           (buffer-substring (overlay-start quail-overlay)
+                             (overlay-end quail-overlay))
+           unread-command-events
+           (string-to-list
+            (substring quail-current-key control-flag)))
+    (let ((lao-str (lao-transcribe-roman-to-lao-string quail-current-key)))
+      (if (> (aref lao-str 0) 255)
+         (setq quail-current-str lao-str)
+       (or quail-current-str
+           (setq quail-current-str quail-current-key)))))
+  control-flag)
 
-(defun lrt-handle-tone-mark ()
-  (interactive)
-  (if (= (length quail-current-key) 0)
-      (quail-self-insert-command)
-    (if (not quail-current-data)
-       (progn
-         (setq unread-command-events
-               (cons last-command-event unread-command-events))
-         (quail-terminate-translation))
-      (if (not (integerp last-command-event))
-         (error "Bogus calling sequence"))
-      (let* ((tone-mark (cdr (assoc (char-to-string last-command-event)
-                                   lrt-tone-mark-table)))
-            (tone-mark-pattern
-             (if (car quail-current-data)
-                 (copy-sequence (nth 1 quail-current-data))
-               ;; No need of copy because lrt-handle-maa-sakod should
-               ;; have already done it.
-               (nth 1 quail-current-data)))
-            (tail tone-mark-pattern)
-            (double-consonant-keys lrt-double-consonant-table)
-            (double-consonant-flag nil)
-            place)
-
-       ;; Set DOUBLE-CONSONANT-FLAG to t if a user entered a double
-       ;; consonant.
-       (while (and double-consonant-keys (not double-consonant-flag))
-         (setq double-consonant-flag
-               (eq (string-match (car (car double-consonant-keys))
-                                 quail-current-key)
-                   0)
-               double-consonant-keys (cdr double-consonant-keys)))
-
-       ;; Find a place to embed TONE-MARK.  It should be after a
-       ;; single or double consonant and following upper or lower vowels.
-       (while (and tail (not place))
-         (if (and
-              (eq (get-char-code-property (car tail) 'phonetic-type)
-                  'consonant)
-              ;; Skip `\e(1K\e(B' if it is the first letter of double consonant.
-              (or (not double-consonant-flag)
-                  (/= (car tail) ?\e(1K\e(B)))
-             (progn
-               (setq place tail)
-               (setq tail (cdr tail))
-               (while (and tail
-                           (memq (get-char-code-property (car tail)
-                                                         'phonetic-type)
-                                 '(vowel-upper vowel-lower semivowel-lower)))
-                 (setq place tail tail (cdr tail))))
-           (setq tail (cdr tail))))
-       ;; Embed TONE-MARK.
-       (setcdr place (cons tone-mark (cdr place)))
-       (quail-delete-region)
-       (insert (lrt-compose-string tone-mark-pattern))
-       (setq quail-current-data nil)
-       (quail-terminate-translation)))))
-
-(defmacro lrt-generate-quail-map ()
-  `(quail-install-map
-    ',(let ((map (list nil))
-           (semi-vowel-key (car lrt-semi-vowel-sign-lo))
-           (semi-vowel-char (cdr lrt-semi-vowel-sign-lo))
-           l1 e1 l2 e2 pattern key)
-       ;; Single consonants.
-       (setq l1 lrt-single-consonant-table)
-       (while l1
-         (setq e1 (car l1))
-         (quail-defrule-internal (car e1) (vector (cdr e1)) map)
-         (quail-defrule-internal
-          (concat (car e1) semi-vowel-key)
-          (if (stringp (cdr e1))
-              (compose-string (format "%s%c" (cdr e1) semi-vowel-char))
-            (compose-string (format "%c%c" (cdr e1) semi-vowel-char)))
-          map)
-         (setq l2 lrt-vowel-table)
-         (while l2
-           (setq e2 (car l2))
-           (setq key (concat (car e1) (car e2))
-                 pattern (lrt-compose-c-s-v (cdr e1) nil (nthcdr 2 e2)))
-           (quail-defrule-internal key pattern map)
-           (quail-defrule-internal
-            (concat key " ")
-            (vector (concat (aref (car pattern) 0) " "))  map)
-           (setq key (concat (car e1) semi-vowel-key (car e2))
-                 pattern (lrt-compose-c-s-v (cdr e1) semi-vowel-char
-                                            (nthcdr 2 e2)))
-           (quail-defrule-internal key pattern map)
-           (quail-defrule-internal
-            (concat key " ")
-            (vector (concat (aref (car pattern) 0) " "))  map)
-           (setq l2 (cdr l2)))
-         (setq l1 (cdr l1)))
-
-       ;; Double consonants.
-       (setq l1 lrt-double-consonant-table)
-       (while l1
-         (setq e1 (car l1))
-         (quail-defrule-internal (car e1) (vector (cdr e1)) map)
-         (quail-defrule-internal
-          (concat (car e1) semi-vowel-key)
-          (vector (concat (compose-string
-                           (format "%c%c" (aref (cdr e1) 0) semi-vowel-char))
-                          (substring (cdr e1) 1)))
-          map)
-         (setq l2 lrt-vowel-table)
-         (while l2
-           (setq e2 (car l2))
-           (setq key (concat (car e1) (car e2))
-                 pattern (lrt-compose-c-s-v (cdr e1) nil (nthcdr 2 e2)))
-           (quail-defrule-internal key pattern map)
-           (quail-defrule-internal
-            (concat key " ")
-            (vector (concat (aref (car pattern) 0) " "))  map)
-           (setq key (concat (car e1) semi-vowel-key (car e2))
-                 pattern (lrt-compose-c-s-v (cdr e1) semi-vowel-char
-                                            (nthcdr 2 e2)))
-           (quail-defrule-internal key pattern map)
-           (quail-defrule-internal
-            (concat key " ")
-            (vector (concat (aref (car pattern) 0) " "))  map)
-           (setq l2 (cdr l2)))
-         (setq l1 (cdr l1)))
-
-       ;; Vowels.
-       (setq l1 lrt-vowel-table)
-       (while l1
-         (setq e1 (car l1) l1 (cdr l1))
-         (quail-defrule-internal (car e1) (vector (nth 1 e1)) map))
-
-       ;; Tone-marks.
-       (setq l1 lrt-tone-mark-table)
-       (while l1
-         (setq e1 (car l1) l1 (cdr l1))
-         (quail-defrule-internal (car e1) (cdr e1) map))
-
-       map)))
 
 (quail-define-package
  "lao-lrt" "Lao" "\e(1E\e(BR" t
 `\\' (backslash) + `\\'                => \e(1f\e(B              LAO KO LA (REPETITION)
 `\\' (backslash) + `$'         => \e(1O\e(B              LAO ELLIPSIS
 "
- '(("k" . lrt-handle-maa-sakod)
-   ("g" . lrt-handle-maa-sakod)
-   ("y" . lrt-handle-maa-sakod)
-   ("d" . lrt-handle-maa-sakod)
-   ("n" . lrt-handle-maa-sakod)
-   ("b" . lrt-handle-maa-sakod)
-   ("m" . lrt-handle-maa-sakod)
-   ("v" . lrt-handle-maa-sakod)
-   ("w" . lrt-handle-maa-sakod)
-   ("'" . lrt-handle-tone-mark)
-   ("\"" . lrt-handle-tone-mark)
-   ("^" . lrt-handle-tone-mark)
-   ("+" . lrt-handle-tone-mark)
-   ("~" . lrt-handle-tone-mark))
- 'forget-last-selection 'deterministic 'kbd-translate 'show-layout
-  nil nil nil nil nil t)
-
-(lrt-generate-quail-map)
-
-;; Additional key definitions for Lao digits.
+ nil 'forget-last-selection 'deterministic 'kbd-translate 'show-layout
+  nil nil nil 'quail-lao-update-translation nil t)
 
-(quail-defrule "\\0" ?\e(1p\e(B)
-(quail-defrule "\\1" ?\e(1q\e(B)
-(quail-defrule "\\2" ?\e(1r\e(B)
-(quail-defrule "\\3" ?\e(1s\e(B)
-(quail-defrule "\\4" ?\e(1t\e(B)
-(quail-defrule "\\5" ?\e(1u\e(B)
-(quail-defrule "\\6" ?\e(1v\e(B)
-(quail-defrule "\\7" ?\e(1w\e(B)
-(quail-defrule "\\8" ?\e(1x\e(B)
-(quail-defrule "\\9" ?\e(1y\e(B)
-(quail-defrule "\\\\" ?\e(1f\e(B)
-(quail-defrule "\\$" ?\e(1O\e(B)
-
-;;; quail/lrt.el ends here
+;; LRT (Lao Roman Transcription) input method accepts the following
+;; key sequence:
+;;     consonant [ semi-vowel-sign-lo ] vowel [ maa-sakod ] [ tone-mark ]
+
+(quail-install-map
+ (quail-map-from-table
+  '((base-state (lao-transcription-consonant-alist . sv-state)
+               lao-transcription-vowel-alist
+               lao-transcription-tone-alist)
+    (sv-state (lao-transcription-semi-vowel-alist . v-state)
+             (lao-transcription-vowel-alist . mt-state))
+    (v-state (lao-transcription-vowel-alist . mt-state))
+    (mt-state (lao-transcription-maa-sakod-alist . t-state)
+             lao-transcription-tone-alist)
+    (t-state lao-transcription-tone-alist))))
+
+;;; arch-tag: f65e4038-e187-4906-997b-d2de7ed813d2
+;;; lrt.el ends here