Macro's Replace All Only Replaces First Occurrence

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
Art Metzer
Posts: 27
Joined: Mon Mar 06, 2006 5:31 pm

Macro's Replace All Only Replaces First Occurrence

Post by Art Metzer »

Windows XP SP 2, TextPad 5.2.0.

I have a macro with two steps.

The first step deletes all lines that do not match a regular expression.

The second step then attempts a replace, where there are multiple occurrences to replace.

The problem lies in the second step.

During macro recording, the replace operation successfully finds and replaces all occurrences of the "Find what" expression; however, during macro playback, it only finds and replaces the first occurrence.

To replicate:

Create the following file, call it dummy.txt:

Code: Select all

0
12
abcdxefxxgh
*$4
zz
My goal: to remove every line that doesn't begin with an "a", and then to put a newline after every remaining "x".

Record the following macro (keystrokes in grey italics, things to type in blue bold, my comments after "//" in green):
  • F5 // Step 1, remove each line not beginning with "a"
    alt+I
    ^a
    alt+M // 1.1. Bookmark each line that starts with an "a"
    Esc
    alt+S // 1.2. Invert bookmarked lines
    A
    alt+E // 1.3. Delete lines now bookmarked (i.e., not starting with "a")
    L
    B
    F8 // Step 2, put a newline after every x
    alt+I
    x // 2.1. Find each "x"...
    alt+P
    &\n // 2.2....to be replaced by "x" plus newline
    alt+A // 2.3. Replace All
    Esc
Immediately after you record the macro, you will have the following result, which I would expect:

Code: Select all

abcdx
efx
x
gh
But if you play the macro back on the original dummy.txt, you will instead see

Code: Select all

abcdx
xefxxgh
The recording/playback discrepancy seems related to the combination of the macro's two steps; a macro made up of step 2 alone plays back fine.

Helios, is this a bug? Is there a workaround that doesn't involve two separate macros?

Thanks,

Art Metzer
Post Reply