Smart indentation for python in gedit

July 10, 2008 – 9:18 pm

A few days ago I developed a plugin for gedit that provides smart indentation for python code.

The code is indented when the previous line ends with ‘:’ and un-indented if the previous line starts with ‘return’, ‘pass’, ‘continue’ or ‘break’. This plugin will use your tab configuration for indentation. To respect PEP8 you should set tab width to 4 and choose to insert spaces instead of tabs.

You can download it on the gedit plugins page or with this direct link.

To install it you should in the folder ~/.gnome2/gedit/plugins/ (or create it if it doesn’t exist) and uncompress the tgz here. Then in gedit:

Edit > Preferences > Plugins > Python Indentation

That’s it.

It seems like gedit is starting to get some cool plugins for code edition. For exemple snipplets that allow the quick insertion of complicated code templates as well as moving between various “fields” in this template with tab.

And someone even provided a plugin for python code completion ! Even if there is still some work to do on this plugin this is a great start.

Anyway gedit is starting to get good for editing python. Maybe one day I won’t have to use eclipse at work anymore. I wish. Eclipse has really lots of functionnalities but it’s too big and heavy, and if it breaks (your project files getting corrupted for example) you’re dead, you had everything in it. I prefer serveral programs to one big. And I’m not much into vi or emacs either … that’s why gedit is my favorite for code editing. If I used KDE it would probably be kwrite which seems nice enough too.

Post a Comment