Page 1 of 1

How would I record this macro?

Posted: Sat Mar 13, 2010 6:09 am
by scottbass
Hi,

I need to convert this sample text:

Code: Select all

VAR1$
LONGVAR2  $
ANOTHERVAR3       $
where $ signifies end of line, i.e. trailing spaces

to this final text:

Code: Select all

* VAR1 ;
VAR1= ;

* LONGVAR2 ;
LONGVAR2= ;

* ANOTHERVAR3 ;
ANOTHERVAR3= ;
I want the macro to execute only on marked text in the editor.

In pseudocode:

Remove trailing spaces from the marked text
For each line in the marked text, repeat it, then add a blank line
Return to the top of the marked text
Add "* " to the beginning of the line
Add " ;" to the end of the line
Advance to the next line
Add "= ;" to the end of the line
Advance to the next non-blank line
Rinse and repeat until end of marked text

The order of these steps can change as long as the end result is as stated.

Can such a macro be recorded? I can't figure out the keystrokes to make this happen, and without a macro editing functionality/language, I'm stuck.

Finally, is it possible to call a macro from another macro? It might be useful to modularize this into a series of smaller macros, then define a "wrapper" macro that calls them all.

I really like TextPad, am a big fan, have used it for years, and have recommended its use at my company. Please tell me I don't have to get UltraEdit for this functionality!!!

Thanks,
Scott

Posted: Sat Mar 13, 2010 9:03 am
by ben_josephs
You can do this throughout the file or on selected lines with a single regular expression search and replace:
Find what: ^([^ ]+) *$
Replace with: * \1 ;\n\1= ;\n

[X] Regular expression

Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
You can construct a macro that jumps to the next bookmarked line and runs that search and replace once. Then run the macro repeatedly to the end of the file.