                                                           (:parameter-names attrs nil)))
                                nil)))
                       (eval `(make-delegate ~typeargs ~args ~f))))))
+(defn my-register-command
+  "Register a Minibuffer command."
+  [cmd-name-or-attrs typeargs args f]
+  (let [attrs (if (string? cmd-name-or-attrs)
+                  {:name cmd-name-or-attrs}
+                  cmd-name-or-attrs)]
+   (with-minibuffer
+    m
+    (.RegisterCommand m
+                      (doto (Command. (:name attrs nil))
+                            (.set_description (:description attrs nil))
+                            (.set_keySequence (:keysequence attrs nil))
+                            (.set_signature   (:signature attrs nil))
+                            (.set_parameterNames
+                             (if (:parameter-names attrs nil)
+                                 ;; There's an extra "closure "parameter in the
+                                 ;; generated method.
+                                 (into-array String (into ["closure"]
+                                                          (:parameter-names attrs nil)))
+                               nil)))
+                      (eval `(make-delegate ~typeargs ~args ~f))))))
 
 (defmacro defcmd2
     "Define a Minibuffer command and function. The docstring is required.

                (if (:typeresult h#)
                    (conj (:typeargs h#) (:typeresult h#))
                  (:typeargs h#))))
(defn register-command
  [cmd-name-or-attrs typeargs args f]
  (let [attrs (if (string? cmd-name-or-attrs)
                  {:name cmd-name-or-attrs}


;; This is just me trying to debug do-with-minibuffer
(defonce defer-count 0)
;; gen-delegate, generate-generic-delegate, sys-func, and sys-action taken from
;; core-clr.clj and reworked from macros to be functions.

(defn- my-gen-delegate
  [type f]
	(clojure.lang.GenDelegate/Create type f))


;; (clojure.string/join "," coll) will substitute for str-join, I think.
(defn- str-join    ;; clojure.string not yet loaded
  [coll]
  (loop [sb (StringBuilder. (str (first coll)))
        more (next coll)]
        (if more
            (recur (-> sb (.Append ",") (.Append (str (first more))))
                   (next more))
                   (str sb))))

(defn- my-generate-generic-delegate
  [typename typesyms f]
  (let [types (map (fn [tsym] (clojure.lang.CljCompiler.Ast.HostExpr/MaybeType tsym false)) typesyms)
        ftype (symbol (str typename "`" (count types) "[" (str-join types) "]"))]
       (my-gen-delegate ftype f)))

(defn- my-sys-func
  "Translates to a gen-delegate for a System.Func<,...> call"
  [typesyms f]
  (my-generate-generic-delegate "System.Func" typesyms f))

(defn- my-sys-action
  "Translates to a gen-delegate for a System.Action<,...> call"
  [typesyms f]
  (my-generate-generic-delegate "System.Action" typesyms f))

(defn do-with-minibuffer
  "Run (f Minibuffer/instance) when Minibuffer/instance is available.
