如何取消多行命令?

当我使用 IEx 并输入一个类似于附加括号或“的错误时,大多数情况下我会得到一个语法错误。但也有类似的案例:

iex(3)> Enum.each '12345', &(IO.puts(&1"))
...(3)> end
...(3)> )
...(3)> '
...(3)> end
...(3)> ""
...(3)> ... ? How to produce syntax error ?
...(3)>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution

我不能犯语法错误,从头开始继续,我必须重新启动整个 IEx。 是否有任何快捷键或命令可以跳过执行当前 iex (3)而转到下一个 iex (4) ?

11642 次浏览

Start your line with #iex:break

iex(1)> Enum.each '12345', &(IO.puts(&1"))
...(1)> ...
...(1)> #iex:break


** (TokenMissingError) iex:1: incomplete expression

In general, you can also press Ctrl + G, which will drop you into to the "User switch command" mode with a ---> prompt. From here, you can type i to interrupt your IEx session, then c to reconnect to it; IEx will then state ** (EXIT) interrupted and return to the state it was in immediately before you got stuck. This is a feature of Erlang's shell (erl) that was inherited by IEx.

Example of this in action:

iex(3)> Enum.each '12345', &(IO.puts(&1"))
...(3)> end
...(3)> )
...(3)> '
...(3)> end
...(3)> ""
...(3)>        <-- Ctrl-G goes here (not shown normally)
User switch command
--> i
--> c
** (EXIT) interrupted
iex(3)>

My quick and dirty solution is to produce a syntax error with by spamming """"""""" (which will be interpreted as heredoc).

In your example:

iex(3)> Enum.each '12345', &(IO.puts(&1"))
...(3)> end
...(3)> '
...(3)> end
...(3)> ""
...(3)> """"""""""""""""""""
** (SyntaxError) iex:8: heredoc allows only zero or more whitespace characters followed by a new line after """