bindする関数を変えられるようにして、一つのkeyを大切に使う。

C-c-jにanything-lisp-complete-symbolを割り当てているんですが、dabbrevをこのキーで使いたいときがあったりしました。そんなわけで、bindされている関数を変えられるようにする設定を考えてみました。anythingで選択できると便利です*1
make-callerは単に楽をするためのものです。*2

(defmacro make-caller (name sources &optional prepare)
  "anythingを呼び出す関数の部分を作成するmacro"
  (let ((head `(defun ,name () (interactive)))
	(body 	 `(let ((anything-sources ,sources)
			(anything-initial-input (my-elisp-current-function)))
		    (anything))))
    (if prepare 
	`(,@head ,@prepare ,body)
      `(,@head ,body))))

(require 'anything-dabbrev-expand)
(require 'anything-c-lisp-complete-symbol)

(setq toggle-cj-sources ;;ここにbindしたい関数を加える。
      '("anything-lisp-complete-symbol" "anything-dabbrev-expand"))

(make-caller toggle-cj-with-anything
	     (list anything-c-source-toggle-cj))

(setq anything-c-source-toggle-cj
      '((name . "list")
	(candidates . toggle-cj-sources)
	(volatile)
	(action . (("Edit C-c-j Binding" . (lambda (c)
					     (message (concat "C-c j: " c))
					     (let ((sym (intern c)))
					       (global-set-key "\C-cj" sym))))))))

(global-set-key "\C-cj" (intern (car toggle-cj-sources)))
(global-set-key "\C-cJ" 'toggle-cj-with-anything)	

*1:以前は循環リストを使って変更するようにしてました。

*2:このような定義を1つしか書かないのなら、別にmacroにする必要はないです。