home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / CompleteWord.FPL < prev    next >
Encoding:
Text File  |  1995-05-18  |  2.5 KB  |  85 lines

  1. // $VER: CompleteWord.FPL 1.1 (02.03.95) © Jesper Skov $
  2.  
  3. int export WC_prevCall;
  4.  
  5. // Preserve for next call
  6. string WC_hitString, WC_orgWord, WC_Direction;
  7. int    WC_prevHitLine, WC_prevHitByte;
  8.  
  9. void export WordComplete()
  10. {
  11.   string searchString, tempString;
  12.   int searchResult;
  13.   int byte, line;
  14.   int currentID = GetEntryID();
  15.  
  16.   if ((ReadInfo("counter")!=(WC_prevCall+1))){
  17.     // First entry
  18.     Output(" "); // So in-word completion may be made
  19.     if (strlen(WC_orgWord = GetWord(-1,ReadInfo("byte_position")-2))){
  20.       // string not empty - init data
  21.       WC_hitString = "*";
  22.       WC_prevHitLine = ReadInfo("line");
  23.       WC_prevHitByte = ReadInfo("byte_position")-1;
  24.       WC_Direction = "";                    // start searching backwards
  25.     } else {
  26.       Backspace();                            // fix space from above
  27.       ReturnStatus("No word to complete!");
  28.       exit;
  29.     }
  30.   }
  31.  
  32.   BackspaceWord();
  33.  
  34.   byte = ReadInfo("byte_position")-1;
  35.   line = ReadInfo("line");
  36.  
  37.   CurrentBuffer(WC_prevCall = DuplicateEntry());
  38.   // internal use of WC_prevCall - search buffer ID. Exported var needed in clean kill below
  39.  
  40.   GotoLine(WC_prevHitLine, WC_prevHitByte);
  41.  
  42.   searchString = joinstr("\\<", WC_orgWord);
  43.  
  44.   do {
  45.     searchResult = Search(searchString, joinstr("=w", WC_Direction, "+"), ReadInfo("size"));
  46.     if (searchResult == -9){
  47.       // not found in this direction
  48.       if (strlen(WC_Direction) == 0){
  49.         // try searching down
  50.         WC_Direction = "f";
  51.         GotoLine(line, byte);
  52.       } else {
  53.         // not found at all...
  54.         ReturnStatus("Not found!");
  55.         searchResult = 0;
  56.         CurrentBuffer(currentID);
  57.         Clean("Kill(WC_prevCall);");
  58.         Output(WC_orgWord);                    // re-insert org word
  59.         exit;
  60.         // WC_pC not updated, thus no problems at next call - will reset
  61.       }
  62.     } else {                                // Yeah, we struck metal
  63.       tempString = GetWord();
  64.       if (stristr(WC_hitString, joinstr("*",tempString,"*"))==-1){
  65.         // Did not appear in hitString! This is gold!
  66.         WC_prevHitLine = ReadInfo("line");
  67.         WC_prevHitByte = ReadInfo("byte")-1;
  68.         WC_hitString = joinstr(WC_hitString, tempString, "*");
  69.         CurrentBuffer(currentID);
  70.         Clean("Kill(WC_prevCall);");
  71.         Output(tempString);
  72.       } else {
  73.         // User already canned this word... Try again
  74.         searchResult = 1;
  75.       }
  76.     }
  77.  
  78.   } while (searchResult != 0);
  79.  
  80.   WC_prevCall=ReadInfo("counter");
  81. }         
  82.  
  83. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Key binding ««
  84. AssignKey("WordComplete();", "amiga /");
  85.