示例#1
0
    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()
示例#2
0
    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])
示例#3
0
    def _process_args(self, args):
        tw_args = util.tw_modstring_to_args(args)

        # If only 'global' argument has been passed, then no
        # filter should be applied
        if tw_args == ['global']:
            return []
        # If unempty filter has been passed, then use that
        elif tw_args != []:
            return tw_args
        # If no argument has been passed, locate the closest viewport,
        # if any exists, and use its filter.
        else:
            port = viewport.ViewPort.find_closest(cache)
            return port.taskfilter if port is not None else []
示例#4
0
    def _process_args(self, args):
        tw_args = util.tw_modstring_to_args(args)

        # If only 'global' argument has been passed, then no
        # filter should be applied
        if tw_args == ['global']:
            return []
        # If unempty filter has been passed, then use that
        elif tw_args != []:
            return tw_args
        # If no argument has been passed, locate the closest viewport,
        # if any exists, and use its filter.
        else:
            port = viewport.ViewPort.find_closest(cache)
            return port.taskfilter if port is not None else []
示例#5
0
    def from_line(cls, number, cache):
        match = re.search(regexp.GENERIC_VIEWPORT, vim.current.buffer[number])

        if not match:
            return None

        taskfilter = util.tw_modstring_to_args(match.group('filter') or '')
        defaults, meta = util.tw_modstring_to_kwargs(
            match.group('filter') + ' ' + (match.group('defaults') or ''))
        name = match.group('name').strip()
        tw = cache.warriors[match.group('source') or 'default']

        self = cls(number, cache, tw, name, taskfilter, defaults, meta)

        return self
示例#6
0
    def from_line(cls, number, cache):
        match = re.search(regexp.GENERIC_VIEWPORT, vim.current.buffer[number])

        if not match:
            return None

        taskfilter = util.tw_modstring_to_args(match.group('filter') or '')
        defaults, meta = util.tw_modstring_to_kwargs(
            match.group('filter') + ' ' + (match.group('defaults') or ''))
        name = match.group('name').strip()
        tw = cache.warriors[match.group('source') or 'default']

        self = cls(number, cache, tw, name, taskfilter, defaults, meta)

        return self
示例#7
0
 def __init__(self, args):
     self.args = []
     self.tw_extra_args = util.tw_modstring_to_args(args)
     self.split_name = self.split_name or self.command
     self.tw = cache.get_relevant_tw()
示例#8
0
 def __init__(self, args):
     self.args = []
     self.tw_extra_args = util.tw_modstring_to_args(args)
     self.split_name = self.split_name or self.command
     self.tw = cache.get_relevant_tw()
示例#9
0
    def process_filterstring(self, filterstring):
        """
        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)
        taskfilter_args += util.tw_modstring_to_args(filterstring)

        # 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 util.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 = 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 = filter(lambda x: x not in self.meta_tokens,
                                 taskfilter_args)

        # All syntactic processing done, return the resulting filter args
        return taskfilter_args, meta
示例#10
0
    def process_filterstring(self, filterstring):
        """
        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)
        taskfilter_args += util.tw_modstring_to_args(filterstring)

        # 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 = 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 = filter(lambda x: x not in self.meta_tokens,
                                 taskfilter_args)

        # All syntactic processing done, return the resulting filter args
        return taskfilter_args, meta