def scratch(self): for vimwikitask in self.tasks: out = util.tw_execute_safely(self.tw, [vimwikitask.uuid, 'export']) if out: # json export of tw task task_exported = json.loads(out[0]) # dict_keys(['id', 'description', 'entry', 'modified', 'start', 'status', 'tags', 'uuid', 'urgency']) task_config = util.tw_execute_safely(self.tw, ['_show']) matcher = re.compile(r"data\.location=(.*)") for element in task_config: taskwarrior_data_location = re.search(matcher, element) if taskwarrior_data_location and len(taskwarrior_data_location.groups()) == 1: taskwarrior_data_location = taskwarrior_data_location.group(1) break else: taskwarrior_data_location = None # TODO: test this code (if location is not set in config) # TODO/FIXME: data_location set in vim/taskwiki always should take precedence! taskwarrior_data_location = taskwarrior_data_location or '~/.task' # Subset of task that should be shown in yaml header task_exported_yaml_header = {key: task_exported[key] for key in task_exported.keys() & {'description', 'status', 'tags', 'project', 'annotations'}} task_scratch_content = """\ # Task | {uuid} # Scratch Stuff goes here """.format(uuid=vimwikitask.uuid).split("\n") task_scratch_content = [l.strip() for l in task_scratch_content] task_scratch_content = (["---"] + yaml.dump(task_exported_yaml_header, Dumper=util.YAML_DUMPER, default_flow_style=False, sort_keys=False).split("\n")[:-1] + ["---"] + task_scratch_content)[:-2] scratch_folder_path = os.path.expanduser(os.path.join(taskwarrior_data_location, 'scratch')) scratch_file_path = os.path.join(scratch_folder_path, str(vimwikitask.uuid) + '.md') os.makedirs(scratch_folder_path, exist_ok=True) vim.command("edit {0}".format(scratch_file_path)) if not os.path.isfile(scratch_file_path): vim.current.buffer.append(task_scratch_content, 0) # TODO: call taskwiki_loadbuffer and safe buffer (to show task under viewport) # TODO: add function to update metadata in header.. # ..and leave the rest of the buffer/everything after "# Scratch" untouched. # Make executable inside vim break # Show only one task
def modify(self, modstring): # If no modstring was passed as argument, ask the user interactively if not modstring: with util.current_line_highlighted(): modstring = util.get_input("Enter modifications: ") # We might have two same tasks in the range, make sure we do not pass the # same uuid twice unique_tasks = set(vimwikitask.task['uuid'] for vimwikitask in self.tasks) uuids = list(unique_tasks) # Generate the arguments from the modstring args = util.tw_modstring_to_args(modstring) # Modify all tasks at once output = util.tw_execute_safely(self.tw, uuids + ['mod'] + args) # Update the touched tasks in buffer, if needed cache().load_tasks() cache().update_vwtasks_from_tasks() cache().update_vwtasks_in_buffer() # Output the feedback from TW if output: print(output[-1]) cache().buffer.push() self.save_action('modify', modstring)
def update_meta_header(): c = cache.load_current() tw = c.get_relevant_tw() # TODO: use util.get_buffer_shortname ? buffer_name = os.path.splitext(vim.current.buffer.name)[0] task_uuid = buffer_name.split("/")[-1] # TODO: only run if task_uuid returns a task # TODO: make more robust? (should only search for uuids) task_data_raw = util.tw_execute_safely(tw, [task_uuid, 'export']) if task_data_raw and len(task_data_raw) and task_data_raw[0] != '': task_json = json.loads(task_data_raw[0]) # Cached buffer content? # print(cache.current_buffer._buffer_data) current_buffer = util.get_buffer(vim.current.buffer.number) # find second occurence of '---' in buffer. # this marks the end of the yaml-header which will be replaced header_end_line_number = [i for i, n in enumerate(current_buffer[:]) if n == '---'][1] task_json = {key: task_json[key] for key in task_json.keys() & {'description', 'status', 'tags', 'project', 'annotations'}} task_yaml_header = (["---"] + yaml.dump(task_json, Dumper=util.YAML_DUMPER, default_flow_style=False, sort_keys=False).split("\n")[:-1] + ["---"]) buffer_content = current_buffer[:] buffer_content = task_yaml_header + buffer_content[header_end_line_number + 1:] current_buffer[:] = buffer_content current_buffer.options['modified'] = True return True
def execute(self): if self.colorful: output = util.tw_execute_colorful(self.tw, self.full_args, allow_failure=False, maxwidth=self.maxwidth, maxheight=self.maxheight) else: output = util.tw_execute_safely(self.tw, self.full_args) util.show_in_split( output, size=self.size, name=self.split_name, vertical=self.vertical, activate_cursorline=self.cursorline, )
def info(self): for vimwikitask in self.tasks: out = util.tw_execute_safely(self.tw, [vimwikitask.uuid, 'info']) if out: util.show_in_split(out, name='info', activate_cursorline=True) break # Show only one task