0

When quickly sharing code with team members, it would be nice to paste code with line numbers into an email/document.

Does anyone know how to do this with UltraEdit?

Current problem: Selected code below

1   PRINT 'WHAT IS YOUR NAME?'
2   INPUT NAME
3   PRINT 'HELLO':NAME

No option to copy/paste with line numbers so paste looks like:

PRINT 'WHAT IS YOUR NAME?'
INPUT NAME
PRINT 'HELLO':NAME

Thanks in advance.

Mofi
  • 46,139
  • 17
  • 80
  • 143

2 Answers2

1

UltraEdit has no built-in command to copy selected lines with line numbers to clipboard.

But it is possible to run an UltraEdit script to add line numbers to text copied before to the clipboard before pasting the block into email application.

// Get content of clipboard as an array of lines assuming that the
// clipboard contains text data and the lines have carriage return
// plus line-feed as line termination.
if (UltraEdit.clipboardContent.length)
{
    var asLines = UltraEdit.clipboardContent.split("\r\n");

    // Remove the last string from array if being empty because
    // the text in clipboard ends with a line termination.
    if (!asLines[asLines.length-1].length) asLines.pop();

    // Convert the number of lines to a string using decimal
    // system and replace each digit in string by character 0.
    var sLeadingZeros = asLines.length.toString(10).replace(/./g,'0');

    // Insert at beginning of each line a number with
    // leading zeros according to maximum number of lines.
    for (var nLine = 0; nLine < asLines.length; nLine++)
    {
        var sLineNumber = (nLine+1).toString(10);
        sLineNumber = sLeadingZeros.substr(sLineNumber.length) + sLineNumber;
        if (asLines[nLine].length)
        {
            asLines[nLine] = sLineNumber + "   " + asLines[nLine];
        }
        else  // For an empty line just add the line number without spaces.
        {
            asLines[nLine] = sLineNumber;
        }
    }

    // Append an empty string to array of lines to have finally the
    // block in clipboard terminated with carriage return and line-feed.
    asLines.push("");
    // Join the modified lines back to a block in clipboard.
    UltraEdit.clipboardContent = asLines.join("\r\n");
}

Copy & paste this script code into a new ANSI file and save it for example with file name Add Line Numbers.js. Then add this script to Scripts list without hotkey for execution from scripts lists after copying a block to clipboard or with a hotkey or chord (multi-key assignment) for quick execution by key.

It is of course also possible that the script itself makes the copy of selected text.

And it is also possible to use the real line numbers in active file when a slightly modified version of this script is executed on a selected text in active file instead of clipboard content.

Mofi
  • 46,139
  • 17
  • 80
  • 143
0

I received a reply to this question from IDM Computer Solutions (producer of UltraEdit):

Thank you for your message. I am sorry to say this feature is not currently available.

But it has been requested before and we are considering it. I've added your contact details to our log on the subject and we will let you know when an updated build is released that includes this capability.

Mofi
  • 46,139
  • 17
  • 80
  • 143