Emacs 和 Python [英] Emacs and Python

查看:28
本文介绍了Emacs 和 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习 Emacs.我浏览了教程,阅读了一些介绍性文章,到目前为止还不错.

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

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

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.

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

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

问题:

  1. 它们有什么区别?
  2. 我应该安装和使用哪种模式?
  3. 是否还有其他对 Python 开发必不可少的 Emacs 附加组件?

相关链接:

  • EmacsEditor @ wiki.python.org
  • PythonMode @ emacswiki.org

推荐答案

如果您使用的是 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,直到我找到不使用的具体原因.

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.

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

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.

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

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.

这篇关于Emacs 和 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