def run(self, edit, *args, **kwargs): if self.only_in_mode is None: pass elif self.only_in_mode == 'browse': if regedit.is_active_in(self.view): raise StopCommand elif self.only_in_mode == 'edit': if not regedit.is_active_in(self.view): raise StopCommand else: raise RuntimeError op.ensure_trailing_nl(self.view, edit) yield
def on_activated(self): if not regedit.is_active_in(self.view): history = History(self.view) regedit.establish( self.view, sublime.Region(history.prompt_regs[-1].end(), self.view.size()))
def run(self, edit): if regedit.is_active_in(self.view): ok = sublime.ok_cancel_dialog("Unsaved changes would be lost. Continue?") if not ok: return op.terminate_edit_mode(self.view) comm.op('refreshModule', {'module': op.view_module_name(self.view)})
def terminate_edit_mode(view): """Exit from edit mode in the most direct and blunt way This must only be used before full module refresh or similar operations. """ assert regedit.is_active_in(view) cxt = edit_cxt_for.pop(view) regedit.discard(view, read_only=True)
def _check_src_available(self, src_module, entry): """Check that we're not attempting to move an entry which is under edit""" src_view = self.window.find_open_file(op.module_filename(src_module)) if src_view is not None and regedit.is_active_in(src_view): entry_obj = op.module_body(src_view).entry_by_name(entry) if entry_obj is None or entry_obj.is_under_edit(): sublime.error_message( "Source entry is under edit or not found") raise StopCommand
def _check_anchor_available(self, dest_module, anchor): """Check that the anchor entry is not under edit (except definition editing). Other kinds of editing might fool the Sublime parser (e.g. ongoing renaming) """ dest_view = self.window.find_open_file(op.module_filename(dest_module)) if dest_view is not None and anchor is not None and \ regedit.is_active_in(dest_view): mcont = op.module_body(dest_view) if anchor is True: entry_obj = mcont.entries[-1] elif anchor is False: entry_obj = mcont.entries[0] else: entry_obj = mcont.entry_by_name(anchor) if (entry_obj is None or entry_obj.is_under_edit() and op.edit_cxt_for[dest_view].target != 'defn'): sublime.error_message( "Anchor entry is under edit or not found") raise StopCommand
def run(self, edit): if not regedit.is_active_in(self.view): return # Protected by keymap binding reg = regedit.editing_region(self.view) reg_stripped = end_strip_region(self.view, reg) if reg_stripped.empty(): sublime.status_message("Empty prompt") return if reg.end() > reg_stripped.end(): self.view.erase(edit, sublime.Region(reg_stripped.end(), reg.end())) reg = reg_stripped code = self.view.substr(reg) try: text = comm.op('eval', { 'module': poli_cur_module[self.view], 'code': code }) success = True except ReplEvalError as e: text = e.stack success = False if success: self.view.insert(edit, self.view.size(), '\n< ') else: self.view.insert(edit, self.view.size(), '\n! ') self.view.insert(edit, self.view.size(), text) self.view.insert(edit, self.view.size(), '\n') insert_prompt_at_end(self.view, edit) hns_for.pop(self.view, None)
def switch_poli_off(window): for view in window.views(): if op.is_view_poli(view): if regedit.is_active_in(view): op.terminate_edit_mode(view) op.teardown_module_view(view)