C/C++/C# programmers would do that with the help of the preprocessor. I don't know if JSP files are precompiled and a preprocessor exists.
There would be a very fast solution by inserting at column 1 an auto-increment number using command Insert Number with a separater column, next use a tagged regular expression replace to replace all the line numbers in content of file and finally delete the separater and the line number columns at start of every line. But this solution does not work for multiple line number references in one line and the undo steps recorded for that fast "update line numbers" method would not be fine when editing.
Therefore I post here a script which makes the line number updates on execution line reference by line reference and shows you in a message box how many line numbers were found and how many of them were updated. Of course without this additional information the script would be a little bit faster.
- Code: Select all
if (UltraEdit.document.length > 0) { // Is any file opened?
// Define the environment for the script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.ueReOn();
// Remember the current cursor position to restore it at end of script.
var nCurLine = UltraEdit.activeDocument.currentLineNum;
var nCurColumn = UltraEdit.activeDocument.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nCurColumn++;
// Go to top of the file and define the needed options for the searches.
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
// Define the variables used in the following loop.
var nLineRefChanged = 0;
var nLineRefCount = 0;
var sFoundLineNum = "";
var sActiveLineNum = "";
var sFoundLineRef = "";
while (UltraEdit.activeDocument.findReplace.find("Line [0-9]+") ) {
nLineRefCount++; // Found one more line reference.
// Get current line number from selected line reference string.
// and compare it with the line number of active line.
sFoundLineRef = UltraEdit.activeDocument.selection;
sFoundLineNum = sFoundLineRef.substring(5);
sActiveLineNum = UltraEdit.activeDocument.currentLineNum.toString(10);
if (sFoundLineNum != sActiveLineNum) {
nLineRefChanged++; // The line number in this reference must be updated.
UltraEdit.activeDocument.write(sFoundLineRef.substr(0,5)+sActiveLineNum);
}
}
UltraEdit.activeDocument.gotoLine(nCurLine,nCurColumn);
sFoundLineRef = nLineRefCount == 1 ? "" : "s";
UltraEdit.messageBox(nLineRefChanged+" of "+nLineRefCount+" line reference"+sFoundLineRef+" updated.","Update Line Reference Result");
}
As you can see the script searches for all occurrences of word
line in any case followed by a single space followed by an integer number. You can define your own rules. The script uses the UltraEdit regular expression engine, but you can use also the Unix or Perl regexp engine by changing the command
UltraEdit.ueReOn(). The search string as is would work with all 3 engines.