Commit a1846f14 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add option to automatically sort the file after an operation.

parent 50eea969
......@@ -17,6 +17,7 @@ tag_due = due
tag_star = star
[sort]
keep_sorted = 0
sort_string = desc:importance,due,desc:priority
; For calculating importance
......
......@@ -106,6 +106,10 @@ class CLIApplication(object):
if archive.is_dirty():
archive_file.write(str(archive))
def execute(self, p_command, p_args):
command = p_command(p_args, self.todolist, lambda o: write(sys.stdout, o), error, raw_input)
return False if command.execute() == False else True
def run(self):
""" Main entry function. """
todofile = TodoFile.TodoFile(config().todotxt())
......@@ -145,16 +149,15 @@ class CLIApplication(object):
subcommand = config().default_command()
args = arguments(1)
command = subcommand_map[subcommand](args, self.todolist,
lambda o: write(sys.stdout, o),
error,
raw_input)
if command.execute() == False:
if self.execute(subcommand_map[subcommand], args) == False:
exit(1)
if self.todolist.is_dirty():
self.archive()
if config().keep_sorted():
self.execute(SortCommand, [])
todofile.write(str(self.todolist))
if __name__ == '__main__':
......
......@@ -47,6 +47,7 @@ class _Config:
'tag_star': 'star',
# sort
'keep_sorted': '0',
'sort_string': 'desc:importance,due,desc:priority',
'ignore_weekends': '1',
}
......@@ -104,6 +105,12 @@ class _Config:
except ValueError:
return int(self.defaults['indent'])
def keep_sorted(self):
try:
return self.cp.getboolean('sort', 'keep_sorted')
except ValueError:
return self.defaults['keep_sorted'] == '1'
def sort_string(self):
return self.cp.get('sort', 'sort_string')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment