home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / CompleteWord.FPL < prev    next >
Encoding:
Text File  |  1995-07-21  |  2.6 KB  |  86 lines

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