def _do_C(view, edit, mode, count=1, motion=None): def f(view, s): return Region(s.begin()) if motion: run_motion(view, motion) elif mode not in (VISUAL, VISUAL_LINE): return ui_bell() view.run_command('toggle_comment', {'block': True}) regions_transformer(view, f) enter_normal_mode(view, mode)
def _next_history(self, edit, backwards): if self.view.size() == 0: raise RuntimeError('expected a non-empty command-line') firstc = self.view.substr(0) if not history_get_type(firstc): raise RuntimeError('expected a valid command-line') if _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX is None: _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX = -1 if backwards else 0 else: _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX += -1 if backwards else 1 count = history_len(firstc) if count == 0: _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX = None return ui_bell() if abs(_nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX) > count: _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX = -count return ui_bell() if _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX >= 0: _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX = 0 if self.view.size() > 1: return self.view.erase(edit, Region(1, self.view.size())) else: return ui_bell() if self.view.size() > 1: self.view.erase(edit, Region(1, self.view.size())) item = history_get(firstc, _nv_cmdline_handle_key.LAST_HISTORY_ITEM_INDEX) if item: self.view.insert(edit, 1, item)
def goto_prev_target(view, mode, count, target): targets = { '{': ('\\{', '\\}'), '(': ('\\(', '\\)'), } brackets = targets.get(target) if not brackets or mode not in (NORMAL, VISUAL, VISUAL_LINE): ui_bell() return 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 regions_transformer(view, f)
def goto_next_target(view, mode, count, target): targets = { '}': ('\\{', '\\}'), ')': ('\\(', '\\)'), } brackets = targets.get(target) if not brackets or mode not in (NORMAL, VISUAL, VISUAL_LINE): ui_bell() return 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 regions_transformer(view, f)
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 _do_c(view, edit, mode, count=1, motion=None): def f(view, s): return Region(s.begin()) if motion: run_motion(view, motion) elif mode not in (VISUAL, VISUAL_LINE): return ui_bell() view.run_command('toggle_comment', {'block': False}) regions_transformer(view, f) line = view.line(view.sel()[0].begin()) pt = line.begin() if line.size() > 0: line = view.find('^\\s*', line.begin()) pt = line.end() set_selection(view, pt) enter_normal_mode(view, mode)