Aligning "=" using script in UE v13.00

Aligning "=" using script in UE v13.00

5
NewbieNewbie
5

    Feb 15, 2007#1

    After giving up on writing this as a macro, I decided to try doing it with JavaScript. The following works, although it is a bit slow.

    Code: Select all

    function getpos()
    {
     pos = 0;
     while (UltraEdit.activeDocument.isColNumGt(pos))
     {
     pos++;
     }
     return pos;
    }
    
    if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
    else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
    
    var longest = 0;
    var pos;
    var current;
    var padding = "";
    
    UltraEdit.activeDocument.top();
    UltraEdit.activeDocument.findReplace.find("=");
    
    while (UltraEdit.activeDocument.isFound())
    {
     current = getpos();
     if (current > longest)
     { 
     longest = current;
     }
     UltraEdit.activeDocument.key("RIGHT ARROW");
     UltraEdit.activeDocument.findReplace.find("=");
    }
    UltraEdit.activeDocument.top();
    UltraEdit.activeDocument.findReplace.find("=");
    while (UltraEdit.activeDocument.isFound())
    {
     current = getpos();
     padding = "";
     for (var i = current; i < longest; i++)
     {
     padding += " ";
     }
     UltraEdit.activeDocument.write(padding+"=");
     UltraEdit.activeDocument.key("RIGHT ARROW");
     UltraEdit.activeDocument.findReplace.find("=");
    }
    UltraEdit.activeDocument.bottom();
    if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
    else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
    Before:

    Code: Select all

    suggestion = "no idea what to write here"
    xp = "quite a bit"
    beginning = "hard"
    asdf = 1233
    // comment line
    asdf2 = skumhest
    After:

    Code: Select all

    suggestion = "no idea what to write here"
    xp         = "quite a bit"
    beginning  = "hard"
    asdf       = 1233
    // comment line
    asdf2      = skumhest
    Regards from Denmark

    Dawk

    344
    MasterMaster
    344

      Feb 22, 2007#2

      Hi dawk,

      I tried to enhance your script by a regexp to replace leading blanks before aligning.
      Otherwise you get

      Code: Select all

      a = 12356
      bbb = 34566
        ccccccc = 0567567567
       dd = 3344
       
      --> your code

      Code: Select all

      a         = 12356
      bbb       = 34566
        ccccccc = 0567567567
       dd       = 3344
      but I want:

      Code: Select all

      a         = 12356
      bbb       = 34566
      ccccccc   = 0567567567
      dd        = 3344
      (or with 2 blanks less before the =)

      rds Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit