EZRTools Newsletter ----------------------------------------- v2 2003

NOTE: this will be the last EZRTools newsletter you will receive unless you act now! I am very sorry for the inconvenience this may cause those of you who have previously specifically chosen to receive this newsletter. But, due to changes in EU laws (about spam) and the occasion of a person receiving the newsletter in error (their email id was provided, but not by them!) I need to move to a double opt-in method. So to continue to receive this free newsletter you need to signup again by clicking here. The page you arrive at should already have your information filled out (unless you have cookies turned off). Submitting that form will send an email to you. Following the link in the email will complete your free subscription signup.

Please note: At Martin Works, we respect your privacy and all information collected by Martin Works Inc. will only be used to identify you as our customer and will never be sold or given to another organization.

Thank you for your patience,

Clay T. Martin


Making your own Active Templates

Clay T Martin

It is fairly easy to create plain old vanilla text templates, but what about ones that do a little activity of their own? There are a number of meta-tags for templates that can add a lot of functionality if you know how to use them. Here are some of the things you might want to do:

  1. Place the cursor within the text of the template.
  2. Highlight for overtyping, a phrase within the template.
  3. Prompt for some text to be added to the template results and offer a default.
  4. Place the current files' path within the text of the expanded template.
  5. Jump past the end of the template's text from within.

Lets walk through an example. Lets say we have a macro called BOB, and we use it throughout our project. Thus, we want to create a template to make it easier to place in the code. First we go to Tools-Edit Templates, make sure we are using the SAS template set, and press the button to insert a template. We are prompted for the template name, macro BOB, of course, and we set up the following values for the template: Keyword - bob; Min length - 3;Space expand - checked, any where.

Ok, so now what do we want the result to look like?. We need the %BOB of course. BOB has three parms, p1, title, and lastparm. We want to use the parm= format for the parameters. Oh yea, we want the second and third parms on their own lines. Therefore here is what we would enter in the results box:

%BOB(p1=,
     title=,
     lastparm=);

So far so good, but it would be nice to do that Cntl-I thing to fill in the parms. To do this we can add the meta command Cursor(<-CUR>) into the middle of the result, so the cursor will be placed there after the template expansion. We can put in a value and surround it with one of those back leaning quote marks like this:

%BOB(p1=<-CUR>`value`,
     title=,
     lastparm=);

Note, undocumented feature here. If you place the Cursor meta command immediately next to text within those back leaning quotes, the text will be highlighted automatically when the template expands.

Next we could do the same for title, but lastparm has a default value(0). If we place the default value in those back quotes then when we press Cntl-I to hop to it, we will have to overtype the default, or manually remove those ticks from around it. That's no good! So for a default value we can use the PROMPT meta command. This provides us a pop-up window where we can either hit enter to keep the default, or overtype the default and hit enter. It looks like this:

%BOB(p1=<-CUR>`value`,
     title=`my title`,
     lastparm=<PROMPT Enter the last parm`0>);

Version 2

We are currently working on Version 2 of EZRTools! Do you have any suggestions for tools? Let us know!

Forum ?

Interested in a forum for EZRTools and other SAS related subjects? If we get enough interest we will host one on the EZRTools site. Let us know your thoughts, Click Here.

Tell a Friend!!
Making your own Active Templates cont.
Enter the last parm

fig. 1

As you can see from fig. 1, the prompt text will be displayed next to an edit box that already has the default value entered and highlighted. And we can hit the enter key to accept or just start typing to replace that value.

Ok, now we can expand the macro BOB template by typing bob followed by a space, enter a value for lastparm, or just press enter to accept 0, overtype the first parm, hit Cntl-I to get to the second parm, and overtype it. But that leaves our cursor just before the comma on the second line. No doubt we have more code to type in. So we would like to hop to the line after the call to BOB and keep typing, without using the mouse or arrow keys. To do that we add another meta command, the Field Marker(<-?>):

%BOB(p1=<-CUR>`value`,
     title=`my title`,
     lastparm=<PROMPT Enter the last parm`0>);
<-?>

Now when the template expands after the last line you will see a /*?*/. To make this work, after overtyping `my title`, you press Cntl-I again and the cursor will move to the place where /*?*/ starts, and /*?*/ will disappear. Now we are all set to go sticking calls to BOB all over our code! But wait! Shouldn't we document this some how? It would be nice to have a comment above the call to BOB to say where it is stored. We could just hardcode this. Nah, that would be too simple.

If we always keep macros for a project in a subdirectory (called macros of course!) under the project directory with the code, we can automate this a bit. We can use the PATH meta command to enter the path to the current file, and just tack macros on to the end. Note, if you have long directory names involved in the path, they will have that squiggly format of being squeezed into DOS format names. Undocumented feature here, we can use the LFN meta command to render the path in a readable, long file name format. So our new template looks like this:

   /**BOB is stored in <LFN><PATH>macros **/
%BOB(p1=<-CUR>`value`,
     title=`my title`,
     lastparm=<PROMPT Enter the last parm`0>);
<-?>

So we should get an expansion of the template that looks like the following with our cursor sitting on the line after "lastparm=" in the same column as %BOB starts in. That is after we have stepped through filling out the parms and Cntl-I'd (three times total) down to that line.

   /** bob is stored in c:\sas\p1\macros **/
%BOB(p1=55,
     title="Some cool title",
     lastparm=0);

You don't have to actually type all the meta commands in the edit window of the template edit dialog. Instead, you can press the metacommand button and pick them off a pop-up list. All except LFN of course!


Submissions

Do you have a article relating to the use of EZRTools or Multi-Edit. We would love to consider it for the next newsletter. You can email it to ezrtnews(AT)martinworks.com


Out of Time?

Do you need a specialized macro written? Need company specific templates? Martin Works Inc. can produce these for you at a reasonable price. We have considerable experience with SAS, Multi-Edit and the CMAC language. If you don't have the resources to get the job done, Martin Works!.

Back Issues

You can view the back issues of the newsletter by clicking here.

Sign Up

If you received this newletter from a friend and wish to receive a copy yourself, you can follow this link and fill out the form.

Cancel

If you received this in error or wish to no longer receive this newsletter follow this link and select "Cancel Newsletter Only" from the radio buttons. We are sorry if you were inconvenienced in any way.


Martin Works Inc. can be contacted at 570-853-0940 weekdays 9a-5p eastern time. 312 Myrtle St. Susquehanna, PA 18847, USA or at support(AT)martinworks.com


Copyright © 2003, Martin Works Inc., Text, graphics, and HTML code are protected by US and International Copyright Laws, and may not be copied, reprinted, published, translated, hosted, or otherwise distributed by any means without explicit permission. SAS® is a registered trademark of SAS Institute, Inc. in Cary, NC. Multi-Edit® is a trademark of Multi-Edit Software Inc. All other logos and trademarks in this site are property of their respective owners.