【问题标题】:ipython emacs IndentationErroripython emacs 缩进错误
【发布时间】:2012-06-06 19:08:36
【问题描述】:

在 emacs 中 ipython 提示符中真的很烦人的问题:

In [128]: if 1==1:
   .....:     print "yes"
   .....: else:    
   .....:     print "no"
   .....:     
IndentationError: unindent does not match any outer indentation level

它看起来与我完全一致,不确定是什么触发了错误。当我在终端中执行此操作时没有这样的问题。

【问题讨论】:

  • 我也有同样的问题。并且它发生在调用 ipython 后的 emacs 中的任何 shell(例如 eshell)中,不仅在 python-mode.el 或 ipython.el 提供的 ipython shell(M-x ipython)中。

标签: emacs ipython


【解决方案1】:

你可以尝试用

切换自动缩进

%autoindent

因为我认为这曾经给我造成了问题。

您可以使用ipython's customization 永久更改此设置。正确导入后(请参阅链接),以下内容应在 ipy_user_conf.py 中起作用:

# Emacs sets the term to dumb so we can distinguish that way
if os.environ['TERM'] == 'dumb':
    ip.options.autoindent = 0

【讨论】:

  • 这样就解决了问题!有什么办法可以保存这条指令,避免每次重新启动 ipython 模式时都必须输入它?
  • 我添加了一条关于使其永久化的说明。当 ipython 启动时,可能只有一种 emacs 方法可以调用 %autoindent,但这似乎不太可靠,因为 %autoindent 总是切换 AFAICT。
【解决方案2】:

是的,这很奇怪。就我而言,在评估代码时,在 emacs shell 中使用标准的 python 解释器可以正常工作,但使用 ipython 会失败。如果您使用python-mode.el 包,您可能需要安装ipython.el 以获得正确的ipython 支持。 OTOH,如果您使用通常随 emacs 提供的python.el,您可能必须切换到标准的python 解释器(我相信ipython.el 仅适用于第三方python-mode.el 包,不是 emacs 默认使用的python.el)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    相关资源
    最近更新 更多