replace words from begin of file until cursor position

Help with writing and playing macros

replace words from begin of file until cursor position

Postby stadi » Thu Jan 20, 2005 7:16 am

Is it posible, to get a macro for replace all words which are selected. But only from start of file until cursers place?

Thanks for helping!
User avatar
stadi
Newbie
 
Posts: 2
Joined: Thu Jan 20, 2005 12:00 am

Re: replace words from begin of file until cursor position

Postby palou » Thu Jan 20, 2005 8:58 am

Hello stadi,

I'm sure that's not the best way to do it, but it seems to work:

Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
Clipboard 9
IfSel
  Copy
  Key LEFT ARROW
  Key RIGHT ARROW
  "~@#"
  Top
  GetString "Replace by:"
  "~@@#
  "
  StartSelect
  Find Select "~@#"
  Find "^c"
  Replace All SelectText "~@r#"
  EndSelect
  Top
  Find RegExp "(.*)~@@#"
  Replace "\1"
  Top
  StartSelect
  Key END
  EndSelect
  Cut
  Delete
  Find "~@r#"
  Replace All "^c"
  Top
  Find "~@#"
  Delete
EndIf
Clipboard 0


Don't be affraid by the code it's quite simple:

1) Copy in the clipboard 9 the selected part (if any, else do nothing)
2) Mark current position (~@#)
3) Go to the top and ask for replacement string and mark its end (~@@#)
4) Select text until the original position
5) Replace, in the selection, the content of the clipboard by an UNIQUE pattern (~@r#)
6) Go to the top and copy in clipboard the replacement string
7) Replace, in the whole text, the unique pattern by the content of the clipboard
8) Go back to the original position

Hope can help you.
User avatar
palou
Basic User
Basic User
 
Posts: 47
Joined: Fri Dec 17, 2004 12:00 am
Location: Geneva / Switzerland

Re: replace words from begin of file until cursor position

Postby stadi » Fri Jan 21, 2005 8:22 am

merci palou,
il fonctionne tres bien.
User avatar
stadi
Newbie
 
Posts: 2
Joined: Thu Jan 20, 2005 12:00 am


Return to Macros