【问题标题】:Why does Emacs Jedi always insert “elif” after I type “else:”?为什么 Emacs Jedi 在我输入“else:”后总是插入“elif”?
【发布时间】:2014-06-26 08:55:52
【问题描述】:

我在 Emacs 中安装了“Jedi”模式,但我发现每次我创建一个新行然后键入 e l时它都会自动插入单词 elif > s e : Enter 因为冒号字符显然启动了 Jedi 的完成逻辑,建议使用 elif 作为最佳建议,我按 Enter 显然选择了它。因此,每次我尝试输入 else 子句时,我总是必须在无关的 elif 上退格,然后再继续。

这个问题是我独有的吗?我通过密切关注文档来激活 Jedi:

(添加钩子'python-mode-hook'绝地:设置) (setq jedi:complete-on-dot t) (setq jedi:get-in-function-call-delay 200) (setq jedi:tooltip-method nil)

你可以在 GitHub 上找到我的整个 .emacs.d/init.el 受版本控制:

https://github.com/brandon-rhodes/dot-emacs

我系统上的 Jedi 及其相关工具的当前版本是:

(:emacs-version "24.3.1" :jedi-version "0.2.0alpha2") ((:version "3.4.0 |Continuum Analytics, Inc.| (default, Mar 17 2014, 16:13:08) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]" :file nil :名称“系统”) (:版本“0.8.0-final0”:文件“/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/jedi/__init__.py”:名称“绝地”) (:版本“0.0.5”:文件“/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/epc/__init__.py”:名称“epc”) (:版本“0.0.3”:文件“/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/sexpdata.py”:名称“sexpdata”))

我注意到 : 字符绑定到 Emacs 函数 python-indent-electric-colon 但我不确定如何确定该函数是否以某种方式无意义地触发 Jedi 的完成逻辑。

【问题讨论】:

  • 而且,如果我在屏幕上出现else:elif 结构后继续输入,它不会被追溯修复、更正或删除。我的 Python 中间只有 else:elif 行。
  • 是否有更新版本的 Emacs 可用于您的平台?我的 Emacs 附带的 python.el 似乎不包含 python-indent-electric-colon 函数。我可以找到它in the python.el GitHub repository,但是最新的版本已经有一年了。 GNU Emacs 源代码does not seem to include that function anymore。 (我也无法在我的 Emacs 上重现您的问题。)
  • 函数 python-indent-electric-colon 在 Ubuntu 14.04 上定义在文件 /usr/share/emacs/24.3/lisp/progmodes/python.el.gz 中,该文件属于 emacs24-el 包,现在它似乎是 Emacs 编辑 Python 的默认模式。
  • 之前我没有想到,但我使用的不是emacs 包(24.3.1 版),而是emacs-snapshot 包(24.3.50.1 版)。 emacs-snapshot 没有定义该函数。尽管即使我安装并运行 emacs 版本,我也没有看到您描述的行为......

标签: python emacs emacs-jedi


【解决方案1】:

我认为这是 python 模式的错误:tab-always-indent 值为 true,但行为与之前相同。

https://www.gnu.org/software/emacs/manual/html_node/emacs/Indent-Convenience.html

我的解决方案:

(add-hook 'python-mode-hook
    (lambda ()
        (setq-local electric-indent-chars (remq ?: electric-indent-chars))
    )
)

【讨论】:

    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 2020-01-24
    相关资源
    最近更新 更多