How to make a character from a namespace available in all namespaces without qualifier?
I have a namespace with debug utilities that are only used in development. I would like to make them available in all unqualified namespaces (same as characters from clojure.core
).
Let's say my project structure looks like this:
dbg_utils.clj:
(ns project.dbg-utils)
(defmacro dbg ...)
db.clj
(ns project.db)
(defn create-entity [...]
...)
After I want to run the REPL and print something like this:
> (require 'project.db)
> (require 'project.dbg-utils)
> (globalize-symbol 'project.dbg-utils/dbg)
And after using a macro dbg
without a qualifier:
(ns project.db) ;; no require of project.dbg-utils
(defn create-entity [...]
(dbg ...) ;; and no qualifier here
...)
Is there something like globalize-symbol
(or near this) available?
source to share
Leiningen provides a function :injections
and profile for this :user
.
This article has some pointers on how to do this. This basically works by adding the debugging functionality you want to use clojure.core
, and since all public vars from that namespace are always included when using the macro ns
(unless you specify otherwise), you will have them available in all namespaces.
source to share