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.
fromNppimport*importstringimportsys# 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.defnextElem(arr,curPos):if(curPos+1<len(arr)):returnarr[curPos+1]else:returnarr[0]checkboxes=['[ ]','[x]','[o]']curLine=editor.getCurLine()curPos=editor.getCurrentPos()curLineNr=editor.lineFromPosition(curPos)strippedLine=curLine.lstrip()insertChkBx=Trueforiinrange(len(checkboxes)):elem=checkboxes[i]ifstrippedLine.startswith(elem):curLine=curLine.replace(elem,nextElem(checkboxes,i),1).rstrip('\n')editor.replaceWholeLine(curLineNr,curLine)editor.gotoPos(curPos)insertChkBx=Falsebreakif(insertChkBx):editor.addText('[ ] ')
Code is under GPLv2. Have fun.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
Code is under GPLv2. Have fun.