egg-980315.
[elisp/egg.git] / its-keydef.el
index e85ee3f..9372491 100644 (file)
@@ -1,39 +1,40 @@
 (eval-when-compile
   (require 'cl))
 
-(defvar its-current-language "Japanese")
-
 (defvar its-zhuyin nil)
 (make-variable-buffer-local 'its-zhuyin)
+(put 'its-zhuyin 'permanent-local t)
 
 (eval-when (eval compile)
-(defun its-make-select-func (key1 key2 name file map &optional lang zhuyin)
-  (setq name (intern (concat "its-select-" (symbol-name name)))
-       file (intern (concat "its/" (symbol-name file)))
-       map (intern (concat "its-" (symbol-name map) "-map"))
-       lang (symbol-name lang))
-  (cons
-   `(defun ,name (&optional mode-line-unchange)
-      (interactive)
-      (cond
-       ((its-in-fence-p)
-       (its-input-end)
-       (its-put-cursor t))
-       ((egg-get-bunsetsu-info (point))
-       (egg-exit-conversion)))
-      ,(if lang `(egg-check-language ,lang))
-      (require ',file)
-      (setq its-current-map ,map)
-      ,(if lang `(setq its-current-language ,lang))
-      ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
-      (if (null mode-line-unchange)
-         (egg-set-mode-line-title)))
-   `(define-key map
-      (if fence
-         ,(concat "\e" (vector key2))
-       ,(concat "\C-x\C-m" (vector key1)))
-      ',name)))
-)
+  (defun its-make-select-func (key1 key2 func file map &optional zhuyin)
+    (setq func (intern (concat "its-select-" (symbol-name func)))
+         file (intern (concat "its/" (symbol-name file)))
+         map (intern (concat "its-" (symbol-name map) "-map")))
+    (cons
+     `(defun ,func (&optional temporally mode-line-unchange)
+       (interactive "P")
+       (if temporally
+           (its-select-mode-temporally ',func)
+         (let ((inhibit-read-only t))
+           (require ',file)
+           (cond
+            ((its-in-fence-p)
+             (its-input-end)
+             (its-put-cursor t))
+            ((egg-get-bunsetsu-info (point))
+             (egg-exit-conversion)))
+           (setq its-current-select-func ',func)
+           (setq its-current-map ,map)
+           (if (its-get-language its-current-map)
+               (setq its-current-language (its-get-language its-current-map)))
+           ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
+           (if (null mode-line-unchange)
+               (its-set-mode-line-title)))))
+     `(define-key map
+       (if fence
+           ,(concat "\e" key2)
+         ,(concat "\C-x\C-m" key1))
+       ',func))))
 
 (defmacro its-do-list-make-select-func (list)
   (eval-when (eval compile)
           ,@keydefs)))))
 
 (its-do-list-make-select-func
- ((?Q    ?Q    upcase               ascii    up)
-  (?q    ?q    downcase             ascii    down)
-  (?h    ?\C-h hiragana             hira     hira             Japanese)
-  (?k    ?\C-k katakana             kata     kata             Japanese)
-  (?x    ?\C-x hankaku-katakana     hankata  han-kata         Japanese)
-  (?Z    ?Z    zenkaku-upcase       zenkaku  zenkaku-up       Japanese)
-  (?z    ?z    zenkaku-downcase     zenkaku  zenkaku-down     Japanese)
-  (?\C-e ?\C-e erpin-cn             erpin    erpin-cn         Chinese-GB NIL)
-  (?\C-p ?\C-p pinyin-cn            pinyin   pinyin-cn        Chinese-GB NIL)
-  (?\C-z ?\C-z zhuyin-cn            zhuyin   zhuyin-cn        Chinese-GB T)
-  (?\C-u ?\C-u quanjiao-upcase-cn   quanjiao quanjiao-up-cn   Chinese-GB)
-  (?\C-d ?\C-d quanjiao-downcase-cn quanjiao quanjiao-down-cn Chinese-GB)
-  (?E    ?E    erpin-tw             erpin    erpin-tw         Chinese-CNS NIL)
-  (?P    ?P    pinyin-tw            pinyin   pinyin-tw        Chinese-CNS NIL)
-  (?Z    ?Z    zhuyin-tw            zhuyin   zhuyin-tw        Chinese-CNS T)
-  (?U    ?U    quanjiao-upcase-tw   quanjiao quanjiao-up-tw   Chinese-CNS)
-  (?C    ?C    quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
-  (?H    ?H    hangul               hangul   hangul           Korean)
-  (?J    ?J    jeonkak-upcase       jeonkak  jeonkak-up       Korean)
-  (?j    ?j    jeonkak-downcase     jeonkak  jeonkak-down     Korean)))
+ (("Q"    "Q"    upcase               ascii    up)
+  ("q"    "q"    downcase             ascii    down)
+  ("h"    "\C-h" hiragana             hira     hira)
+  ("k"    "\C-k" katakana             kata     kata)
+  ("x"    "\C-x" hankaku-katakana     hankata  han-kata)
+  ("Z"    "Z"    zenkaku-upcase       zenkaku  zenkaku-up)
+  ("z"    "z"    zenkaku-downcase     zenkaku  zenkaku-down)
+  ("\C-e" "\C-e" erpin-cn             erpin    erpin-cn          NIL)
+  ("\C-p" "\C-p" pinyin-cn            pinyin   pinyin-cn         NIL)
+  ("\C-z" "\C-z" zhuyin-cn            zhuyin   zhuyin-cn         T)
+  ("\C-u" "\C-u" quanjiao-upcase-cn   quanjiao quanjiao-up-cn)
+  ("\C-d" "\C-d" quanjiao-downcase-cn quanjiao quanjiao-down-cn)
+  ("E"    "E"    erpin-tw             erpin    erpin-tw          NIL)
+  ("P"    "P"    pinyin-tw            pinyin   pinyin-tw         NIL)
+  ("C"    "C"    zhuyin-tw            zhuyin   zhuyin-tw         T)
+  ("U"    "U"    quanjiao-upcase-tw   quanjiao quanjiao-up-tw)
+  ("D"    "D"    quanjiao-downcase-tw quanjiao quanjiao-down-tw)
+  ("H"    "H"    hangul               hangul   hangul)
+  ("J"    "J"    jeonkak-upcase       jeonkak  jeonkak-up)
+  ("j"    "j"    jeonkak-downcase     jeonkak  jeonkak-down)))
 
 (provide 'its-keydef)