Sync up with egg-980627.
[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-and-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                   its-current-map ',map)
28             (if (its-get-language ,map)
29                 (setq its-current-language (its-get-language ,map)))
30             ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
31             (if (null mode-line-unchange)
32                 (its-set-mode-line-title)))))
33      `(,func ,(concat "\C-x\C-m" key1) ,(concat "\e" key2)))))
34
35 (defmacro its-do-list-make-select-func (list)
36   (let (funcs keydefs pair)
37     (while list
38       (setq pair (apply 'its-make-select-func (car list))
39             funcs (cons (car pair) funcs)
40             keydefs (cons (cdr pair) keydefs)
41             list (cdr list)))
42     `(progn
43        ,@funcs
44        (defvar its-define-select-key-list ',keydefs))))
45
46 (defmacro its-add-select-funcs (list)
47   (let (funcs keydefs pair)
48     (while list
49       (setq pair (apply 'its-make-select-func (car list))
50             funcs (cons (car pair) funcs)
51             keydefs (cons (cdr pair) keydefs)
52             list (cdr list)))
53     `(progn
54        ,@funcs
55        (setq its-define-select-key-list
56              (append ',keydefs its-define-select-key-list)))))
57
58 (defun its-define-select-keys (map &optional fence)
59   (let ((key-list its-define-select-key-list))
60     (while key-list
61       (define-key map (nth 1 (car key-list)) (car (car key-list)))
62       (if fence
63           (define-key map (nth 2 (car key-list)) (car (car key-list))))
64       (setq key-list (cdr key-list)))))
65
66 (its-do-list-make-select-func
67  (("Q"    "Q"    upcase               ascii    up)
68   ("q"    "q"    downcase             ascii    down)
69   ("h"    "\C-h" hiragana             hira     hira)
70   ("k"    "\C-k" katakana             kata     kata)
71   ("x"    "\C-x" hankaku-katakana     hankata  han-kata)
72   ("Z"    "Z"    zenkaku-upcase       zenkaku  zenkaku-up)
73   ("z"    "z"    zenkaku-downcase     zenkaku  zenkaku-down)
74   ("\C-e" "\C-e" erpin-cn             erpin    erpin-cn          NIL)
75   ("\C-p" "\C-p" pinyin-cn            pinyin   pinyin-cn         NIL)
76   ("\C-z" "\C-z" zhuyin-cn            zhuyin   zhuyin-cn         T)
77   ("\C-u" "\C-u" quanjiao-upcase-cn   quanjiao quanjiao-up-cn)
78   ("\C-d" "\C-d" quanjiao-downcase-cn quanjiao quanjiao-down-cn)
79   ("E"    "E"    erpin-tw             erpin    erpin-tw          NIL)
80   ("P"    "P"    pinyin-tw            pinyin   pinyin-tw         NIL)
81   ("C"    "C"    zhuyin-tw            zhuyin   zhuyin-tw         T)
82   ("U"    "U"    quanjiao-upcase-tw   quanjiao quanjiao-up-tw)
83   ("D"    "D"    quanjiao-downcase-tw quanjiao quanjiao-down-tw)
84   ("H"    "H"    hangul               hangul   hangul)
85   ("J"    "J"    jeonkak-upcase       jeonkak  jeonkak-up)
86   ("j"    "j"    jeonkak-downcase     jeonkak  jeonkak-down)))
87
88 (provide 'its-keydef)