// -*- ASCII:EDT -*- // // purpose: insert a template file, but keep formatting // (former lines may be indented). So switch to // block mode and insert as many new lines // as the template file possesses // author: Georges Schmitz // version: 0.9 (2001-11-3) first working version // 1.0 (2002-04-17) introduced SetBlock(0)... instead of // menu commands BeginGroup; Mark(0); IfFileExists('%$("insFilename");','Relax','Prompt("No such template file!%\ ***%$(''insFilename'');***",2);CMD("Undo");Exit;'); ReadFile('%$("insFilename");',0); // **************************************************************** // here comes the trick for keeping indentations of a template file // "Block Mode" is necessary SetBlock(1); // "Indent Mode" should be used, else this macro makes no sense at all SetIndent(1); // **************************************************************** // even with Insert Mode, block mode can overwrite existing text, // because no newlines are created. // so first insert as many new lines as the template file contains Loop(!* > SetOK; > // find EOL's (">") with RegExp > FindInString("%!0",">",2,3,1001,%!3+1); > // did we find something? If yes, make a newline, else leave loop > IfNum("%!2","%!3","<=","NewLine;","Stop;"); > *) // Back to starting point Goto(0); // use InsText(); instead of Ins();. This simulates // keybord like "newlines" (keeping absolute indenting) InsText('%!0'); Mark(1); // Restore to previous values RestoreBlock; RestoreIndent; EndGroup; End;