【问题标题】:IEx - How to cancel multiline command?IEx - 如何取消多行命令?
【发布时间】:2015-02-19 21:17:15
【问题描述】:

当我使用 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)?

【问题讨论】:

  • 这个问题的解决方案很烦人,我希望他们在BREAK 菜单中包含一个选项来取消当前的多行命令,或者让第一个 ctrl-c 取消它...

标签: elixir


【解决方案1】:

#iex:break开始您的线路

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

** (TokenMissingError) iex:1: incomplete expression

【讨论】:

【解决方案2】:

通常,您也可以按 Ctrl + G,这将使您进入带有---> 提示符的“用户切换命令”模式。从这里,您可以输入i 中断您的IEx 会话,然后输入c 重新连接它;然后 IEx 将声明 ** (EXIT) interrupted 并返回到您卡住之前的状态。这是 IEx 继承的 Erlang 的 shell (erl) 的一个特性。

实际操作示例:

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)> 

【讨论】:

    【解决方案3】:

    我快速而肮脏的解决方案是通过发送垃圾邮件""""""""" (将被解释为heredoc)产生语法错误。

    在你的例子中:

    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 """
    

    【讨论】:

    • #iex:break 对我不起作用,所以这是一个很好的解决方案:+1
    猜你喜欢
    • 2017-06-04
    • 2019-03-26
    • 2016-11-07
    • 2010-12-15
    • 1970-01-01
    • 2010-12-30
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多