getcom indentation, if you need it

getcom indentation, if you need it

51
NewbieNewbie
51

    May 31, 2009#1

    Code: Select all

    // ----------------------------------------------------------------------------
    // getcom_indent.js
    // KrisK 5/31/2009 3:20:41 PM
    // ----------------------------------------------------------------------------
    
    // Create new file.  This will also become the active file.
    // because I am not genius!
    
    UltraEdit.activeDocument.selectAll();
    UltraEdit.activeDocument.copy();
    UltraEdit.newFile();
    UltraEdit.activeDocument.paste();
    
    // RegEx...
    // ? I cannot get /1 inside as a variable so I am
    // rolling back to pure javaScript
    //
    //UltraEdit.perlReOn(); /* Let's use Unix regexp syntax */
    //UltraEdit.activeDocument.findReplace.regExp = true;
    //UltraEdit.activeDocument.findReplace.replaceAll = false;
    //var regexpFind = "^.*(\d+)\s+(.*)$";
    
    //we will try to process something like this...
    //
    //0 @I1@ INDI
    //1 NAME Bernt Olaf /Skonnord/
    //1 SEX M
    //1 BIRT
    //2 DATE 14 Jun 1860
    //2 PLAC Snertingdal, Oppland, Norway
    //1 DEAT Y
    //1 SOUR @S2@
    //1 FAMC @F306458249@
    //
    
    UltraEdit.activeDocument.top();
    
    while ( ! UltraEdit.activeDocument.isEof() )
    {
       UltraEdit.activeDocument.selectLine();
       var textt = UltraEdit.activeDocument.selection;
       UltraEdit.activeDocument.cut();
    
       // JavaScipt String magic
    
       // to reset prior indentation ;-)
       // it is not implemented - trim here so we have to use function
       // to simulate - but that will be verssion 2
       // we can use UE replace to cleanup the leading spaces if need to
       //
       //textt = textt.trim();
    
       var pos = textt.indexOf(" ");
    
       if (pos >=0 )
       {
          var count = textt.substring(0,pos);
    
          // we do not want to dlete value of indentation
          // textt = textt.substr(pos+1);
    
          var space = "";
    
          for (var i = 0; i < count; i++) {
             //space = space.concat(space," ");
             space += "    ";
          }
    
         // s4=s1.concat(s2,s3) // returns "Oh what a beautiful mornin'."
    
       }
    
       UltraEdit.activeDocument.write(space +textt);
    
       // UltraEdit.activeDocument.paste();
    }
    
    
    
    // reposition to top after renumbering
    UltraEdit.activeDocument.top();
    
    UltraEdit.outputWindow.write("DEBUG ending.");
    
    Enjoy, if you have better solution, please post it :-)