Script for Equal-sign alignment

Help with writing and running scripts

Script for Equal-sign alignment

Postby Bego » Wed Apr 18, 2007 1:41 pm

Hi guys,

Here is my Align script I was unable to do with UE-macro language.
Imagine you have (huge) code like this:
Code: Select all
     lala   =  abc
  lalalalala     =   def
    la  = ghi
  baba = jkl asdf sdsdfas


and want it to be like this (left align):

Code: Select all
     lala       = abc
     lalalalala = def
     la         = ghi
     baba       = jkl asdf sdsdfas


or that (right align):

Code: Select all
           lala = abc
     lalalalala = def
             la = ghi
           baba = jkl asdf sdsdfas


So from now on you can call my macro. Remember: Moving the mouse while the macro runs accelerates the macro.
This is known UE/JS-behaviour. Don't ask me ....

Here is the script alignEqual.js, that has also posted-code from other Forum members. Thx for that again.:

EDIT: SEE BELOW FOR IMPROVED CODE

Hope it is helpful.

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby jorrasdk » Wed Apr 18, 2007 2:04 pm

To your question: "UE seems to stop here. but why ?" in
Code: Select all
...
closeFile();

//UE seems to stop here. but why ?
//UltraEdit.activeDocument.write("Will not work: UltraEdit.activeDocument.paste()");
UltraEdit.selectClipboard(8);
UltraEdit.document[0].paste();
UltraEdit.selectClipboard(0);
...


my guess would be that since you close the active file further down
Code: Select all
UltraEdit.closeFile(CurrentFileName,2);


no other file automatically takes focus. Use setActive on the document you want to be activeDocument.
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Script for Equal-sign alignment

Postby Bego » Thu Apr 19, 2007 5:13 am

I thought of sth. like this too, but if you save the original document-index with this:
Code: Select all
var myDocNo;
myDocNo = getActiveDocumentIndex();  //properly set


after the close & reset you get an UE-crash:
Code: Select all
UltraEdit.document[myDocNo].setActive();


It also chrashes here with a hardcoded 0 in it, by the way.
Can you confirm ? If so, I'll write an error report.

There seems to be "sth. wrong in the state of Denmark" ;-) with file/tab handling and javascript here..

rds Bego :-)
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby mik0001 » Thu Apr 19, 2007 5:47 am

The crash was also recognized here:
http://www.ultraedit.com/index.php?name ... pic&t=4575

You can write an error-report if you want.
User avatar
mik0001
Basic User
Basic User
 
Posts: 37
Joined: Fri Mar 16, 2007 11:00 pm
Location: Germany

Re: Script for Equal-sign alignment

Postby Bego » Thu Apr 19, 2007 5:48 am

Danke Mik, I'll do this evening.
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby jorrasdk » Thu Apr 19, 2007 6:31 am

Yeah, setActive is defect. But I found a way to get your alignEqual.js to work with only minor dependence of activeDocument:

Notice that the source document you are going to paste the aligned text back to is captured this way:
Code: Select all
sourceDoc = UltraEdit.document[getActiveDocumentIndex()];

(sourceDoc = UltraEdit.activeDocument; will not work! For some reason we need to work with the document[] object).


Then we don't need to set anything active and just perform
Code: Select all
sourceDoc.paste();


Every other reference to UltraEdit.activeDocument is replaced by orgDoc. Here is the full script again:

Code: Select all
//alignEqual.js
//Bego
//Aligns the SELECTION by the Equal-sign. Might be configured with Left or Right alignment!
//
var sourceDoc;
var orgDoc;
var maxColEqual = 0;
var pos1 = 0;
var MYSIGN = "=";
var MYALIGN = "L";   //(L)eft or (R)ight
//ZUM TEST ALLES MARKIEREN UND KOPIEREN STATT MOVEN:
//UltraEdit.activeDocument.selectAll();

sourceDoc = UltraEdit.document[getActiveDocumentIndex()];
UltraEdit.selectClipboard(8);
sourceDoc.cut();

UltraEdit.newFile();
orgDoc = UltraEdit.activeDocument;
orgDoc.paste();
orgDoc.top();

