Proposal: analogue of node's .editor for iex

47 views
Skip to first unread message

amitt...@agtinternational.com

unread,
Sep 23, 2018, 10:23:51 AM9/23/18
to elixir-lang-core
Hi all,

I've recently stumbled across the .editor feature in Node.js' REPL. It sets the REPL in to editor mode, which allows for easily inputting (or pasting) multi-line code into the REPL. 
With iex, one of its shortcoming is its treatment of the pipe operator. If I want to paste code such as

value
|> fun1()
|> fun2()

into iex I must first rewrite it into

value |> fun1() |> fun2()

As the former is usually the preferred style of writing piped expressions, this means that whenever I want to try out code from a project that contains any such expression I must first manually reformat it. With a functionality such as the .editor mode this could be elegantly avoided.

With the help of a macro this might be easily added, for example, as part of IEx.Helpers. If we had a macro `e` defined as

defmacro e(do: block) do
  quote
do unquote(block) end
end

then `e` would become an editor mode like call in iex. For example, I could now write

iex> e do
...> 1..5
...> |> Enum.map(fn x -> x + 1 end)
...> end
[2,3,4,5,6]

allowing me to easily paste more complex expressions including pipes in new lines into iex.

Looking forward for feedback and comments.

Regards
Arno




Wojtek Mach

unread,
Sep 23, 2018, 10:31:27 AM9/23/18
to elixir-l...@googlegroups.com
We can achieve the same thing today with wrapping pipeline in `(...)`:

iex(1)> (
...(1)> 1..5
...(1)> |> Enum.map(fn x -> x + 1 end)
...(1)> )
[2, 3, 4, 5, 6]


--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6611b3ce-0cbd-4e40-b212-a880e7a0f8ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Wojtek Mach

amitt...@agtinternational.com

unread,
Sep 23, 2018, 10:58:24 AM9/23/18
to elixir-lang-core
That is even better. Thanks for the tip. 

What about adding a section "Pasting into iex" to https://hexdocs.pm/iex/IEx.html?

Steve Morin

unread,
Sep 23, 2018, 11:23:28 AM9/23/18
to elixir-l...@googlegroups.com
Think that would be a good idea

José Valim

unread,
Sep 23, 2018, 11:27:22 AM9/23/18
to elixir-l...@googlegroups.com
Yes, please do send a pull request!
--


José Valim
Skype: jv.ptec
Founder and Director of R&D

amitt...@agtinternational.com

unread,
Sep 23, 2018, 11:29:37 AM9/23/18
to elixir-lang-core
will do.

amitt...@agtinternational.com

unread,
Sep 23, 2018, 12:42:23 PM9/23/18
to elixir-lang-core
I've added a draft for the documentation: Link to pull request.
Reply all
Reply to author
Forward
0 new messages