Created
January 31, 2014 15:56
-
-
Save macdrifter/8734840 to your computer and use it in GitHub Desktop.
Sublime Text method for use with the TaskPaper format. Function to display list of all projects and allow jumping to one from the list.
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 | |
# For use with the TaskPaper format. Function to display list of all projects and allow jumping to one from the list. | |
class ListProjectsCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
self.markers = [] | |
self.view.find_all(r'^\s*(\w+.+:\s*(\@[^\s]+(\(.*?\))?\s*)*$\n?)|^\s*---.{3,5}---+$', 0, "$1", self.markers) | |
self.view.window().show_quick_panel(self.markers, self.goto_project, sublime.MONOSPACE_FONT) | |
def goto_project(self, choice): | |
if choice == -1: | |
return | |
else: | |
findmarker = self.markers[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