Topic: Replace_Block problem (1 of 3), Read 28 times
Conf: VEDIT Macro Language Support
From: Steve Rawling
Date: Sunday, October 02, 2005 09:15 PM

I have a problem with the behavior of Replace_Block

Firstly I create the following string

12345 abcde

Now with the cursor on "1" of that string I apply any of the the following command strings

bb(cp) c(5) be(cp) eol rb("2","b",bb,be)
or
bb(cp) c(5) be(cp) c(-3) rb("2","b",bb,be)
or
bb(cp) c(5) be(cp) c(-2) rb("2","b",bb,be)
or
bb(cp) c(5) be(cp) c(-1) rb("2","b",bb,be)

I get the rror message "cannot find 2"

But if I do one of the two following commands
bb(cp) c(5) be(cp) bol rb("2","b",bb,be)
or
bb(cp) c(5) be(cp) c(-4) rb("2","b",bb,be)

I can successfully modify the string 12345 to become 1b345

So rb will only work if the cursor sits before that part of the bb-be string which contains the search string


I see why this may be so.... Replace_Block is a subset of Replace and that command only searches forward unless REVERSE is specified)

However the command gp(bb) and db(bb,be) will work when the cursor is forward of the block bb,be so I would have thought RB would work similarly


An even more confusing related problem is the following

say I have a string
abc 23 abc

with the cursor on "2"

the I execute the commands

bb(cp) c(2) be(cp) c(-2) rb("23","2a3a",bb,be) db(bb.be)

which results in the following string
abc 2a abc

 


Topic: Replace_Block problem (2 of 3), Read 28 times
Conf: VEDIT Macro Language Support
From: Ian Binnie
Date: Sunday, October 02, 2005 10:42 PM

th s lmst imps 2 rd


On 10/2/2005 9:15:59 PM, Steve Rawling wrote:
>I have a problem with the
>behavior of Replace_Block
>
>So rb will only work if the
>cursor sits before that part
>of the bb-be string which
>contains the search string
>
I don't see why you would expect Replace_Block to operate differently to Replace.

If you want to start at the beginning , there is a simple option, include BEGIN in your replace.
>
>I see why this may be so....
>Replace_Block is a subset of
>Replace and that command only
>searches forward unless
>REVERSE is specified)
>
>
>An even more confusing related
>problem is the following
>
>say I have a string
>abc 23 abc
>
>with the cursor on "2"
>
>the I execute the commands
>
>bb(cp) c(2) be(cp) c(-2)
>rb("23","2a3a",bb,be)
>db(bb.be)
>
>which results in the following
>string
>abc 2a abc
You may have a point about the last replace

 


Topic: Re: Replace_Block problem (3 of 3), Read 20 times
Conf: VEDIT Macro Language Support
From: Ted Green
Date: Monday, October 24, 2005 05:20 PM

At 09:16 PM 10/2/2005, you wrote:
>An even more confusing related problem is the following
>
>say I have a string
>abc 23 abc
>
>with the cursor on "2"
>
>the I execute the commands
>
>bb(cp) c(2) be(cp) c(-2)
>rb("23","2a3a",bb,be)
>db(bb,be)
>
>which results in the following string
>abc 2a abc

Even I was surprised by these results as both BB and BE increased by two. I expected BB=BE with both pointing past the "2a3a". Evidently a replace() has some unusual effect on BB and BE.

BB and BE tend to "stick" to characters, adjusting as text is deleted and inserted.

A replace of "23" by "2a3a" is implemented by inserting two blanks before the "23" (hence BB and BE increase by two) and then overwriting the blanks and the "23" with "2a3a".

Sometimes it is easier to use simple variables instead of BB and BE, as in:

#1=cp c(2) #2=cp c(-2)
rb("23","2a3a",#1,#2)
db(#1,#2)

Although the effect of Replace() on BB and BE is predictable (if strange), it is probably better to reset BB and BE (if needed) after a Replace().

Ted.