def run(self, edit): blocks = list_blocks(self.view) this_block = region_at(blocks, cursor_pos(self.view)) if not this_block: return prev_block = region_b(blocks, this_block.begin() - 1) if not prev_block: return swap_regions(self.view, edit, prev_block, this_block) self.view.show(prev_block)
def run(self, edit): pos = cursor_pos(self.view) region = word_at(self.view, pos) if not region: return word = self.view.substr(region) all_regions = self.view.find_all(r'\b%s\b' % word) next_region = region_b(all_regions, region.begin() - 1) or last(all_regions) set_cursor(self.view, next_region.begin())
def func_at(view, pos): defs = _func_defs(view) if source(view, pos) == 'python': is_junk = lambda r: re_test('^(lambda|\s*\@)', view.substr(r)) defs = lremove(is_junk, defs) func_def = region_b(defs, pos) lang = source(view, pos) if lang == 'python': next_line = newline_f(view, func_def.end()) return func_def.cover(view.indented_region(next_line)) elif lang == 'js': start_bracket = view.find(r'{', func_def.end(), sublime.LITERAL) end_bracket = find_matching_bracket(view, start_bracket) return func_def.cover(end_bracket) else: return func_def
def smart_up(pos): target = region_b(regions, pos.begin() - 1) or last(regions) return target.begin()