StrongED:Building tables efficiently

StrongED: Building tables efficiently
Building tables can be a tedious if there are many items. Especially when the items are almost the same but not quite it would be useful if the process could be (semi)automated. One such table was required for StrongED 4.68 to allow its choices be stored in a text file as key-value pairs.

In order to keep the internal tables required for this to a fixed size, the strings to be used as keys were placed in a messages file. The internal tables could then used message tokens to read them.

Of course this required that a messages file be constructed that contained a list of all the keys. The various options that StrongED supports are all one-offs so there's nothing to automate there, but the keys for the colour configuration are much the same for each of the colour elements available.

This article will show to use StrongED's facilities to take the tedium out of creating such a table.

The list of colour elements known to StrongED 4.68 is given below:

Text Caret Block Mark Ctrl Tabs Border Margin Brackets Hardwrap Linenumbers Identifiers Functions Strings Comments Numbers Punctuation Group1 Group2 Group3 Group4 Group5 Group6 Group7 Group8 Group9 Group10 Group11 Group12 Group13 Group14 Group15 Group16

For each of these elements the following message tokens and values will need to be created:

MC00:Foreground_Text MC01:Background_Text MC02:BitmapStyle_Text MC03:ColourFlags_Text .           .            .  MC80:Foreground_Group16 MC81:Background_Group16 MC82:BitmapStyle_Group16 MC83:ColourFlags_Group16

As you can see the entries for each element are the same apart from the number in the message token and the element's name at the end of the token value. So, lets see how this table can be built without laboriously typing in the lot.

Since each colour element is going to need four entries we start doubling up the list of colour elements using Search$Replace:

Search: < * > Replace: @@ \n @@

Make sure Advanced is on and that scope is Text and press Return. In the What Now? window that appears press Replace All. The list now contains each element name twice, but we'll need 4 copies of each so we press F4 again and repeat the previous S&R.

Now we need to add the text 'Foreground_' to the first occurrence of each element's name. there are two ways to achieve this; Search&Replace or recording a sequence of keypresses.

If using Search&Replace

First we'll add :Foreground_. We need to enter the following into the S&R dbox:

Search: { < * \n }4 Replace: ":Foreground_" @@

After entering the search and replace patterns, press Return (or click GO). In the "What now?" window that pops up press "Replace All". (The leading colon in :Foreground_ is so we can exclude lines from subsequent S&Rs.)

Now that we have done Foreground we move on to Background:

Search: { < ~":". * \n }3 Replace: ":Background_" @@

Next we do BitmapStyle:

Search: { < ~":". * \n }2 Replace: ":BitmapStyle_" @@

And finally ColourFlags:

Search: { < ~":". * \n }1 Replace: ":ColourFlags_" @@

If using recording of keypresses:

First we'll add :Foreground_. Place the caret on the first line of the list, press Shift-F9 and enter:

Ctrl-Right ":Foreground_" (without the quotes) Down arrow Down arrow Down arrow Down arrow

Now press Shift-F9 again to stop recording. Playback the recorded keys by pressing F9   Continue to do so until we've come to the end of the list.

Now that we have done Foreground we move on to Background:

We put the caret on the second line Repeat the above recording and playback but instead of :Foreground_ we enter :Background_.

Next we do BitmapStyle:

Repeat again but starting on the third line and with :BitmapStyle_.

And finally ColourFlags:

Start on the fourth line and use :ColourFlags_.

If all went well you should now have a list in which each element has the correct set of 4 token values. The only thing missing now is the message token at the start of each line. The letters "MC" can be added using S&R or Block-edit:

Search: ":" Replace: "MC:"

The final step is to add the correct number after each "MC", this unfortunately has to be done by hand. Because this still leaves a bit of tedium 4.68 has a better way of doing it:

Search: ":" Replace: "MC" Cnt ":"

The "Cnt" in the Replace string inserts a number from a sequential counter built into the Replace box. The number of digits, start number, step size, padding, hexadecimal or decimal numbers can all be configured.