// -*- ASCII:EDT -*- // fill.edt // formats a paragraph // in block mode // (schlicht 20010605) ////////////////////////// //\\\\\\\\\\\\\\\\\\\\\\\\ //\ CHANGE THIS //\ if you want a //\ different line length: //\\\\\\\\\\\\\\\\\\\\\\\\ Assign("LineLength","105"); // Or: This would get the line length from your right margin: // (adjustable in Options | Preferences | Editor) //GetRM(0); //Assign("LineLength","%!0"); BeginGroup; SetTracking(0); IfSel(1,"=","","CMD('Select Paragraph');"); GetSel(0,0); // Indented paragraph? Release("LineIndent") FindInString("%!0","<+{ }~ ",8,9,1); IfOK(!`> IfNum(%!8,0,"=",> !"LetRegNum(7,%!9-%!8+1);> Repeat(%!7,> !'Assign(''LineIndent'',''%$(|LineIndent|); '');');> LetRegNum(7,'%$(|LineLength|);-%!7');> Assign('LineLength','%!7');> ReplaceInString('%!0','',%!8,%!9,0,0);"> );`> ); // remove line ends and multiple spaces first: LetRegNum(9,0);> Loop(!"> SetOK(1);> FindInString('%!0','{@{ }>}|{ +{ }}',8,9,1001,%!9);> IfOK(!'ReplaceInString(''%!0'','' '',%!8,%!9,0,0); > LetRegNum(9,''%!9-(%!9-%!8)'');',> 'Stop;');> "); // truncate lines: LetRegNum(6,0);> LetRegNum(7,-1);> LetRegNum(9,-1);> Loop(!"> SetOK(1);> FindInString('%!0',' ',9,9,1000,%!9+1);> IfOK('','Stop;');> IfNum('%!9-(%!7)','%$(''LineLength'');','>',> !'IfNum(%!6+1,%!7,''='',''LetRegNum(6,%!9);'');> ReplaceInString(''%!0'',''>'',%!6,%!6,1,0);> LetRegNum(7,%!6+1);',> !'LetRegNum(6,%!9);');> "); // fill lines: LetRegNum(5,0); LetRegNum(9,-1); Loop(!`> SetOK(1);> // get the next line; FindInString("%!0","<*>",8,9,1001,%!9+1);> IfOK(!"> ExtractByIndex(1,'%!0',%!8,%!9);> GetLength(3,'%!1');> // swap direction every new line: IfNum(%!5,0,'=',> !'LetRegNum(5,1); LetRegNum(7,%!3);',> !'LetRegNum(5,0); LetRegNum(7,0);');> // how many spaces do I still have to fill? IfNum(%!3,'%$(|LineLength|);+1','=',> !'LetRegNum(3,0);',> !'LetRegNum(3,''%$(|LineLength|);+1-%!3'');');> // I see, let's go: Loop(!'> IfNum(%!3,0,''>'',> !''SetOK(1);> LetRegNum(4,%!6);> // This is dirty: register as a flag. -- It works...! FindInString(|%!1|,| {~ }{~>}|,6,7,1%!501,%!7);> IfOK(!|> ReplaceInString(||%!1||,|| ||,%!7,%!7,0,1);> LetRegNum(3,%!3-1);> IfNum(%!5,0,||=||,> !||LetRegNum(7,%!7+2);||,> !||LetRegNum(7,%!7-2);||> );|,> !|IfNum(%!4,0,||=||,> !||ReplaceInString(*%!0*,*%$(**LineIndent**);%!1*,%!8,%!9,0,0); Stop;||,> // there are still spaces left to fill, so let's run the other way round: !||IfNum(%!5,0,``=``,> !``LetRegNum(5,1);``,> !``LetRegNum(5,0);``);||> );|> );> '',> // replace with the formatted line: !''ReplaceInString(|%!0|,|%$(*LineIndent*);%!1|,%!8,%!9,0,0); Stop;'');'> );> ",> // The last line: !"SetOK(1);> FindInString('%!0','<*',8,9,0101,%!9);> IfNum(%!8,0,'=',> !'LetReg(0,''%$(|LineIndent|);%!0'');',> !'ReplaceInString(''%!0'',''%$(|LineIndent|);'',%!8-1,%!8-1,0,0);');> Stop;");> `); // insert the whole paragraph: InsText("%!0%\"); SetTracking(1); Refresh; EndGroup; End; /////////////////////////////////////////////////////////////////// // This macro formats a paragraph in block mode by filling the // spaces until the specified line length is reached. (The text you // are reading right now is formatted by this macro, with // %$('LineLength'); = 65. (In case you're wondering why the last // column is actually nr. 68: That's because I formatted it first // and then inserted '// ' at the beginning of all lines ;-).) // // If nothing is selected, the macro selects the current paragraph // (until it finds an empty line). You can format parts of a // paragraph by selecting the lines before invoking the macro. // Formatting more than one paragraph at once will concatenate // them. // // If at least the first line is indented, the paragraph will // be aligned according to this indentation, so that the right // margin is in correspondence with unaligned paragraphs (this // paragraph is an example). // // Choosing too small a number for the line length will make your // paragraphs look silly, since they will consist mainly of spaces. // If a line contains a single word which is too long for the line, // it will stick over (what can I do? ...) // // R Schlicht w.m.l@gmx.net /////////////////////////////////////////////////////////////////// $Id: fill.edt,v 1.7 2001-11-28 06:09:40+01 standard Exp standard $ Bonus Macro ************* Here is a macro that you can use to change line lengths easily: Save it as changefill.edt, and define a menu item (in Option | Menu Setup) in your favourite menu as Exe('%B\Macros\text\changefill.edt'); Then you don't have to open, edit and save the macro fill.edt, only to change the line length. +--%B\Macros\text\changefill.edt-------------------------------------+ // -*- ASCII:EDT -*- // changefill.edt // change LineLength // in fill.edt /////////////////////// IfFileExists("%B\Macros\text\fill.edt",> "ReadFile('%B\Macros\text\fill.edt',0)",> "Prompt('File not found.'); Exit;"); FindInString("%!0", "Assign(""LineLength"",""+[0-9]"");",1,2,0001,0); IfOK(!"> ExtractByIndex(9,'%!0',%!1+21,%!2-3);> EnterReg(9,'Change line length to:','Line Length');> ReplaceInString('%!0','%!9',%!1+21,%!2-3,0,0);> "); OpenOutput("%B\Macros\text\fill.edt"); WrS("%!0"); CloseOutput; End; +--------------------------------------------------------------------+