Feature request : autoindent

2 replies [Last post]
Offline
Last seen: 27 weeks 4 days ago
Joined: 12/27/2010
Posts:

Great site.

I couldn't search the forum, so do not know whether other people have already made this request.

It would be nice to have a button which automatically indents the code.

Thanks

magius96's picture
Offline
Last seen: 14 weeks 1 day ago
Joined: 04/13/2009
Posts:
Autoindent

I doubt this would need to be a button. Actually I think it should work as your typing the code, though this scheme would be a bit difficult to implement.

The simplest solution to do this would be to automatically move the cursor the same number of spaces as used in the previous line. If you do it this way, then her button suggestion would work great to indent all the code based on opening and closing brackets. Her request would be much harder to implement, as not only would you have to look for opening and closing brackets, but you'd have to look for specific keywords and detect if they've been terminated on the same line.

For instance:

For(int a=0;a < 100;a++) Console.Write("Hello");

This would not cause the next line to indent because the for block is terminated, however these would:

For(int a=0;a < 100;a++)
Console.Write("Hello");

and:

For(int a=0;a < 100;a++){
Console.Write("Hello");
}

Do you see the problem here? It's quite frankly a coding nightmare. Not saying it can't be done, but it would be rather difficult. If you were to attack this suggestion, I'd advise simply starting with bracket based indention, then add support for keywords, one keyword at a time. Then after all the keywords have been added, add code to check for keyword termination.

You'll obviously need to use a Stack to track what indents have been opened, this way you can add one to the stack when an indent is added, and remove one from the stack when an indent is removed.

----------------------------------------------------------------------------------------------------
"Coding your life, Compiling your dreams, and crashing your future."
Compilr - C# and VB.NET Advisor

tim.speed's picture
Offline
Last seen: 17 hours 25 min ago
Joined: 02/24/2010
Posts:
We will probably implement

We will probably implement this in the future as it's quite a common feature in IDEs

-----------------
Tim Speed
Compilr Developer and CTO