Setting up Emacs for Python development
I've started tinkering with Emacs again! Some cool add-ons which have gotten me excited about Emacs again:
- Get the latest version of Emacs from this Ubuntu PPA.
- Ubuntu packages to install:
emacs24 autocutsel - Basic .emacs from Imperial
- Many (if not all) of the extensions below could be installed using Emacs24's package manager
M-x list-packages - color themes
- recently used files
- iSwitch buffers (switch buffers by typing any part of the buffer name)
- magit (better git support)
- Browse URL. I set
(setq browse-url-browser-function 'browse-url-firefox)and(global-set-key "\C-c\C-u" 'browse-url-at-point) - 80 column rule
- buffer move (easily move buffers around)
- FlySpell
- setup emacs python mode to use ipython
- el-get package manager (get the dev version) (might not need this on emacs24, given that emacs24 has a built-in package manager?)
- emacs-jedi (autocomplete, go-to-source etc)
- Emacs IPython Notebook (EIN)
- Collection of Emacs Development Environment Tools (CEDET). SpeedBar is especially cool. (CEDET is installed by default with ubuntu's emacs24 package, but you need to manually install CEDET to get the latest versions)
- flymake config for Python (i.e. enable on-the-fly checking of Python code)
- goto-last-change
- ropemacs - refactoring, go to definition etc.
Some commands
M-qreformat comment test. From SO.- emacs-jedi keybinds
- EIN keybinds (also see the screenshots for more examples)
C-zundo (orC-_)C-g C-_orC-g C-zredoC-c C-ubrowse URL- If you modify
.emacs, you don't need to restart Emacs for the changes to take effect. See this SO post. - reload changes recursively in IPython
- magit cheat sheet
- debugging Python in Emacs
C-<number>-x tabrigidly indent region byspaces. e.g. C-4-x taborC-minus-4-x tabC-x C-v RETreload file
Alternative editors
- spyder (scientific dev environment)
Update 2nd July 2012
I've gone back to using PyDev (an Eclipse plug-in) for my Python development. I do enjoy Emacs but PyDev is simply too pleasurable and powerful to ignore. Plus PyDev appears to be receiving increasing amounts of development effort, in contrast to some of the Emacs tools I experimented with. And Eclipse offers enough configuration options to mean that I can get Eclipse to feel pretty "Emacs-like". The notes below are only about two thirds complete but they might still be useful...
So, I've settled on using Python 2.7 for the development of my disaggregation system. I'm very happy with Python so far. The more I learn about Python, the more excited I get; which is the oposite to the situation I experienced with MATLAB: the more I learnt about MATLAB, the more repulsed I became.
So, the next question becomes: which IDE to develop in? I spent a few days using the Eclipse plugin PyDev but several things started to bug me; notably the fact that the interactive console doesn't respect the correct Eclipse keybindings. Plus Eclipse requires lots of messing about with the mouse which can slow you down a bit. So I started thinking seriously about using my old friend Emacs to develop Python in. Pedro produced an excellent blog post describing how to install a bunch of add-ons to Emacs to make it a powerful Python IDE. Unfortunately things have changed a bit since 2010 when that blog post was produced. Hence this blog post is a list of modifications to Pedro's blog post to bring it up to date. I certainly don't intend to replicate Pedro's excellent work; I'm just producing a "diff" to bring his blog post up to date. There's also some good notes on vanguard33's blog.
- Install iPython
- Install python-mode into
~/.emacs.d/as per the instructions in theREADMEandINSTALLfiles - Don't bother manually putting
(setq py-shell-name "ipython")into your~/.emacsfile. Instead, in emacs, typeM-x customize-variable py-shell-nameand change it toipython easy_install rope ropemacs. Modify.emacsto get ropemacs to work as described in the ropemacs readme. Install Pymacs (there's a bug in the install at the time of writing; to get the install to work follow the step described in the bug report fix install of Pymacs on Python 2.7 (issue #28)). You might also need to add(setq py-load-pymacs-p 'nil)to your.emacs- Magit is now hosted on github.
Useful resources
Tools I tinkered with but am not using
emacs-for-python looks like a quick and easy way to install lots of useful stuff. But I decided to install individual packages.
ipython.el: I'm not certain if ipython.el is required or not (the latest version can be found
in the ipython repository on
github).
There's lots of discussion about ipython.el
on
StackOverflow
and github. There's also
some discussion in the ipython editors.txt
file
(which I need to read). this recent comment by Andreas
Röhler
suggests that ipython.el should no longer be
necessary. My assumption for the time being is that ipython.el is not required.
Autocompletion
The anything project has been
superceded by the helm project.
You can get the files using something like
cd ~/.emacs.d; git clone git://github.com/emacs-helm/helm.git and then read the README.md file. There is also
a helm-ipython project.
HOWEVER, helm-python requires ipython.el (I submitted a bug
report); and I'm
fairly sure that ipython.el is now redundant.
auto-complete works pretty
well. I grabbed the latest auto-complete from
github. Before installing, it's
necessary to also grab popul-el and
fuzzy-el and put these two files in
the auto-complete directory prior to
installing. (It looks like the author has split fuzzy-el and popup-el
from auto-complete but hasn't updated the documentation yet.) I like
autocomplete to only offer help when I explicitly ask for help so I
added (ac-set-trigger-key "TAB") (setq ac-auto-start nil) to my .emacs
Add new comment