Reloading an entire project in IEx

1,757 views
Skip to first unread message

James Norton

unread,
Jan 6, 2015, 10:13:59 PM1/6/15
to elixir-l...@googlegroups.com
Hello all,

I am working on an IEx package (using a lot of the code form the Term 2 plugin) for the Atom editor. The basic functionality is working now (starting IEx in a tab and interacting with it), but I want to add interaction from within other editor tabs/panes (executing code, reloading/restarting the project, running tests, etc.). I have been using the Clojure REPL in Sublime Text for some time now and I would really like to duplicate as much of that functionality as possible.

I have read this thread about executing mix commands in IEx and I can execute simple mix commands, but I am having trouble with more complicated interactions (no doubt due to my limited Elixir knowledge). I have read the Mix API documentation, but I could use some help. In particular, how can one reload and restart an application in IEx (via invoking mix commands or otherwise). I am okay if this involves adding custom code to mix.exs. The only real limitation I have is I would not want to have to restart IEx unless absolutely necessary.

I could use help with the other interactions (particularly running tests), but reloading is the main one. Ideally I would be able to provide a key binding (e.g., alt+cmd+R) that would reload the project in an open IEx session. Other interactions would have their own bindings, e.g., alt+cmd+X to run all the tests. 

Any help or advice would be greatly appreciate, and feel free to suggest any interactions that would be useful to Elixir developers. 

Thanks,

James

James Norton

unread,
Jan 10, 2015, 1:19:17 AM1/10/15
to elixir-l...@googlegroups.com
Should I assume from the lack of replies here that there is no way to reload a project in IEx short of restarting it?

Eduardo Gurgel

unread,
Jan 10, 2015, 2:45:51 AM1/10/15
to elixir-l...@googlegroups.com
This conversation may be somehow related to what you want: https://groups.google.com/d/msg/elixir-lang-core/80zxDVRawDA/8nNxnbg4KJAJ

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eduardo

José Valim

unread,
Jan 10, 2015, 8:29:55 AM1/10/15
to elixir-l...@googlegroups.com
Here is some code you can try out. Put this in a .iex.exs file inside your project root:

defmodule R do
  def reload! do
    Mix.Task.reenable "compile.elixir"
    Application.stop(Mix.Project.config[:app])
    Mix.Task.run "compile.elixir"
    Application.start(Mix.Project.config[:app], :permanent)
  end
end

Now you can do: R.reload!

Others are welcome to try it. We could even include it in iex helpers by default if it is working fine for multiple users (notice it won't reload your configuration though).




José Valim
Skype: jv.ptec
Founder and Lead Developer

James Norton

unread,
Jan 10, 2015, 12:17:19 PM1/10/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Works for me! Thanks so much to José and Eduardo.

Rob O'Dwyer

unread,
Apr 4, 2015, 7:30:18 PM4/4/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
This solution worked really well for me, but recently (possibly after upgrading to Elixir 1.0.3), it doesn't seem to reload the modules.

Has something changed in the operation of the Mix compile task? I'm able to use l(MyModule) to reload individual modules, but reloading the whole project would be great to have again.

Thanks,
Rob
Reply all
Reply to author
Forward
0 new messages