|
5 | 5 |
|
6 | 6 | from orgmode._vim import echom, ORGMODE, apply_count, repeat, realign_tags |
7 | 7 | from orgmode import settings |
8 | | -from orgmode.liborgmode.base import Direction, flatten_list |
| 8 | +from orgmode.liborgmode.base import Direction |
9 | 9 | from orgmode.menu import Submenu, ActionEntry |
10 | 10 | from orgmode.keybinding import Keybinding, Plug |
11 | 11 |
|
@@ -104,53 +104,54 @@ def _get_next_state( |
104 | 104 |
|
105 | 105 | # TODO this would not work if there are 2 keys with same name... this |
106 | 106 | # also causes problem for find in below method |
107 | | -def find_current_todo_state(current, all_states, stop=0): |
108 | | -u""" Find current todo state |
109 | | -
|
110 | | -Args: |
111 | | -current: Current todo state |
112 | | -all_states: List of todo states |
113 | | -stop: Internal parameter for parsing only two levels of lists |
114 | | -
|
115 | | -Returns: |
116 | | -list: First position of todo state in list in the form |
117 | | -(IDX_TOPLEVEL, IDX_SECOND_LEVEL (0|1), IDX_OF_ITEM) |
118 | | -""" |
119 | | -for i, element in enumerate(all_states): |
120 | | -if type(element) in (tuple, list) and stop < 2: |
121 | | -res = find_current_todo_state(current, element, stop=stop + 1) |
122 | | -if res: |
123 | | -res.insert(0, i) |
124 | | -return res |
125 | | -# ensure that only on the second level of sublists todo states |
126 | | -# are found |
127 | | -if type(element) == unicode and stop == 2: |
128 | | -if current == split_access_key(element)[0]: |
129 | | -return [i] |
130 | | - |
131 | | -ci = find_current_todo_state(current_state, all_states) |
| 107 | +# def find_current_todo_state(current, all_states, stop=0): |
| 108 | +# u""" Find current todo state |
| 109 | + |
| 110 | +# Args: |
| 111 | +# current: Current todo state |
| 112 | +# all_states: List of todo states |
| 113 | +# stop: Internal parameter for parsing only two levels of lists |
| 114 | + |
| 115 | +# Returns: |
| 116 | +# list: First position of todo state in list in the form |
| 117 | +# (IDX_TOPLEVEL, IDX_SECOND_LEVEL (0|1), IDX_OF_ITEM) |
| 118 | +# """ |
| 119 | +# for i, element in enumerate(all_states): |
| 120 | +# if type(element) in (tuple, list) and stop < 2: |
| 121 | +# res = find_current_todo_state(current, element, stop=stop + 1) |
| 122 | +# if res: |
| 123 | +# res.insert(0, i) |
| 124 | +# return res |
| 125 | +# # ensure that only on the second level of sublists todo states |
| 126 | +# # are found |
| 127 | +# if type(element) == unicode and stop == 2: |
| 128 | +# if current == split_access_key(element)[0]: |
| 129 | +# return [i] |
| 130 | + |
| 131 | +# ci = find_current_todo_state(current_state, all_states) |
| 132 | + |
| 133 | +cleaned_todos = [[split_access_key(todo)[0] for todo in |
| 134 | + it.chain.from_iterable(x)] for x in all_states] |
| 135 | +todo_position = [1 if current_state in set else 0 for set in cleaned_todos] |
| 136 | +# TODO This is the case when there are 2 todo states with the same |
| 137 | +# name. Wat do? |
| 138 | +if sum(todo_position) > 1: pass |
132 | 139 |
|
133 | 140 | # backward direction should really be -1 not 2 |
134 | | -dir = 1 |
135 | | -if direction == Direction.BACKWARD: |
136 | | -dir = -1 |
| 141 | +dir = -1 if direction == Direction.BACKWARD else 1 |
137 | 142 | # work only with top level index |
138 | 143 | if next_set: |
139 | | -top_set = ci[0] if ci is not None else 0 |
140 | | -ind = (top_set + dir) % len(all_states) |
| 144 | +top_set = todo_position.index(1) if todo_position else 0 |
| 145 | +ind = (top_set + dir) % len(cleaned_todos) |
141 | 146 | echom("Using set: %s" % str(all_states[ind])) |
142 | | -# NOTE: List must be flatten because todo states can be empty, this |
143 | | -# is also valid for above use of flat_list |
144 | | -return split_access_key(flatten_list(all_states[ind])[0])[0] |
| 147 | +return cleaned_todos[ind][0] |
145 | 148 | # No next set, cycle around everything |
146 | 149 | else: |
147 | | -tmp = [split_access_key(x)[0] for x in flatten_list(all_states)] + [None] |
148 | | -# TODO same problem as above if there are 2 todo states with same |
149 | | -# name |
| 150 | +tmp = list(it.chain.from_iterable(cleaned_todos)) + [None] |
150 | 151 | try: |
151 | 152 | ind = (tmp.index(current_state) + dir) % len(tmp) |
152 | 153 | except ValueError: |
153 | | -# TODO should this return None like or first todo item? |
| 154 | +# TODO should this return None or first todo item? |
154 | 155 | ind = 0 |
155 | 156 | return tmp[ind] |
156 | 157 |
|
|
0 commit comments