def run(self, edit): state = VintageState(self.view) if state.mode == MODE_VISUAL: state.store_visual_selections() self.view.run_command('collapse_to_direction') self.view.run_command('dont_stay_on_eol_backward') state.enter_normal_mode()
def run(self, edit, commands): for cmd, args in commands: self.view.run_command(cmd, args) # XXX: Sequence is a special case in that it doesn't run through vi_run, so we need to # ensure the next mode is correct. Maybe we can improve this by making it more similar to # regular commands? state = VintageState(self.view) state.enter_normal_mode()
def run(self, edit, commands): for cmd, args in commands: self.view.run_command(cmd, args) # XXX: Sequence is a special case in that it doesn't run through vi_run, so we need to # ensure the next mode is correct. Maybe we can improve this by making it more similar to # regular commands? state = VintageState(self.view) state.enter_normal_mode()
def run(self, edit): state = VintageState(self.view) if state.mode == MODE_VISUAL: state.store_visual_selections() self.view.run_command('collapse_to_direction') self.view.run_command('dont_stay_on_eol_backward') state.enter_normal_mode()
def run(self, edit): state = VintageState(self.view) if state.mode == MODE_VISUAL: state.store_visual_selections() # When returning to normal mode from select mode, we want to keep the non-Vintageous # selections just created. if state.mode != MODE_SELECT: self.view.run_command('collapse_to_direction') self.view.run_command('dont_stay_on_eol_backward') state.enter_normal_mode()
def run(self, edit): state = VintageState(self.view) if state.mode == MODE_VISUAL: state.store_visual_selections() # When returning to normal mode from select mode, we want to keep the non-Vintageous # selections just created unless it's the last one. if not (state.mode == MODE_SELECT and len(self.view.sel()) > 1): self.view.run_command('collapse_to_direction') self.view.run_command('dont_stay_on_eol_backward') state.enter_normal_mode()
def testFromNormalModeToNormalMode(self): set_text(self.view, 'abc\nxxx\nabc\nabc') add_sel(self.view, self.R((1, 0), (1, 0))) state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode') prev_mode = state.mode self.view.run_command('ex_copy', {'address': '3'}) state = VintageState(self.view) new_mode = state.mode self.assertEqual(prev_mode, new_mode, MODE_NORMAL)
def testFromNormalModeToNormalMode(self): set_text(self.view, 'abc\nxxx\nabc\nabc') add_sel(self.view, self.R((1, 0), (1, 0))) state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode') prev_mode = state.mode self.view.run_command('ex_copy', {'address': '3'}) state = VintageState(self.view) new_mode = state.mode self.assertEqual(prev_mode, new_mode, MODE_NORMAL)
def testFromNormalModeToNormalMode(self): self.write("abc\nxxx\nabc\nabc") self.clear_sel() self.add_sel(self.R((1, 0), (1, 0))) state = VintageState(self.view) state.enter_normal_mode() self.view.run_command("vi_enter_normal_mode") prev_mode = state.mode self.view.run_command("ex_move", {"address": "3"}) state = VintageState(self.view) new_mode = state.mode self.assertEqual(prev_mode, new_mode)
def testFromNormalModeToNormalMode(self): set_text(self.view, 'abc\nxxx\nabc\nabc') add_selection(self.view, self.R((1, 0), (1, 0))) state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode') prev_mode = state.mode self.range['left_offset'] = 2 self.range['text_range'] = '2' self.view.run_command('ex_delete', {'line_range': self.range}) state = VintageState(self.view) new_mode = state.mode self.assertEqual(prev_mode, new_mode)
def testFromNormalModeToNormalMode(self): set_text(self.view, 'abc\nxxx\nabc\nabc') add_sel(self.view, self.R((1, 0), (1, 0))) state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode') prev_mode = state.mode self.range['left_offset'] = 2 self.range['text_range'] = '2' self.view.run_command('ex_delete', {'line_range': self.range}) state = VintageState(self.view) new_mode = state.mode self.assertEqual(prev_mode, new_mode)
def run(self, edit): sels = list(self.view.sel()) self.view.sel().clear() new_sels = [] for s in sels: if s.a <= s.b: if (self.view.line(s.a).a != s.a): new_sels.append(sublime.Region(s.a - 1, s.a - 1)) else: new_sels.append(sublime.Region(s.a, s.a)) else: new_sels.append(s) for s in new_sels: self.view.sel().add(s) state = VintageState(self.view) state.enter_normal_mode()
def run(self, edit): sels = list(self.view.sel()) self.view.sel().clear() new_sels = [] for s in sels: if s.a <= s.b: if (self.view.line(s.a).a != s.a): new_sels.append(sublime.Region(s.a - 1, s.a - 1)) else: new_sels.append(sublime.Region(s.a, s.a)) else: new_sels.append(s) for s in new_sels: self.view.sel().add(s) state = VintageState(self.view) state.enter_normal_mode() self.view.window().run_command('hide_auto_complete')
def run(self, line_range=None, forced=False, file_name='', plusplus_args='', operator='', target_redirect='', subcmd=''): if file_name and target_redirect: sublime.status_message('Vintageous: Too many arguments.') return appending = operator == '>>' a_range = line_range['text_range'] self.view = self.window.active_view() content = get_region_by_range(self.view, line_range=line_range) if a_range else \ [sublime.Region(0, self.view.size())] read_only = False if self.view.file_name(): mode = os.stat(self.view.file_name()) read_only = (stat.S_IMODE(mode.st_mode) & stat.S_IWUSR != stat.S_IWUSR) if target_redirect: target = self.window.new_file() target.set_name(target_redirect) elif file_name: def report_error(msg): sublime.status_message('Vintageous: %s' % msg) file_path = os.path.abspath(os.path.expanduser(file_name)) if os.path.exists(file_path) and (file_path != self.view.file_name()): # TODO add w! flag # TODO: Hook this up with ex error handling (ex/errors.py). msg = "File '{0}' already exists.".format(file_path) report_error(msg) return if not os.path.exists(os.path.dirname(file_path)): msg = "Directory '{0}' does not exist.".format(os.path.dirname(file_path)) report_error(msg) return try: # FIXME: We need to do some work with encodings here, don't we? with open(file_path, 'w+') as temp_file: for frag in reversed(content): temp_file.write(self.view.substr(frag)) temp_file.close() sublime.status_message("Vintageous: Saved {0}".format(file_path)) row, col = self.view.rowcol(self.view.sel()[0].b) encoded_fn = "{0}:{1}:{2}".format(file_path, row + 1, col + 1) self.view.set_scratch(True) w = self.window w.run_command('close') w.open_file(encoded_fn, sublime.ENCODED_POSITION) return except IOError as e: report_error( "Failed to create file '%s'." % file_name ) return window = self.window window.open_file(file_path) return else: target = self.view if (read_only or self.view.is_read_only()) and not forced: utils.blink() sublime.status_message("Vintageous: Can't write read-only file.") return start = 0 if not appending else target.size() prefix = '\n' if appending and target.size() > 0 else '' if appending or target_redirect: for frag in reversed(content): target.run_command('append', {'characters': prefix + self.view.substr(frag) + '\n'}) elif a_range: start_deleting = 0 text = '' for frag in content: text += self.view.substr(frag) + '\n' start_deleting = len(text) self.view.run_command('ex_replace_file', {'start': 0, 'end': 0, 'with_what': text}) else: dirname = os.path.dirname(self.view.file_name()) if not os.path.exists(dirname): os.makedirs(dirname) self.window.run_command('save') # This may unluckily prevent the user from seeing ST's feedback about saving the current # file. state = VintageState(self.window.active_view()) if state.mode != MODE_NORMAL: state.enter_normal_mode() self.window.run_command('vi_enter_normal_mode')
def set_mode(self): state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode')
def run(self, edit): state = VintageState(self.view) self.view.run_command('collapse_to_direction') self.view.run_command('dont_stay_on_eol_backward') state.reset() state.enter_normal_mode()
def set_mode(self): state = VintageState(self.view) state.enter_normal_mode() self.view.run_command('vi_enter_normal_mode')
def run(self, line_range=None, forced=False, file_name='', plusplus_args='', operator='', target_redirect='', subcmd=''): if file_name and target_redirect: sublime.status_message('Vintageous: Too many arguments.') return appending = operator == '>>' a_range = line_range['text_range'] self.view = self.window.active_view() content = get_region_by_range(self.view, line_range=line_range) if a_range else \ [sublime.Region(0, self.view.size())] if target_redirect: target = self.window.new_file() target.set_name(target_redirect) elif file_name: def report_error(msg): sublime.status_message('Vintageous: %s' % msg) file_path = os.path.abspath(os.path.expanduser(file_name)) if os.path.exists(file_path) and (file_path != self.view.file_name()): # TODO add w! flag # TODO: Hook this up with ex error handling (ex/errors.py). msg = "File '{0}' already exists.".format(file_path) report_error(msg) return if not os.path.exists(os.path.dirname(file_path)): msg = "Directory '{0}' does not exist.".format( os.path.dirname(file_path)) report_error(msg) return try: # FIXME: We need to do some work with encodings here, don't we? with open(file_path, 'w+') as temp_file: for frag in reversed(content): temp_file.write(self.view.substr(frag)) temp_file.close() sublime.status_message( "Vintageous: Saved {0}".format(file_path)) row, col = self.view.rowcol(self.view.sel()[0].b) encoded_fn = "{0}:{1}:{2}".format(file_path, row + 1, col + 1) self.view.set_scratch(True) w = self.window w.run_command('close') w.open_file(encoded_fn, sublime.ENCODED_POSITION) return except IOError as e: report_error("Failed to create file '%s'." % file_name) return window = self.window window.open_file(file_path) return else: target = self.view start = 0 if not appending else target.size() prefix = '\n' if appending and target.size() > 0 else '' if appending or target_redirect: for frag in reversed(content): target.run_command( 'append', {'characters': prefix + self.view.substr(frag) + '\n'}) elif a_range: start_deleting = 0 text = '' for frag in content: text += self.view.substr(frag) + '\n' start_deleting = len(text) self.view.run_command('ex_replace_file', { 'start': 0, 'end': 0, 'with_what': text }) else: dirname = os.path.dirname(self.view.file_name()) if not os.path.exists(dirname): os.makedirs(dirname) self.window.run_command('save') state = VintageState(self.window.active_view()) state.enter_normal_mode() self.window.run_command('vi_enter_normal_mode')