pos1 = getColOfFirstChar() - 1;
stripEqualRemoveLeadingSpaces();
maxColEqual = getMaxColEqual();
stuff(pos1, maxColEqual, MYALIGN);

UltraEdit.selectClipboard(8);
orgDoc.selectAll();
orgDoc.copy();
closeFile();

UltraEdit.selectClipboard(8);
sourceDoc.paste();
UltraEdit.selectClipboard(0);

///////////////////////////////////////////////////////////////////////////////////////////////////

function stuff(pPos1, pMaxCol, pAlign) {
   var col;
   var spaces = "                                                                                                                                   "

   orgDoc.top();
   //go through once again and stuff spaces, depending on the position of the equal-sign and the calculated maxPosition
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      orgDoc.key("LEFT ARROW"); orgDoc.key("RIGHT ARROW"); //unmark selection
      col = getCol();
      orgDoc.key("HOME");
      if (pAlign == "R") {
         orgDoc.write(spaces.substring(0,pMaxCol - col + pPos1));
      }
      else
      {
         orgDoc.write(spaces.substring(0,pPos1));
         //reposition in front of sign and stuff here
         orgDoc.findReplace.find(MYSIGN);
         orgDoc.key("LEFT ARROW");   
         orgDoc.write(spaces.substring(0,pMaxCol - col));         
      }
      orgDoc.key("END");
   }
}   

function getMaxColEqual() {
  //get the mostright equal-sign in the selection. This is the orientation for the stuffing-spaces at the beginning of the line.
  var max = 0;
  var col = 0;
  orgDoc.top();
  orgDoc.findReplace.replaceAll = false;
  orgDoc.findReplace.regExp = false;
  while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {     
      col = getCol();
      orgDoc.key("END");//continue search in next line
      if (col > max) {
         max = col;
      }
  }
  return max;
}
 


function stripEqualRemoveLeadingSpaces() {
   //ONE space before and after equal-sign. cut all leading spaces.
   orgDoc.top();
   orgDoc.findReplace.replaceAll = true;
   orgDoc.findReplace.regExp = true;
   orgDoc.findReplace.replace("\\s*\=\\s*", " = ");
   orgDoc.findReplace.replace("^\\s*", "");
}
   
 
function closeFile() {
   UltraEdit.selectClipboard(9);
   orgDoc.copyFilePath();
   orgDoc.top();
   orgDoc.paste();
   orgDoc.selectToTop();
   var CurrentFileName = orgDoc.selection;
   orgDoc.deleteText();
   UltraEdit.closeFile(CurrentFileName,2);
   UltraEdit.clearClipboard();
   UltraEdit.selectClipboard(0);
}

function getColOfFirstChar() {
   orgDoc.findReplace.regExp = true;
   orgDoc.key("HOME");
   orgDoc.findReplace.find("\\w");   
   return getCol();
}

function getCol() {
  //get the current Column.
  //speed-optimized. Hop to the right in steps. Then, when being bigger, hop back one by one.
  //Kind of "binary-tree" for fools ;-)
  var i = 1;
  var iStep = 10;
 
  orgDoc.key("LEFT ARROW"); orgDoc.key("RIGHT ARROW"); //unmark selection
  while (true) {
    if (orgDoc.isColNumGt(i)) {
       //still too much on the left side.
       i = i + iStep;
    }
    else
    {
      //hopped too far. go a little bit back
      for (var j = 0; j < iStep; j++) {
        //UltraEdit.document[1].write(String(j));
        if (orgDoc.isColNum(i-j)) {
          //match !
          //UltraEdit.document[1].write("Match mit " + String(j));
          return (i-j);
        }
      }
    };
  }
  return i;
}

/* Find the tab index of the active document */
function getActiveDocumentIndex() {
   var tabindex = -1; /* start value */

   for (i = 0; i < UltraEdit.document.length; i++)
   {
      if (UltraEdit.activeDocument.path==UltraEdit.document[i].path) {
         tabindex = i;
         break;
      }
   }
   return tabindex;
}
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Script for Equal-sign alignment

