Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs and Python

Tags:

python

emacs

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:

  • EmacsEditor @ wiki.python.org
  • PythonMode @ emacswiki.org
like image 313
Alexander Kojevnikov Avatar asked Oct 01 '08 10:10

Alexander Kojevnikov


People also ask

Can I use Emacs for Python?

The built-in python-mode allows you to use Emacs for Python code debugging with pdb .

Can Emacs run code?

Emacs can run compilers for noninteractive languages such as C and Fortran as inferior processes, feeding the error log into an Emacs buffer. It can also parse the error messages and show you the source lines where compilation errors occurred.


2 Answers

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.

like image 74
Thomas Wouters Avatar answered Sep 28 '22 18:09

Thomas Wouters


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.

like image 28
James Sulak Avatar answered Sep 28 '22 16:09

James Sulak