Re: macrohelp

From: Philip Spaelti (spaelti@SHOIN.AC.JP)
Date: Tue Jan 16 2001 - 01:04:50 AEDT


On Mon, 15 Jan 2001 08:25:26 -0500 Christian Matzerath wrote...
>Hi Macroists,

>just because I am curious and I want to learn more:

>I have build myself a simple macro, which repeats the
>following phrase over and over again:

>//Find all paragraphs with the following structure
>Find All ":d*\.\rChemie\r.+\r.+\r.+\r\r" "oO-SAi-wt-Gg"
>//do the Collect Noncontiguously Macro
>Key  commandkey CN
>Send Back
>Paste
>Send Back

>after this as I said the same thing would happen but
>with another word in the Find expression (Physik,
>Sport, Musik and 20 more)

>so actually these are 20somewhat macros only differing
>in the find expression and I thought that there must
>be a clever way to avoid a very long macro by looping
>this somehow.

The trick is to replace the part of the find expression that changes (i.e. "Chemie" with the clipboard. To do that you need to do 2 things:

1. insert "\CC" for the clipboard
2. replace the double quotes (") around the expression with single quotes (').

The result looks like this.
Find All ':d*\.\r\CC\r.+\r.+\r.+\r\r' "oO-SAi-wt-Gg"

Now you need to put the bit that changes on the clipboard first, so that looks like this.

clipboard = "Chemie"
Find All ':d*\.\r\CC\r.+\r.+\r.+\r\r' "oO-SAi-wt-Gg"

Remember the single quotes, as these are crucial. The single quotes cause Nisus to do 2 'passes' on the find expression. On the first pass the \CC is replaced with its value (i.e. what's on the clipboard). So on the second pass the expression will read as if you had written "Chemie" there.

Since you have now removed the changing bit from the find expression it's a piece of cake to make some kind of 'loop'. There are a number of ways to do this. Here is one that uses the idea of a 'subroutine'. Put the repeating part into one macro like this:

// Macro Extract_Topic_Sections
Find All ':d*\.\r\CC\r.+\r.+\r.+\r\r' "oO-SAi-wt-Gg"
Key  commandkey CN
Send Back
Paste
Send Back
// end Extract_Topic_Sections macro

Now you can write a 'controlling' macro which calls this macro for each topic like this

// Main Macro
clipboard = "Chemie"
Extract_Topic_Sections

clipboard = "Physik"
Extract_Topic_Sections

clipboard = "Musik"
Extract_Topic_Sections

clipboard = "Sport"
Extract_Topic_Sections

etc.

// end macro

So here the main macro repeatedly calls the Extract_Topic_Sections macro.

The loop part can be handled in other ways, but for this type of job this is probably the simplest and clearest.

best
--------------------------------------
Philip Spaelti
Kobe Shoin Women's University
spaelti@shoin.ac.jp
--------------------------------------



This archive was generated by hypermail 2b29 : Thu Jan 18 2001 - 23:01:54 AEDT