コード例 #1
0
    def __init__(self, buffer_number):
        # Determine defaults
        default_rc = util.get_var('taskwiki_taskrc_location') or '~/.taskrc'
        default_data = util.get_var('taskwiki_data_location') or None
        extra_warrior_defs = util.get_var('taskwiki_extra_warriors', {})
        markup_syntax = util.get_var('taskwiki_markup_syntax') or 'default'

        # Handle bytes (vim returnes bytes for Python3)
        if six.PY3:
            default_rc = util.decode_bytes(default_rc)
            default_data = util.decode_bytes(default_data)
            extra_warrior_defs = util.decode_bytes(extra_warrior_defs)
            markup_syntax = util.decode_bytes(markup_syntax)

        # Validate markup choice and set it
        if markup_syntax in ["default", "markdown"]:
            self.markup_syntax = markup_syntax
        else:
            msg = "Unknown markup given: {}".format(markup_syntax)
            raise errors.TaskWikiException(msg)

        # Initialize all the subcomponents
        self.buffer = BufferProxy(buffer_number)
        self.task = store.TaskStore(self)
        self.presets = store.PresetStore(self)
        self.vwtask = store.VwtaskStore(self)
        self.viewport = store.ViewportStore(self)
        self.line = store.LineStore(self)
        self.warriors = store.WarriorStore(default_rc, default_data,
                                           extra_warrior_defs)
        self.buffer_has_authority = True
コード例 #2
0
    def __init__(self, buffer_number):
        # Determine defaults
        default_rc = util.get_var('taskwiki_taskrc_location') or '~/.taskrc'
        default_data = util.get_var('taskwiki_data_location') or None
        extra_warrior_defs = util.get_var('taskwiki_extra_warriors', {})
        #markup_syntax = vim.eval("vimwiki#vars#get_wikilocal('syntax')") or 'default'
        markup_syntax = 'markdown'

        # Validate markup choice and set it
        if markup_syntax in ["default", "markdown"]:
            self.markup_syntax = markup_syntax
        else:
            msg = "Unknown markup given: {}".format(markup_syntax)
            raise errors.TaskWikiException(msg)

        # Initialize all the subcomponents
        self.buffer = BufferProxy(buffer_number)
        self.completion = store.CompletionStore(self)
        self.task = store.TaskStore(self)
        self.presets = store.PresetStore(self)
        self.vwtask = store.VwtaskStore(self)
        self.viewport = store.ViewportStore(self)
        self.line = store.LineStore(self)
        self.warriors = store.WarriorStore(default_rc, default_data, extra_warrior_defs)
        self.buffer_has_authority = True
コード例 #3
0
    def get_selected_tag(self):
        tag_re = re.compile(r'^(?P<name>[^\s]+)\s+[0-9]+$')
        match = tag_re.match(vim.current.line)

        if match:
            return match.group('name')
        else:
            raise errors.TaskWikiException("No tag selected.")
コード例 #4
0
    def _get_selected_tag(self):
        tag_re = re.compile(r'^(?P<name>[^\s]+)\s+[0-9]+$', re.UNICODE)
        match = tag_re.match(vim.current.line)

        if match:
            tag = match.group('name')
            tag = tag.decode('utf-8') if six.PY2 else tag
            return tag
        else:
            raise errors.TaskWikiException("No tag selected.")
