Skip to content

Commit

Permalink
Pressing enter on TODO now changes to WORKING, and then DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
martisak committed Feb 20, 2018
1 parent ab2b1c0 commit bf5f7b4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
10 changes: 5 additions & 5 deletions messages/install.org
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@
- Checkbox checked: "cc"
- Checkbox summary: "cs"

* Todo [14/31]
* Todo [15/31]
- [X] Persistant folding of headlines
- needs indented formatting to work.
- [X] Autocomplete for inserting current date, write "date" => 2013-05-25 18:53
- [X] configure in settings
- [X] Port to Sublime Text 3
- [X] test
- [X] mac,
- [X] win,
- [X] test
- [X] mac,
- [X] win,
- [X] linux
- [X] merge into sub2 branch, test both versions
- [X] [[mailto:daniel@testtest.se]]
Expand Down Expand Up @@ -130,7 +130,7 @@
- [ ] Open call [[email:ok@ryotic.de/inbox/some title]]
- [X] Create call [[mailto:ok@ryotic.de]]
- [X] Create call with subject [[mailto:ok@ryotic.de/some subject]]
- [ ] Pressing return on a TODO chain shall set it to DONE
- [X] Pressing return on a TODO chain shall set it to DONE
- [ ] ASCII tables.
- [ ] Code remark collector. Recursively scans a specified folder for files with given filename pattern for code remarks and shows them as a list. Should be realized with begin and end markers to support later update on pressing enter on either marker.

Expand Down
50 changes: 49 additions & 1 deletion orgmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,54 @@ def toggle_checkbox(self, edit, region, checked=None, recurse_up=False, recurse_
self.update_line(edit, parent)


class OrgmodeCycleTodoCommand(sublime_plugin.TextCommand):

def __init__(self, *args, **kwargs):
super(OrgmodeCycleTodoCommand, self).__init__(*args, **kwargs)

self.status = ["TODO", "WORKING", "DONE"]
todo_pattern = r"|".join(self.status)
self.todo_regex = re.compile(todo_pattern)


def run(self, edit):

print("run")

view = self.view
sels = view.sel()
sel = sels[0]

if 'orgmode.todo' not in view.scope_name(sel.end()):
return

region = view.extract_scope(sel.end())

todo = self.get_todo(region)
content = self.view.substr(todo)

next_status_index = (self.status.index(content) + 1) % len(self.status)
view.replace(edit, todo, self.status[next_status_index])


def get_todo(self, line):
view = self.view
row, _ = view.rowcol(line.begin())
content = view.substr(line)
# print content
match = self.todo_regex.search(content)
if not match:
return None
# checkbox = match.group(1)
# print repr(checkbox)
# print dir(match), match.start(), match.span()
col_start, col_stop = match.span()
return sublime.Region(
view.text_point(row, col_start),
view.text_point(row, col_stop),
)


class OrgmodeToggleCheckboxCommand(AbstractCheckboxCommand):

def run(self, edit):
Expand Down Expand Up @@ -477,4 +525,4 @@ def has_file_ext(view, ext):
if not ext.startswith('.'):
ext = '.' + ext

return view.file_name().endswith(ext)
return view.file_name().endswith(ext)
6 changes: 6 additions & 0 deletions orgmode.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
<key>match</key>
<string>(^|\s):[\w\d:]+:</string>
</dict>
<dict>
<key>name</key>
<string>orgmode.todo</string>
<key>match</key>
<string>TODO|WORKING|DONE</string>
</dict>
<dict>
<key>name</key>
<string>orgmode.python.traceback</string>
Expand Down

0 comments on commit bf5f7b4

Please sign in to comment.