python-mode gone wrong

November 16, 2012 | categories: Python, Emacs, Programming | View Comments

tl;dr

If you recently upgraded Emacs' python-mode to version 6.0 or higher, and it feels wrong (indentation seems broken, the menu is confusing), downgrade to version 5. In Debian or Ubuntu you can do it like so:

sudo aptitude install python-central pymacs
wget http://launchpadlibrarian.net/22053597/python-mode_5.1.0-1_all.deb
sudo dpkg -i python-mode_5.1.0-1_all.deb

Broken hearts

Something terrible happened. My beloved python-mode for Emacs has been infested with featuritis, and it doesn't look like it's coming back.

Yesterday I upgraded to Xubuntu 12.10 for my work laptop. That was after it turned out that I'm not manly enough to install Debian Wheezy proper. (What the f--k is wrong with your WLAN support, Debian!!)

With Xubuntu and a few tweaks you can luckily ignore all the less fortunate decisions that Ubuntu has made recently. No Unity means no Dash means no broken privacy out of the box.

Synaptic and GDebi are quickly installed to replace the ad-ridden and sluggish Ubuntu Software Center. And packages rock again and are fast. Also, I've come to really like Xfce; but I digress...

So far so good. Then I installed Emacs and python-mode and started editing my first Python file. Which was when I fell into a deep shock. A few things felt just plain wrong. In fact so wrong that I was sure I had the wrong mode active (namely the other python.el, which ships with Emacs). For hours and hours I searched for a way to disable Emacs' own Python mode and enable the "good one", tried some hacks, but it wouldn't work. Because, really I was using the right mode all the time, but python-mode had changed so much I couldn't recognize it anymore.

Firstly, the menu entries are completely different. Instead of the two entries "IM-Python", and "Python" (which I hardly ever used), there's now five different menus called "PyShell", "PyEdit", "PyExec", "PyTools" and "Outline", each with a shitload of entries inside, with mostly either trivial things, or stuff I have no idea what they're good for.

Take an example: The newer python-mode added skeletons. So that now instead of writing a for statement, you can now call up a macro that will ask you what to put into the name and expression parts of the statement, and then it'll write it. Yes, friends, imagine that instead of writing for foo in baz:, you can now call up this insanely useful macro and it will ask you to enter foo and then you hit enter and then it asks for baz, enter, and then it will write the line for foo in baz:.

What the f--k?

Surely, you could say I can ignore all of this seemingly useless functionality. After all, it might be useful to someone (it's NOT!!). But it still leaves a very bad taste in my mouth. I feel alarmed that my beloved python-mode seems to have taken a step into a very bad direction. And I wonder if with all these added features, is it going to be as well-maintained? Is it going to make similar decisions in the future, ones that will affect me more? (This is software that I rely on for my daily work.)

And it looks like my fears are already confirmed. It turns out python-mode gets indentation wrong, arguably the most fundamental feature of any Python editing mode, or has anyway changed the way it works. As an example, if you hit enter where the X is below, it will indent four characters:

class Bar:
    def foo(self):
        pass

Xclass Baz:

So that you'll end up with:

class Bar:
    def foo(self):
        pass

    class Baz:

(Where what you really wanted is put a blank line between them, or maybe add a new method to Bar.)

So what I did after I realized what was going on was to downgrade to python-mode 5.1, and finally my blood pressure went back to normal.

I'd be interested to hear other people's experiences with python-mode 6, I wonder if I'm alone.

Screenshots

Here's the two versions with their respective menus.

python-mode version 5

Simple is better than complex

python-mode version 5

python-mode version 6

F--k simple, let's do a million features because we can

python-mode version 6