tags:

views:

40

answers:

2

In Visual Studio, editing a C# file, when I type in three slashes in succession, it auto-generates a template for XML code documentation.

Can I get emacs to do something similar?

+1  A: 

Have you looked at yasnippet? It's a pretty extensible template system, with an easy to understand syntax. You could have three /// bound to the template you want.

Trey Jackson
Hey Trey, yes I have looked at yasnippet and actually use it for code template injection: for loops, foreach loops, while loops, etc. But, I didn't think to use it for comment injection, because I was thinking that the doc template I want is context-dependent. In other words, I don't always want the same thing. But now that you've mentioned yasnippet, it's possible to write snippets that run elisp code, to determine what snip to inject. This may be a good approach. Thanks for the hint.
Cheeso
+1  A: 

I took a shot at implementing some logic to automatically insert XML comments in csharp-mode. I've published it to the EmacsWiki as csharp-mode v0.7.2 I could have done this with yasnippet or some other template package, but I didn't want to tie csharp-mode to a specific template package.

The behavior is that, if you type three slashes (///), then you get a template for a summary comment;

  /// <summary>
  ///   (point)
  /// </summary>

If you then type three slashes after THAT, then you get a remarks section:

  /// <summary>
  ///   Lorem ipsum....
  /// </summary>
  /// <remarks>
  ///   <para>
  ///     (point)
  ///   </para>
  /// </remarks>

That behavior sort of mimics what you get in Visual Studio 2008, when you type 3 slashes. Try it out.

Cheeso