12
12
except :
13
13
from UserList import UserList
14
14
15
+ from orgmode import settings
16
+
15
17
from orgmode .liborgmode .base import MultiPurposeList , flatten_list , Direction , get_domobj_range
16
18
from orgmode .liborgmode .headings import Heading , HeadingList
17
19
18
20
from orgmode .py3compat .encode_compatibility import *
19
21
from orgmode .py3compat .unicode_compatibility import *
20
22
23
+ import re
24
+ REGEX_LOGGING_MODIFIERS = re .compile (r"[!@/]" )
25
+
21
26
class Document (object ):
22
27
u"""
23
28
Representation of a whole org-mode document.
@@ -51,7 +56,8 @@ def __init__(self):
51
56
self ._tag_column = 77
52
57
53
58
# 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 )
55
61
56
62
def __unicode__ (self ):
57
63
if self .meta_information is None :
@@ -61,6 +67,65 @@ def __unicode__(self):
61
67
def __str__ (self ):
62
68
return u_encode (self .__unicode__ ())
63
69
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
+
64
129
def get_all_todo_states (self ):
65
130
u""" Convenience function that returns all todo and done states and
66
131
sequences in one big list.
@@ -71,7 +136,7 @@ def get_all_todo_states(self):
71
136
# TODO This is not necessary remove
72
137
return flatten_list (self .get_todo_states ())
73
138
74
- def get_todo_states (self ):
139
+ def get_todo_states (self , strip_access_key = True ):
75
140
u""" Returns a list containing a tuple of two lists of allowed todo
76
141
states split by todo and done states. Multiple todo-done state
77
142
sequences can be defined.
@@ -82,7 +147,12 @@ def get_todo_states(self):
82
147
# TODO this should be made into property so todo states can be set like
83
148
# this too.. or there was also some todo property around... oh well..
84
149
# 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
86
156
87
157
@property
88
158
def tabstop (self ):
0 commit comments