// -*- ASCII:EDT -*- // complete.edt // complete a word from // words of the file // (schlicht 20010804) /////////////////////// SetTracking(0); Mark(0); BeginGroup; SaveFind; SetFindTextSelect(1); SetNotFoundNotify(0); SetSearchSelected; SetSearchCurrentDoc; SetSearchCyclic(1); SetSearchEntire(0); SetRegEx(1); SetSearchCaseSensitive(1); SetSearchForward(0); SearchReset; CMD("Select Word Left"); LetReg(7,"%S"); GetLength(6,"%!7"); SetSel(0); // Escape special characters: LetRegNum(2,-2); Loop(!`> SetOK(1);> FindInString("%!7","\(0[\\\$\[\]\{\}\>\<\.\?\+\@\*\|\~\^]\)",1,2,1001,%!2+2);> IfOK(!"ReplaceInString('%!7','\\\0',%!1,%!2,1,7);",> "Stop;");> `); // Do you want a LaTeX command? ExtractByIndex(2,"%!9",0,0); IfStr("%!2","\","=",> !"LetReg(2,'');",> !"LetReg(2,'{$~Alpha$|<}');"); GetLength(5,"%!7"); IfStr("%!7","%!8","=",> // We're looking for another possibility to complete the word: !"Goto(1);> SetFindStr('%!2%!9{+$Alpha$}{>|$~Alpha$}');",> // or: !"Release('completions');> // Is the last character a space? ExtractByIndex(3,'%!7',%!5-1,%!5-1);> SetOK(1);> IfStr('%!3',' ','=',> !'> // ... we're either trying to complete a phrase: Goto(1);> IfStr(''%!7'',''%!9 '',''='',> ''> // try another completion of the phrase: CMD(|Word Left|);'',> ''> // no, I want this phrase: SetSearchForward(1);'');> ReplaceInString(''%!7'','''',%!5-1,%!5-1,0,9);> SetFindStr(''%!2%!9+{@$~Alpha$@{ }@>}{+$Alpha$}{>|$~Alpha$}'');',> !'> // ... or it's the first try to find a word: Mark(1);> LetReg(9,''%!7'');> SetFindStr(''%!2%!9{+$Alpha$}{>|$~Alpha$}'');');> CMD('Word Left');> CMD('Char Left');"> ); Loop(!`> IfFound(!"> GetSel(0,8);> SetSel(0);> // Remove the first character, if it's not a letter or a "\": ExtractByIndex(2,'%!8',0,0);> FindInString('%!2','$Alpha$|\\',2,3,0011,0);> IfOK('',!'ReplaceInString(''%!8'','''',0,0,0,8);');> // Remove last character resp. : GetLength(3,'%!8');> ExtractByIndex(2,'%!8',%!3-2,%!3);> FindInString('%!2','>',1,2,0101,0);> IfOK('LetRegNum(1,%!3-2);','LetRegNum(1,%!3-1);');> ReplaceInString('%!8','',%!1,%!3,0,8);> CMD('Char Left');> // Escape special characters: LetRegNum(1,-2);> LetReg(2,'%!8');> Loop(!'> SetOK(1);> FindInString(''%!8'',''\(0[\\\$\[\]\{\}\>\<\.\?\+\@\*\|\~\^]\)'',3,1,1001,%!1+2);> IfOK(!''ReplaceInString(|%!8|,|\\\0|,%!3,%!1,1,8);'',> ''Stop;'');> ');> // Don't show the same word again: SetOK(1);> FindInString('%$(|completions|);','<%!8>',1,3,0001,0);> IfOK(> !'LetReg(8,''%!7'');',> !'Mark(1);> Goto(0);> Repeat(''%!6'',''CMD(|Select Char Left|);'');> Ins(''%!2'');> Assign(''completions'',''%!2%\%$(|completions|);'');> Stop;> ');> ",> "Goto(0);> Mark(1);> Release('completions');> Beep(0);> Stop;> "> );> `); RestoreFind; EndGroup; SetTracking(1); Refresh(1); End; /////////////////////////////////////// // Suppose you had written this textš: // // As the industrial revolution concludes in bigger and better // bombs, an intellectual revolution opens with bigger and // better robots. The former revolution replaced muscles by // engines and was limited by the law of the conversation of // energy, or of mass-energy. The new revolution threatens us, // the thinkers, with technological unemployment, for it will // replace brains with machines limited by the law that // entropy never decreases. // // Now suppose you want to type "revolution" again. All you need to // do is to type "rev" and invoke this macro. It will search in the // file for words beginning with "rev" and complete the current // word to "revolution". // // Now suppose you type "in" and invoke the macro. Which of the // possible completions will the macro choose? Answer: All! But of // course not at the same time... First, it will complete your "in" // to "intellectual" because that is the last word in the file // beginning with "in". // Now, if you invoke the macro again it will continue searching // and will find "industrial". Invoke it another time and it will // go back to "intellectual" since there's no other word beginning // with "in" (except for the word "in" of course). The macro will // search backwards, cyclic. // // Now suppose you have chosen "intellectual" and don't want to // type "revolution" again. No problem! Simply type a space and // invoke the macro again. It will fetch the "revolution" and // append it. This way you could copy complete paragraphs. If you // didn't want an "intellectual revolution" you can undo the // "revolution" (but leave the space) and invoke the macro again. // It will find the next possible completion to "intellectual" (in // this case none). // // This macro really only makes sense if you assign a shortcut to // it. (I use ALT- / (which is ALT- - on my german keyboard).) // // 1 Of course you haven't since you're not Warren McCulloch and // you are still alive. // // R Schlicht w.m.l@gmx.net /////////////////////////////////////// $Id: complete.edt,v 1.2 2001-11-13 19:05:40+01 standard Exp standard $