About QuickCodes

A QuickCode basically consists of a pattern and a set of replacements, one for each available language. The pattern may contain arguments, which can be used in the replacements.

Arguments

An argument is specified in the pattern by enclosing it in double percentage characters, like so:

prop %%type%% %%name%%

This QuickCode takes two arguments: type and name. To use these in the replacement for C#, you could define the replacement for that language as follows:

public %%type%% %%name%%
{
   get
   {
      return this.%%name%%;
   }
   set
   {
      this.%%name%% = value;
   }
}

To use the arguments in a replacement, surround them with double percentage characters as well.

Argument casing

In this above example, the name of the property and the name of the member variable used to store it are the same: %%name%%. This will cause a recursive property definition. By convention, in C# property names should start with an upper case letter, while member variables should start with lower case letters. QuickCode.NET can do this for you. Simply append :u or :l to the use of the argument in the replacement:

public %%type%% %%name:u%%
{
   get 
   { 
      return this.%%name%%:l; 
   } 
   set 
   { 
      this.%%name:u%% = value; 
   } 
} 

Similarly, you can use :U to convert the argument to all upper case and :L to convert to all lowercase:

Suffix Meaning testVar becomes
:u Make first letter upper case TestVar
:l Make first letter lower case testVar
:U Capitalize argument TESTVAR
:L Make argument all lower case testvar

Special replacement words

There are three special replacement words you can use inside a replacement:

Word Meaning Example
#USER# The name of the current user Markus
#DATE# The current date in the default date format of the machine 20-05-2008
#LINE# The original line the QuickCode operated on prop int test

Additionally, you can use the special code of %. to position the cursor inside the replacement.

Using these special words, we can make a very useful QuickCode: the signed, dated comment. We define the pattern like this:

'

and we give it the following series of replacements:

Language Replacement
C# // #USER# (#DATE#): %.
Basic ' #USER# (#DATE#): %.
T-SQL -- #USER# (#DATE#): %.
CSS /* #USER# (#DATE#): %. */

This way, typing ' on a line by itself and pressing Tab yields a comment of the form:

// Markus (20-05-2008):

in the correct form for the current language. The cursor is positioned at the end of the line, ready for typing the actual comment.

Optional arguments

But wouldn't it be nice to be able to type

' TODO: fix this properly

then press Tab? For this purpose, you can use optional arguments. These are not surrounded by %%, but by %{ and }%. Using them in the replacements is equal to normal arguments: enclosed in %%'s. The difference is, that the QuickCode will match, even if the argument is missing.

Using an optional argument, we can now define our comment QuickCode's pattern like this:

' %{comment}%

The replacement for C# would then become:

// #USER (#DATE): %%comment%% %.

Typing

' TODO: fix this properly

followed by Tab would indeed show:

// Markus (20-05-2008): TODO: fix this properly |

with the cursor in the location indicated by the vertical bar. Because the argument is optional, launching the QuickCode on

'

will simply yield

// Markus (20-05-2008): |

Optional arguments can also be used to supply more information to a QuickCode. Suppose we made a QuickCode with a pattern of

class %%name%% %{description}%

We could then execute that on

class MyNewClass

where the argument name would be 'MyNewClass' and description would be empty, or

class MyNewClass This is a new class I made

where description would be 'This is a new class I made'.

A QuickCode can have only a single optional argument, and it has to be the last one in the pattern.