Introducing Template Fields

The next Programmer’s Notepad testing release (2.1.2) adds support for Template Fields. This is the first new feature in a series of improvements to Code Templates/Text Clips which I’ll talk about more in a future post.

Template Fields are the first part of the work necessary to support TextMate Snippet-style features. The best way to show you what’s supported so far is with a quick screencast:

Here are the standard snippet features that are not supported (yet):

  • Regular Expression Modifiers
  • Environment Variables / Contextual values, e.g. Current File Name
  • Inclusion of output from external tools / scripts

These will all be delivered in future releases. I’ve included some sample clips for PHP with the 2.1.2 distribution, but due to a bug with the way new clips are detected you’ll need to delete your InstallClipCache.xml file to force an update – this will be fixed for the next release. You can find the InstallClipCache.xml file in your User Settings directory (e.g. c:\users\myuser\AppData\Roaming\Echo Software\PN2).

Adding new clips is easy, just go to Code Templates in the Options dialog and add templates to the relevant scheme. You insert template fields with this notation:

$(1:Text User Will Replace)

The number is used to link different fields together, the first instance of each one is the “master” field for that number. The number 0 is special and will cause the cursor to be positioned there at the end of clip insertion, e.g.:

while ($(1:Condition))
{
    $(0)
}

Clips you add yourself in options will be available straight away in the editor, just type the shortcut (or part of it) and press Ctrl-Alt-Space. In the future pressing Tab will expand templates where the name is matched.

I hope you enjoy trying out this new feature, a lot of work went into making it!

2 comments

  1. Great editor! Great improvement. I love this editor.