This little script is for using checkboxes in ASCII files.
If you don't have a checkbox in the current line the script adds a " " at the current position. If you do have a checkbox it toggles its state.
from Npp import *
# A simple helper script for using ASCII todo lists
# The basic implementation knows 3 different states
# [ ] To Do
# [x] Done
# [o] Currently not possible to do
# The script is able to toggle between this states. If
# you want only two states or if you want more states
# just edit the checkboxes string list.
# If a line doesn't contain a checkbox the script
# just inserts one at the current position.
def nextElem(arr, curPos):
if (curPos + 1 < len(arr)):
return arr[curPos + 1]
checkboxes = ['[ ]', '[x]', '[o]']
curLine = editor.getCurLine()
curPos = editor.getCurrentPos()
curLineNr = editor.lineFromPosition(curPos)
strippedLine = curLine.lstrip()
insertChkBx = True
for i in range(len(checkboxes)):
elem = checkboxes[i]
curLine = curLine.replace(elem, nextElem(checkboxes, i), 1).rstrip('\n')
insertChkBx = False
editor.addText('[ ] ')
Code is under GPLv2. Have fun.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.