Editorial Workflows

[TP] Archive @done

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Moves all @done tasks in a TaskPaper document to the "Archive" project (created if needed).

Shared by: @olemoritz

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import editor
import re
import sys

text = editor.get_text()
archive_match = re.search('\\s*Archive:\\s*', text)
if archive_match:
	archive_loc = archive_match.start(0)
else:
	archive_loc = sys.maxint

# Find tasks that are done and above the Archive project:
done_task_ranges = []
done_tasks = []
for m in re.finditer('.*@done.*\\n', text):
	if m.start(0) < archive_loc:
		done_task_ranges.append(m.span(0))
		done_tasks.append(m.group(0))

# Remove the tasks from their original position:
for r in reversed(done_task_ranges):
	editor.replace_text(r[0], r[1], '')

# Add them at the top of the Archive project:
done_tasks_str = ''.join(done_tasks)
text = editor.get_text()
if len(done_tasks) > 0:
	archive_match = re.search('\\s*Archive:\\s*', text)
	if archive_match:
		archive_loc = archive_match.end(0)
	else:
		done_tasks_str = '\nArchive:\n' + done_tasks_str
		archive_loc = len(text) - 1
	editor.replace_text(archive_loc, archive_loc, done_tasks_str)