def update_environment_status(window: sublime.Window, env_name: str): for view in window.views(): if view.match_selector(0, "source.julia"): if view.settings().get("lsp_active"): view.set_status(STATUS_BAR_KEY, env_name) else: view.erase_status(STATUS_BAR_KEY)
def agenda_meta_info_get_or_create_view(window: sublime.Window, meta_info: Agenda.AgendaItemMetaInfo): if meta_info.file_name is not None: view = window.find_open_file(meta_info.file_name) if view is not None: return view return window.open_file(meta_info.file_name) for view in window.views(): if view.id() == meta_info.view_id: return view raise ZorgmodeError("Cannot find file for this item")
def close_window(window: sublime.Window, *, force: bool = False) -> None: """Close the given window, discarding unsaved changes if `force` is ``True``. :raise ValueError: if any view in the window has unsaved changes and `force` is not ``True``. .. versionadded:: 1.2 """ for view in window.views(): if view.is_dirty() and not view.is_scratch(): if force: view.set_scratch(True) else: raise ValueError('A view has unsaved changes.') window.run_command('close_window')
def close_window(window: sublime.Window, *, force: bool = False) -> None: """Close the given window, discarding unsaved changes if `force` is ``True``. :raise ValueError: if any view in the window has unsaved changes and `force` is not ``True``. .. versionadded:: 1.2 """ unsaved = [ view for view in window.views() if view.is_dirty() and not view.is_scratch() ] if unsaved: if not force: raise ValueError('A view has unsaved changes.') with _temporarily_scratch_unsaved_views(unsaved): window.run_command('close_window') else: window.run_command('close_window')
def sample_one_error(window: sublime.Window) -> "Optional[str]": # Samples one error for the nice help message for the TextInputHandler. # We take the store in `sublime_linter` bc that's the one that only holds # *filtered* errors. We do the sorting to *prioritize* errors from the # active view or at least current window. view = window.active_view() top_filename = canonical_filename(view) if view else '' other_filenames = {canonical_filename(view) for view in window.views()} def key_fn(filename_errors): filename, _ = filename_errors return ('a' if filename == top_filename else 'b' if filename in other_filenames else 'c') for filename, errors in sorted(persist.file_errors.items(), key=key_fn): if not errors: continue error = errors[0] return format_error(error) else: return None
def _window_has_output_views(window: sublime.Window): for view in window.views(): if view.settings().has('debugger.OutputView'): return True return False
def remove_highlights(window: sublime.Window): for view in window.views(): if view.file_name(): for kind in settings.document_highlight_scopes.keys(): view.erase_regions("lsp_highlight_{}".format(kind))