Skip to content

Commit 984df1a

Browse files
move todo state setting prsing a document function.
1 parent bb1569d commit 984df1a

File tree

3 files changed

+75
-67
lines changed

3 files changed

+75
-67
lines changed

ftplugin/orgmode/liborgmode/documents.py

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
except:
1313
from UserList import UserList
1414

15+
from orgmode import settings
16+
1517
from orgmode.liborgmode.base import MultiPurposeList, flatten_list, Direction, get_domobj_range
1618
from orgmode.liborgmode.headings import Heading, HeadingList
1719

1820
from orgmode.py3compat.encode_compatibility import *
1921
from orgmode.py3compat.unicode_compatibility import *
2022

23+
import re
24+
REGEX_LOGGING_MODIFIERS = re.compile(r"[!@/]")
25+
2126
class Document(object):
2227
u"""
2328
Representation of a whole org-mode document.
@@ -51,7 +56,8 @@ def __init__(self):
5156
self._tag_column = 77
5257

5358
# TODO this doesn't differentiate between ACTIVE and FINISHED todo's
54-
self.todo_states = [u'TODO', u'DONE']
59+
self.todo_states_stripped = self.get_settings_todo_states(True)
60+
self.todo_states = self.get_settings_todo_states(False)
5561

5662
def __unicode__(self):
5763
if self.meta_information is None:
@@ -61,6 +67,65 @@ def __unicode__(self):
6167
def __str__(self):
6268
return u_encode(self.__unicode__())
6369

70+
def get_done_states(self, strip_access_key=True):
71+
all_states = self.get_todo_states(strip_access_key)
72+
done_states = list([ done_state for x in all_states for done_state in x[1]])
73+
74+
return done_states
75+
76+
def parse_todo_settings(self, setting, strip_access_key = True):
77+
def parse_states(s, stop=0):
78+
res = []
79+
if not s:
80+
return res
81+
if type(s[0]) in (unicode, str):
82+
r = []
83+
for i in s:
84+
_i = i
85+
if type(_i) == str:
86+
_i = u_decode(_i)
87+
if type(_i) == unicode and _i:
88+
if strip_access_key and u'(' in _i:
89+
_i = _i[:_i.index(u'(')]
90+
if _i:
91+
r.append(_i)
92+
else:
93+
_i = REGEX_LOGGING_MODIFIERS.sub("", _i)
94+
r.append(_i)
95+
if not u'|' in r:
96+
if not stop:
97+
res.append((r[:-1], [r[-1]]))
98+
else:
99+
res = (r[:-1], [r[-1]])
100+
else:
101+
seperator_pos = r.index(u'|')
102+
if not stop:
103+
res.append((r[0:seperator_pos], r[seperator_pos + 1:]))
104+
else:
105+
res = (r[0:seperator_pos], r[seperator_pos + 1:])
106+
elif type(s) in (list, tuple) and not stop:
107+
for i in s:
108+
r = parse_states(i, stop=1)
109+
if r:
110+
res.append(r)
111+
return res
112+
return parse_states(setting)
113+
114+
115+
def get_settings_todo_states(self, strip_access_key=True):
116+
u""" Returns a list containing a tuple of two lists of allowed todo
117+
states split by todo and done states. Multiple todo-done state
118+
sequences can be defined.
119+
120+
:returns: [([todo states], [done states]), ..]
121+
"""
122+
states = settings.get(u'org_todo_keywords', [])
123+
124+
if type(states) not in (list, tuple):
125+
return []
126+
127+
return self.parse_todo_settings(states, strip_access_key)
128+
64129
def get_all_todo_states(self):
65130
u""" Convenience function that returns all todo and done states and
66131
sequences in one big list.
@@ -71,7 +136,7 @@ def get_all_todo_states(self):
71136
# TODO This is not necessary remove
72137
return flatten_list(self.get_todo_states())
73138

