title: Smart Indent algorithm documentation?
body: <p>I'm a big fan of documenting the proper behavior of IDE features that have a subtle but significant impact on coding flow - things like <em>auto-completion selection</em> and <em>commenting/uncommenting code</em> you might not realize you take advantage of but at the end of the day you got just a bit more done than you might have. I do so in hopes that other language services I have to use incorporate the feature(s), subsequently improving my daily coding life. "Real" Smart Indent, i.e. the Visual Studio 2008 C# editor, is one of those features.</p>
  
  <p>Basic block code indentation is reasonably straightforward and can be hacked together in a reasonable amount of time well enough to get the job done. True Smart Indent, on the other hand, is quite possibly the most technically challenging task I've had to implement in the IDE to date, and I've implemented my fair share. Even full-blown on-the-fly automatic code reformatting is easier; it just defers to Smart Indent for the heavy lifting.</p>
  
  <p>I'm looking for high-level discussions of general purpose Smart Indent algorithms. <strong>In particular, I'm looking for either research on smart indent strategies, or an objective description of all normal and "edge" cases that could be tested to ensure repeatable, bug-free results.</strong> Eventually, I'd like to provide both a detailed workflow of the functionality, a concrete foundation for actually implementing the feature, and finally assembling a language-specific version from that and integrating it into my language services.</p>
  
  <p>PS: Visual Studio 2010's C# editor has several small bugs in this feature. Having implemented it myself, I have a whole new respect for the work it takes to polish it.</p>
  
  <p><strong>Edit (8/25):</strong> I managed to <a href="http://www.280z28.org/downloads/vsx/2009-08-25-SmartIndent.pdf" rel="noreferrer">write down a draft the rules</a> for how I think things should be handled when the smart indent is inside a code comment. I'll probably be working from a C++/C# perspective on the rules, but later they should be able to be parameterized for aspects of other languages.</p>