egg-980217.
[elisp/egg.git] / its.el
diff --git a/its.el b/its.el
index 6a19430..26aeb04 100644 (file)
--- a/its.el
+++ b/its.el
@@ -1,21 +1,22 @@
 ;;; its.el --- Input Translation Systam AKA "ITS(uDekirunDa!)"
 
-;; Copyright (C) 1997 Mule Project, Powered by Electrotechnical
+;; Copyright (C) 1997, 1998 Mule Project, Powered by Electrotechnical
 ;; Laboratory, JAPAN.
 ;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
 
 ;; Author: NIIBE Yutaka <gniibe@mri.co.jp>
+;;         KATAYAMA Yoshio <kate@pfu.co.jp>
 ;; Maintainer: NIIBE Yutaka <gniibe@mri.co.jp>
 ;; Keywords: mule, multilingual, input method
 
 ;; This file will be part of GNU Emacs (in future).
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; EGG is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
-;; GNU Emacs is distributed in the hope that it will be useful,
+;; EGG is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
 ;;; Code:
 
+(require 'cl)
+
+(defvar its-current-language)
+(make-variable-buffer-local 'its-current-language)
+\f
 ;; Data structure in ITS
 ;; (1) SYL and CURSOR
 ;;
 
 ;; Data structure in ITS (3) Map
 ;;
-;; <map>         ::= ( <name> . ( <indicator> . <start-state> ) )
-;; <start-state> ::= <state>
+;; <map>         ::= ( <name> <indicator> <language> . <start-state> )
 ;; <name>        ::= "string"
 ;; <indicator>   ::= "string"
+;; <language>    ::= "string"
+;; <start-state> ::= <state>
 ;;
 \f
 (defsubst its-new-state (output keyseq back)
   (cons output (cons keyseq back)))
 
-(defsubst its-new-map (name indicator)
-  (cons name (cons indicator (its-new-state "" "" nil))))
+(defsubst its-new-map (name indicator language)
+  (cons name (cons indicator (cons language (its-new-state "" "" nil)))))
 
 (defsubst its-get-indicator (map)
-  (car (cdr map)))
+  (nth 1 map))
 
-(defsubst its-set-indicator (map indicator)
-  (setcar (cdr map) indicator))
+(defsubst its-get-language (map)
+  (nth 2 map))
 
 (defsubst its-get-start-state (map)
-  (cdr (cdr map)))
-
-(defsubst its-reset-start-state (map)
-  (setcdr (cdr map) (its-new-state "" "" nil))
-  map)
+  (nthcdr 3 map))
 
 (defsubst its-get-kst/t (state)
   (cdr (cdr state)))
 
 (defsubst its-set-keyseq (state keyseq)
   (setcar (cdr state) keyseq))
