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
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
def strict_delete_selection(view, edit, region): replace_char = str(chr(1)) offset = region.begin() out = list(view.substr(region)) point = region.begin() while point < region.end(): if (shared.is_inside_comment(view, point) or shared.is_inside_string(view, point)): out[point - offset] = replace_char point += 1 continue (a, b) = shared.get_next_expression(view, point, True) if shared.truthy(a, b): if shared.is_inside_word(view.substr(a)): if a > region.end(): break a = max(a, region.begin()) b = min(b, region.end()) if b > region.end(): break if not a < region.begin(): a_local = a - offset b_local = b - offset out[a_local:b_local] = list(replace_char * (b - a)) point = b else: break out = "".join(out) out = out.replace(replace_char, "").strip() view.replace(edit, region, out) return region.begin()
def f(region): if not region.a == region.b: return region (a, b) = shared.get_next_expression(view, region.a, skip_words=True) if a: return a + 1
def f(region): if not region.a == region.b: return insert_brackets(view, edit, lbracket, rbracket, region) point = region.a (lb, rb) = shared.get_next_expression(view, point) if shared.truthy(lb, rb): return insert_brackets(view, edit, lbracket, rbracket, sublime.Region(lb, rb)) return point
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
def f(region): if not region.a == region.b: return region point = region.a (lb, rb) = shared.get_expression(view, point) if shared.truthy(lb, rb): (lexp, rexp) = shared.get_next_expression(view, point) lexp = lexp or point rexp = rexp or point view.erase(edit, sublime.Region(rexp, rb)) view.erase(edit, sublime.Region(lb, lexp)) return lb else: return point
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
def strict_delete_selection(view, edit, region): replace_char = str(chr(1)) point = region.begin() while point < region.end(): (a, b) = shared.get_next_expression(view, point, True) if a and b: if shared.is_inside_word(view.substr(a)): if a > region.end(): break a = max(a, region.begin()) b = min(b, region.end()) if b > region.end(): break if not a < region.begin(): view.replace(edit, sublime.Region(a, b), replace_char * (b - a)) point = b else: break view.replace(edit, region, view.substr(region).replace(replace_char, "").strip()) return region.begin()
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