PushTagsandRegisters; // Improvements : // - File names can contain spaces. // - Works with WinEdt 5.5 et 5.6 (the macro no longer uses LstGetItem). // Weakness of that macro : its good functioning relies on the way the macro ListFolderFiles lists files for a given path. StopWorking; // the variable "keyword" contains the key word CMD("Backspace"); // deletes the '*' at the end of the keyword Declare("keyword");LetReg(0, "%W" ); Assign("keyword","%!0"); //Prompt("%$('keyword');"); SelWord(1);CMD("Backspace"); CMD("Set Mark");Mark(0); LetRegNum(5,"%l"); LetRegNum(4,"%c"); Declare("stop"); // that variable will allow to stop the macro whenever something modifies the file during the execution of the macro Declare("fileok"); // that variable will allow to check wether the current file is the good one or not anymore. Assign("fileok","%f"); IfFileExists( "%b\Macros\LaTeX\Choice\%$('keyword');\*.tex", "Relax;", "Prompt(`File does not exist, or put some spaces before the keyword...`);End;" ); ListFolderFiles(8,"%b\Macros\LaTeX\Choice\%$('keyword');",".tex",0,2); // Create a list (string) with first the path and then the list of all the files *.tex //Ins("%!8");PopTagsandRegisters;End; FindInString( "%!8", "\", 1, 3,100); LetRegNum(1,%!1+4); // the register 1 contains the first character's index of the first file FindInString( "%!8", ".tex", 2, 3,100); LetRegNum(2,%!2-1); LetRegNum(3,%!2); // the register 3 contains the last character's index of the last file FindInString( "%!8", ".tex", 2, 9); LetRegNum(2,%!2-1); // the register 2 contains the last character's index of the first file //Prompt("%!2");PopTagsandRegisters;End; LetRegNum(9,%!1); // the register 9 is a backup of the first character's index of the first file Declare("direction"); // that variable defines the direction of navigation. Direction = "next" ou "precedent" JMP("FirstLoop"); :Loop:: Goto(0);Sel(1);Goto(2);CMD("Delete"); IfStr("%f","%$('fileok')","<>","SetTracking(1);Prompt(`You changed the file...`);PopTagsandRegisters;End;"); // some security Assign("stop","0"); //IfStr("%$('direction');","next","=",'JMP("Next");'); IfStr("%$('direction');","precedent","=",'JMP("Previous");'); :Next:: LetRegNum(1,%!2+8); IfNum(%!1,%!3,">=","LetRegNum(1,%!9);"); FindInString( "%!8", ".tex", 2, 6,1000,%!1); LetRegNum(2,%!2-1); JMP("FirstLoop"); //Prompt("%$('direction');");PopTagsandRegisters;End; :Previous:: LetRegNum(2,%!1-8);//Prompt("%!2");PopTagsandRegisters;End; IfNum(%!2,%!9,'<','JMP("case1");','JMP("case2");'); :case1:: //Prompt("cas1");PopTagsandRegisters;End; LetRegNum(2,%!3);//Prompt("%!2");PopTagsandRegisters;End; FindInString( "%!8", ".tex", 1, 6,1100,%!2); LetRegNum(1,%!1+7); //Prompt("%!1");//PopTagsandRegisters;End; JMP("FirstLoop"); :case2:: //Prompt("cas2");PopTagsandRegisters;End; FindInString( "%!8", ".tex", 1, 6,1100,%!2); IfOK('LetRegNum(1,%!1+7);','LetRegNum(1,%!9);'); //Prompt("%!1 %!2");PopTagsandRegisters;End; :FirstLoop: ExtractByIndex(7, "%!8",%!1,%!2); // the register 7 contains the name of the current file GetFileName( "%!7", 7 ); // but it has to be converted into a file name, or it won't work ReadFile( "%b\Macros\LaTeX\Choice\%$('keyword');\%!7.tex",0); IfStr("%f","%$('fileok')","<>","SetTracking(1);Prompt(`You changed the file...`);PopTagsandRegisters;End;"); // we never know... InsText("************ %!7 *************");NewLine;NewLine; Mark(1);Ins("%!0");Mark(2);CMD("Select From Mark");SetSel(5);CMD("Caret <-> Select");SetTracking(1);SetTracking(0);WaitForFocus(100); Loop(!|IfNum( %!5, %l, "<>", "Assign('stop','1');");> IfNum( %!4, %c, "<>", "Assign('stop','1');");> IfStr("%f","%$('fileok')","<>","SetTracking(1);PopTagsandRegisters;End;");> IfKeyDown(39,0,0,'Assign("direction","next");JMP("Loop");',> 'WaitForMessage(10,1);');> IfKeyDown(37,0,0,'Assign("direction","precedent");JMP("Loop");',> 'WaitForMessage(10,1);');> IfKeyDown(13,0,1,'JMP("Write");','WaitForMessage(10,1);');> IfStr("%$('stop')", "1", "=", "Goto(0);Sel(1);Goto(2);CMD('Delete');Ins('%$('keyword');');SetTracking(1);PopTagsandRegisters;End;");> |); // to stop the macro : Esc key //IfKeyDown(27,0,1,'Goto(0);Sel(1);Goto(2);CMD("Delete");Ins("%!6");SetTracking(1);PopTagsandRegisters;End;','WaitForMessage(10,1);');> :Write:: SetSel(0); CMD('Clear Right');Goto(1);Repeat(3,'CMD("Backspace");');//CMD("Backspace"); Exe("%b\Menus\Tools\Next Bullet.edt"); IfOK( "Relax;", "Goto(2);" ); SetTracking(1);Refresh(1,0); PopTagsandRegisters;End;