[Qt-creator] Indentation and tab/space nightmare
Andre Poenitz
andre.poenitz at mathematik.tu-chemnitz.de
Mon Jan 5 20:18:34 CET 2009
On Fri, Dec 19, 2008 at 12:51:48PM -0600, Adam M wrote:
> Hello,
>
> A lot of current editors get indentation completely wrong. So, how
> should indentation work? I expect indentation to be,
>
> 1. flexible - user can change how much each indent is (this implies tab)
> 2. multi-line stuff aligns properly - this implies spaces
>
> To have the best of two worlds, tabs *and* spaces must be used.
"must" is a bit strong. There are lots of coding styles around,
some require one, some the other, some mixed. I would not call
either of these "wrong".
> The way that most editors get it wrong is by magically changing
> spaces/tabs around to "help the user". And that is *wrong*.
>
> As an example, here's a line of code,
>
> for( int i=0; i<blah; i++ )
> test( test1(), test2(), test3(),
> test1() + test2() + test3());
>
> So, what's the dillio? You'd notice that ALL indentation here are tabs
> but the alignment for the second line is spaces. So, the 2nd line of the
> test(...) function call is
>
> <tab><tab><space><space>....<space>
>
> This addresses the problem where someone likes 3-space-tab and someone
> else lines 8-space-tab or 4-space-tab.
It's certainly a reasonable style to use, but equally certainly not
the only reasonable style there.
Rest assured that some people working on Qt Creator also work on
projects using this particular style, so it is not unreasonable to
assume that Qt Creator will support it "properly" at some time,
one way or the other...
> How is Qt Creator wrong with this? It will automagically substitute
> space => tabs where it sees fit. Attached are two files. One as entered
> into Qt Creator and one as saved by Qt Creator.
>
> Now, an editor that has almost 100% correct usage of tab/spaces is gEdit
> - the GNOME editor. It seems to do the correct thing by copying the
> previous line's indentation to the next line.
And there are people that do not like auto-indentation at all etc etc.
It's just too many options to support for a flegdling project in its
first release...
> To make it more flexible to what Qt Creator tried to do, and that is
> auto-indent the beginning of line and close indentation at the right
> time, do the following,
>
> 1. copy last line's indentation over to new line
> 2. are we removing indentation? If yes, remove a <tab> from the front
> of the line
> 3. are we adding indentation? If yes, add a <tab> in from of the line
>
> Note: substitute space in tabs if someone selects spaces.
>
> Additional feature may be to remove the spaces, if any, when a block is
> closed. Just reset user indentation when a block is closed.
>
>
> A complementary and great option would be for the editor to draw the
> tabs on the line that is being edited like so,
>
> -->| -->|blah blah blah
>
> where the -->| would be some sort of unobtrusive light color, like light
> red or maybe even selectable color. When line is not edited, no need to
> have the tabs shown.
You can visual all whitespace already using Ctrl-E,Ctrl-V.
> PS. Most have given up with the "IDEs doing indentation" and opt for
> "use spaces instead of tab" hack.
*shrug* It's a proper solution in my eyes, too. One out of many...
Andre'
More information about the Qt-creator-old
mailing list