SlickEdit Community
SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: mark0978 on August 02, 2006, 02:30:19 AM
-
What I want to do is replace every occurance of "this" with "that" on a line or in a region. To achieve this goal
I have some code like so:
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
while(replace("this", "that"", "MR*P") != STRING_NOT_FOUND_RC) {
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
} ;
The first _restore_pos2(begrec) and _restore_pos2(endrec) work fine but inside the while loop, I get:
Invalid selection Handle.
Removing the body of the loop gets me the same thing.
What appears to be missing from the macro language is an easy way to do bounded things, and simple commands you can use. I'm not trying to write an editor, I'm trying to write some short Macros to accomplish a task. I need nice simple commands I can put into my macros!
GNU emacs had these simple building blocks. The command line prepared the arguments for the underlying commands. here it seems like the commands you have at your disposal either don't do what you want, or involve prompting.
-
Where is the _save_pos2() ;)
Assume copy'n paste glitch...
Anyway, always use matching PAIRS with the SAME pos-var (it's like let's say locking / release a mutex).
The pos-var is NOT a begin or end 'marker' here.
_save_pos2 ( orig_pos );
// ...
_restore_pos2 ( orig_pos );
HS2
-
Sorry about that, I figured it was obvious. I did both _save_pos2(begrec) and _save_pos2(endrec) at the beginning of the macro, then did some modificiations, then got into the replace loops.
Here is the whole macro.
_command PrettifyMarcRecord() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
_save_pos2(begrec);
end_line();
_save_pos2(endrec);
_restore_pos2(begrec);
keyin("\"");
cursor_right(24);
keyin("\"");
split_line();
cursor_right(1);
ch = get_text(1, -3);
for(i=0; (i < 200) && (ch != "\036"); ++i) {
keyin("\"");
cursor_right(3);
keyin("\" \"");
cursor_right(4);
keyin("\" \"");
cursor_right(5);
keyin("\"");
split_line();
cursor_right(1);
ch = get_text(1, -3);
}
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
while(replace("\\x1e\\x1d", "\\\\036\\\\035\"", "R*P") != STRING_NOT_FOUND_RC) {
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
} ;
while(replace("\\x1e", "\\\\036\"\\n\"", "R*P") != STRING_NOT_FOUND_RC) {
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
} ;
while(replace("\\x1f", "\\\\037", "R*P") != STRING_NOT_FOUND_RC) {
_restore_pos2(begrec);
select_line();
_restore_pos2(endrec);
select_line();
} ;
}
The idea is to convert this:
00685nz 2200181n 4500003000600000008004100006010001600047035002300063040001800086100010700104400008800211400008100299643003600380644001100416645001100427646001100438670005400449OCoLC830429n| acabbaaan |a ana an 42030975 a(OCoLC)ocm00028972 aDLCcDLCdDLC1 aBoccherini, Luigi,d1743-1805.tSonatas,mvioloncello, continuo.kSelections (Edizioni Suvini Zerboni)1 aBoccherini, Luigi,d1743-1805.tDodici sonate per violoncello e basso.pParte prima1 aBoccherini, Luigi,d1743-1805.tSonate per violoncello e basso.pParte prima aMilanobEdizioni Suvini Zerboni af5DLC at5DLC as5DLC aBoccherini, L. Sonata in do minore, J.G.2B, 1981.
into a compilable:
"00685nz 2200181n 4500"
"003" "0006" "00000"
"008" "0041" "00006"
"010" "0016" "00047"
"035" "0023" "00063"
"040" "0018" "00086"
"100" "0107" "00104"
"400" "0088" "00211"
"400" "0081" "00299"
"643" "0036" "00380"
"644" "0011" "00416"
"645" "0011" "00427"
"646" "0011" "00438"
"670" "0054" "00449\036"
"OCoLC\036"
"830429n| acabbaaan |a ana \036"
" \037an 42030975\036"
" \037a(OCoLC)ocm00028972\036"
" \037aDLC\037cDLC\037dDLC\036"
"1 \037aBoccherini, Luigi,\037d1743-1805.\037tSonatas,\037mvioloncello, continuo.\037kSelections (Edizioni Suvini Zerboni)\036"
"1 \037aBoccherini, Luigi,\037d1743-1805.\037tDodici sonate per violoncello e basso.\037pParte prima\036"
"1 \037aBoccherini, Luigi,\037d1743-1805.\037tSonate per violoncello e basso.\037pParte prima\036"
" \037aMilano\037bEdizioni Suvini Zerboni\036"
" \037af\0375DLC\036"
" \037at\0375DLC\036"
" \037as\0375DLC\036"
" \037aBoccherini, L. Sonata in do minore, J.G.2B, 1981.\036\035"