Aligning "=" using script in UE v13.00

Help with writing and running scripts

Aligning "=" using script in UE v13.00

Postby Dawk » Thu Feb 15, 2007 4:02 pm

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;
}

UltraEdit.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();
UltraEdit.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
User avatar
Dawk
Newbie
 
Posts: 5
Joined: Fri Feb 09, 2007 12:00 am
Location: Denmark

Re: Aligning "=" using script in UE v13.00

Postby Bego » Wed Feb 21, 2007 8:04 pm

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Scripts