Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

date increase in sublime, also sublime-settings file

also moved tests

new features allready!? Whaaaa?!
  • Loading branch information...
commit 08381cf55b59dd510e1120fe05914ff6499aa27b 1 parent f74db27
@bevesce authored
Showing with 141 additions and 18 deletions.
  1. 0  {topy → }/tests/__init__.py
  2. 0  {topy → }/tests/in/big.todo
  3. 0  {topy/tests/min → tests/in}/empty.todo
  4. 0  {topy → }/tests/in/one_task.todo
  5. 0  {topy → }/tests/min/big.todo
  6. 0  {topy/tests/in → tests/min}/empty.todo
  7. 0  {topy → }/tests/min/one_task.todo
  8. 0  {topy → }/tests/mout/ProjectB.todo
  9. 0  {topy → }/tests/mout/add_abc.todo
  10. 0  {topy → }/tests/mout/due-and-not-done.todo
  11. 0  {topy → }/tests/mout/due.todo
  12. 0  {topy → }/tests/mout/index0.todo
  13. 0  {topy → }/tests/mout/index2.todo
  14. 0  {topy → }/tests/mout/level0.todo
  15. 0  {topy → }/tests/mout/level12.todo
  16. 0  {topy → }/tests/mout/level2up.todo
  17. 0  {topy → }/tests/mout/misc1.todo
  18. 0  {topy → }/tests/mout/misc2.todo
  19. 0  {topy → }/tests/mout/next_and_done.todo
  20. 0  {topy → }/tests/mout/notA.todo
  21. 0  {topy → }/tests/mout/notD.todo
  22. 0  {topy → }/tests/mout/only-notes.todo
  23. 0  {topy → }/tests/mout/only-projects.todo
  24. 0  {topy → }/tests/mout/only-tasks.todo
  25. 0  {topy → }/tests/mout/parentA.todo
  26. 0  {topy → }/tests/mout/project-project.todo
  27. 0  {topy → }/tests/mout/projectA.todo
  28. 0  {topy → }/tests/mout/removeC.todo
  29. 0  {topy → }/tests/mout/task1+d.todo
  30. 0  {topy → }/tests/out/ProjectA.todo
  31. 0  {topy → }/tests/out/ProjectB.todo
  32. 0  {topy → }/tests/out/add_abc.todo
  33. 0  {topy → }/tests/out/due-and-not-done.todo
  34. 0  {topy → }/tests/out/due.todo
  35. 0  {topy → }/tests/out/index.todo
  36. 0  {topy → }/tests/out/index0.todo
  37. 0  {topy → }/tests/out/index2.todo
  38. 0  {topy → }/tests/out/level0.todo
  39. 0  {topy → }/tests/out/level12.todo
  40. 0  {topy → }/tests/out/level123.todo
  41. 0  {topy → }/tests/out/level2up.todo
  42. 0  {topy → }/tests/out/line_contains.todo
  43. 0  {topy → }/tests/out/line_contins.todo
  44. 0  {topy → }/tests/out/misc1.todo
  45. 0  {topy → }/tests/out/misc2.todo
  46. 0  {topy → }/tests/out/next_and_done.todo
  47. 0  {topy → }/tests/out/notA.todo
  48. 0  {topy → }/tests/out/notD.todo
  49. 0  {topy → }/tests/out/only-notes.todo
  50. 0  {topy → }/tests/out/only-projects.todo
  51. 0  {topy → }/tests/out/only-tasks.todo
  52. 0  {topy → }/tests/out/parentA.todo
  53. 0  {topy → }/tests/out/project-project.todo
  54. 0  {topy → }/tests/out/removeC.todo
  55. 0  {topy → }/tests/out/task1+d.todo
  56. 0  {topy → }/tests/test.py
  57. +123 −17 utilities/SublimeTodoFlow/TodoFlow.py
  58. +18 −1 utilities/SublimeTodoFlow/TodoFlow.sublime-settings
