Skip navigation
dhladky

UltraEdit scripting

Posted by dhladky Aug 8, 2013

I got really mad while trying to do scripting in Fedora version of UltraEdit.  I have been trying simple thing: I have XML file with repositories:

<repository>

<id>someid</id>

.....

</repository>

 

I wanted to create a script, that will copy paste some of the repositories to another file based on an array of repository identifiers. I spent two days until I gave up.

 

Problem 1 - Reverted Search

 

UltraEdit.activeDocument.findReplace.searchDown=true;

UltraEdit.activeDocument.findReplace.find("<id>"+repotofind+"</id>");

 

What would you expect from such script? I thought it will start searching from the current position until it finds the searched string. The problem was that in a loop it always returned the first search hit in the file. It took me four hours until I realized searchDown means search from the current position up to the begining of the file. Sigh! Problem solved, let us continue with the script.

 

Problem 2 - Unsupported Selection

I finally moved to the repository definition. Now I would like to go to the <repository> tag, select everything up to </repository> and write it to another file. Based on http://www.ultraedit.com/help/article/scripting-commands-1245.html it should be easy. Knowing how to set searchDown property to go up and down, it was easy to find the proper start end end tag, read the position and copy the selection into clipboard.

 

UltraEdit.activeDocument.findReplace.searchDown=false;

UltraEdit.activeDocument.findReplace.find("</repository>");

var endposition=UltraEdit.activeDocument.currentPos;

UltraEdit.activeDocument.findReplace.searchDown=true;

UltraEdit.activeDocument.findReplace.find("<repository>");

UltraEdit.activeDocument.gotoPosSelect(endposition);

UltraEdit.activeDocument.copy();

 

But alas! gotoPosSelect makes the script to report failure. The same with function cancelSelect(); Operation as easy as select everything from here to there is not supported.

Problem 3 - Regular Pattern Search

I than had a brilliant idea. I will let the search to select the whole block. UltraEdit supports three regex modes - Unix, UltraEdit and Perl. After some time I realized, that it is not possible to make a regular pattern, that would select text broken by a new line character(s). Both "*" (in Linux mode) and "++" (in UltraEdit mode) stop working on the end of the line. Even in case like [.\n]*.

 

Based on the documentation by UltraEdit (http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/perl-regular-expressions-digging-deeper.html), multiline search is possible in Perl way. I tried "(?s)<repository>\s*<id>orgfusesource.*</id>.*?</repository>" in search dialog and everything was fine (".*?" is a non-greedy variant of zero or more characters).

 

I put the search string into the script file, changed the hardcoded repository name to a variable, so it looked like

 

UltraEdit.activeDocument.findReplace.find("(?s)<repository>\s*<id>"+reponame+"</id>.*?</repository>");

 

And UltraEdit ended up in an infinite loop of some type, probably. When I aborted the text, I realized it is trying to do the greedy variant o .* (despite the question mark).

 

No Other Way To Do The Selection - Giving Up

 

And this is it. After two days of searching any way to select text, I am giving up and searching for another solution. I am very sad I put such effort to make it work and not to mention I spent quite a lot of money for the UltraEdit license. This article is based on UltraEditProfessional Text/HEX Editor, Version 4.1.0.5, Fedora 17 (Linux version of UltraEdit).

Filter Blog

By date: