1

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 (csharp-mode) to do something similar?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.