如何在emacs python模式下取消解释器命令



如果我在python解释器中输入错误的命令,有时我只看到...。例如,如果我输入help(random.unif并按enter键,则无法输入新命令。我必须退出emacs,重新启动python和解释器。有办法纠正吗?

正如Pavel Anossov所解释的,你想给Python发送一个CTRL-C来中断它。

但是在emacs中,默认情况下,CTRL-C是一个前缀键。

幸运的是,在大多数交互shell模式中,包括python模式和替代模式,在一行中按两次CTRL-C会向解释器发送一个CTRL-C。或者,更专业地说,CTRL-CCTRL-Ccomint-interrupt-subjob绑定。(当然,您也可以以其他方式运行它——如果您确实需要的话,甚至可以使用META-X comint-interrupt-subjob。)结果如下所示:

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help(f
...   ^C ^C
KeyboardInterrupt
>>> 

另一种选择是使用quoted-insert命令,通常绑定到CTRL-Q,然后按CTRL-C。但是,由于这不会中断通常的行输入,因此通常必须在它后面加上换行符。结果如下所示:

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help(f
... ^C
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> 

通常CTRL-C有效。不确定emacs嵌入式解释器。或者,只需向解释器提供它正在等待的任何内容(在您的示例中,是))。

最新更新