+
 (defun its-get-keyseq-cooked (state)
   (let ((keyseq (its-get-keyseq state))
        (back (its-get-kst/t state)))
     (insert (its-get-output newsyl))
     (add-text-properties p (point)
                         (list 'its-syl newsyl
+                              'its-map its-current-map
+                              'its-lang its-current-language
                               'intangible 'its-part-1))
     (if its-fence-face
        (put-text-property p (point) 'face its-fence-face))))
       (setq its-map-alist (cons map its-map-alist)))
     map))
 
-(defun its-define-state-machine (name indicator &optional continue)
-  "NAME \e$B$G;XDj$5$l$?\e(B State Machine \e$B$NDj5A$r3+;O$9$k!#\e(B
-INDICATOR \e$B$O\e(B mode line \e$B$KI=<($9$k\e(B indicator \e$B$r;XDj$9$k!#\e(B
-CONTINUE \e$B$,\e(B nil \e$B$N;~$K$O\e(B State Machine \e$B$NDj5A$r6u$K$9$k!#\e(Bits-defrule 
-\e$B$r;2>H!#\e(B"
-  (setq its-current-map
-       (if (null (its-get-map name))
-           (its-register-map (its-new-map name indicator))
-         (let ((map (its-get-map name)))
-           (its-set-indicator map indicator)
-           (if continue
-               map
-             (its-reset-start-state map))))))
-
-(defmacro define-its-state-machine (map name indicator doc &rest exprs)
-  `(let ((its-current-map (its-new-map ,name ,indicator)))
-     ,(cons 'progn exprs)
-     (defconst ,map its-current-map ,doc)))
-
-;;(defmacro define-its-state-machine (map name indicator doc &rest exprs)
-;;  (let ((its-current-map (its-new-map name indicator)))
-;;    (eval (cons 'progn exprs))
-;;    `(defconst ,map ',its-current-map ,doc)))
+(defmacro define-its-state-machine (map name indicator lang doc &rest exprs)
+  `(progn
+     (eval-when (eval compile)
+       (let ((its-current-map (its-new-map ,name ,indicator ,lang)))
+        ,@exprs
+        (setq ,map its-current-map)))
+     (define-its-compiled-map ,map ,doc)))
+
+(defmacro define-its-compiled-map (map doc)
+  `(defconst ,map ',(symbol-value map) ,doc))
 
 (defmacro define-its-state-machine-append (map &rest exprs)
   (append
@@ -525,8 +518,8 @@ Return last state."
       (let ((begpos (previous-single-property-change (point) 'its-start)))
        ;; Make SYLs have property of "part 2"
        (put-text-property begpos (point) 'intangible 'its-part-2)
-       (goto-char begpos)
-       (its-put-cursor t))))
+       (goto-char begpos)))
+  (its-put-cursor t))
 
 (defun its-end-of-input-buffer ()
   (interactive)
@@ -535,8 +528,8 @@ Return last state."
       (let ((endpos (next-single-property-change (point) 'its-end)))
        ;; Make SYLs have property of "part 1"
        (put-text-property (point) endpos 'intangible 'its-part-1)
-       (goto-char endpos)
-       (its-put-cursor t))))
+       (goto-char endpos)))
+  (its-put-cursor t))
 
 ;; TODO: move in VSYL
 (defun its-backward-SYL (n)
@@ -568,7 +561,7 @@ Return last state."
       (setq syl (get-text-property p 'its-syl))
       (setq n (1- n)))
     ;; Make SYLs have property of "part 1"
-    (put-text-property p old-point'intangible 'its-part-1)
+    (put-text-property p old-point 'intangible 'its-part-1)
     (goto-char p)
     (its-put-cursor t)
     (if (> n 0)
@@ -631,7 +624,8 @@ Return last state."
 (defun its-delete-backward-within-SYL (syl n killflag)
   (let* ((keyseq (its-get-keyseq-syl syl))
         (len (length keyseq))
-        (p (point)))
+        (p (point))
+        (its-current-map (get-text-property (1- (point)) 'its-map)))
     (if (> n len)
        (signal 'args-out-of-range (list p n)))
     ;; Delete CURSOR
@@ -695,10 +689,12 @@ Return last state."
     (delete-region end (1+ end))
     ;; Remove all properties added by ITS
     (remove-text-properties start end '(its-syl nil
+                                       its-map nil
                                        face nil
                                        intangible nil))
     (if proceed-to-conversion
        (egg-convert-region start end)
+      (remove-text-properties start end '(its-lang nil))
       (egg-do-auto-fill)
       (run-hooks 'input-method-after-insert-chunk-hook))))
 
@@ -706,6 +702,10 @@ Return last state."
   (interactive)
   (its-input-end)
   (its-exit-mode-internal t))
+
+(defun its-in-fence-p ()
+  (let ((prop (get-text-property (point) 'intangible)))
+    (or (eq prop 'its-part-1) (eq prop 'its-part-2))))
 \f
 (defvar its-translation-result nil "")
 
@@ -739,51 +739,7 @@ Return last state."
     (delete-region start end)
     (apply 'insert (reverse its-translation-result))))
 \f
-(defvar its-select-map-menu '(menu "Map:" nil))
-
-(defun its-select-map-from-menu ()
-  (interactive)
-  (setcar (nthcdr 2 its-select-map-menu) its-map-alist)
-  (setq its-current-map (menudiag-select its-select-map-menu))
-  (force-mode-line-update))
-
-(defun its-select-hiragana ()
-  (interactive)
-  (its-select-map "roma-kana"))
-
-(defun its-select-katakana ()
-  (interactive)
-  (its-select-map "roma-kata"))
-
-(defun its-select-downcase ()
-  (interactive)
-  (its-select-map "downcase"))
-
-(defun its-select-upcase ()
-  (interactive)
-  (its-select-map "upcase"))
-
-(defun its-select-zenkaku-downcase ()
-  (interactive)
-  (its-select-map "zenkaku-downcase"))
-
-(defun its-select-zenkaku-upcase ()
-  (interactive)
-  (its-select-map "zenkaku-upcase"))
-
-(defun its-select-map (name)
-  (interactive (list (completing-read "ITS map: " its-map-alist)))
-  (if (its-get-map name)
-      (progn
-       (setq its-current-map (its-get-map name))
-       (force-mode-line-update))
-    (ding)))
-\f
-;; Escape character to Zenkaku inputs
-(defconst its-zenkaku-escape "Z")
-
-;; Escape character to Hankaku inputs
-(defconst its-hankaku-escape "~")
+(load "its-keydef.el")
 
 (provide 'its)
 ;;; its.el ends here.