Here's a wrapper over (refresh) that updates the aliases in the user namespace
as well.  You can put it in the :repl-options in your project.clj.

:init (do
        (require '[clojure.tools.namespace.repl :refer [refresh]])
        (defn r []
          (refresh)
          ; https://github.com/clojure/tools.namespace#warnings-for-aliases
          (doseq [[sym target-ns] (ns-aliases 'user)]
            (ns-unalias 'user sym)
            ; (the-ns (ns-name ...)) gets the post-refresh namespace object
            (.addAlias (the-ns 'user) sym (the-ns (ns-name target-ns))))))


Ivan

On Sun, May 4, 2014 at 7:40 AM, Ivan Kozik <i...@ludios.org> wrote:
> Hi Petr,
>
> Did you see this?
> https://github.com/clojure/tools.namespace#warnings-for-aliases
>
> Also mentioned: "Aliases to reloaded namespaces will break if the
> namespace containing the alias is not reloaded also."
>
> I've been writing per-project wrappers over the refresh function to do
> the ns-unalias+alias calls.  I wonder if it would be feasible to have
> something that keeps track of just aliases in the user namespace, and
> do the re-aliasing after a refresh.
>
> Ivan
>
> On Sat, May 3, 2014 at 4:04 PM, Petr <petrg...@gmail.com> wrote:
>> Hello.
>>
>> I experienced non obvious behavior of "require namespace as alias" when
>> using clojure.tools.namespace.repl/refresh.
>> If I use aliased namespace then after changing source files and call to
>> refresh I seem to have old values in that alias. If I use plain require all
>> seem to work as expected, new definitions take effect after reload.
>>
>> For example, in first case:
>> (ns a (require [b :as b-alias]))
>> (println b-alias/x) ; original value
>> ; change sources of b or it's dependencies
>> (clojure.tools.namespace.repl/refresh)
>> (println b-alias/x) ; original value
>> ; and also
>> (println b/x) ; new value
>>
>> In second case:
>> (ns a (require [b]))
>> (println b/x) ; original value
>> ; change sources of b or it's dependencies
>> (clojure.tools.namespace.repl/refresh)
>> (println b/x) ; new value
>>
>> Can anyone explain why require acts like this? Does it mean that alias is
>> not just naming change but some data structure in memory?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to