def ui_blink(msg=None, times=4, delay=55): if msg: status_message(msg) view = active_window().active_view() if not view: return settings = view.settings() if settings.get('vintageous_belloff') == 'all': return if settings.get('vintageous_wip'): return _ui_bell() # Ensure we leave the setting as we found it. times = times if (times % 2) == 0 else times + 1 def do_blink(): nonlocal times if times > 0: settings.set('highlight_line', not settings.get('highlight_line')) times -= 1 set_timeout(do_blink, delay) do_blink()
def ui_bell(msg=None): if msg: status_message(msg) window = active_window() if not window: return view = window.active_view() if not view: return settings = view.settings() if settings.get('vintageous_belloff') == 'all': return color_scheme = settings.get('vintageous_bell_color_scheme', 'dark') if color_scheme in ('dark', 'light'): color_scheme = 'Packages/NeoVintageous/res/Bell-%s.hidden-color-scheme' % color_scheme duration = int(0.3 * 1000) times = 4 delay = 55 style = settings.get('vintageous_bell') if style == 'view': settings.set('color_scheme', color_scheme) def remove_bell(): settings.erase('color_scheme') set_timeout(remove_bell, duration) elif style == 'views': views = [] for group in range(window.num_groups()): view = window.active_view_in_group(group) if view: view.settings().set('color_scheme', color_scheme) views.append(view) def remove_bell(): for view in views: view.settings().erase('color_scheme') set_timeout(remove_bell, duration) elif style == 'blink': # Ensure we leave the setting as we found it. times = times if (times % 2) == 0 else times + 1 def do_blink(): nonlocal times if times > 0: settings.set('highlight_line', not settings.get('highlight_line')) times -= 1 set_timeout(do_blink, delay) do_blink()
def window_tab_control(window, action: str, count: int = 1, index: int = None) -> None: view = window.active_view() if not view: return status_message('view not found') view_count = len(window.views_in_group(window.active_group())) group_index, view_index = window.get_view_index(view) if action == 'next': window.run_command('select_by_index', {'index': (view_index + count) % view_count}) elif action == 'previous': window.run_command( 'select_by_index', {'index': (view_index + view_count - count) % view_count}) elif action == 'last': window.run_command('select_by_index', {'index': view_count - 1}) elif action == 'first': window.run_command('select_by_index', {'index': 0}) elif action == 'goto': if index: window.run_command('select_by_index', {'index': index - 1}) elif action == 'only': group_views = window.views_in_group(group_index) if any(view.is_dirty() for view in group_views): return status_message('E445: Other window contains changes') for group_view in group_views: if group_view.id() == view.id(): continue window.focus_view(group_view) # TODO [review] Probably doesn't need use :quit (just close the view). from NeoVintageous.nv.ex_cmds import do_ex_command do_ex_command(window, 'quit') window.focus_view(view) elif action == 'close': window.run_command('close_by_index', { 'group': group_index, 'index': view_index }) else: raise ValueError('unknown tab control action: %s' % action)
def _close_current_view(self, do_not_close_if_last): """ Close current view. If {do_not_close_if_last} then this command fails when there is only one view on screen. Modified views are not removed, so changes cannot get lost. If it's not a file on disk and contains only whitespace then it is closed. """ views_in_group = self.window.views_in_group(self.window.active_group()) if len(views_in_group) == 0: self.window.run_command('destroy_pane', {'direction': 'self'}) return current_view = self.window.active_view() if not current_view: return # If it's not a file on disk and contains only whitespace then close it if not current_view.file_name() and current_view.substr( Region(0, current_view.size())).strip() == '': current_view.set_scratch(True) current_view.close() views_in_group = self.window.views_in_group( self.window.active_group()) if len(views_in_group) == 0: self.window.run_command('destroy_pane', {'direction': 'self'}) return if do_not_close_if_last and len(self.window.views()) < 2: return status_message('cannot close last view') if current_view.is_dirty(): dirty_buffer_message = 'No write since last change' if current_view.file_name() is not None: dirty_buffer_message += ' for buffer "%s"' % current_view.file_name( ) return status_message(dirty_buffer_message) current_view.close() views_in_group = self.window.views_in_group(self.window.active_group()) if len(views_in_group) == 0: self.window.run_command('destroy_pane', {'direction': 'self'}) return
def goto_help(window): view = window.active_view() if not view: raise ValueError('view is required') if not view.sel(): raise ValueError('selection is required') sel = view.sel()[0] score = view.score_selector(sel.b, 'text.neovintageous jumptag') # TODO goto to help for any word in a help file. See :h bar Anyway, you can # use CTRL-] on any word, also when it is not within |, and Vim will try to # find help for it. Especially for options in single quotes, e.g. # 'compatible'. if score == 0: return subject = view.substr(view.extract_scope(sel.b)) if not subject: return if len(subject) > 35: return status_message('E149: Sorry, no help found') # TODO Refactor ex cmd internets to this common utility from NeoVintageous.nv.ex_cmds import do_ex_command do_ex_command(window, 'help', {'subject': subject})
def _close_view(window, forceit: bool = False, close_if_last: bool = True, **kwargs) -> None: """Close view. When quitting the last view, unless close_if_last is false, exit Sublime. When forceit is true the view is closed and the buffer contents are lost. """ views_in_group = window.views_in_group(window.active_group()) if len(views_in_group) == 0: window.run_command('destroy_pane', {'direction': 'self'}) return if not close_if_last and len(window.views()) < 2: return view = window.active_view() if not view: return if forceit: view.set_scratch(True) if view.is_dirty(): buffer_name = view.file_name() if buffer_name is None: buffer_name = '[No Name]' status_message('No write since last change for buffer "%s"' % buffer_name) return view.close() views_in_group = window.views_in_group(window.active_group()) if len(views_in_group) == 0: window.run_command('destroy_pane', {'direction': 'self'})
def run(self): rcfile.reload() status_message('rc file reloaded')
def run(self): rc.reload() status_message('runtime configuation file reloaded')