Menu

Modify Lines

l0basetom
2015-06-24
2015-06-24
  • l0basetom

    l0basetom - 2015-06-24

    This script emulates the basic functionality of the Modify Lines command in Notepad2. It allows you to select a bunch of lines and add some text before and at the end of each of the selected lines. If no text is selected, then it will act on every line in the document.

    Code:

    sInput = notepad.prompt('Enter the text to prefix before each selected line, followed by a line break (Ctrl+Enter), then the text to append to the end of each selected line.', 'Modify Lines', editor.getProperty('modify_lines'))
    if sInput:
        # Save to reuse the next time this script is called
        editor.setProperty('modify_lines', sInput)
        # aInput[0] = line prefix
        # aInput[1] = line postfix (optional)
        aInput = sInput.splitlines()
        # aSelLines[0] = start line number of selection
        # aSelLines[1] = end line number of selection
        aSelLines = editor.getUserLineSelection()
        # Do the replacement (multi-line mode is enabled by default)
        editor.rereplace('^', aInput[0], 0, editor.positionFromLine(aSelLines[0]), editor.getLineEndPosition(aSelLines[1]))
        if len(aInput) > 1:
            editor.rereplace('$', aInput[1], 0, editor.positionFromLine(aSelLines[0]), editor.getLineEndPosition(aSelLines[1]))
    
     
    • Sasumner

      Sasumner - 2015-06-24

      Nice! I don't know if I'll use it directly, but I learned some techniques from it (.setProperty/.getProperty, use of ctrl+enter) that I will apply to my own scripts. Thanks.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.