1212except :
1313 from UserList import UserList
1414
15+ from orgmode import settings
16+
1517from orgmode .liborgmode .base import MultiPurposeList , flatten_list , Direction , get_domobj_range
1618from orgmode .liborgmode .headings import Heading , HeadingList
1719
1820from orgmode .py3compat .encode_compatibility import *
1921from orgmode .py3compat .unicode_compatibility import *
2022
23+ import re
24+ REGEX_LOGGING_MODIFIERS = re .compile (r"[!@/]" )
25+
2126class 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 ):
0 commit comments