technomancy / nrepl-discover

proof-of-concept middleware for auto-discovery of nrepl ops
36 stars 7 forks source link

Op names should be more specific #4

Open coventry opened 10 years ago

coventry commented 10 years ago

If nrepl-discover gets popular, it's going to end up with colliding op names. Including the ns containing the var and "nrepl-discover" in the name might be a good idea.

coventry commented 10 years ago

The main problem with my suggestion above is that it will result in unfriendly function names on the elisp side. Maybe nrepl.discover/ops ought to throw an exception or tell emacs to when there is name collision, though. Or maybe nrepl-discover should instead/as well, because there is also the risk of overwriting existing nrepl.el functions.

If we wanted to include namespaces in the names, I guess it would look something more like this (untested code.)

(defn ops []
  (into {"nrepl.discover/discover" #'discover}
        (for [n (all-ns)
              ;; Namespace symbols aren't necessarily translatable on
              ;; the emacs side.  E.g., (ns ?foo)
              :let [ns-str (->> n ns-name str
                                (replace Compiler/CHAR_MAP)
                                (apply str))]              
              [_ v] (ns-publics n)
              :when (:nrepl/op (meta v))]
          [(str ns-str (:name (:nrepl/op (meta v))))) v])))```