Emacs and Python
Asked Answered
F

3

34

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

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.

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?

Relevant links:

Flatto answered 1/10, 2008 at 10:29 Comment(1)
I used Emacs for 2 years, but read and write Python in Emacs is still a nightmare for me. The complex configuration of rope, ropemace, pymacs... drives me crazy. So, personally, I recommend Eclipse + pydev.Southworth
S
21

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.

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.

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.

Successive answered 1/10, 2008 at 10:47 Comment(1)
As an GNU emacs 22 user (on windows). I second this. python-mode.el doesn't really buy you anything (although it does work). The only real reason to use python-mode.el might be to get ipython to work in emacs, however, this doesn't appear to work well in windows, unfortunately. On unix, YMMV....Hyozo
Z
8

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

Zeculon answered 1/10, 2008 at 17:52 Comment(3)
I use ropemacs (not the cutting-edge version though), it is rather easy to install and use according to instruction.Blackpool
I just tried ropemacs and I can agree with the other commentators :) rope + ropemode + ropemacs == awesome. A good blog entry about python development with emacs btw.: enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide still a good reference even if it is a bit datedLeekgreen
Ropeemacs links is deadTempestuous
L
7

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

Pyflakes also aids productivity.

Loam answered 31/12, 2010 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.