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]))
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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.