Postby Bego » Thu Apr 19, 2007 7:18 am

GREAT. Thank you!
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby Bego » Sun May 27, 2007 5:36 pm

Here is the script in a new version that I modified while BETA TESTING 13.10.
So this is ONLY for the other Beta-guys here or for UE from version 13.10 on.
Some new enhancements / bugfixes let the code shrink quite a bit :-)
Here we go:

Code: Select all
//alignEqual.js
//Bego
//Aligns the SELECTION by the Equal-sign. Might be configured with Left or Right alignment!
//
var orgDoc;
var sourceDoc;
var maxColEqual = 0;
var pos1 = 0;
var myDocNo;
var MYSIGN = "=";
var MYALIGN = "L"; //(L)eft or (R)ight
sourceDoc = UltraEdit.document[getActiveDocumentIndex()];

//ZUM TEST ALLES MARKIEREN UND KOPIEREN STATT MOVEN:
//UltraEdit.activeDocument.selectAll();
UltraEdit.selectClipboard(8);
UltraEdit.activeDocument.cut();
UltraEdit.newFile();
orgDoc = UltraEdit.activeDocument;
orgDoc.paste();
orgDoc.top();

pos1 = getColOfFirstChar() - 1;
stripEqualRemoveLeadingSpaces();
maxColEqual = getMaxColEqual();
stuff(pos1, maxColEqual, MYALIGN);

UltraEdit.selectClipboard(8);
orgDoc.selectAll();
orgDoc.copy();
UltraEdit.closeFile(); //ab UE 13.10

//UltraEdit.document[3].setActive(); //CRASH. Still a bug !!!
UltraEdit.selectClipboard(8);
sourceDoc.paste();
UltraEdit.selectClipboard(0);

///////////////////////////////////////////////////////////////////////////////////////////////////

function stuff(pPos1, pMaxCol, pAlign) {
   var col;
   var spaces = "                                                                 "
   
   orgDoc.top();
   //go through once again and stuff spaces, depending on the position of the equal-sign and the calculated maxPosition
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      orgDoc.key("LEFT ARROW"); orgDoc.key("RIGHT ARROW"); //unmark selection     
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("HOME");
      if (pAlign == "R") {
         orgDoc.write(spaces.substring(0,pMaxCol - col + pPos1));     
      }
      else
      {
         orgDoc.write(spaces.substring(0,pPos1));       
         //reposition in front of sign and stuff here
         orgDoc.findReplace.find(MYSIGN);
         orgDoc.key("LEFT ARROW");         
         orgDoc.write(spaces.substring(0,pMaxCol - col));   
      }
      orgDoc.key("END"); 
   }
}

function getMaxColEqual() {
   //get the mostright equal-sign in the selection. This is the orientation for the stuffing-spaces at the beginning of the line.
   var max = 0;
   var col = 0;
   
   orgDoc.top();
   orgDoc.findReplace.replaceAll = false;
   orgDoc.findReplace.regExp = false;
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) { 
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("END");//continue search in next line 
      if (col > max) {
         max = col;
      }
   }
   return max;
}
 


function stripEqualRemoveLeadingSpaces() {
   //ONE space before and after equal-sign. cut all leading spaces.
   orgDoc.top();
   orgDoc.findReplace.replaceAll = true; 
   orgDoc.findReplace.regExp = true;
   orgDoc.findReplace.replace("\\s*\=\\s*", " = ");
   orgDoc.findReplace.replace("^\\s*", "");
}

function getColOfFirstChar() {
   //determins in which column the line starts with content
   orgDoc.findReplace.regExp = true;
   orgDoc.key("HOME");
   orgDoc.findReplace.find("\\w");
   //return getCol();
   var col = orgDoc.currentColumnNum;  //ab 13.10
   if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
}

function getActiveDocumentIndex() {
   var tabindex = -1; /* start value */

   for (i = 0; i < UltraEdit.document.length; i++)
   {
      if (UltraEdit.activeDocument.path == UltraEdit.document[i].path) {
         tabindex = i;
         break;
      }
   }
   return tabindex;
}


Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby jorrasdk » Mon May 28, 2007 10:15 am

