Saturday, March 10, 2007

Indenting case contents

On Friday, I decided to start implementing some customizable settings for my Smart Indent feature in MonoDevelop. I started off easy by adding the ability to choose how you'd like to indent (or not) your goto labels:



When I had first implemented Smart Indent, I did a lot of mimicking of Emacs because that was my choice in editors. Having programmed in (nay, lived in) Emacs for going on a decade, I did with goto labels what Emacs did (in C), which is to say that I put them in column 2 (one space over from fully left-justified).

However, when I was rewriting my original implementation in C# using Emacs csharp-mode, I decided that when editing C# code, I much preferred the way csharp-mode unindented the goto label by only a single level. At first I was simply going to change the behavior but I had remembered that Visual Studio 2005 had an option for this, so I decided to implement the 3 options it had instead, defaulting, of course, to the same style as csharp-mode.

Today I implemented something a little more useful, a config option for case label indentation. While I was looking at Visual Studio's C# Formatting options, I discovered they had a "Indent case contents" option, so I figured I'd have a go at implementing that as well. After getting it to mostly work, I decided to test how exactly the option was handled in some situations in Visual Studio. Turns out, the option is completely ignored - no matter what the toggle state of the option was, it always indented case contents exactly the same. After discovering this, thinking it was a rather absurd option anyway, I decided to just drop it.

2 comments:

David Makovsky said...

Hi Jeff,
I'm away from my emial so hopefully it's not lost here :}
Firstly I appreciate you work on formatting code, that is personaly with debugger and codefolding a feature I'm addicted to :}
One tip for you, have you looked into NRefactory? There is PrettyPrinter functionality which is really similar to what you are doing right now. This one is quite connected to parser tree and allows formating of whole document. And that is what I would like to have :} Basically I love the VS2005 formating features and advanced settnings. What I'm missing there are profiles for kind of formatting style. Eg for my work I use our defined, MD has different style and there are lot of others. Switching to such profile would save you a lot of time when hacking on such code or re-formatting one from other codebase.
What do you think about such functionality? (would be better to contact me over mail if you want to discuss it: yakeen AT sannyas-on.net)
Thanks for reading and coding for MD :}

Jeffrey Stedfast said...

No, I have not yet looked into NRefactory - I will have to check it out.

As far as "profiles" for indent/code formatting, someone else has suggested a similar type feature. What they suggested was that they be able to set formatting rules on a per-project basis (as well as, presumably, having a global preference which new projects would inherit?)

I think that would be a cool feature to have, as you have noted - sometimes different projects have different formatting rules and it'd be nice to auto-magically have MD change style based on the project.

Code Snippet Licensing

All code posted to this blog is licensed under the MIT/X11 license unless otherwise stated in the post itself.