Search Unity

Monodevelop annoying auto indentation

Discussion in 'External Tools' started by Andrey-Postelzhuk, Nov 26, 2013.

  1. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    70
    I've started working with MD 4.0.1

    Indentation became a big problem for me. When a just press ENTER and move to the new line MD adds one more tab to the beginning of the line. So after every ENTER pressing I need to press BACKSPACE.

    I changed indentation mode from Smart to Automatic at [Tools -> Text Editor -> Behavior -> Indentation mode]. This solved problem with ENTER.

    But Monodevelop still more "smart" than me! When I paste in any position in the line MD adds one more tab to the beginning of the line. So after evert Ctrl+V pressing I need to press Ctrl+Z.
    ----------
    Does anyone else have this problem?
     
    darkhog, Miscellaneous and balaam like this.
  2. mdeletrain

    mdeletrain

    Joined:
    Jun 8, 2011
    Posts:
    46
    Yes, and this is making me crazy !
    I tried modifying policies to force indentation to act as I wish, but the indent-on-paste behavior seems to be impossible to override...
    And no matter what indentation style I set (none, auto or smart (auto is dumb and smart is auto+smart :confused:)) :sad: !

    Anybody here with a solution for this ?
     
    Miscellaneous and balaam like this.
  3. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,034
    Bump. Same for me :-(
     
  4. pneill

    pneill

    Joined:
    Jan 21, 2007
    Posts:
    207
    Oh thank havens, I'm not the only person that noticed this. Yes, if anyone has a work around would be great.

    Has anyone submitted this to the issue tracker?
     
    Miscellaneous likes this.
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,412
    ahaa!

    for me it happens when namespace block was not indented,
    so auto-intend was actually correctly trying to add the extra tab..
     
  6. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    295
    I've noticed it as well, what works for me is typing escape before hitting enter. Pain in the neck
     
  7. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    122

    that doesn't seem to work for me. i love the new autocomplete and the method structure outline look, and zooming text is great for my older eyes but i wish improvements like this didn't have to come at the expense of extra unwanted indenting. frustrating...it does two tab spaces to the right when i hit Enter on any line. BTW on a Mac ML10.8, Unity 4.2.1 but using the new MonoDevelop.
     
  8. leonardozimbres

    leonardozimbres

    Joined:
    Jul 9, 2012
    Posts:
    29
    So I'm not exactly noob, there's something wrong with the tool?
     
  9. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    232
    Same problem here! Using Unity 4.3.1 on windows 8.1. Auto indentation is out of order! :)
    Can anyone confirm if it's fixed in Unity 4.3.2? This is embarrassing really. Indentation worked much better on previous versions of MonoDevelop and now it's broken. :(
     
  10. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    232
    Ok I seemed to have found a fix (that at least worked for me) for the wacky indentation problem.
    First thing that I did was to start Unity in Administrator mode (talking about Windows 8.1). Don't know why but this seems to make Unity and MonoDevelop behave better overall.
    Then...
    The following steps apply for the windows version of Unity built-in MonoDevelop:
    1) Start MonoDevelop and go to Tools -> Options
    2) In the left side menus scroll down to the "Code Formatting" menu and click it
    3) In the right side options you will see a row with: "C# source code" and on the "Policy" column you should see "Custom". Click on that "Custom" field and select "Microsoft Visual Studio" from the drop-down menu.

    After this indentation and auto-completion seems to be golden in Unity 4.3.1 MonoDevelop (on Windows 8.1).

    Hope this helps anyone.
     
  11. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,034
    Still no luck here. I've tried your solution, but within namespace block the problem still preserves.
     
  12. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    232
    But does it fix indentation issues for all other scenarios without using namespaces? Or nothing changed for you with the suggested fix.
     
  13. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,034
    My specific problem may be described in that way:
    I'm used to not to indent namespace block, because nearly all of my code lies within namespace blocks and this is a waste of space imo. So my code looks like this:

    Code (csharp):
    1. namespace Something {
    2.  
    3. class Anything {
    4.     public Anything() {} // normal indent rules here
    5. }
    6.  
    7. } // namespace
    MonoDevelop 4.0.1 problem is that it ignores custom indent rules for namespaces (I don't know about other blocks), and when pasting anything inside namespace block (no matter where, it may be inside if, while, method, etc) it always will add one extra indent.

    I cloned Unity MonoDevelop branch the other day and I wanted to find out where's the code responsible for this behavior, but still I didn't have the time to do so.
     
  14. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    232
    Oh now I understand! :) Don't know about custom indentation rules.
    It adds the extra indent because he applies normal indentation and because of the existence of the namespace bracket "{" he will add one
    extra indent for everything else.
    Give us a buzz back on this thread if you do manage to find a way to customize this.
     
  15. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,493
    This is EXACTLY my situation. Let us know if you find a fix!
     
  16. BinaryOrange

    BinaryOrange

    Joined:
    Jul 27, 2012
    Posts:
    136
    Kind of related/unrelated, but on Mac, does anybody else have problems with MonoDevelop slowing to a crawl after about half an hour of coding, so you have to save, close the program, and then restart it to get it back up to speed?


    Feels like a memory leak is occurring somewhere in it. And yes, the auto-indentation is driving me NUTS!
     
  17. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    352
    Yes! I've seen that... also the problem where when you open a file via Unity, sometimes MonoDevelop will demand to reload the entire program.
     
  18. BinaryOrange

    BinaryOrange

    Joined:
    Jul 27, 2012
    Posts:
    136
    It's a shame the current version has so many issues, I actually quite like MonoDevelop as an IDE.

    At the moment though, does anybody have any replacement IDE's? Just curious, I'm probably still going to use MD, but if there is an alternative, I'd be glad to hear it!
     
  19. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,034
    Just for the record: I've found that in the CSharpTextEditorIndetiation file in HandleTextPaste() method there is a line that looks like this:

    Code (csharp):
    1. string newIndent = stateTracker.Engine.ThisLineIndent;
    This particular line is used in one more place: when Smart indent is turned on. This simply means that pasting code triggers similar behavior to using Smart indent (which is behaving wrong).

    StateTracker is using CSharpIndentEngine and it counts blocks to determine the indent depth, but it has no reference to formatting rules (so it ignores namespace indent rule). I may be wrong, but it looks like somebody changed how indentation should work in the new MonoDevelop, and there's now 2 ways for doing the same thing.

    Now I will try to build MonoDevelop on Windows, but it may take several days because of lack of time.
     
  20. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    295
    is there a way to revert to the older version of monodevelop and use the current Unity?
     
  21. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    70
    Oh, gods! I'm not alone! I checked thread for the first week. But than I lost any hope.

    I'll try to do this tomorrow.

    Now I work on Mac and I didn't find any alternative.

    genail, It's very nobly from your side to research sources. It should help MD developers to fix bug.
     
  22. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    70
  23. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,034
    You shouldn't report this bug to MonoDevelop developers. Unity has it's own MonoDevelop branch and most probably the newest MonoDevelop has this issue fixed.
    Normally you have to fill a form using Unity: Help -> Report a Bug. I will do it including link to this thread.

    P.S. There's one thing worth trying. To install official newest MonoDevelop and try to run Unity MD plugin with it.
     
  24. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,493
    On Mac I use TextWrangler. On Windows, I use Notepad++

    Just take note that in Unity 4.3 (I think?) onwards you can now supply the command line parameters to your IDE. See http://docs.unity3d.com/Documentation/Manual/Preferences.html
     
  25. BinaryOrange

    BinaryOrange

    Joined:
    Jul 27, 2012
    Posts:
    136
    I looked at TextWrangler but there's no C# support. :(

    Unity really need to get their version of MD back to running well! It's seriously hindering my ability to code.
     
  26. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,493
    For syntax coloring? Pretty sure I found some way for that.

    As for code completion/Intellisense stuff, I don't use that so TextWrangler is enough for me.

    I suppose you can just install an older version of Unity that has the MonoDevelop that you like using, then use that one.
     
  27. BinaryOrange

    BinaryOrange

    Joined:
    Jul 27, 2012
    Posts:
    136
    No, I couldn't even get it to recognize the .cs extension - the file was just greyed out completely and I couldn't even click it.

    Is there a plugin I could install to get it to load .cs files?

    Worst comes to worst, I can just rewrite stuff in JS/UnityScript, sort of was thinking about doing that anyway since there's so many more tutorials for that than C#.
     
  28. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,493
    Weird. Might be a setting in your file associations. I can't remember how all that works; it's been a while since I last used a Mac...

    In any case TextWrangler can open any text-based file, and a .cs is certainly that. So there *should* be a way...

    You can also try dragging the .cs file from Finder to the TextWrangler window.
     
  29. BinaryOrange

    BinaryOrange

    Joined:
    Jul 27, 2012
    Posts:
    136
    Oh jeez, I figured out why it wasn't working.

    I had it set to only open "All TextWrangler Documents", so I changed it to "Everything", and now C# files load just fine!

    Thank you for telling me about TextWrangler, it's the perfect replacement to MonoDevelop. It's so fast and stable! :D
     
  30. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    486
    The auto-indenting when you *paste part of a line* is utterly infuriating...

    On the subject of copy+paste, it would be nice if block-copying (alt-dragged selections) behaved a bit more predictably. The only thing predictable about it at the moment it it will make a great big mess...
     
  31. agstanescu

    agstanescu

    Joined:
    Jan 31, 2013
    Posts:
    13
    I should say that this setting applies only to new solutions/projects. If you already have a project that behaves weird, then go to Project->Solution settings and set this policy too.
    This fixed it for me
     
    angrypenguin likes this.
  32. SasugaShogun

    SasugaShogun

    Joined:
    Jul 18, 2013
    Posts:
    9
    It is driving me crazy! In some of my projects I'm able to fix it by going to the project settings, in other's Monodevelop doesn't seem to care what I tell it to do it just simply adds 8 spaces or a double-tab before every line. It's extra annoying for me that when I hit enter, it only does a single tab, so the lines look all funny. However, when I save, it adds a double-tab. If I backspace the lines, it just adds the double-tabs back in.

    I created a policy in one of my projects where I was actually able to get it to behave the way I wanted it to, then exported that policy, and then in other projects told it to use that policy. In some of the projects it works, in others it doesn't, and I can't figure out the rhyme or reason why.

    Monodevelop is driving me fricken crazy now, ever since Unity 4.3.

    I've uninstalled Unity and reinstalled it with the old Monodevelop, then updated Unity and told it to not use the new Monodevelop. However, the last patch I forgot to tell it not to install the new Monodevelop and after realizing my mistake I thought I'd try it out and see if the problem has been fixed. It hasn't, and it feels more annoying then ever.

    Why is it behaving this way? Why can't it be fixed? Why are we all asking about this, but not seeing any official responses on what's causing it or how to fix it? I'm not finding any anyway. I've found people saying they've fixed it by doing something (usually going to project->solution options->etc.->etc.), but the problem is that it seems like a temporary fix, if it fixes it at all!

    I am getting sick and tired of fighting with my tools.
     
  33. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,383
    I "solved" this by giving up and strictly following MonoDevelop's indentation rules, i.e. have the classes within the namespaces indented so that MD doesn't mess up my code.

    If you'd like to try my Si2 I'd be glad to send you a copy for evaluation :)

    "alt-dragged selections"? Is that on OS X? Because I've tried all the shift keys combinations on Windows and nothing seems to work :confused:

    Well, bugs in MD get fixed sometimes, but also new bugs appear at nearly the same rate. ;)

    And we can't expect Unity people to be fixing MD bugs since that's a third party software. Unity people have enough of their own bugs to work on, I guess...
     
  34. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    891
    In the past I've been told by them that they have taken ownership of the bugs in their branch, and intend to fix them. WHEN they intend to fix them hasn't been discussed :D
     
  35. BahamutGundam

    BahamutGundam

    Joined:
    Nov 4, 2012
    Posts:
    38
    I decided to revert to using the old Monodevelop. In addition to the latest Unity, I have to have an installation of Unity 4.2 which has the old Monodevelop though.

    After that, go to Preferences -> External Tools, and change the editor there.
     
    frankrs likes this.
  36. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    351
    the auto formatting make me want to pull my hair out
     
  37. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    295
    I just bit the bullet and learned c# so I could write in visual studio
     
  38. monkeyThunk

    monkeyThunk

    Joined:
    Oct 6, 2011
    Posts:
    13
    Project -> Solution -> Code Formatting - set tab and indent width to 4

    Preferences -> Code Formatting - set tab and indent width to 4
     
    TheFreeze likes this.
  39. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,383
    Is that really going to help? It is already set to 4 and autoindent doesn't work as expected. The problem is in the number of tabs MonoDevelop inserts or removes for autoindent, not in tabs size.
     
    TheFreeze and Darwinfx like this.
  40. Darwinfx

    Darwinfx

    Joined:
    Oct 15, 2014
    Posts:
    1
    This is exactly what I´m looking for, thanks.
     
  41. unitynetworkguy

    unitynetworkguy

    Joined:
    Nov 27, 2014
    Posts:
    1
    This worked for me. Thanks for posting
     
  42. chai

    chai

    Joined:
    Jun 3, 2009
    Posts:
    82
    @floky thanks ! worked great but had to do it from from Project -> solution options -> sourcecode instead.

    I find even if you click edit and customize formatting and it changes to "custom", it still works fine.
    Probably something bugged with the formatting out of the box in mono

    Edit: I think I've found the culprit, in the code formatting, if I change ident width from 8 to 4 it seems to fix the funkiness, have no idea why but that seems to be it.
    Now just need to find a way to turn off auto white space formatting in parenthesis ...
     
    Last edited: Nov 29, 2014
  43. jakisa

    jakisa

    Joined:
    Dec 10, 2012
    Posts:
    1
    I want to COMPLETELY turn off any kind of auto-formatting in MonoDevelop. I am by far smarter than any IDE when it comes to choice of what my code should look like.
     
  44. TheMave

    TheMave

    Joined:
    Jan 9, 2015
    Posts:
    7
    Solution

    A Solution for me (Using Win 8.1, Unity 4.5.5.f and MonoDevelop 4.0.1):
    Copy-Paste content of .cs file to notepad. Then: Copy-paste it back to monodevelop and save.

    Background:
    I did like @floky, but unchecked "convert tabs to spaces", because I like to keep tabs.
    Still, both problems seemed to be there: Extra Tab on return + extra Tab on Copy-Paste.
    Then, I realized I recently had updated all my files using a VIM-script, to convert the spaces into tabs again - and I used to do the column editing in FlashDevelop.

    It looks like one of these actions has made a "hidden" change to the file that disrupts MonoDevelop.
    Copying to Notepad and back again appears to fix it.
    (extra tab on return only if line does not end with ; now)
     
  45. ReynV

    ReynV

    Joined:
    Sep 24, 2014
    Posts:
    33
    Hi.
    Due to driver issue in bootcamp I'm forced to use monodevelop in osx.

    It is truly a terrible experience. I'm building a fluent api, monodevelop just completely destroys the indent structure no matter what its settings are. Visual studio 2013 community edition worked beautifully.

    I believe most of the users of unity are using monodevelop and won't be able to use my api because of it.

    Is there any way to completely turn off code formatting ?
     
  46. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    933
    Hey! Does anybody know if there is a way to disable indents only inside classes? I like to write inside classes without indents and it's a pain to adjust that all the time when I paste some code.

    EDIT:
    Alright, at least it seems like it should work because I found a setting that might do this exactly:

    Preferences -> Source Code -> Code Formatting -> C# source code -> C# Format -> Edit -> within classes (set to off)

    But it won't work. Within classes, there are still indentations for everything.
     
    Last edited: Sep 6, 2015
  47. kapyar

    kapyar

    Joined:
    Dec 13, 2014
    Posts:
    6
    Hey, I finally found a solution go to Preferences->Text Editor->Behavior->Format document on save - turn off:)
     
    GMT and Shushustorm like this.
  48. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    933
    This is a good hint! Thanks! Unfortunately, if you do this, you have to save each time to format and at least for me, the braces get all messed up:
    Code (CSharp):
    1. void Before () {
    2.     // stuff
    3. }
    4.  
    5. void After ()
    6. {
    7.     // stuff
    8. }
     
    kapyar likes this.
  49. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,219
    Bumping this topic, because it's now 2015, MD was changed again to 5.9 and this issue still isn't resolved. It should be added either by UT or MD team, I don't really care, an option that basically tells MD "shut up, I'll format my code whatever I want and don't you dare touch it when I'm pasting it or doing other stuff". Because this behaviour is scandalous (to use an euphemism).
     
    TheWarper likes this.
  50. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    352
    With the endless complaints regarding this bottom barrel IDE, and Unity continuing to integrate and support it, I can only imagine they have some sort of in perpetuity deal with its makers. Unity has been generally pretty good listening to its users on everything except for this one singular topic - which unfortunately is a rather major one.

    I think the best thing we can all do is just abandon MonoDevelop. Bury it alive where it belongs and switch en masse to Visual Studio / Visual Studio Code. Or really any IDE that is an improvement over MD (like TextEdit).

    Maybe showing Unity we all refuse to use this POS will open their eyes....