Exemplo n.º 1
0
    def f(region):
        if not region.a == region.b:
            return region
        point = region.a

        (a_exp, b_exp) = shared.get_expression(view, point, direction)

        if shared.truthy(a_exp, b_exp):
            (anext_exp, bnext_exp) = reversed(
                shared.get_next_expression(
                    view,
                    shared.step(b_exp, -1 if direction == "backward" else -2,
                                direction), True,
                    shared.opposite_direction(direction)))
            if shared.truthy(anext_exp, bnext_exp):
                end_bracket = shared.get_char(
                    view, shared.step(b_exp, -1, direction), direction)

                view.erase(
                    edit,
                    sublime.Region(shared.step(b_exp, -1, direction), b_exp))
                target_point = anext_exp
                for (i, c) in shared.walk(
                        view,
                        shared.step(anext_exp,
                                    -1 if direction == "forward" else -2,
                                    direction),
                        shared.opposite_direction(direction)):
                    if not c.isspace():
                        target_point = shared.step(i, 1, direction)
                        break

                shared.insert(view, edit, target_point, end_bracket, direction)

        return point
Exemplo n.º 2
0
	def f(region):
		if not region.a == region.b:
			return region

		point = region.a

		if shared.is_inside_string(view, point):
			(a, b) = shared.get_expression(view, point, direction)
			target_point = shared.step(b, -1, direction)
			if point == target_point:
				return shared.step(point, 1, direction)
			return shared.step(b, -1, direction)

		if direction == "backward":
			point -= 1

		(word_a, word_b) = shared.get_word(view, point, direction)
		if shared.truthy(word_b):
			return word_b

		(next_a, next_b) = shared.get_next_expression(view, point, False, direction)
		if shared.truthy(next_b):
			return next_b

		expr_point = point
		if direction == "backward":
			expr_point += 1

		(a, b) = shared.get_expression(view, expr_point, direction)
		if shared.truthy(b): return b

		if direction == "forward":
			return shared.step(point, 1, direction)
		else:
			return point
Exemplo n.º 3
0
	def f(region):
		if not region.a == region.b:
			return region
		point = region.a

		(a_exp, b_exp) = shared.get_expression(view, point, direction)

		if a_exp and b_exp:
			(anext_exp, bnext_exp) = shared.get_next_expression(view, b_exp, True, direction)
			if anext_exp and bnext_exp:
				end_bracket = shared.get_char(view, shared.step(b_exp, -1, direction), direction)
				view.erase(edit, sublime.Region(shared.step(b_exp, -1, direction), b_exp))
				shared.insert(view, edit, shared.step(bnext_exp, -1, direction), end_bracket, direction)

		return point
Exemplo n.º 4
0
    def f(region):
        if not region.a == region.b:
            return region
        point = region.a

        (a_exp, b_exp) = shared.get_expression(view, point, direction)

        if shared.truthy(a_exp, b_exp):
            (anext_exp,
             bnext_exp) = shared.get_next_expression(view, b_exp, True,
                                                     direction)
            if shared.truthy(anext_exp, bnext_exp):
                end_bracket = shared.get_char(
                    view, shared.step(b_exp, -1, direction), direction)
                view.erase(
                    edit,
                    sublime.Region(shared.step(b_exp, -1, direction), b_exp))
                shared.insert(view, edit, shared.step(bnext_exp, -1,
                                                      direction), end_bracket,
                              direction)

        return point
Exemplo n.º 5
0
	def f(region):
		if not region.a == region.b:
			return region
		point = region.a

		(a_exp, b_exp) = shared.get_expression(view, point, direction)

		if a_exp and b_exp:
			(anext_exp, bnext_exp) = reversed(shared.get_next_expression(
				view, shared.step(b_exp, -1 if direction == "backward" else -2, direction), True, shared.opposite_direction(direction)))
			if anext_exp and bnext_exp:
				end_bracket = shared.get_char(view, shared.step(b_exp, -1, direction), direction)

				view.erase(edit, sublime.Region(shared.step(b_exp, -1, direction), b_exp))
				target_point = anext_exp
				for (i, c) in shared.walk(view, shared.step(anext_exp, -1 if direction == "forward" else -2, direction), shared.opposite_direction(direction)):
					if not c.isspace():
						target_point = shared.step(i, 1, direction)
						break

				shared.insert(view, edit, target_point, end_bracket, direction)

		return point
Exemplo n.º 6
0
    def f(region):
        if not region.a == region.b:
            return region

        point = region.a

        if shared.is_inside_string(view, point):
            (a, b) = shared.get_expression(view, point, direction)
            target_point = shared.step(b, -1, direction)
            if point == target_point:
                return shared.step(point, 1, direction)
            return shared.step(b, -1, direction)

        if direction == "backward":
            point -= 1

        (word_a, word_b) = shared.get_word(view, point, direction)
        if shared.truthy(word_b):
            return word_b

        (next_a, next_b) = shared.get_next_expression(view, point, False,
                                                      direction)
        if shared.truthy(next_b):
            return next_b

        expr_point = point
        if direction == "backward":
            expr_point += 1

        (a, b) = shared.get_expression(view, expr_point, direction)
        if shared.truthy(b): return b

        if direction == "forward":
            return shared.step(point, 1, direction)
        else:
            return point