コード例 #5
0
    def process_filterstring(self, filterstring, use_presets=True):
        """
        This method processes taskfilter in the form or filter string,
        parses it into list of filter args, processing any syntax sugar
        as part of the process.

        Following syntax sugar in filter expressions is currently supported:

        * Expand @name with the definition of 'context.name' TW config
          variable

        * Interpret !+DELETED as forcing the +DELETED token.
        * Interpret !-DELETED as forcing the -DELETED token.
        * Interpret !?DELETED as removing both +DELETED and -DELETED.
        """

        # Get the initial version of the taskfilter args
        taskfilter_args = list(constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS)
        if use_presets:
            taskfilter_args += list(
                preset.PresetHeader.from_line(self.line_number,
                                              self.cache).taskfilter)
        taskfilter_args += "("
        taskfilter_args += util.tw_modstring_to_args(filterstring)
        taskfilter_args += ")"

        # Process syntactic sugar: Context expansion
        detected_contexts = []
        for token in filter(lambda x: x.startswith('@'), taskfilter_args):
            context_variable_name = 'context.{0}'.format(token[1:])
            context_definition = self.tw.config.get(context_variable_name)

            if context_definition:
                context_args = util.tw_modstring_to_args(context_definition)
                detected_contexts.append((token, context_args))
            else:
                raise errors.TaskWikiException("Context definition for '{0}' "
                                               "could not be found.".format(
                                                   token[1:]))

        for context_token, context_args in detected_contexts:
            # Find the position of the context token
            token_index = taskfilter_args.index(context_token)

            # Replace the token at token_index by context_args list
            taskfilter_args = (taskfilter_args[:token_index] + context_args +
                               taskfilter_args[(token_index + 1):])

        # Process syntactic sugar: Forcing virtual tags
        tokens_to_remove = set()
        tokens_to_add = set()

        is_forced_virtual_tag = lambda x: x.isupper() and (x.startswith(
            '!+') or x.startswith('!-') or x.startswith('!?'))

        for token in filter(is_forced_virtual_tag, taskfilter_args):
            # In any case, remove the forced tag and the forcing
            # flag from the taskfilter
            tokens_to_remove.add(token)
            tokens_to_remove.add('+' + token[2:])
            tokens_to_remove.add('-' + token[2:])

            # Add forced tag versions
            if token.startswith('!+'):
                tokens_to_add.add('+' + token[2:])
            elif token.startswith('!-'):
                tokens_to_add.add('-' + token[2:])
            elif token.startswith('!?'):
                pass

        for token in tokens_to_remove:
            if token in taskfilter_args:
                taskfilter_args.remove(token)

        taskfilter_args = list(tokens_to_add) + taskfilter_args

        # Deal with the situation when both +TAG and -TAG appear in the
        # taskfilter_args. If one of them is from the defaults, the explicit
        # version wins.

        def detect_virtual_tag(tag):
            return tag.isupper() and tag[0] in ('+', '-')

        def get_complement_tag(tag):
            return ('+' if tag.startswith('-') else '-') + tag[1:]

        virtual_tags = list(filter(detect_virtual_tag, taskfilter_args))
        tokens_to_remove = set()
        # For each virtual tag, check if its complement is in the
        # taskfilter_args too. If so, remove the tag that came from defaults.
        for token in virtual_tags:
            complement = get_complement_tag(token)
            if complement in virtual_tags:
                # Both tag and its complement are in the taskfilter_args.
                # Remove the one from defaults.
                if token in constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS:
                    tokens_to_remove.add(token)
                if complement in constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS:
                    tokens_to_remove.add(complement)

        for token in tokens_to_remove:
            if token in taskfilter_args:
                taskfilter_args.remove(token)

        # Process meta tags, remove them from filter
        meta = dict()

        for token in taskfilter_args:
            if token == '-VISIBLE':
                meta['visible'] = False

        taskfilter_args = [
            x for x in taskfilter_args if x not in self.meta_tokens
        ]

        # If, after all processing, any empty parens appear in the
        # seqeunce of taskfilter_args, remove them
        def deempty_parenthesize(tokens):
            empty_paren_index = None

            # Detect any empty parenthesis pair
            for index, token in enumerate(tokens):
                if token == '(' and tokens[index + 1] == ')':
                    empty_paren_index = index

            # Delete empty pair, if found
            if empty_paren_index is not None:
                del tokens[empty_paren_index]
                del tokens[empty_paren_index]

                # Attempt to delete next one, if it exists
                deempty_parenthesize(tokens)

        deempty_parenthesize(taskfilter_args)

        # All syntactic processing done, return the resulting filter args
        return taskfilter_args, meta
コード例 #6
0
 def __getitem__(self, key):
     try:
         return self.warriors[key]
     except KeyError:
         raise errors.TaskWikiException(
             "Taskwarrior with key '{0}' not available.".format(key))