Avoid fence destruction on input error.
[elisp/egg.git] / its-keydef.el
index d295424..8c617f7 100644 (file)
@@ -6,38 +6,43 @@
 (defvar its-zhuyin nil)
 (make-variable-buffer-local 'its-zhuyin)
 
-(defmacro its-make-slect-func (key name file map &optional lang zhuyin)
+(defun its-make-select-func (key 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))
-  `(progn
-     (defun ,name ()
-       (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)))
-       (egg-set-mode-line-title (its-get-indicator its-current-map)))
-     (define-key mule-keymap ,key ',name)))
+  (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 ,(concat "\C-x\C-m" key) ',name)))
 
-(defmacro its-do-list-make-slect-func (list)
+(defmacro its-do-list-make-select-func (list)
   (eval-when (eval compile)
-    (let (e l)
+    (let (funcs keydefs pair)
       (while list
-       (setq e (car list))
-       (setq l (cons `(its-make-slect-func ,@(car list)) l))
+       (setq pair (apply 'its-make-select-func (car list)))
+       (setq funcs (cons (car pair) funcs)
+             keydefs (cons (cdr pair) keydefs))
        (setq list (cdr list)))
-      (cons 'progn l))))
+      `(progn
+        ,@funcs
+        (defun its-define-select-keys (map)
+          ,@keydefs)))))
 
-(its-do-list-make-slect-func
+(its-do-list-make-select-func
  (("Q"    upcase               ascii    up)
   ("q"    downcase             ascii    down)
   ("h"    hiragana             hira     hira             Japanese)
@@ -54,7 +59,7 @@
   ("P"    pinyin-tw            pinyin   pinyin-tw        Chinese-CNS NIL)
   ("Z"    zhuyin-tw            zhuyin   zhuyin-tw        Chinese-CNS T)
   ("U"    quanjiao-upcase-tw   quanjiao quanjiao-up-tw   Chinese-CNS)
-  ("D"    quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
+  ("C"    quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
   ("H"    hangul               hangul   hangul           Korean)
   ("J"    jeonkak-upcase       jeonkak  jeonkak-up       Korean)
   ("j"    jeonkak-downcase     jeonkak  jeonkak-down     Korean)))