- Home /
Indentation formatting issue in MonoDevelop-Unity 4.0.1 (Win7)
Hi all,
I'm having an issue with MonoDevelop that came with Unity 4.3.2f1 on Windows 7 where the conditional and iterative blocks I write get "corrected" with excessive indentation and badly-aligned closing braces, like so:
I've tried looking into the C# formatting options, but couldn't tweak or find anything that would solve this issue. Google search turned up nothing either. Anyone able to help?
Thanks!
This looks like ins$$anonymous$$d of excessive indenting, you're missing a tab before all your statements.
If you put the opening braces on a new line by pressing enter, do they align with the closing braces?
Having opened a block in the beginning of the code can cause this (a namespace, being in a nested class...). Opening braces ("{") add an intentation level to anything after them in $$anonymous$$onoDevelop, by default.
I tried doing that as well (opening brace on new line), but upon applying the closing brace, the thing auto-formats and pulls the opening brace to the same line as the block opener and formats its contents the same way.
if you're inside a namespace or some such block of code, the editor will add a level of indentation. In fact, it will add a level of indentation for any opening brace.
If you're bothered by the added indentation, you need to edit the indentation policy for C# files, as described below, to not indent for whatever block of code causes you trouble.
Have the same problem. Same version and I do also use windows 7, but it only happens to one of my computers. The settings are the same, quite annoying. Hope I will find a fix soon.
I have the same problem... It is very annoying and I hope it'll get fixed ASAP.
Answer by Berzeger · Mar 14, 2014 at 07:16 PM
This was driving me nuts! But I found a fix -- in MonoDevelop go to Tools -> Options -> Text Editor -> Behavior and switch Indentation Mode from Smart to Automatic. Not so smart after all, huh? Kudos to BoNaNa from Unity forums who solved it.
Answer by RowedRage0 · Jan 14, 2014 at 07:00 PM
First let me say I had a lot of trouble with this. I find the Policy setup very confusing in MonoDevelop. I had a similar issue but found in the end that I was formatting my document based on the wrong policy. I'll try to explain why it wasn't working, but that might not be the issue here.
Essentially, there are Personal Preference formatting options, Solution formatting options, and Project formatting options. Project options can inherit from the Solution options. I think it uses Personal formatting options as defaults when you create a project, but I'm not sure. When I had issues with formatting, it was because I had Project specific formatting stomping on the Solution's options.
To set Solution formatting, go to Project -> Solution Options -> Source Code / Formatting. There you can set the format for each filetype to a standard policy or one that you've imported. To set Project formatting, make sure you have your project loaded and then go to Project -> Options -> Source code / Formatting. Same deal with setting the policies here, it's just that it applies to the Solution. You can also set the policy to Inherited to get the settings from the Solution.
After you've adjusted the options, Formatting the document should apply those to the code.
Hope that's helpful, even if it's not the answer you were looking for.
Note: I think Project -> "Apply Policy" adjusts the options for the Project only. I'm probably not going to touch that feature in the future.
The policy I have seems to look good, but trying to apply it just causes the same indentation issues. This basically happened upon installation, so no configuration was done before I saw this problem :(
Hmm sorry it wasn't helpful. The weird bracket indentation seems strange, and suggests it's not a formatting thing at all, since no scheme I've seen would do it like that.
If you go to view the formatting options for your code does it show up in the preview window the same way it shows up here? And also, I assumed the code shown is the result after formatting but is that true? If you "fix" it and then format it does it go back to what is shown here?
Answer by Transigence · Oct 20, 2014 at 11:39 AM
MonoDevelop 4.0.12 on Ubuntu 14.04 I found this issue as well and put a video of it up here: http://youtu.be/kyjBUsQU3rs
Your answer
![](https://koobas.hobune.stream/wayback/20220613125834im_/https://answers.unity.com/themes/thub/images/avi.jpg)