Iex -S mix: alias r() to recompile()

Inside an “iex -S mix” session, is it possible to alias “r()” to “recompile()” ?

If in iex you do h alias you will see that you can only alias a module, and you want to do it for a function.

As a side note they are two distinct functions as you can see by doing in iex h r and h recompile.

1 Like

Interesting, I did not even realize, until now, that r/1 existed. How difficult is it to define a new r/0 ? Can this be achieved without recompiling mix, or is there no other way to do this?

You will want to try this:

While we are at it, you may want to take a look to:

https://itnext.io/a-collection-of-tips-for-elixirs-interactive-shell-iex-bff5e177405b

2 Likes

In your $HOME/.iex.exs write:

defmodule Hauleth.IExHelpers do
  defdelegate r(), to: IEx.Helpers, as: :recompile
  defdelegate r!(), to: IEx.Helpers, as: :recompile!
end

import Hauleth.IExHelpers
4 Likes

According to the post I linked this will not work, it will throw:

But if you compile it first and then import it in $HOME/.iex.exs it will work fine :slight_smile:

I like your module simplicity.

1 Like

@hauleth , @Exadra37 : Thanks for pointing out the right pieces.

For anyone else finding this via search, here is the full solution:

cat dev/iex/y.elixir 
defmodule Y.IExHelpers do
  defdelegate r(), to: IEx.Helpers, as: :recompile
end
cat .iex.exs 
IEx.configure colors: [ eval_result: [:cyan, :bright ]]
import Y.IExHelpers

iex -pa ~/dev/iex -S mix

2 Likes