def add_projects_and_notes(self, dues): '''Context is important, if due task has note and belongs to projects, make em visible''' def add_note(region): # refactor: method in ArchiveCommand next_line_begins = region.end() + 1 while self.view.scope_name(next_line_begins) == 'text.todo notes.todo ': note = self.view.line(next_line_begins) if note not in dues: dues.append(note) next_line_begins = self.view.line(next_line_begins).end() + 1 projects = [r for r in get_all_projects_and_separators(self.view) if r.a < dues[~0].a] for d in reversed(dues): add_note(d) for p in reversed(projects): # refactor: different implementation in ArchiveCommand project_block = self.view.indented_region(p.end() + 1) due_block = self.view.indented_region(d.begin()) if all((p not in dues, project_block.contains(due_block))): dues.append(p) add_note(p) if self.view.indented_region(p.begin()).empty(): break dues.sort() return dues
def add_projects_and_notes(self, dues): '''Context is important, if due task has note and belongs to projects, make em visible''' def add_note(region): # refactor: method in ArchiveCommand next_line_begins = region.end() + 1 while self.view.scope_name(next_line_begins) == 'text.todo notes.todo ': note = self.view.line(next_line_begins) if note not in dues: dues.append(note) next_line_begins = self.view.line(next_line_begins).end() + 1 projects = [r for r in get_all_projects_and_separators(self.view) if r.a < dues[~0].a] for d in reversed(dues): add_note(d) for p in reversed(projects): # refactor: different implementation in ArchiveCommand project_block = self.view.indented_region(p.end() + 1) due_block = self.view.indented_region(d.begin()) if all((p not in dues, project_block.contains(due_block))): dues.append(p) add_note(p) if self.view.indented_region(p.begin()).empty(): break dues.sort() return dues
def runCommand(self, edit, partial=False): rds = 'meta.item.todo.completed' rcs = 'meta.item.todo.cancelled' # finding archive section archive_pos = self.view.find(self.archive_name, 0, sublime.LITERAL) if partial: all_tasks = self.get_archivable_tasks_within_selections() else: all_tasks = self.get_all_archivable_tasks(archive_pos, rds, rcs) if not all_tasks: sublime.status_message('Nothing to archive') else: if archive_pos and archive_pos.a > 0: line = self.view.full_line(archive_pos).end() else: create_archive = u'\n\n___________________\n%s\n' % self.archive_name self.view.insert(edit, self.view.size(), create_archive) line = self.view.size() projects = get_all_projects_and_separators(self.view) # adding tasks to archive section for task in all_tasks: line_content = self.view.substr(task) match_task = re.match(r'^\s*(\[[x-]\]|.)(\s+.*$)', line_content, re.U) current_scope = self.view.scope_name(task.a) if rds in current_scope or rcs in current_scope: pr = self.get_task_project(task, projects) if self.project_postfix: eol = u'{0}{1}{2}{3}\n'.format( self.before_tasks_bullet_spaces, line_content.strip(), (u' @project(%s)' % pr) if pr else '', ' ' if line_content.endswith(' ') else '') else: eol = u'{0}{1}{2}{3}\n'.format( self.before_tasks_bullet_spaces, match_task.group(1), # bullet (u'%s%s:' % (self.tasks_bullet_space, pr)) if pr else '', match_task.group(2)) # very task else: eol = u'{0}{1}\n'.format( self.before_tasks_bullet_spaces * 2, line_content.lstrip()) line += self.view.insert(edit, line, eol) # remove moved tasks (starting from the last one otherwise it screw up regions after the first delete) for task in reversed(all_tasks): self.view.erase(edit, self.view.full_line(task)) self.view.run_command('plain_tasks_sort_by_date')
def runCommand(self, edit, partial=False): rds = 'meta.item.todo.completed' rcs = 'meta.item.todo.cancelled' # finding archive section archive_pos = self.view.find(self.archive_name, 0, sublime.LITERAL) if partial: all_tasks = self.get_archivable_tasks_within_selections() else: all_tasks = self.get_all_archivable_tasks(archive_pos, rds, rcs) if not all_tasks: sublime.status_message('Nothing to archive') else: if archive_pos and archive_pos.a > 0: line = self.view.full_line(archive_pos).end() else: create_archive = u'\n\n___________________\n' + self.archive_name + '\n' self.view.insert(edit, self.view.size(), create_archive) line = self.view.size() projects = get_all_projects_and_separators(self.view) # adding tasks to archive section for task in all_tasks: match_task = re.match('^\s*(\[[x-]\]|.)(\s+.*$)', self.view.substr(task), re.U) current_scope = self.view.scope_name(task.a) if rds in current_scope or rcs in current_scope: pr = self.get_task_project(task, projects) if self.project_postfix: eol = (self.before_tasks_bullet_spaces + self.view.substr(task).lstrip() + (' @project(' if pr else '') + pr + (')' if pr else '') + '\n') else: eol = ( self.before_tasks_bullet_spaces + match_task.group(1) + # bullet (self.tasks_bullet_space if pr else '') + pr + (':' if pr else '') + match_task.group(2) + # very task '\n') else: eol = self.before_tasks_bullet_spaces * 2 + self.view.substr( task).lstrip() + '\n' line += self.view.insert(edit, line, eol) # remove moved tasks (starting from the last one otherwise it screw up regions after the first delete) for task in reversed(all_tasks): self.view.erase(edit, self.view.full_line(task)) self.view.run_command('plain_tasks_sort_by_date')
def runCommand(self, edit, partial=False): rds = 'meta.item.todo.completed' rcs = 'meta.item.todo.cancelled' # finding archive section archive_pos = self.view.find(self.archive_name, 0, sublime.LITERAL) if partial: all_tasks = self.get_archivable_tasks_within_selections() else: all_tasks = self.get_all_archivable_tasks(archive_pos, rds, rcs) if not all_tasks: sublime.status_message('Nothing to archive') else: if archive_pos and archive_pos.a > 0: line = self.view.full_line(archive_pos).end() else: create_archive = u'\n\n___________________\n%s\n' % self.archive_name self.view.insert(edit, self.view.size(), create_archive) line = self.view.size() projects = get_all_projects_and_separators(self.view) # adding tasks to archive section for task in all_tasks: line_content = self.view.substr(task) match_task = re.match(r'^\s*(\[[x-]\]|.)(\s+.*$)', line_content, re.U) current_scope = self.view.scope_name(task.a) if rds in current_scope or rcs in current_scope: pr = self.get_task_project(task, projects) if self.project_postfix: eol = u'{0}{1}{2}{3}\n'.format( self.before_tasks_bullet_spaces, line_content.strip(), (u' @project(%s)' % pr) if pr else '', ' ' if line_content.endswith(' ') else '') else: eol = u'{0}{1}{2}{3}\n'.format( self.before_tasks_bullet_spaces, match_task.group(1), # bullet (u'%s%s:' % (self.tasks_bullet_space, pr)) if pr else '', match_task.group(2)) # very task else: eol = u'{0}{1}\n'.format(self.before_tasks_bullet_spaces * 2, line_content.lstrip()) line += self.view.insert(edit, line, eol) # remove moved tasks (starting from the last one otherwise it screw up regions after the first delete) for task in reversed(all_tasks): self.view.erase(edit, self.view.full_line(task)) self.view.run_command('plain_tasks_sort_by_date')
def runCommand(self, edit, partial=False): rds = 'meta.item.todo.completed' rcs = 'meta.item.todo.cancelled' # finding archive section archive_pos = self.view.find(self.archive_name, 0, sublime.LITERAL) if partial: all_tasks = self.get_archivable_tasks_within_selections() else: all_tasks = self.get_all_archivable_tasks(archive_pos, rds, rcs) if not all_tasks: sublime.status_message('Nothing to archive') else: if archive_pos and archive_pos.a > 0: line = self.view.full_line(archive_pos).end() else: create_archive = u'\n\n___________________\n' + self.archive_name + '\n' self.view.insert(edit, self.view.size(), create_archive) line = self.view.size() projects = get_all_projects_and_separators(self.view) # adding tasks to archive section for task in all_tasks: match_task = re.match('^\s*(\[[x-]\]|.)(\s+.*$)', self.view.substr(task), re.U) current_scope = self.view.scope_name(task.a) if rds in current_scope or rcs in current_scope: pr = self.get_task_project(task, projects) if self.project_postfix: eol = (self.before_tasks_bullet_spaces + self.view.substr(task).lstrip() + (' @project(' if pr else '') + pr + (')' if pr else '') + '\n') else: eol = (self.before_tasks_bullet_spaces + match_task.group(1) + # bullet (self.tasks_bullet_space if pr else '') + pr + (':' if pr else '') + match_task.group(2) + # very task '\n') else: eol = self.before_tasks_bullet_spaces * 2 + self.view.substr(task).lstrip() + '\n' line += self.view.insert(edit, line, eol) # remove moved tasks (starting from the last one otherwise it screw up regions after the first delete) for task in reversed(all_tasks): self.view.erase(edit, self.view.full_line(task)) self.view.run_command('plain_tasks_sort_by_date')