def f(view, s): if mode == NORMAL: start = s.b if view.substr(start) == target: start -= 1 prev_target = find_prev_lone_bracket(view, start, brackets) if prev_target is not None: return Region(prev_target.a) elif mode in (VISUAL, VISUAL_LINE): start = s.b if s.b > s.a: start -= 1 if view.substr(start) == target: start -= 1 prev_target = find_prev_lone_bracket(view, start, brackets) if prev_target: if mode == VISUAL: resolve_visual_target(s, prev_target.a) elif mode == VISUAL_LINE: resolve_visual_line_target(view, s, prev_target.a) return s
def run(self, edit, mode, count, search=None, forward=True, save=True): if len(self.view.sel()) != 1: ui_bell('sneak does not support multiple cursors') return if not search: search = _get_last_sneak_search(self.view) if not search: ui_bell('no previous sneak search') return clear_search_highlighting(self.view) flags = _get_search_flags(self.view, search) s = self.view.sel()[0] start_pt = get_insertion_point_at_b(s) if forward: occurrences = view_find_all_in_range(self.view, search, start_pt + 1, self.view.size(), flags) else: occurrences = list( view_rfind_all(self.view, search, start_pt, flags)) occurrences = occurrences[count - 1:] if not occurrences: ui_bell('not found: %s' % search) return target = occurrences[0].a if mode == NORMAL: s.a = s.b = target elif mode == VISUAL: resolve_visual_target(s, target) elif mode == VISUAL_LINE: resolve_visual_line_target(self.view, s, target) elif mode == INTERNAL_NORMAL: s.b = target else: return set_selection(self.view, s) add_search_highlighting(self.view, occurrences) if save: set_last_char_search_command( self.view, 'sneak_s' if forward else 'sneak_big_s') _set_last_sneak_search(self.view, search)
def f(view, s): if mode == NORMAL: start = s.b if view.substr(start) == target: start += 1 bracket = find_next_lone_bracket(view, start, brackets, count) if bracket is not None: s = Region(bracket.a) elif mode in (VISUAL, VISUAL_LINE): start = s.b if s.b <= s.a and view.substr(start) == target: start += 1 next_target = find_next_lone_bracket(view, start, brackets) if next_target: if mode == VISUAL: resolve_visual_target(s, next_target.a) elif mode == VISUAL_LINE: resolve_visual_line_target(view, s, next_target.a) return s