Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(use '[clojure.contrib.macro-utils :only [macrolet]])
(defmacro defplugin [& body]
(let [g (gensym)]
(macrolet [(defcommand [docs words cmdkey & method-stuff]
`(do (dosync (doseq [word# ~words]
(assoc ~g word# {:cmd ~cmdkey :doc ~docs})))
(defmethod respond ~cmdkey ~@method-stuff)))]
`(let [~g (ref [])]
(let [m-name# (keyword (last (.split (str *ns*) "\\.")))]
(alter modules merge
{:load #(dosync (alter commands assoc m-name# ~g))
:unload #(dosync (alter commands dissoc m-name#))}})))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.