Variables in Macros? Possible?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Stephen

Variables in Macros? Possible?

Post by Stephen »

I want to know how to use a variable in a Macro?... or is it possible?

Eg. I have a macro now, that closes any standard XML tag.


<foo>sometext
becomes...
<foo>sometext</foo>

<apply-templates select="bars/bar" mode="new">HelloWorld
becomes...
<apply-templates select="bars/bar" mode="new">HelloWorld</apply-templates>

The macro works great, but I had to use the clipboard to "copy" the tag name, and "paste" it in the right spot.

I want to set a variable (even if only one), to a value.... how?

Steve.
Doug Wong

Re: Variables in Macros? Possible?

Post by Doug Wong »

Steve -
I don't think this is possible in TextPad :-( The macro function is a simple key stroke recording function. It would be nice if TextPad had a full programming language for its macro capability with variables and branching - perhaps some sort of Perl scripting.
Mark Schnitzius

Re: Variables in Macros? Possible?

Post by Mark Schnitzius »

I use copy and paste in my macros all the time; I assume you don't want to
because you don't want to lose your clipboard contents?

You could do it with regular expressions on a replace command; do something
like

Replace: <\([^ >]+\)\(.*\)>\(.+\)
With: <\1\2>\3<\1>
Stephen

Re: Variables in Macros? Possible?

Post by Stephen »

Mark,

Thanks! that looks like it will solve it!

I'd never really used the Search and Replace 'variables'...

One final thought?... can you search 'up' the document with the find portion of the replace function?...

E.g. '][' represents the Carat...


<foobar>HelloWorld][

(press hotkey...)

<foobar>HelloWorld</foobar>

Cheers,

Steve
Stephen

Re: Variables in Macros? Possible?

Post by Stephen »

;o)

Nothing like replying to your own message because you realized just after posting, what the answer was.

I modified the suggestion above, to close any SGML type tag, with or without attributes or content.

E.g All lines below will "close" when the macro is run.
][ = (cursor location)


<td class="bigtitle">Hello World][
<td class="bigtitle">Hello][ World
<td class="bigtitle">][Hello World
<td class="big][title">Hello World
<td>Hello World][


The macro:
- place cursor at desired location (similar to above)
- Start recording
- [F5] Find: < 'up' the document, and close dialog
- press [left] arrow key once to position left of bracket
- [F8] Replace: <\([^ >]+\)\(.*\)>\(.*\)
with: <\1\2>\3</\1>
- Close dialog
- press [right] arrow key once to position right of bracket
- End recording


Works great!... anyone that wants a copy, and doesn't feel like typing, just email me.

Cheers all, and thanks for the tips!

Steve
Mark Schnitzius

Re: Variables in Macros? Possible?

Post by Mark Schnitzius »

You should mail this macro in to support@textpad.com so they can put it out on the site...
Stephen

Re: Variables in Macros? Possible?

Post by Stephen »

Yup!, did that too!...

Steve
Post Reply