Bug 325187 (MONO82520) - Bug in smart indent
Summary: Bug in smart indent
Status: RESOLVED FIXED
: 365454 405078 (view as bug list)
Alias: MONO82520
Product: MonoDevelop
Classification: Mono
Component: texteditor (show other bugs)
Version: SVN
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mike Krueger
QA Contact: MD Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-21 20:48 UTC by Alan McGovern
Modified: 2010-09-15 11:39 UTC (History)
3 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:49:36 UTC


---- Reported by alan.mcgovern@gmail.com 2007-08-21 13:48:27 MST ----

Write the construct below and the 'else' statement indents incorrectly.

foreach(int i in myints)
    if(i == 6)
        Console.WriteLine("Yeah");
else
    Console.WriteLine("Bad indent");



---- Additional Comments From fejj@novell.com 2007-09-14 13:34:04 MST ----

this is gonna be hard to fix I think... :(

the problem is that the ';' after the 'then' clause will pop the stack
all the way back up to the "foreach" indent level, and so we lose all
previous stack-state by the time the "else" is written.


Unknown operating system unknown. Setting to default OS "Other".

Comment 1 Tim Sarbin 2008-04-11 19:09:10 UTC
I would like to add something to this.

In visual studio, when you put a ";" at the end of a valid line of code, it auto-indents that line properly. Also, when you close a {} section by typing "}", it auto-indents properly for the entire code block. I use said features all of the time and it greatly increases productivity.

Something else that may be just a difference between mono and ms .net is that when doing property members, getter/setter {}s are on a seperate line, so if I type:

public string MyProperty
{
   get {

}
and then on the line after the get, type }, it places the { after the get onto the next line. MonoDevelop doesn't seem to go by any standard as it seems to not care how you format the code at all.
Comment 2 Michael Hutchinson 2008-04-11 20:45:07 UTC
MonoDevelop has a stack-based indenter, not a formatter, so we tend only to modify indentation whitespace to avoid messing up your preferred coding style.

We'd like to add a configurable C# autoformatter at some point, but it won't be easy.

FYI, the tab key can be used to auto-indent the current line.
Comment 3 Tim Sarbin 2008-04-11 21:16:35 UTC
That reminds me, the tab key to auto-indent really messes me up since I use the tab character for indentions generally. This constantly prevents me from formatting my lines properly. My work around is to select the whole line and tab/shift-tab to get it to the right place..
Comment 4 Michael Hutchinson 2008-05-19 15:13:50 UTC
*** Bug 365454 has been marked as a duplicate of this bug. ***
Comment 5 Lluis Sanchez 2008-11-17 20:01:52 UTC
So, can this be fixed with the indenter we have or not? is it feasible to fix it for 2.0 or does it require major changes?
Comment 6 Michael Hutchinson 2008-11-17 21:42:23 UTC
I'm not too familiar with parser internals, but if jeff says it's hard, it probably is.

I'll take a look when I'm adding indenter style options.
Comment 7 Mike Krueger 2010-02-23 12:23:19 UTC
*** Bug 405078 has been marked as a duplicate of this bug. ***
Comment 8 Mike Krueger 2010-09-15 11:39:17 UTC
the new on the fly formatter is capable of formatting this correctly.

closing.