Delphi Live Templates are just one of the many cool features of the BDS and Turbo IDEs. Have you wondered how to get in and tweak the template that you are presented with when you've gone through the steps required to create a new Live Template? It's not that hard, but it's one of those features, that if you don't know it's there ... it's really easy to miss.
The trick is to start the IDE without a project in it. If you've already set the IDE to start up without the last project you had open -or- creating a new empty one, you are all set if not you can start the IDE using the -np command-line argument. The reason for this is, once you open a file into the IDE, you can't get at the template you need to edit.
With the empty IDE up and running, open the Templates window and expand the IDE tree. There you should find a template called ... template_template. you need to select that file and click on the Edit Button on the ToolBar [or Right_Click and select Edit from the pop-up menu that is presented]. That should have opened the file in the IDE.
As I mentioned, once you open anything ... the IDE tree is no longer available in the Templates window - that includes the file you just opened.
There are a number of things you can do to enhance the template so that when you create Live Templates from it, it will be a little easier or at least customized to your needs.
The first thing you should do is change the delimiter used for the Live Templates created for you. You'll find that information between the innermost brackets of the
<![CDATA[ ]]> item - about two thirds the way down the code block. In the output code you will find the
node. You need to add a
delimiter="|" parameter so that the whole thing looks like
<code language="$language$" delimiter="|">
It has been noted in a number of place that leaving the delimiter in its default state of
$ is a bad idea -
$ can be used in code so if you don't change it and your code includes a
$ it will confuse the script parser when it tries to output the code contained in your template into the IDE. The remainder of the output block can pretty well remain the same unless there are more complex changes that you would like to make.
One of the enhancements you can make is to add default text to some of the data entry points. If you look further up from where we've been working you will find some
<point> nodes. Live Templates Technical Info covers these much better than I ever could except to say the ones where we're working are pretty generic. To give you an example of what can be done, I've added my name [changed here to protect the guilty] as default in the "author" point:
<point name="author"> <text>Ima Wannabe</text> <hint>Name of the author</hint> </point>
Because I always work with Delphi I've also changed the "language" point to:
<point name="language"> <text>Delphi</text> <hint>Language that the template targets</hint> </point>
Of note in the point node changes I've show above all this does is set the default values, they can easily be changed by simply typing in something new when you're in the automated mode of creating a new template. If you want to make changes that are permanent and not part of the automated process ... delete the related point node and replace the appropriate text [the
name="whatever" parameter of the node] in the output code block.
Another change you might want to make is adding $end$ to the CDATA section, so your cursor doesn't stay in the Language entry point but moves on to the actual content of the template:
I've also changed the output code to have all the minor nodes be single line but I won't show that here [except in the samples above] ... bigger wars have started over much smaller things. You get the idea now.
Here's a handy template you can add to your system to use when creating templates. It will automate the process of adding
<point>s to your code:
<?xml version="1.0" encoding="utf-8" ?> <codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0"> <template name="point" invoke="manual"> <description>Used to enter points in Live Templates</description> <author>Stolen from Nick Hodges who borrowed it from Deborah Pate</author> <point name="pointname"> <text>pointname</text> <hint>The name to be used for this point.</hint> </point> <point name="pointtext"> <text /> <hint>The default text to insert.</hint> </point> <point name="pointhint"> <text /> <hint>The text describing the point.</hint> </point> <code language="XML" delimiter="|"> <![CDATA[ <point name="|pointname|"> |*|<text>|pointtext|</text> |*|<hint>|pointhint|</hint> </point> |end|]]> </code> </template> </codetemplate>
Have fun with the BDS/Turbo you've chosen to use as your programming IDE.
If you want to learn more about templates and how the above works, see Live Templates Technical Info.