Ask Reuben

File Templates

How can I type code quicker and consistently?

How can I create an example program quickly?

Within Genero Studio, there is the concept of Code Templates.  This is functionality whereby you can type Control-T, select a code template and have code inserted into the Code Editor that will save typing and speed up your development as well as improving code consistency.

This is useful functionality and it has some functionality that is overlooked.

  • You can edit what code templates are available in the Template Configuration screen, found via Preferences -> Code Editor -> Template
  • Within Template Configuration, you can share templates with your team via the Import and Export buttons so that your team are all using the same set of templates.
  • When editing a template, place | where you want the cursor to be positioned after the template is inserted into your code. i.e foo(|) will place the cursor in the middle of the brackets so you can start typing the parameters.
  • Before you press Control-T, type some characters to narrow what templates are made available to you in the drop down.  For example, if you type ca then instead of seeing every template, you will see the two templates that begin ca i.e the two case options.
  • Within Template Configuration, note the language field.  For code templates used as part of .4ad, .4st, .4tb, .4tm, .4sm i.e XML files, set the Language to XML.
  • There is no length restriction on the template.  (there maybe one but I have not found it).  The point is that the template does not have to be 3-10 lines but can be longer.

It is this last point I want to emphasise with this article.  You can use templates to insert long copyright notices at the beginning of your source code.  You can also use it for example programs.  So in my last article I talked about minimal reproducible examples to help with support cases.  In my Code Templates I have a couple of example programs so that I can simply open a new .4gl/.per/.4st file, type ex and then Control-T, and then from the list select the appropriate example to use as my starting point.

So as a small exercise, find the Template Configuration in Genero Studio preferences. with language = Genero BDL, use the + icon to create a few examples that have names beginning “ex” …

… and then in the Code Editor, with  a new 4gl, type ex and then Control-T, and select a template you have just created …

… to see how quickly you can create a new .4gl with many lines of code.

Hopefully you see that with 5-15 minutes of investment, you can put yourself in a much better position to create small examples quickly.

Note: There is another longer way to create templates that appear in the File->New dialog, if you are interested in that have a read of this section about creatables.conf.