Steve Frécinaux

Indenting with spaces

Indentation is like love: there are as many ways to do it than there are people doing it. Some people prefer spaces, while other ones prefer tabs. Some say that using only spaces is cleaner than using tabs, and the others argue that tabs allow everyone to chose his own indentation settings if it’s well done.

I don’t have any strong opinion about that. I usually follow the convention of the project I’m working on, or the recommended way of indenting of the language I’m using now. For instance, it means I usually use 8-spaces tabs for C, because that’s how we do that in Gnome. Anyway, despite PEP 8 recommands it, I was reluctant to use spaces to indent my python code. Well, mixing tabs and spaces is really problematic in python (since python relies on a consistant indentation and can’t know what tab size you’re using) but no matter, I carried on using tabs.

The reason is indeed quite silly: it’s annoying to remove four (or worse, eight) spaces when you want to unindent. I don’t know how other editors handle that, but with my beloved one, it was just too painful. Either you can hit backspace four times, or you can use the unindent plugin and hit Shift+Ctrl+T

But this time is over, since there are a few hot news related to… indentation, yeah, you got it right! First of all there is a patch against GtkSourceView (gedit’s text widget) from Paolo Borelli which allows the use of Ctrl+Tab and Shift+Ctrl+Tab to respectively indent and unindent selected blocks of code. It also work with the current line if nothing is selected.

Second, there is a brand new plug-in in the gedit-plugins module, which is intended to handle spaces in a smart way, when gedit is configured to insert spaces instead of tabs. Currently, “smart” just means the backspace key removes as many spaces as needed to come back to the last multiple of 4 (if you use a 4-space indentation). That’s it. Pretty simple but really handy. Well, it’s still some kind of a hack, but you’ll soon forget it completely… and that’s why it’s great :-).

This plugin is brand new, so don’t hesitate to give us feedback, be it random taughts, bugs or requests for enhancements. I’m also quite interested in how your favourite editor handles that case.

Note: jdub just introduced me into Planet Gnome, so hello everybody, I hope I won’t be to annoying, ta ta ta, bla bla bla, and so on :-). Also, don’t hesitate to point me language errors, English is not my mother tongue.