View
0  topy/tests/__init__.py → tests/__init__.py
File renamed without changes
View
0  topy/tests/in/big.todo → tests/in/big.todo
File renamed without changes
View
0  topy/tests/min/empty.todo → tests/in/empty.todo
File renamed without changes
View
0  topy/tests/in/one_task.todo → tests/in/one_task.todo
File renamed without changes
View
0  topy/tests/min/big.todo → tests/min/big.todo
File renamed without changes
View
0  topy/tests/in/empty.todo → tests/min/empty.todo
File renamed without changes
View
0  topy/tests/min/one_task.todo → tests/min/one_task.todo
File renamed without changes
View
0  topy/tests/mout/ProjectB.todo → tests/mout/ProjectB.todo
File renamed without changes
View
0  topy/tests/mout/add_abc.todo → tests/mout/add_abc.todo
File renamed without changes
View
0  topy/tests/mout/due-and-not-done.todo → tests/mout/due-and-not-done.todo
File renamed without changes
View
0  topy/tests/mout/due.todo → tests/mout/due.todo
File renamed without changes
View
0  topy/tests/mout/index0.todo → tests/mout/index0.todo
File renamed without changes
View
0  topy/tests/mout/index2.todo → tests/mout/index2.todo
File renamed without changes
View
0  topy/tests/mout/level0.todo → tests/mout/level0.todo
File renamed without changes
View
0  topy/tests/mout/level12.todo → tests/mout/level12.todo
File renamed without changes
View
0  topy/tests/mout/level2up.todo → tests/mout/level2up.todo
File renamed without changes
View
0  topy/tests/mout/misc1.todo → tests/mout/misc1.todo
File renamed without changes
View
0  topy/tests/mout/misc2.todo → tests/mout/misc2.todo
File renamed without changes
View
0  topy/tests/mout/next_and_done.todo → tests/mout/next_and_done.todo
File renamed without changes
View
0  topy/tests/mout/notA.todo → tests/mout/notA.todo
File renamed without changes
View
0  topy/tests/mout/notD.todo → tests/mout/notD.todo
File renamed without changes
View
0  topy/tests/mout/only-notes.todo → tests/mout/only-notes.todo
File renamed without changes
View
0  topy/tests/mout/only-projects.todo → tests/mout/only-projects.todo
File renamed without changes
View
0  topy/tests/mout/only-tasks.todo → tests/mout/only-tasks.todo
File renamed without changes
View
0  topy/tests/mout/parentA.todo → tests/mout/parentA.todo
File renamed without changes
View
0  topy/tests/mout/project-project.todo → tests/mout/project-project.todo
File renamed without changes
View
0  topy/tests/mout/projectA.todo → tests/mout/projectA.todo
File renamed without changes
View
0  topy/tests/mout/removeC.todo → tests/mout/removeC.todo
File renamed without changes
View
0  topy/tests/mout/task1+d.todo → tests/mout/task1+d.todo
File renamed without changes
View
0  topy/tests/out/ProjectA.todo → tests/out/ProjectA.todo
File renamed without changes
View
0  topy/tests/out/ProjectB.todo → tests/out/ProjectB.todo
File renamed without changes
View
0  topy/tests/out/add_abc.todo → tests/out/add_abc.todo
File renamed without changes
View
0  topy/tests/out/due-and-not-done.todo → tests/out/due-and-not-done.todo
File renamed without changes
View
0  topy/tests/out/due.todo → tests/out/due.todo
File renamed without changes
View
0  topy/tests/out/index.todo → tests/out/index.todo
File renamed without changes
View
0  topy/tests/out/index0.todo → tests/out/index0.todo
File renamed without changes
View
0  topy/tests/out/index2.todo → tests/out/index2.todo
File renamed without changes
View
0  topy/tests/out/level0.todo → tests/out/level0.todo
File renamed without changes
View
0  topy/tests/out/level12.todo → tests/out/level12.todo
File renamed without changes
View
0  topy/tests/out/level123.todo → tests/out/level123.todo
File renamed without changes
View
0  topy/tests/out/level2up.todo → tests/out/level2up.todo
File renamed without changes
View
0  topy/tests/out/line_contains.todo → tests/out/line_contains.todo
File renamed without changes
View
0  topy/tests/out/line_contins.todo → tests/out/line_contins.todo
File renamed without changes
View
0  topy/tests/out/misc1.todo → tests/out/misc1.todo
File renamed without changes
View
0  topy/tests/out/misc2.todo → tests/out/misc2.todo
File renamed without changes
View
0  topy/tests/out/next_and_done.todo → tests/out/next_and_done.todo
File renamed without changes
View
0  topy/tests/out/notA.todo → tests/out/notA.todo
File renamed without changes
View
0  topy/tests/out/notD.todo → tests/out/notD.todo
File renamed without changes
View
0  topy/tests/out/only-notes.todo → tests/out/only-notes.todo
File renamed without changes
View
0  topy/tests/out/only-projects.todo → tests/out/only-projects.todo
File renamed without changes
View
0  topy/tests/out/only-tasks.todo → tests/out/only-tasks.todo
File renamed without changes
View
0  topy/tests/out/parentA.todo → tests/out/parentA.todo
File renamed without changes
View
0  topy/tests/out/project-project.todo → tests/out/project-project.todo
File renamed without changes
View
0  topy/tests/out/removeC.todo → tests/out/removeC.todo
File renamed without changes
View
0  topy/tests/out/task1+d.todo → tests/out/task1+d.todo
File renamed without changes
View
0  topy/tests/test.py → tests/test.py
File renamed without changes
View
140 utilities/SublimeTodoFlow/TodoFlow.py
@@ -3,7 +3,19 @@
import re
import sublime_plugin, sublime
-from datetime import date
+from datetime import date, timedelta
+
+
+settings = sublime.load_settings('TodoFlow.sublime-settings')
+
+
+append_date_to_done = settings.get("append_date_to_done")
+today_tag = settings.get("today_tag")
+done_tag = settings.get("done_tag")
+next_tag = settings.get("next_tag")
+excluded_tags = settings.get("excluded_tags")
+allways_included_tags = settings.get("allways_included_tags")
+default_date_increase = settings.get("default_date_increase")
def is_task(line):
@@ -16,9 +28,9 @@ def is_task(line):
tag_pattern_without_at = re.compile(tag_regexp_without_at)
tag_pattern = re.compile('(@' + tag_regexp_without_at + ')')
-next_tag = re.compile(r'@next(?=(\s|$))')
-done_tag = re.compile(r'@done(\(([^)]*)\)|(?=(\s|$)))')
-today_tag = re.compile(r'@today(?=(\s|$))')
+next_tag_pattern = re.compile(r'@' + next_tag + r'(?=(\s|$))')
+done_tag_pattern = re.compile(r'@' + done_tag + r'(\(([^)]*)\)|(?=(\s|$)))')
+today_tag_pattern = re.compile(r'@' + today_tag + r'(?=(\s|$))')
def is_project(line):
@@ -31,8 +43,8 @@ def is_project(line):
# only tags are allowed after `:`
after_colon = splitted[-1].split(u'@')
only_tags_after_colon = all([
- tag_pattern_without_at.match(tag) for tag in after_colon
- ])
+ tag_pattern_without_at.match(tag) for tag in after_colon
+ ])
return only_tags_after_colon
@@ -49,19 +61,20 @@ def run(self, edit):
work_on_file(self, edit)
def process(self, line):
- if re.search(next_tag, line):
- line = next_tag.sub('@today', line)
- elif re.search(today_tag, line):
- line = today_tag.sub(
- '@done({0})'.format(date.today().isoformat()),
+ if re.search(next_tag_pattern, line):
+ line = next_tag_pattern.sub('@' + today_tag, line)
+ elif re.search(today_tag_pattern, line):
+ line = today_tag_pattern.sub(
+ '@' + done_tag +
+ ('({0})'.format(date.today().isoformat()) if append_date_to_done else ''),
line
)
- elif re.search(done_tag, line):
- line = done_tag.sub('', line)
+ elif re.search(done_tag_pattern, line):
+ line = done_tag_pattern.sub('', line)
else:
if line[-1] != ' ':
line += ' '
- line += '@next'
+ line += '@' + next_tag
if line[-1] == ' ':
line = line[0:-1]
return line
@@ -113,10 +126,12 @@ def process(self, line):
def is_banned_tag(tag):
- banned = ['project(', 'due(', 'done(', 'in(']
- for b in banned:
+ for b in [t + '(' for t in excluded_tags]:
if tag.startswith(b):
return True
+ for b in [t in excluded_tags]:
+ if b == tag:
+ return True
class AddTagCommand(sublime_plugin.TextCommand):
@@ -130,12 +145,15 @@ def run(self, edit):
self.tags_list += re.findall(' @[^\(\s]*\s', text)
## strip tags
self.tags_list = [tag[2:].strip() for tag in self.tags_list]
- ## exluce banned tags
+ ## exlude excluded tags
self.tags_list = [tag for tag in self.tags_list if not is_banned_tag(tag)]
## add versions of tags without parameter
self.tags_list += [tag[0:tag.find('(')] for tag in self.tags_list if '(' in tag]
+ ## add allways included tags
+ self.tags_list += allways_included_tags
## remove duplicates
self.tags_list = list(set(self.tags_list))
+ # show tags
self.view.window().show_quick_panel(self.tags_list, self.on_selection)
def on_selection(self, selection):
@@ -150,6 +168,8 @@ def process(self, line, selection):
def work_on_file(self, edit, *args):
+ # process every line in selection
+ # and replace it with result
for region in self.view.sel():
line_region = self.view.line(region)
line = self.view.substr(line_region)
@@ -157,3 +177,89 @@ def work_on_file(self, edit, *args):
processed_line = '\n'.join([self.process(each_line, *args) for each_line in lines])
if processed_line != line:
self.view.replace(edit, line_region, processed_line)
+
+
+class IncreaseDateCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ change_date(self.view, edit, change=1)
+
+
+def change_date(view, edit, change=1):
+ # change date by `change` value,
+ # what is changed (year, month, day)
+ # depends on cursor position
+ for region in view.sel():
+ old_date, date_region, what_selected = find_date(view, region)
+ if what_selected == 'nothing':
+ new_date = date.today()
+ elif what_selected == 'day':
+ new_date = old_date + timedelta(days=change)
+ elif what_selected == 'month':
+ month = old_date.month + change
+ if month == 0:
+ month = 12
+ if month == 13:
+ month = 1
+ new_date = date(old_date.year, month, old_date.day)
+ elif what_selected == 'year':
+ new_date = date(old_date.year + change, old_date.month, old_date.day)
+ new_date_str = '(' + new_date.isoformat() + ')'
+ view.replace(edit, date_region, new_date_str)
+ view.sel().subtract(date_region)
+ view.sel().add(region)
+
+
+def find_date(view, region):
+ max_iter = 20
+ citer = 0
+ start = region.begin()
+
+ if (region.end() - region.begin()) == 0:
+ x = view.substr(sublime.Region(region.begin(), region.end() + 1))
+ if len(x) > 0 and x[-1] == '(':
+ print x
+ region = sublime.Region(region.begin() + 1, region.end() + 3)
+ print view.substr(region)
+ else:
+ region = sublime.Region(region.begin() - 1, region.end())
+ while view.substr(region)[-1] != ')' and view.substr(region)[-1] != '\n':
+ citer += 1
+ if citer > max_iter:
+ break
+ region = sublime.Region(region.begin(), region.end() + 1)
+ while view.substr(region)[0] != '(' and view.substr(region)[0] != '\n':
+ citer += 1
+ if citer > max_iter:
+ break
+ region = sublime.Region(region.begin() - 1, region.end())
+ date_str = view.substr(region).strip()
+
+ # what was selcted depends on cursor position in date
+ # `|` shows possible cursor positions
+ what = default_date_increase # |(2013-12-31)
+ if start > region.begin(): # (|2|0|1|3|-12-31)
+ what = 'year'
+ if start > region.begin() + 5: # (2013-|1|2|-31)
+ what = 'month'
+ if start > region.begin() + 8: # (2013-12-|3|1|)
+ what = 'day'
+ if start > region.begin() + 11: # (2013-12-31)|
+ what = default_date_increase
+ try:
+ ddate = calc_date(date_str)
+ return ddate, region, what
+ except Exception as e:
+ # calc_date fails when date was not selected,
+ # so insert new one
+ print e
+ return date.today(), sublime.Region(start, start), 'nothing'
+
+
+def calc_date(date_str):
+ date_str = date_str[1:-1]
+ return date(*(int(x) for x in date_str.split('-')))
+
+
+class DecreaseDateCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ change_date(self.view, edit, change=-1)
View
19 utilities/SublimeTodoFlow/TodoFlow.sublime-settings
@@ -6,5 +6,22 @@
],
"trim_trailing_white_space_on_save": false,
"translate_tabs_to_spaces": false,
- "highlight_line": true
+ "highlight_line": true,
+
+
+ "append_date_to_done": true,
+ "today_tag": "today",
+ "next_tag": "next",
+ "done_tag": "done",
+
+ // tags not included in quick panel when adding tags
+ // you can use it for tags that have many not repeating parameters
+ "excluded_tags": ["project", "due", "done", "in", "mail"],
+
+ // tags that are allways in quick panel, even when they are not in file
+ "allways_included_tags": ["next", "mail", "due", "done", "tool", "tool(mac)", "tool(notmac)"],
+
+ // what to increase/decrease in date when cursor is outside parenthesis
+ "default_date_increase": "day"
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.