home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / TabConvert.FPL < prev    next >
Encoding:
Text File  |  1995-01-20  |  2.0 KB  |  83 lines

  1. void TabToSpace()
  2. {
  3.   int id=GetEntryID();
  4.   int new=DuplicateEntry();
  5.  
  6.   if (new) {
  7.     int lines, size, tabsize, bytepos, del, counter;
  8.     Visible(0);
  9.     CurrentBuffer(new);
  10.     Status(id, "Tab converting.");
  11.     tabsize=ReadInfo("tab_size");
  12.     lines=ReadInfo("lines");
  13.     GotoLine(lines, ReadInfo("line_length", new, lines));
  14.     SearchSet("f-");
  15.     while (Search("\t")>=0) {
  16.       bytepos=ReadInfo("byte_position")-1;
  17.       size=0;
  18.       del=1;
  19.       while (bytepos>=0 && GetChar(bytepos)=='\t') {
  20.         bytepos--;
  21.         size+=tabsize;
  22.         del++;
  23.         CursorLeft();
  24.       }
  25.       size+=tabsize-((ReadInfo("column")-1)%tabsize);
  26.       Delete(del);
  27.       Output(sprintf(joinstr("%",ltostr(size), "lc"), ' '));
  28.       if (!(counter++&15))
  29.         Status(id, ltostr(ReadInfo("line")));
  30.     }
  31.     Kill(new);
  32.     CurrentBuffer(id);
  33.     Visible(1);
  34.   }
  35. }
  36.  
  37. void SpaceToTab()
  38. {
  39.   int id=GetEntryID();
  40.   int new=DuplicateEntry();
  41.  
  42.   if (new) {
  43.     int lines, tabsize, bytepos, del, column, counter;
  44.     string output;
  45.     Visible(0);
  46.     CurrentBuffer(new);
  47.     Status(id, "Space converting.");
  48.     tabsize=ReadInfo("tab_size");
  49.     lines=ReadInfo("lines");
  50.     GotoLine(lines, ReadInfo("line_length", new, lines));
  51.     SearchSet("f-");
  52.     while (Search("  ")>=0) {
  53.       switch ((ReadInfo("column"))%tabsize) {
  54.       case tabsize-1:
  55.         bytepos=ReadInfo("byte_position")-1;
  56.         del=2;
  57.         output="\t";
  58.         while (bytepos>=0 && GetChar(bytepos)==' ') {
  59.           bytepos--;
  60.           if (!(del%tabsize))
  61.             output+="\t";
  62.           del++;
  63.           CursorLeft();
  64.         }
  65.         Delete(del);
  66.         Output(output);
  67.         if (!(counter++&15))
  68.           Status(id, ltostr(ReadInfo("line")));
  69.         break;
  70.       case 0:
  71.         CursorRight();
  72.       }
  73.     }
  74.     Kill(new);
  75.     CurrentBuffer(id);
  76.     Visible(1);
  77.   }
  78. }
  79.  
  80. AssignKey("ExecuteFile(\"TabConvert.FPL\", \"TabToSpace();\");", "Amiga 'tab'");
  81. AssignKey("ExecuteFile(\"TabConvert.FPL\", \"SpaceToTab();\");", "Amiga Shift 'tab'");
  82.  
  83.