"Productivity: TaskList" by JohnLBevan
Rating:









(0 votes)
| Name: | Productivity: TaskList |
|---|---|
| Uploaded By: | JohnLBevan |
| Date Created: | July 14, 2010 5:46 p.m. |
| Date Modified: | July 14, 2010 5:46 p.m. |
| Description: | Pulls comments beginning with //todo: or #todo: into a separate output window, and displays which line number they appear on in the original. If you only want to extract comments from part of your document, highlight only the part that's of interest. |
| Num Views: | 440 |
| Num Downloads: | 168 |
Contents
# ########################################################### #
# created: 2010-07-14
# developer: JohnLBevan (http://developer42.wordpress.com)
# description: Pulls task comments out of code (just //todo:... or #todo:... for now; but easily customisable)
#
# modified: 2010-07-04
# by: JohnLBevan
import pn
import scintilla
import re, string
from pypn.decorators import script
todo = re.compile(r"((?:\/{2}|#)todo:.*$)",re.M)
offset = 0
@script("Task List", "Productivity")
def GetTaskList():
"""Pulls tasks from the doc (or selected text) and outputs to a new window"""
data = GetSelectedText(scintilla.Scintilla(pn.CurrentDoc()))
data = InsertLineNos(data)
lines = todo.findall(data) #NOfEachTuple(todo.findall(data),1) (required before I figured out ?:)
data = "\n".join(lines)
UpdateDocument(scintilla.Scintilla(pn.NewDocument(None)),data)
def GetSelectedText(editor):
"""pulls the selected text from the editor window, or the whole docs content if nothings selected"""
start = editor.SelectionStart
end = editor.SelectionEnd
if (start == end):
start = 0
end = editor.Length
else:
GetOffset(editor)
return editor.GetTextRange(start, end)
def GetOffset(editor):
"""works out what line number the selection starts at & stores it in a global variable"""
global offset
end = editor.SelectionStart
text = editor.GetTextRange(0, end)
offset = text.count("\n") #assumes there are no docs with just \r as a line break
def UpdateDocument(editor, content):
"""puts the content into the editor window"""
editor.BeginUndoAction()
editor.ClearAll()
editor.AddText(len(content), content)
editor.EndUndoAction()
def InsertLineNos(data):
"""puts in line numbers"""
data = data.replace("\r\n","\r") + '\r'
data = data.replace("\n","\r")
global offset
i = offset
while '\r' in data:
i = i + 1
data = data.replace("\r"," :: at line " + str(i)+"\n",1)
return data
def NOfEachTuple(tuples, n):
"""takes an array of tuples and returns a list containing just the nth item of each tuple"""
result = [0]
result.pop()
for t in tuples:
result.append(t[n])
return result