Emacs 和 Python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/157018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 19:34:17  来源:igfitidea点击:

Emacs and Python

pythonemacs

提问by Alexander Kojevnikov

I recently started learning Emacs. I went through the tutorial, read some introductory articles, so far so good.

我最近开始学习Emacs。我浏览了教程,阅读了一些介绍性文章,到目前为止一切顺利。

Now I want to use it for Python development. From what I understand, there are two separate Python modes for Emacs: python-mode.el, which is part of the Python project; and python.el, which is part of Emacs 22.

现在我想用它来进行 Python 开发。据我了解,Emacs 有两种独立的 Python 模式:python-mode.el,它是 Python 项目的一部分;和 python.el,它是 Emacs 22 的一部分。

I read all information I could find but most of it seems fairly outdated and I'm still confused.

我阅读了我能找到的所有信息,但其中大部分似乎已经过时,我仍然感到困惑。

The questions:

问题:

  1. What is their difference?
  2. Which mode should I install and use?
  3. Are there other Emacs add-ons that are essential for Python development?
  1. 它们的区别是什么?
  2. 我应该安装和使用哪种模式?
  3. 是否还有其他对 Python 开发必不可少的 Emacs 附加组件?

Relevant links:

相关链接:

采纳答案by Thomas Wouters

If you are using GNU Emacs 21 or before, or XEmacs, use python-mode.el. The GNU Emacs 22 python.el won't work on them. On GNU Emacs 22, python.el does work, and ties in better with GNU Emacs's own symbol parsing and completion, ElDoc, etc. I use XEmacs myself, so I don't use it, and I have heard people complain that it didn't work very nicely in the past, but there are updates available that fix some of the issues (for instance, on the emacswiki page you link), and you would hope some were integrated upstream by now. If I were the GNU Emacs kind, I would use python.el until I found specific reasons not to.

如果您使用的是 GNU Emacs 21 或更早版本,或者 XEmacs,请使用 python-mode.el。GNU Emacs 22 python.el 对它们不起作用。在 GNU Emacs 22 上,python.el 确实有效,并且与 GNU Emacs 自己的符号解析和完成、ElDoc 等更好地结合。我自己使用 XEmacs,所以我不使用它,我听说有人抱怨它没有过去工作得不是很好,但是有可用的更新来解决一些问题(例如,在您链接的 emacswiki 页面上),您希望现在已经集成到上游。如果我是 GNU Emacs 类型的人,我会使用 python.el,直到我找到不使用的具体原因。

The python-mode.el's single biggest problem as far as I've seen is that it doesn't quite understand triple-quoted strings. It treats them as single-quoted, meaning that a single quote inside a triple-quoted string will throw off the syntax highlighting: it'll think the string has ended there. You may also need to change your auto-mode-alist to turn on python-mode for .py files; I don't remember if that's still the case but my init.el has been setting auto-mode-alist for many years now.

就我所见,python-mode.el 的一个最大问题是它不太理解三引号字符串。它将它们视为单引号,这意味着三引号字符串中的单引号将导致语法突出显示:它会认为字符串已在那里结束。您可能还需要更改自动模式列表以打开 .py 文件的 python 模式;我不记得情况是否仍然如此,但我的 init.el 多年来一直在设置 auto-mode-alist。

As for other addons, nothing I would consider 'essential'. XEmacs's func-menu is sometimes useful, it gives you a little function/class browser menu for the current file. I don't remember if GNU Emacs has anything similar. I have a rst-mode for reStructuredText editing, as that's used in some projects. Tying into whatever VC you use, if any, may be useful to you, but there is builtin support for most and easily downloaded .el files for the others.

至于其他插件,我认为没有什么是“必不可少的”。XEmacs 的 func-menu 有时很有用,它为您提供当前文件的一些功能/类浏览器菜单。我不记得 GNU Emacs 是否有类似的东西。我有一个用于 reStructuredText 编辑的 rst 模式,因为它在某些项目中使用。绑定到您使用的任何 VC(如果有)可能对您有用,但是对于大多数和易于下载的其他 .el 文件都有内置支持。

回答by James Sulak

This sitehas a description of how to get Python code completion in Emacs. Ropemacsis a way to get Rope to work in emacs. I haven't had extensive experience with either, but they're worth looking into.

该站点描述了如何在 Emacs 中完成 Python 代码。 Ropemacs是一种让 Rope 在 emacs 中工作的方法。我对这两者都没有丰富的经验,但它们值得研究。

回答by seb

Given the number of times I have several open buffers all called __init__.py, I consider the uniquifylibrary essential for python development.

鉴于我有几个打开的缓冲区都被调用的次数__init__.py,我认为uniquify库对于 python 开发至关重要。

Pyflakes also aids productivity.

Pyflakes 还有助于提高生产力。