[anything] kyr な anything ソースセレクター

文脈に応じたコマンドを提示する anything-kyr.el をリリース - http://rubikitch.com/に移転しました のパーツをザクタンクよろしく流用して、kyrに anything-c-source-xxxを選択するインターフェースを作って使っている。
既存の機能のような気もするが。
ところで、lispで大同小異なプログラムを流用するのって、どうするのがエレガントなんだろうか。
コピペはなぁ。。。

(defvar anything-kyr-source-select-by-major-mode nil
  "Show commands by major-mode.
It is a list of elements of (MAJOR-MODE COMMAND1 ...) or ((MAJOR-MODE1 MAJOR-MODE2) COMMAND1 ...).")
(defvar anything-kyr-source-select-by-file-name nil
  "Show commands by file name.
It is a list of elements of (REGEXP COMMAND1 ...).")
(defvar anything-kyr-source-select-by-condition nil
  "Show commands by condition.
It is a list of elements of (CONDITION COMMAND1 ...).")
(defvar anything-kyr-source-select-kinds
  '((anything-kyr-source-select-by-condition . eval)
    (anything-kyr-source-select-by-file-name
     . (lambda (re) (string-match re (or buffer-file-name ""))))
    (anything-kyr-source-select-by-major-mode
     . (lambda (mode) (if (listp mode)
                          (memq major-mode mode)
                        (eq major-mode mode))))))

(defun anything-kyr-source-select-sources ()
  (interactive)
  (loop for (varname . condition-func) in anything-kyr-source-select-kinds append
        (loop for (condition . cmds) in (symbol-value varname)
              when (save-excursion (funcall condition-func condition))
              append  cmds)))

(defun anything-kyr-source-select-by-major-mode ()
  (assoc-default major-mode anything-kyr-source-select-by-major-mode))

(setq anything-kyr-source-select-by-condition
      '((t anything-c-source-kyr
           anything-c-source-extended-command-history)))

(setq anything-kyr-source-select-by-major-mode
      '((c++-mode anything-c-source-semantic)
      ))

(defun anything-for-do ()
  (interactive)
  (anything (anything-kyr-source-select-sources)))