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