Last active
May 27, 2018 05:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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