Hi Bego

As I am also a beta tester, I tested your new 13.10betaI version and it worked fine except for:

Code: Select all
...
UltraEdit.closeFile(); //ab UE 13.10

//UltraEdit.document[3].setActive(); //CRASH. Still a bug !!!
...


From the Beta-helpfile, I can't see that closefile() will be able to be called without file path and save mode. At least it doesn't work for me.

But rumour has it that the path property of the document object is going to be documented in the final 13.10, so you can write:
Code: Select all
UltraEdit.closeFile(orgDoc.path,2);


And I confirm, that setActive still crashes UE in 13.10betaI. The UE developers have received a dump file and is looking into it.
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Script for Equal-sign alignment

Postby Bego » Mon May 28, 2007 5:11 pm

Hi Jo,

You are right, I must have missed that one. UE just runs through this line WITHOUT closing and WITHOUT an error.
With the path-issue it runs ok, so I can also live with it :-)

Thank you, Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby toddm » Wed Oct 24, 2007 9:30 pm

Bego, I didn't spend more than a couple minutes looking at your script, but I'm wondering if you know offhand how to make it align other strings like <=.

I tried changing MYSIGN and that didn't work.

Also, the code I'm trying to align is indented and after aligning there is one less indentation space. Is this expected?

Thanks.
User avatar
toddm
Advanced User
Advanced User
 
Posts: 83
Joined: Wed Jul 28, 2004 11:00 pm

Re: Script for Equal-sign alignment

Postby Bego » Thu Oct 25, 2007 9:16 am

Hi todd,

Unfortunately the script is quite hard based for aligning ONE character.
For more I would also have to think about more and I don't have the time right now.
But I disabled the feature "move to left one columns" ;-)

@Jorgen: Can you pls have a look at the function stripEqualRemoveLeadingSpaces ?
I try to put the search-string into a variable and fail because of the backslashes in it.
Code: Select all
orgDoc.findReplace.replace("\\s*\=\\s*", " = ");


Thx, Bego

Code: Select all
//alignEqual.js
//Bego
//Aligns the SELECTION by the Equal-sign. Might be configured with Left or Right alignment!
//Version 1.1     25.10.2007 result once was shifting 1 column to the left for each run:   pos1 = getColOfFirstChar();// - 1;
//
var orgDoc;
var sourceDoc;
var maxColEqual = 0;
var pos1 = 0;
var myDocNo;
var MYSIGN = "=";
var MYALIGN = "L"; //(L)eft or (R)ight
sourceDoc = UltraEdit.document[getActiveDocumentIndex()];

//ZUM TEST ALLES MARKIEREN UND KOPIEREN STATT MOVEN:
//UltraEdit.activeDocument.selectAll();
UltraEdit.selectClipboard(8);
UltraEdit.activeDocument.cut();
UltraEdit.newFile();
orgDoc = UltraEdit.activeDocument;
orgDoc.paste();
orgDoc.top();

pos1 = getColOfFirstChar();
stripEqualRemoveLeadingSpaces();

maxColEqual = getMaxColEqual();
stuff(pos1, maxColEqual, MYALIGN);

UltraEdit.selectClipboard(8);
orgDoc.selectAll();
orgDoc.copy();
UltraEdit.closeFile(); //ab UE 13.10

//UltraEdit.document[3].setActive(); //CRASH. Still a bug !!!
UltraEdit.selectClipboard(8);
sourceDoc.paste();
UltraEdit.selectClipboard(0);



///////////////////////////////////////////////////////////////////////////////////////////////////

function stuff(pPos1, pMaxCol, pAlign) {
   var col;
   var spaces = "                                                                 "
   
   orgDoc.top();
   //go through once again and stuff spaces, depending on the position of the equal-sign and the calculated maxPosition
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      orgDoc.key("LEFT ARROW"); orgDoc.key("RIGHT ARROW"); //unmark selection     
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("HOME");
      if (pAlign == "R") {
         orgDoc.write(spaces.substring(0,pMaxCol - col + pPos1));     
      }
      else
      {
         orgDoc.write(spaces.substring(0,pPos1));       
         //reposition in front of sign and stuff here
         orgDoc.findReplace.find(MYSIGN);
         orgDoc.key("LEFT ARROW");         
         orgDoc.write(spaces.substring(0,pMaxCol - col));   
      }
      orgDoc.key("END");
   }
}

