[MonoDevelop] Who ate my code templates ?

Michael Hutchinson m.j.hutchinson at gmail.com
Mon Mar 23 12:39:58 EDT 2009


First up, let me say that this feature is really cool. Thanks for
implementing it so quickly!

On Mon, Mar 23, 2009 at 1:42 AM, Mike Krüger <mkrueger at novell.com> wrote:
<snip>
> Context sensitive templates
>
> Note that templates can be context sensitive, therefore not all
> templates are available anywhere.

Is it possible for extensions to add template contexts?

> Automatically defined fields
>
> Automatically defined fields are fields that are not defined by the user
> instead the template fills the contents of the field using a pre-defined
> method. For example the constructor template "ctor" expands to:
>
> $TypeName$ ()
> {
> $end$
> }
>
> And the $TypeName$ is inserted automatically. The auto fields are used
> too for fully qualified type names. Fully qualified type names can be
> shortened with a function depending on the usings that are available at
> the template insertion point. (remember the old 'scwl' template that
> always expanded to 'System.Console.WriteLine' ? The new 'cw' (OMG it's
> 50% shorter !!!) template only expands to 'System.Console.WriteLine' if
> there is no 'using System' in that file)

BTW, VS templates have a feature where templates can add references
and imports. I'm not sure which is the best approach -- automatic
import insertion or automatic namespace shortening.

<snip>
> Templates can be extended using the template editor available through
> the settings dialog or adding them manually. Open the template editor
> and closing it generates a template folder in the
>
> ~/.config/MonoDevelop/templates/code
>
> Directory. All user defined templates are stored here. The template
> format is very straightforward. For example the mn template looks like:

Is it possible to add templates in an extension?
<snip>
>
> What needs to be done ?
>
> The template system is very new therefore I except that there are bugs
> here and there.

It seems pretty usable so far! I've only run into a couple of issues
-- the undo stack seems to get confused by templates, and it's not
possible to use "enter" to end the template when a completion dropdown
is present. Maybe including the end position in the tabbable regions
would help for this, and typing there would end the template.

> The functions that are available through the extension object need to be
> extended. I think we should let drive this by the requests of the
> template writers.

This would also be useful to be able to implement in extensions.

> More contexts for the templates. Currently there are only expressions
> and 'normal' contexts.
> Sub 'mime types': Currently the set of templates are the same for the
> whole file based on the mime types. But some files have a different
> 'language' depending on the position. For example inside 'doc' comments
> could be a context for XML files. I think these sub contexts could be
> very useful for embedded ASP.NET code.

Definitely! This is something we also need to consider in the context
of file parsing, code completion, syntax highlighting and style
policies, since none of these really work for "mixed" pages yet.
ASP.NET is only going to get harder --as well as inline C# or VB,
sometime we're going to need to support JS & CSS too.

> The 'Surround With' list needs an input field to filter the templates.

That would be useful, yes.

Also in this area, SlickEdit has a really cool way to handle
surround-with templates when the user doesn't have a selection:
http://www.slickedit.com/content/view/353/217/#surroundwith
Maybe we could have something a bit like this -- allow the user to tab
to the "surround with region" then use arrow keys to capture/uncapture
lines.

> Maybe the template/surround with pop ups need a category tree too.

That would be nice. Probably not an issues until people start writing
hundreds of templates though :)

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list