예제 #1
0
파일: main.py 프로젝트: tmerse/taskwiki
    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
예제 #2
0
 def push(self):
     with util.current_line_preserved():
         buffer = util.get_buffer(self.buffer_number)
         # Only set the buffer contents if the data is changed.
         # Avoids extra undo events with empty diff.
         if buffer[:] != self.data:
             buffer[:] = self.data
             buffer.options['modified'] = True
예제 #3
0
    def update_from_tw():
        """
        Updates all the incomplete tasks in the vimwiki file if the info from TW is different.
        """

        c = cache.load_current()
        c.reset()
        c.load_tasks()
        c.load_presets()
        c.load_vwtasks(buffer_has_authority=False)
        c.load_viewports()
        c.update_vwtasks_from_tasks()
        c.update_vwtasks_in_buffer()
        c.evaluate_viewports()
        c.buffer.push()

        # TODO: add autowrite option
        # grab the cache BufferProxy object, get the true vim buffer, check if it's
        # modified and write it if so
        if util.get_buffer(c.buffer.buffer_number).options['modified']:
            vim.command('w')
예제 #4
0
파일: cache.py 프로젝트: rouxb/taskwiki
 def push(self):
     with util.current_line_preserved():
         # Only set the buffer contents if the data is changed.
         # Avoids extra undo events with empty diff.
         if util.get_buffer(self.buffer_number)[:] != self.data:
             util.get_buffer(self.buffer_number)[:] = self.data
예제 #5
0
파일: cache.py 프로젝트: rouxb/taskwiki
 def obtain(self):
     self.data = util.get_buffer(self.buffer_number)[:]
예제 #6
0
파일: cache.py 프로젝트: kwrobert/taskwiki
 def push(self):
     with util.current_line_preserved():
         util.get_buffer(self.buffer_number)[:] = self.data
예제 #7
0
파일: cache.py 프로젝트: jbaum98/taskwiki
 def push(self):
     util.get_buffer(self.buffer_number)[:] = self.data