function getMaxColEqual() {
   //get the mostright equal-sign in the selection. This is the orientation for the stuffing-spaces at the beginning of the line.
   var max = 0;
   var col = 0;
   
   orgDoc.top();
   orgDoc.findReplace.replaceAll = false;
   orgDoc.findReplace.regExp = false;
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("END");//continue search in next line
      if (col > max) {
         max = col;
      }
   }
   return max;
}
 


function stripEqualRemoveLeadingSpaces() {
   //ONE space before and after equal-sign. cut all leading spaces.
   orgDoc.top();
   orgDoc.findReplace.replaceAll = true;
   orgDoc.findReplace.regExp = true;
   orgDoc.findReplace.replace("\\s*\=\\s*", " = ");
   orgDoc.findReplace.replace("^\\s*", "");
}

function getColOfFirstChar() {
   //determins in which column the line starts with content
   orgDoc.findReplace.regExp = true;
   orgDoc.key("HOME");
   orgDoc.findReplace.find("\\w");
   //return getCol();
   var col = orgDoc.currentColumnNum;  //ab 13.10
   if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
   return col;
}

function getActiveDocumentIndex() {
   var tabindex = -1; /* start value */

   for (i = 0; i < UltraEdit.document.length; i++)
   {
      if (UltraEdit.activeDocument.path == UltraEdit.document[i].path) {
         tabindex = i;
         break;
      }
   }
   return tabindex;
}
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Script for Equal-sign alignment

Postby Mofi » Thu Oct 25, 2007 9:33 am

Hi Bego,

what I miss in your script is UltraEdit.perlReOn();

And orgDoc.findReplace.replace("\\s*=\\s*", " = ");
works also fine. No need to escape the equal sign.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Script for Equal-sign alignment

Postby jorrasdk » Thu Oct 25, 2007 10:02 am

Hi Bego

It's quite annoying with javascripts escape character \ and regexp's ditto meaning you have to escape the escape character when writing regexp's as strings like

orgDoc.findReplace.replace("\\s*=\\s*", " = ");

Lately I have started to use the following trick that makes me able to cut and paste regexp to and from javascripts without always remembering to escape backslashes. This way its easy to copy a Regexp to UE's find box to test it (or test it in RegexBuddy).

First assign a variable a Regexp object (note: no surrounding string characters, and no need for double backslash):

var myRegexp = /\s*=\s*/;

At the top of my script I extend the Regexp object with an extra method using Prototype. This method removes the starting and ending forwardslash when a Regexp object is converted to string. UE's replace and find only take string objects:

RegExp.prototype.toUEregexp = function() { return this.toString().replace(/^\/|\/$/g, ""); };

Then I can use my regexp object variable directly in a UE replace/find like this:

orgDoc.findReplace.replace(myRegexp.toUEregexp(), " = ");

or even like this:
orgDoc.findReplace.replace(/\s*=\s*/.toUEregexp(), " = ");

Note: I almost always use Perl regexp's in scripts as the same regexp can be used in internal javascript (like in the match method) and in UE's find and replace.

You can't use this trick if you use UE style regexp for UE find/replace as assigning a non-Perl regexp to a javascript Regexp object will fail.
Example: This will fail as it is not valid Perl regexp syntax:
var myRegexp = /[ ]++=[ ]++/;
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Script for Equal-sign alignment

Postby Bego » Thu Oct 25, 2007 10:09 am

Hi Mofi,

thx for the tips.

ADDED: Hi Jorgen, very good :-) Thx a lot. Will have a closer look at it at home :-)

I added them now in Version 1.2:
Code: Select all
//        1.2     25.10.2007 Now MYSIGN can be really sth. else like "=", e.g. "/", but yet still only ONE character


