Skip to content

Instantly share code, notes, and snippets.

@macdrifter
Last active May 27, 2018 05:11
Show Gist options
  • Save macdrifter/8736798 to your computer and use it in GitHub Desktop.
Save macdrifter/8736798 to your computer and use it in GitHub Desktop.
Sublime Text function to display available tasks from a TaskPaper file. Looks for @start, @Due and @started tags with dates before today's date
import sublime, sublime_plugin
import re
import time
class AvailableTasksCommand(sublime_plugin.TextCommand):
def run(self, edit):
today_date = time.strftime('%Y-%m-%d')
self.available_marker = []
self.markers = []
self.view.find_all(r'(^\n*(\s*)(.+)(@start|@due|@started)\((20[1-9][0-9]\-[0-1][0-9]\-[0-3][0-9])\))', 0, "$0,$5", self.markers)
for marker in self.markers:
if time.strptime(marker.split(',')[1], '%Y-%m-%d') <= time.strptime(today_date, '%Y-%m-%d'):
self.available_marker.append(marker.split(',')[0])
self.view.window().show_quick_panel(self.available_marker, self.goto_task, sublime.MONOSPACE_FONT)
def goto_task(self, choice):
if choice == -1:
return
else:
findmarker = self.available_marker[choice]
self.view.sel().clear()
# re.escape escapes a single quote. That breaks the Sublime find function.
# Need to substitute escaped single quote with just single quote
findmarker = findmarker.replace("{", "\{").replace("}", "\}").replace("[", "\[").replace("]", "\]").replace("(", "\(").replace(")", "\)").replace("+", "\+")
pt = self.view.find(findmarker, 0)
self.view.sel().add(pt)
self.view.show(pt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment