Last update forgot its-map change of fence mode.
[elisp/egg.git] / its-keydef.el
1 (eval-when-compile
2   (require 'cl))
3
4 (defvar its-current-language "Japanese")
5
6 (defvar its-zhuyin nil)
7 (make-variable-buffer-local 'its-zhuyin)
8
9 (defun its-make-select-func (key1 key2 name file map &optional lang zhuyin)
10   (setq name (intern (concat "its-select-" (symbol-name name)))
11         file (intern (concat "its/" (symbol-name file)))
12         map (intern (concat "its-" (symbol-name map) "-map"))
13         lang (symbol-name lang))
14   (cons
15    `(defun ,name (&optional mode-line-unchange)
16       (interactive)
17       (cond
18        ((its-in-fence-p)
19         (its-input-end)
20         (its-put-cursor t))
21        ((egg-get-bunsetsu-info (point))
22         (egg-exit-conversion)))
23       ,(if lang `(egg-check-language ,lang))
24       (require ',file)
25       (setq its-current-map ,map)
26       ,(if lang `(setq its-current-language ,lang))
27       ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
28       (if (null mode-line-unchange)
29           (egg-set-mode-line-title)))
30    `(define-key map
31       (if fence
32           ,(concat "\e" (vector key2))
33         ,(concat "\C-x\C-m" (vector key1)))
34       ',name)))
35
36 (defmacro its-do-list-make-select-func (list)
37   (eval-when (eval compile)
38     (let (funcs keydefs pair)
39       (while list
40         (setq pair (apply 'its-make-select-func (car list)))
41         (setq funcs (cons (car pair) funcs)
42               keydefs (cons (cdr pair) keydefs))
43         (setq list (cdr list)))
44       `(progn
45          ,@funcs
46          (defun its-define-select-keys (map &optional fence)
47            ,@keydefs)))))
48
49 (its-do-list-make-select-func
50  ((?Q    ?Q    upcase               ascii    up)
51   (?q    ?q    downcase             ascii    down)
52   (?h    ?\C-h hiragana             hira     hira             Japanese)
53   (?k    ?\C-k katakana             kata     kata             Japanese)
54   (?x    ?\C-x hankaku-katakana     hankata  han-kata         Japanese)
55   (?Z    ?Z    zenkaku-upcase       zenkaku  zenkaku-up       Japanese)
56   (?z    ?z    zenkaku-downcase     zenkaku  zenkaku-down     Japanese)
57   (?\C-e ?\C-e erpin-cn             erpin    erpin-cn         Chinese-GB NIL)
58   (?\C-p ?\C-p pinyin-cn            pinyin   pinyin-cn        Chinese-GB NIL)
59   (?\C-z ?\C-z zhuyin-cn            zhuyin   zhuyin-cn        Chinese-GB T)
60   (?\C-u ?\C-u quanjiao-upcase-cn   quanjiao quanjiao-up-cn   Chinese-GB)
61   (?\C-d ?\C-d quanjiao-downcase-cn quanjiao quanjiao-down-cn Chinese-GB)
62   (?E    ?E    erpin-tw             erpin    erpin-tw         Chinese-CNS NIL)
63   (?P    ?P    pinyin-tw            pinyin   pinyin-tw        Chinese-CNS NIL)
64   (?Z    ?Z    zhuyin-tw            zhuyin   zhuyin-tw        Chinese-CNS T)
65   (?U    ?U    quanjiao-upcase-tw   quanjiao quanjiao-up-tw   Chinese-CNS)
66   (?C    ?C    quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
67   (?H    ?H    hangul               hangul   hangul           Korean)
68   (?J    ?J    jeonkak-upcase       jeonkak  jeonkak-up       Korean)
69   (?j    ?j    jeonkak-downcase     jeonkak  jeonkak-down     Korean)))
70
71 (provide 'its-keydef)