Example #1
0
    def task_info_or_vimwiki_follow_link():
        # Reset the cache() to use up-to-date buffer content
        cache().reset()

        # If the line under cursor contains task, toggle info
        # otherwise do the default VimwikiFollowLink
        row = util.get_current_line_number()
        column = util.get_current_column_number()
        line = cache().buffer[row]

        # Detect if the cursor stands on a vimwiki link,
        # if so, trigger it
        inside_vimwiki_link = all([
            '[[' in line, ']]' in line, column >= line.find('[['),
            column <= line.find(']]') + 1
        ])

        if inside_vimwiki_link:
            vim.command('VimwikiFollowLink')
            return

        # No link detected, check for viewport or a task
        if cache().vwtask[row] is not None:
            SelectedTasks().info()
            return
        else:
            port = viewport.ViewPort.from_line(row, cache())
            if port is not None:
                Meta().inspect_viewport()
                return

        # No link detected, not a viewport or a task, so delegate to
        # VimwikiFollowLink for link creation
        vim.command('VimwikiFollowLink')
Example #2
0
    def task_done_or_vimwiki_toggle_list_item():
        # Reset the cache() to use up-to-date buffer content
        cache().reset()

        # If the line under cursor contains a task, mark as done
        # otherwise fallback to VimwikiToggleListItem
        row = util.get_current_line_number()
        if cache().vwtask[row] is not None:
            vim.command('TaskWikiDone')
            return
        vim.command('VimwikiToggleListItem')
Example #3
0
    def find_closest(cls, cache):
        current_line = util.get_current_line_number()

        # Search lines in order: first all above, than all below
        line_numbers = itertools.chain(
            reversed(range(0, current_line + 1)),
            range(current_line + 1, len(cache.buffer)))

        for i in line_numbers:
            vwtask = cls.from_line(cache, i)
            if vwtask:
                return vwtask
Example #4
0
    def task_info_or_vimwiki_follow_link():
        # Reset the cache to use up-to-date buffer content
        cache.reset()

        # If the line under cursor contains task, toggle info
        # otherwise do the default VimwikiFollowLink
        position = util.get_current_line_number()

        if cache.vwtask[position] is not None:
            SelectedTasks().info()
        else:
            port = viewport.ViewPort.from_line(position, cache)
            if port is not None:
                Meta().inspect_viewport()
            else:
                vim.command('VimwikiFollowLink')
Example #5
0
    def inspect_viewport(self):
        position = util.get_current_line_number()
        port = viewport.ViewPort.from_line(position, cache())

        if port.meta.get('visible') is False:
            cache().reset()
            cache().load_vwtasks()
            cache().load_tasks()

        template = (
            "ViewPort inspection:\n"
            "--------------------\n"
            "Name: {0}\n"
            "Filter used: {1}\n"
            "Defaults used: {2}\n"
            "Ordering used: {3}\n"
            "Matching taskwarrior tasks: {4}\n"
            "Displayed tasks: {5}\n"
            "Tasks to be added: {6}\n"
            "Tasks to be deleted: {7}\n"
        )

        if port is not None:
            # Load the tasks under the viewport
            port.load_tasks()

            to_add, to_del = port.get_tasks_to_add_and_del()

            # Fill in the interesting info in the template
            template_formatted = template.format(
                port.name if six.PY3 else port.name.encode('utf-8'),
                port.raw_filter if six.PY3 else port.raw_filter.encode('utf-8'),
                port.raw_defaults if six.PY3 else port.raw_defaults.encode('utf-8'),
                port.sort,
                len(port.matching_tasks),
                len(port.tasks),
                ', '.join(map(six.text_type, to_add)),
                ', '.join(map(six.text_type, to_del)),
            )

            # Show in the split
            lines = template_formatted.splitlines()
            util.show_in_split(lines, activate_cursorline=True)
Example #6
0
    def inspect_presetheader(self):
        position = util.get_current_line_number()
        header = preset.PresetHeader.from_line(position, cache())

        template = (
            "ViewPort inspection:\n"
            "--------------------\n"
            "Filter used: {0}\n"
            "Defaults used: {1}\n"
        )

        if header is not None:

            # Fill in the interesting info in the template
            template_formatted = template.format(
                header.raw_filter if six.PY3 else header.raw_filter.encode('utf-8'),
                header.raw_defaults if six.PY3 else header.raw_defaults.encode('utf-8'),
            )

            # Show in the split
            lines = template_formatted.splitlines()
            util.show_in_split(lines, activate_cursorline=True)