How to kill/cancel line input in IEx

Sometimes when poking around in IEx, I will mis-pair a bracket or quote and get “stuck”. This often happens if I mispaste something.

In irb I could always just ctrl-c to basically cancel the current input buffer and put me back in the “root” of the interpreter.

irb(main):002:1* arst(
irb(main):003:1*   nieo
irb(main):004:1>
^C
irb(main):002:0>

In IEx I get this

iex(1)> arst(
...(1)> nieo
...(1)>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution

And from my poking around, a/A quit IEx, c puts me back where I was, p,i,l,v,D,d,k are informational or for killing processes (maybe the current IEx is hidden in there).

Is there a way to just throw out all the current input (short of working out what pair is open and manually closing them all)? I want to retain the rest of my IEx state.

1 Like

#iex:break
Noted in documentation here: IEx — IEx v1.13.0-dev

4 Likes

I’ll admit that I’ve wondered this for months without bothering to look at the documentation. It’s a bit less convenient than a ctrl+c but maybe I’ll set up a keyboard macro (with Karabiner on Mac)

Another alternative (which is what I use) is pressing Ctrl-g i<RET>c<RET> (you can press Ctrl-g h<RET> to get an associated help menu). Sometimes I’ve also used Ctrl-] to close the currently open bracket, but that hasn’t actually come in handy too often for me when I get stuck.

There was a email thread on the Elixir Google group a while back about this, but if I recall correctly changes would have to be made to Erlang’s erl in order to change the Ctrl-c behavior.

3 Likes

Ah I did look at ctrl-g but didn’t put the interrupt-reconnect together.

There was a email thread on the Elixir Google group a while back about this, but if I recall correctly changes would have to be made to Erlang’s erl in order to change the Ctrl-c behavior.

It would be nice if there were a hotkey for it, doesn’t have to be ctrl-c. ctrl-d (“EOF/EOT”, exits the python interpreter IIRC) just rings my term bell, I don’t think it’s used for anything in IEx atm and is reasonably semantic.

I assume that could just be a patch to IEx to basically macro #iex:break?