Emacs Python IDE Recipe

My initial goal was to set up Emacs, in the simplest way possible, as a Python development environment that offers basic code browsing and code completion.

This might not be the brightest way to get the job done, and I am open to suggestions, but for now this works just fine for me.




OSes and SW versions

The steps described below were tested successfully on Mac OS X 10.6.8 and Ubuntu GNU Linux 12.04 64 bit with GNU Emacs 23.1.1 and cedet-1.0pre7ecb-2.40 and auto-complete-1.3.1.

Code Browsing

This section is programming/scripting language independent (works with Python, Tcl, Lisp and C, at the least).

ECB, needs CEDET >= 1.0pre7.

(If you are using an Emacs release newer that 23.2, CEDET is already included. Check the Emacs Wiki on “How to enable the CEDET tools which were merged with Emacs”.
Haven’t tried it since I decided to use Emacs 23.1.)

Download cedet1.0pre7 and follow the steps in the INSTALL readme or the ones in the online simple setup guide.

CEDET is a very powerful development environment tool collection, but here, it is only used as a requirement for ECB. This means that we only need to add one line to our .emacs file:

(load-file “~/cedet-1.0pre7/common/cedet.el”)

Once CEDET is installed, download ecb-2.40 and follow the detailed installation steps provided here.
Documentation can be found here.

Here is the code browsing section of my .emacs:

;;code browsing
(load-file “~/cedet-1.0pre7/common/cedet.el”)
(add-to-list ‘load-path “~/ecb-snap”)
(require ‘ecb)
(setq stack-trace-on-error nil) ;;don’t popup Backtrace window
(setq ecb-tip-of-the-day nil)
(setq ecb-auto-activate t)
(setq ecb-layout-name “left6”)
(setq ecb-options-version “2.40”)
(setq ecb-primary-secondary-mouse-buttons (quote mouse-1–mouse-2))
(setq ecb-source-path (quote (“~/”)))

Restart Emacs after modifying the init file, and this is what it should look like:

Emacs after modifying the init file

Some default key bindings:

  • C-c . r  – refresh the methods buffer
  • C-c . g m  – go to methods window
  • C-c . g 1  – go to edit buffer

For more info and configuration options check the ECB menu entry or the docs.

Code Completion

Auto Complete Mode

Download auto-complete-1.3.1 and install it following the steps here.
(I installed it by running the install.py script from Emacs.)

Set up as below, Auto Complete generates completion candidates based on a dictionary and on words entered by the user in the present session (in the form of code or comments).

Check the manual for more info.


“It is a plugin for Auto Complete (in Emacs) which provides a quick, simple completion source for available python symbols.”
Check this link for setup and usage.


The code completion section of my .emacs:

;;code completion
(add-to-list ‘load-path “~/.emacs.d/”)
(require ‘auto-complete-config)
(add-to-list ‘ac-dictionary-directories “/Users/bogdan/.emacs.d/ac-dict”)
(require ‘ac-python)

the code completion section of my .emacs

To Do

  • Python quick help (displays docstring popup for the highlighted option while navigating the completion popup – by default auto-complete (?) does something similar for Lisp).
  • Key binding for docstring display (e.g. C-c d Display doc string – see “init_python.el” and “How to use” sections here).
  • Syntax checking on the fly (look here for ideas and configuring example).
  • Have a look here for more ideas (semantic, yasnippet, etc.).
  • Revision control integration.

Subscribe to our newsletter

And get our best articles in your inbox

 Back to top

Leave a Reply

Your email address will not be published. Required fields are marked *