Programming Python in Emacs - 2015

Emacs is an excellent programming environment for Python. I've selected a handful of packages here that together give a very neat coding experience. There are many alternatives for just about every package on display here, but these are my current favourites when coding Python.

Auto completion, syntax checking and method help

In just this wee picture you see several great Emacs features at play: auto completion by anaconda-mode and autocomplete-mode, on the fly syntax checking using pyflakes and flymake, as well as intelligent method help in the minibuffer thanks to eldoc and anaconda-mode:

python in emacs

Auto completion with documentation lookup

If you just hold on for a bit longer, Emacs will also give you the full documentation of the method which you are about to complete:

python in emacs

Documentation lookup

anaconda-mode will also look up any documentation for you on any symbol when you hit M-?:

python doc lookup in emacs

Code navigation

anaconda-mode hooks into Emacs' standard tagging feature, which means you use the standard shortcut M-. for jumping to the definition of the symbol under your cursor and M-* for jumping back to where you were. It's really, really fast and let's you drill down or up your call stacks with amazing speed.

Show usage of symbol at point

Hitting M-r will show you all the usages in your project of the symbol at point:

python usage in emacs

Embedded Python shell

Naturally, Emacs gives you a Pythons hell inside Emacs so that you easily can try out code before adding it to your own source code. Just type M-x python-shell-switch-to-shell and the Python interpreter opens up in a new buffer:

python shell in emacs


And that concludes my wee tour through some of Emacs' Python features. Happy coding!

Useful links

Licensed under CC BY Creative Commons License ~ ✉ torstein.k.johansen @ gmail ~ 🐘 ~ 🐦 @torsteinkrause