74-
def get_todo_states(self):
139+
def get_todo_states(self, strip_access_key=True):
75140
u""" Returns a list containing a tuple of two lists of allowed todo
76141
states split by todo and done states. Multiple todo-done state
77142
sequences can be defined.
@@ -82,7 +147,12 @@ def get_todo_states(self):
82147
# TODO this should be made into property so todo states can be set like
83148
# this too.. or there was also some todo property around... oh well..
84149
# TODO there is the same method in vimbuffer
85-
return self.todo_states
150+
151+
ret = self.todo_states
152+
if strip_access_key:
153+
ret = self.todo_states_stripped
154+
155+
return ret
86156

87157
@property
88158
def tabstop(self):

ftplugin/orgmode/plugins/Todo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def init_org_todo(cls):
292292

293293
if all_states is None:
294294
vim.command(u_encode(u'bw'))
295-
echom(u'No todo states avaiable for buffer %s' % vim.current.buffer.name)
295+
echom(u'No todo states available for buffer %s' % vim.current.buffer.name)
296296

297297
for idx, state in enumerate(all_states):
298298
pairs = [split_access_key(x, sub=u' ') for x in it.chain(*state)]

ftplugin/orgmode/vimbuffer.py

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
is UTF-8.
1919
"""
2020

21+
2122
try:
2223
from collections import UserList
2324
except:
@@ -33,7 +34,6 @@
3334
from orgmode.py3compat.encode_compatibility import *
3435
from orgmode.py3compat.unicode_compatibility import *
3536

36-
3737
class VimBuffer(Document):
3838
def __init__(self, bufnr=0):
3939
u"""
@@ -89,68 +89,6 @@ def changedtick(self):
8989
def changedtick(self, value):
9090
self._changedtick = value
9191

92-
def get_done_states(self, strip_access_key=True):
93-
all_states = self.get_todo_states(strip_access_key)
94-
done_states = list([ done_state for x in all_states for done_state in x[1]])
95-
96-
return done_states
97-
98-
def get_todo_states(self, strip_access_key=True):
99-
u""" Returns a list containing a tuple of two lists of allowed todo
100-
states split by todo and done states. Multiple todo-done state
101-
sequences can be defined.
102-
103-
:returns: [([todo states], [done states]), ..]
104-
"""
105-
states = settings.get(u'org_todo_keywords', [])
106-
# TODO this function gets called too many times when change of state of
107-
# one todo is triggered, check with:
108-
# print(states)
109-
# this should be changed by saving todo states into some var and only
110-
# if new states are set hook should be called to register them again
111-
# into a property
112-
# TODO move this to documents.py, it is all tangled up like this, no
113-
# structure...
114-
if type(states) not in (list, tuple):
115-
return []
116-
117-
def parse_states(s, stop=0):
118-
res = []
119-
if not s:
120-
return res
121-
if type(s[0]) in (unicode, str):
122-
r = []
123-
for i in s:
124-
_i = i
125-
if type(_i) == str:
126-
_i = u_decode(_i)
127-
if type(_i) == unicode and _i:
128-
if strip_access_key and u'(' in _i:
129-
_i = _i[:_i.index(u'(')]
130-
if _i:
131-
r.append(_i)
132-
else:
133-
r.append(_i)
134-
if not u'|' in r:
135-
if not stop:
136-
res.append((r[:-1], [r[-1]]))
137-
else:
138-
res = (r[:-1], [r[-1]])
139-
else:
140-
seperator_pos = r.index(u'|')
141-
if not stop:
142-
res.append((r[0:seperator_pos], r[seperator_pos + 1:]))
143-
else:
144-
res = (r[0:seperator_pos], r[seperator_pos + 1:])
145-
elif type(s) in (list, tuple) and not stop:
146-
for i in s:
147-
r = parse_states(i, stop=1)
148-
if r:
149-
res.append(r)
150-
return res
151-
152-
return parse_states(states)
153-
15492
def update_changedtick(self):
15593
if self.bufnr == vim.current.buffer.number:
15694
self._changedtick = int(vim.eval(u_encode(u'b:changedtick')))

0 commit comments

Comments
 (0)