defmacroを使ってみた

defmacroの実行の順序は

  • macro展開
  • macro展開で生成された式を実行

という感じみたいです。
byte-compileをしたときにmacro展開された式が保存されるみたいです。

取り合えず使ってみました。

関数を調べるdescribe-functionとかのanything版です。
(変数の値を調べるdescribe-variableもある)

(defmacro make-anything-c-source (valname pred action)
  `(setq ,valname
         (quote ((name . "candidate")
                 (candidates .  (lambda () 
                                  (let ((re '()))
                                    (mapatoms 
                                     (lambda (ele)
                                       (when (funcall ,pred ele)
					 (push (symbol-name ele) re))))
                                    re)))
                 (delayed)
                 (action . (("describe" . (lambda (c)
                                            (,action (intern c))))))))))

(defmacro make-caller (name source)
  `(defun ,name () (interactive)
     (let ((anything-sources (list ,source)))
       (anything))))

(make-anything-c-source
 anything-c-source-describe-functions
 (lambda (e) (fboundp e))
 describe-function)

(make-anything-c-source
 anything-c-source-describe-variables
 (lambda (e) (not (fboundp e)))
 describe-variable)

(make-caller anything-describe-function 
	     anything-c-source-describe-functions)
(make-caller anything-describe-variable 
	     anything-c-source-describe-variables)

こんな感じで使い方は合っているのかな?