xmotions.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:VintageousPlus 作者: trishume 项目源码 文件源码
def run(self, char=None, mode=None, count=1, inclusive=True, skipping=False):
        # Contrary to *f*, *t* does not look past the caret's position, so if
        # @character is under the caret, nothing happens.

        def f(view, s):
            if mode == modes.VISUAL_LINE:
                raise ValueError(
                    'this operator is not valid in mode {}'.format(mode))

            b = s.b
            # If we are in any visual mode, get the actual insertion point.
            if s.size() > 0:
                b = resolve_insertion_point_at_b(s)

            # Vim skips a character while performing the search
            # if the command is ';' or ',' after a 't' or 'T'
            if skipping:
                b = b + 1

            eol = view.line(b).end()

            match = R(b + 1)
            for i in range(count):
                # Define search range as 'rest of the line to the right'.
                search_range = R(match.end(), eol)
                match = find_in_range(view, char, search_range.a,
                            search_range.b, sublime.LITERAL)

                # Count too high or simply no match; break.
                if match is None:
                    return s

            target_pos = match.a
            if not inclusive:
                target_pos = target_pos - 1

            if mode == modes.NORMAL:
                return R(target_pos)
            elif mode == modes.INTERNAL_NORMAL:
                return R(s.a, target_pos + 1)
            # For visual modes...
            else:
                new_a = resolve_insertion_point_at_a(s)
                return utils.new_inclusive_region(new_a, target_pos)

        if not all([char, mode]):
            raise ValueError('bad parameters')

        char = utils.translate_char(char)

        state = self.state

        regions_transformer(self.view, f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号