Bugzilla – Bug 325187
Bug in smart indent
Last modified: 2010-09-15 11:39:17 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".
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.
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.
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..
*** Bug 365454 has been marked as a duplicate of this bug. ***
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?
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.
*** Bug 405078 has been marked as a duplicate of this bug. ***
the new on the fly formatter is capable of formatting this correctly. closing.