Originally Posted by kingsinger
Here's what I've got as far as the code I'm entering:
I've split it up to make it easier to comment on what I think's happening.
 -p 'note="#currentfocus"'
 -a flatten
 -t next
 -E -a done=any
 -E -t "name='Phase 2: Substantive Work'"
 -E -t "name='Phase 3: Tie up loose ends and close transaction'"
 -E -t "name='Phase 1: Admin'"
 -E -t "name='Document Drafting:'"
 -E -t "name='Document Review:'"
 -E -t "name='Invoice and Payment'"
 -E -t "name='Draft Remaining Formation Paperwork'"
 -C -a prune
 -t "sort due"
 -T flat
 --open -o ~/Desktop/x.txt
I think the tool is doing what it's "supposed" to do, but not what you want :-)
Sort Issue 1 - fixable:
 -t "sort due" --> -c "sort due"
The sort feature
works by sorting the contents of a structural item. Here you want the contents of contexts sorted so you'd use -c "sort due". This might seem needlessly weird - but I did start out by specifying the items you wanted TO BE sorted, but it didn't work at the conceptual level. The problem is that Folders can contain Sub-Folders AND Projects and Context can contain Sub-Contexts AND Tasks. To say that you want a particular type in sort order doesn't cover the case where two types are mixed in the same list.
Sort Issue 2 - Not so fixable:
 -T flat
So with the first problem sorted it's all ok? Well no. By the time we get to 15 you should have all your tasks organised into contexts and all the tasks within them sorted by due. However the flat template simply omits the parent contexts in the output, the internal structure remains. So what you'd see would be blocks of tasks in sort order but then a discontinuity as it jumped to the next context.
In hindsight the "flat" template is a bit of a hack, I think what's required is a filter like the flatten filter but that pulls all the tasks up to the root in the model so that the other filters (like sort) can do their thing on that.
I might have a look at that, it would seem to be quite useful and avoids the need for template hackery.