def f(region): if not region.begin() == region.end(): if shared.is_strict_mode(): return strict_delete_selection(view, edit, region) else: return shared.erase_region(view, edit, region) point = region.begin() if is_forward: direction = 1 next_char = view.substr(point) skip_char_type = "lbracket" else: direction = -1 next_char = view.substr(point - 1) skip_char_type = "rbracket" next_char_type = shared.char_type(next_char) if shared.is_inside_comment(view, point): pass # pass to else below elif next_char_type == "string": if shared.is_inside_string(view, point): if ((not is_forward) and (point - 2 >= 0) and view.substr(point - 2) == "\\"): return shared.erase_region( view, edit, sublime.Region(point, point - 2)) else: return remove_empty_expression(view, edit, point, direction) else: return region.begin() + direction elif shared.is_inside_string(view, point): # Same purpose as is_inside_comment above # but has to be tested after the elif above. if (is_forward and (point + 2 < view.size()) and view.substr( sublime.Region(point, point + 2)) == "\\\""): return shared.erase_region(view, edit, sublime.Region(point, point + 2)) else: pass elif next_char_type == skip_char_type: return region.begin() + direction elif next_char_type: return remove_empty_expression(view, edit, point, direction) # else return standard_delete(view, edit, point, is_forward)
def f(region): if not region.begin() == region.end(): if shared.is_strict_mode(): return strict_delete_selection(view, edit, region) else: return shared.erase_region(view, edit, region) point = region.begin() if is_forward: direction = 1 next_char = view.substr(point) skip_char_type = "lbracket" else: direction = -1 next_char = view.substr(point - 1) skip_char_type = "rbracket" next_char_type = shared.char_type(next_char) if shared.is_inside_comment(view, point): pass # pass to else below elif next_char_type == "string": if shared.is_inside_string(view, point): if ((not is_forward) and (point - 2 >= 0) and view.substr(point - 2) == "\\"): return shared.erase_region(view, edit, sublime.Region(point, point - 2)) else: return remove_empty_expression(view, edit, point, direction) else: return region.begin() + direction elif shared.is_inside_string(view, point): # Same purpose as is_inside_comment above # but has to be tested after the elif above. if (is_forward and (point + 2 < view.size()) and view.substr(sublime.Region(point, point + 2)) == "\\\""): return shared.erase_region( view, edit, sublime.Region(point, point + 2)) else: pass elif next_char_type == skip_char_type: return region.begin() + direction elif next_char_type: return remove_empty_expression(view, edit, point, direction) # else return standard_delete(view, edit, point, is_forward)
def f(region): begin = region.begin() end = region.end() if shared.is_strict_mode(): text = view.substr(region) if not (shared.bracket_count(text, "(", ")") == 0 and shared.bracket_count(text, "[", "]") == 0 and shared.bracket_count(text, "{", "}") == 0): return region view.insert(edit, begin, left_bracket) if not (begin == end and (shared.is_inside_string(view, begin) or shared.is_inside_comment(view, begin))): view.insert(edit, end + 1, right_bracket) return begin + 1