Skip to content

Commit

Permalink
cancelled tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkkk committed Oct 27, 2012
1 parent f6e8d08 commit 8e3c2f7
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{ "keys": ["ctrl+d"], "command": "complete","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+m"], "command": "cancel", "context": [{"key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+enter"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+i"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+shift+a"], "command": "archive","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] }
]

]
1 change: 1 addition & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{ "keys": ["super+d"], "command": "complete","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["super+m"], "command": "cancel", "context": [{"key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["super+enter"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["super+i"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["super+shift+a"], "command": "archive","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] }
Expand Down
1 change: 1 addition & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{ "keys": ["ctrl+d"], "command": "complete","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+m"], "command": "cancel", "context": [{"key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+enter"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+i"], "command": "new","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] },
{ "keys": ["ctrl+shift+a"], "command": "archive","context": [{ "key": "selector", "operator": "equal", "operand": "text.todo" }] }
Expand Down
2 changes: 1 addition & 1 deletion Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
"command": "open_file",
"args": {
"file": "${packages}/Tasks/Default (Windows).sublime-keymap",
"file": "${packages}/PlainTasks/Default (Windows).sublime-keymap",
"platform": "Windows"
},
"caption": "Key Bindings – Default"
Expand Down
3 changes: 2 additions & 1 deletion PlainTasks (Linux).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"open_tasks_bullet": "☐", // options: - | ❍ | ❑ | ■ | □ | ☐ | ▪ | ▫ | – | — ≡ → ›
"done_tasks_bullet": "✔", // options: + | ✓ | ✔
"canc_tasks_bullet": "✘",
"date_format": "(%y-%m-%d %H:%M)",
"done_tag": true,
"done_tag": true, // related to @cancelled as well
"color_scheme": "Packages/PlainTasks/tasks.hidden-tmTheme",
"font_size": 15,
"font_face": "Consolas",
Expand Down
3 changes: 2 additions & 1 deletion PlainTasks (OSX).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"open_tasks_bullet": "☐", // options: - | ❍ | ❑ | ■ | □ | ☐ | ▪ | ▫ | – | — ≡ → ›
"done_tasks_bullet": "✔", // options: + | ✓ | ✔
"canc_tasks_bullet": "✘",
"date_format": "(%y-%m-%d %H:%M)",
"done_tag": true,
"done_tag": true, // related to @cancelled as well
"color_scheme": "Packages/PlainTasks/tasks.hidden-tmTheme",
"font_size": 15,
"font_face": "Consolas",
Expand Down
3 changes: 2 additions & 1 deletion PlainTasks (Windows).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"open_tasks_bullet": "☐", // options: - | ❍ | ❑ | ■ | □ | ☐ | ▪ | ▫ | – | — ≡ → ›
"done_tasks_bullet": "✔", // options: + | ✓ | ✔
"canc_tasks_bullet": "✘",
"date_format": "(%y-%m-%d %H:%M)",
"done_tag": true,
"done_tag": true, // related to @cancelled as well
"color_scheme": "Packages/PlainTasks/tasks.hidden-tmTheme",
"font_size": 11,
"font_face": "Consolas",
Expand Down
46 changes: 46 additions & 0 deletions PlainTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ class SublimeTasksBase(sublime_plugin.TextCommand):
def run(self, edit):
self.open_tasks_bullet = self.view.settings().get('open_tasks_bullet')
self.done_tasks_bullet = self.view.settings().get('done_tasks_bullet')
self.canc_tasks_bullet = self.view.settings().get('canc_tasks_bullet')
self.date_format = self.view.settings().get('date_format')
if self.view.settings().get('done_tag'):
self.done_tag = "@done"
self.canc_tag = "@cancelled"
else:
self.done_tag = ""
self.canc_tag = ""
self.runCommand(edit)


Expand Down Expand Up @@ -68,8 +71,10 @@ def runCommand(self, edit):
line_contents = self.view.substr(line).rstrip()
rom = '^(\s*)' + re.escape(self.open_tasks_bullet) + '\s*(.*)$'
rdm = '^(\s*)' + re.escape(self.done_tasks_bullet) + '\s*([^\b]*?)\s*(%s)?[\(\)\d\w,\.:\-/ ]*\s*$' % self.done_tag
rcm = '^(\s*)' + re.escape(self.canc_tasks_bullet) + '\s*([^\b]*?)\s*(%s)?[\(\)\d\w,\.:\-/ ]*\s*$' % self.canc_tag
open_matches = re.match(rom, line_contents)
done_matches = re.match(rdm, line_contents)
canc_matches = re.match(rcm, line_contents)
if open_matches:
grps = open_matches.groups()
self.view.insert(edit, line.end(), done_line_end)
Expand All @@ -80,12 +85,53 @@ def runCommand(self, edit):
replacement = u'%s%s %s' % (grps[0], self.open_tasks_bullet, grps[1].rstrip())
self.view.replace(edit, line, replacement)
offset = -offset
elif canc_matches:
grps = canc_matches.groups()
self.view.insert(edit, line.end(), done_line_end)
replacement = u'%s%s %s' % (grps[0], self.done_tasks_bullet, grps[1].rstrip())
self.view.replace(edit, line, replacement)
offset = -offset
self.view.sel().clear()
for ind, pt in enumerate(original):
ofs = ind * offset
new_pt = sublime.Region(pt.a + ofs, pt.b + ofs)
self.view.sel().add(new_pt)

class CancelCommand(SublimeTasksBase):
"""docstring for CancelledCommand"""
def runCommand(self, edit):
original = [r for r in self.view.sel()]
canc_line_end = ' %s %s' % (self.canc_tag, datetime.now().strftime(self.date_format))
offset = len(canc_line_end)
for region in self.view.sel():
line = self.view.line(region)
line_contents = self.view.substr(line).rstrip()
rom = '^(\s*)' + re.escape(self.open_tasks_bullet) + '\s*(.*)$'
rdm = '^(\s*)' + re.escape(self.done_tasks_bullet) + '\s*([^\b]*?)\s*(%s)?[\(\)\d\w,\.:\-/ ]*\s*$' % self.done_tag
rcm = '^(\s*)' + re.escape(self.canc_tasks_bullet) + '\s*([^\b]*?)\s*(%s)?[\(\)\d\w,\.:\-/ ]*\s*$' % self.canc_tag
open_matches = re.match(rom, line_contents)
done_matches = re.match(rdm, line_contents)
canc_matches = re.match(rcm, line_contents)
if open_matches:
grps = open_matches.groups()
self.view.insert(edit, line.end(), canc_line_end)
replacement = u'%s%s %s' % (grps[0], self.canc_tasks_bullet, grps[1].rstrip())
self.view.replace(edit, line, replacement)
elif done_matches: pass
# grps = done_matches.groups()
# replacement = u'%s%s %s' % (grps[0], self.canc_tasks_bullet, grps[1].rstrip())
# self.view.replace(edit, line, replacement)
# offset = -offset
elif canc_matches:
grps = canc_matches.groups()
replacement = u'%s%s %s' % (grps[0], self.open_tasks_bullet, grps[1].rstrip())
self.view.replace(edit, line, replacement)
offset = -offset
self.view.sel().clear()
for ind, pt in enumerate(original):
ofs = ind * offset
new_pt = sublime.Region(pt.a + ofs, pt.b + ofs)
self.view.sel().add(new_pt)

class ArchiveCommand(SublimeTasksBase):
def runCommand(self, edit):
Expand Down
29 changes: 28 additions & 1 deletion PlainTasks.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<dict>
<key>match</key>
<string>^\s*((?!-|\+|✓|✔|❍|❑|■|□|☐|▪|▫|–|—|_)\S).*((?!:\s*).\s*)$</string>
<string>^\s*((?!-|\+|✓|✔|❍|❑|■|□|☐|▪|▫|–|—|_|✘)\S).*((?!:\s*).\s*)$</string>
<key>name</key>
<string>notes.todo</string>
</dict>
Expand Down Expand Up @@ -75,6 +75,13 @@
<string>meta.tag.todo.completed</string>
</dict>

<dict>
<key>match</key>
<string>(?&lt;=\s)(\@[\w\d\.\-!?]+\s+)*(\@cancelled)[\(\)\d\w,\.:\-/\s]*\s*\n</string>
<key>name</key>
<string>meta.tag.todo.cancelled</string>
</dict>

<dict>
<key>match</key>
<string>(?&lt;=\s)\@(?!today|completed|done)[\w\d\.\(\)\-!?]+\s*</string>
Expand Down Expand Up @@ -103,6 +110,26 @@
<string>string.other.tag.todo.today</string>
</dict>

<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.bullet.cancelled.todo</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>text.cancelled.todo</string>
</dict>
</dict>
<key>match</key>
<string>^\s*(✘)\s+((?:[^\@]|(?&lt;!\s)\@)*)</string>
<key>name</key>
<string>meta.item.todo.cancelled</string>
</dict>

</array>
<key>scopeName</key>
<string>text.todo</string>
Expand Down
39 changes: 39 additions & 0 deletions tasks.hidden-tmTheme
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Cancelled bullet</string>
<key>scope</key>
<string>punctuation.definition.bullet.cancelled</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F00000</string>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Cancelled task</string>
<key>scope</key>
<string>meta.item.todo.cancelled</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#68654F</string>
<key>fontStyle</key>
<string>italic</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Done meta info</string>
Expand All @@ -110,6 +136,19 @@
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Cancel meta info</string>
<key>scope</key>
<string>meta.tag.todo.cancelled</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000050</string>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Keyword</string>
Expand Down

0 comments on commit 8e3c2f7

Please sign in to comment.