Code: Select all
//alignEqual.js
//Bego
//Aligns the SELECTION by the Equal-sign. Might be configured with Left or Right alignment!
//Version 1.1     25.10.2007 result once was shifting 1 column to the left for each run:   pos1 = getColOfFirstChar();// - 1;
//        1.2     25.10.2007 Now MYSIGN can be really sth. else like "=", e.g. "/", but yet still only ONE character
var orgDoc;
var sourceDoc;
var maxColEqual = 0;
var pos1 = 0;
var myDocNo;
var MYSIGN = "=";
var MYALIGN = "L"; //(L)eft or (R)ight
sourceDoc = UltraEdit.document[getActiveDocumentIndex()];

UltraEdit.perlReOn();
//ZUM TEST ALLES MARKIEREN UND KOPIEREN STATT MOVEN:
//UltraEdit.activeDocument.selectAll();
UltraEdit.selectClipboard(8);
UltraEdit.activeDocument.cut();
UltraEdit.newFile();
orgDoc = UltraEdit.activeDocument;
orgDoc.paste();
orgDoc.top();

pos1 = getColOfFirstChar();
stripEqualRemoveLeadingSpaces();

maxColEqual = getMaxColEqual();
stuff(pos1, maxColEqual, MYALIGN);

UltraEdit.selectClipboard(8);
orgDoc.selectAll();
orgDoc.copy();
UltraEdit.closeFile(); //ab UE 13.10

//UltraEdit.document[3].setActive(); //CRASH. Still a bug !!!
UltraEdit.selectClipboard(8);
sourceDoc.paste();
UltraEdit.selectClipboard(0);



///////////////////////////////////////////////////////////////////////////////////////////////////

function stuff(pPos1, pMaxCol, pAlign) {
   var col;
   var spaces = "                                                                 "
   
   orgDoc.top();
   //go through once again and stuff spaces, depending on the position of the equal-sign and the calculated maxPosition
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      orgDoc.key("LEFT ARROW"); orgDoc.key("RIGHT ARROW"); //unmark selection     
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("HOME");
      if (pAlign == "R") {
         orgDoc.write(spaces.substring(0,pMaxCol - col + pPos1));     
      }
      else
      {
         orgDoc.write(spaces.substring(0,pPos1));       
         //reposition in front of sign and stuff here
         orgDoc.findReplace.find(MYSIGN);
         orgDoc.key("LEFT ARROW");         
         orgDoc.write(spaces.substring(0,pMaxCol - col));   
      }
      orgDoc.key("END");
   }
}

function getMaxColEqual() {
   //get the mostright equal-sign in the selection. This is the orientation for the stuffing-spaces at the beginning of the line.
   var max = 0;
   var col = 0;
   
   orgDoc.top();
   orgDoc.findReplace.replaceAll = false;
   orgDoc.findReplace.regExp = false;
   while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
      col = orgDoc.currentColumnNum;  //getCol();
      if (typeof(UltraEdit.activeDocumentIdx) == "number") col--;
      orgDoc.key("END");//continue search in next line
      if (col > max) {
         max = col;
      }
   }
   return max;
}
 


function stripEqualRemoveLeadingSpaces() {
   //ONE space before and after equal-sign. cut all leading spaces.
   orgDoc.top();
   orgDoc.findReplace.replaceAll = true;
   orgDoc.findReplace.regExp = true;
   var strFind = "\\s*" + MYSIGN + "\\s*";
   orgDoc.findReplace.replace(strFind, " " + MYSIGN + " ");
   orgDoc.findReplace.replace("^\\s*", "");
}

function getColOfFirstChar() {
   //determins in which column the line starts with content
   orgDoc.findReplace.regExp = true;
   orgDoc.key("HOME");
   orgDoc.findReplace.find("\\w");
   //return getCol();
   return orgDoc.currentColumnNum;  //ab 13.10
}

function getActiveDocumentIndex() {
   var tabindex = -1; /* start value */

   for (i = 0; i < UltraEdit.document.length; i++)
   {
      if (UltraEdit.activeDocument.path == UltraEdit.document[i].path) {
         tabindex = i;
         break;
      }
   }
   return tabindex;
}
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Next

Return to Scripts