def run(self, edit): cxt = op.edit_cxt_for[self.view] reg = op.edit_region_for[self.view] if cxt.adding_new: with op.quitting_edit_mode(self.view): self.view.erase(edit, end_plus_1(reg)) return body = op.module_body(self.view) entry = body.entry_under_edit() if entry.is_def_under_edit(): defn = comm.op('getDefinition', { 'module': op.view_module_name(self.view), 'name': entry.name() }) with op.quitting_edit_mode(self.view): self.view.replace(edit, reg, defn) elif entry.is_name_under_edit(): name = comm.op('getNameAt', { 'module': op.view_module_name(self.view), 'at': entry.myindex }) with op.quitting_edit_mode(self.view): self.view.replace(edit, reg, name) else: raise RuntimeError
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 run(self, edit, direction): body = op.module_body(self.view) loc = body.cursor_location_or_stop(single_selected_region(self.view), require_fully_selected=True) comm.op( 'moveBy1', { 'module': op.view_module_name(self.view), 'name': loc.entry.name(), 'direction': direction })
def run(self, edit): edit_region = op.edit_region_for[self.view] cxt = op.edit_cxt_for[self.view] body = op.module_body(self.view) if cxt.adding_new: index = body.remove_ephemeral_entry() templ = op.RE_FULL_ENTRY[op.view_lang(self.view)] mtch = re.search(templ, self.view.substr(edit_region), re.DOTALL) if mtch is None: sublime.status_message("Invalid entry definition") return if mtch.group('def').isspace(): sublime.status_message("Empty definition not allowed") return comm.op( 'addEntry', { 'module': op.view_module_name(self.view), 'name': mtch.group('name'), 'def': mtch.group('def'), 'index': index }, committing_module_name=op.view_module_name(self.view) ) return entry = body.entry_under_edit() if entry.is_def_under_edit(): res = comm.op( 'editEntry', { 'module': op.view_module_name(self.view), 'name': entry.name(), 'newDef': self.view.substr(edit_region) }, committing_module_name=op.view_module_name(self.view) ) elif entry.is_name_under_edit(): comm.op( 'renameEntry', { 'module': op.view_module_name(self.view), 'index': entry.myindex, 'newName': self.view.substr(edit_region) }, committing_module_name=op.view_module_name(self.view) ) else: raise RuntimeError
def process_destination(view, edit): with regedit.region_editing_suppressed(view): if anchor is None: insert_at = op.reg_body(view).begin() else: mcont = op.module_body(view) if anchor is False: insert_at = mcont.entries[0].reg_entry_nl.begin() elif anchor is True: insert_at = mcont.entries[-1].reg_entry_nl.end() else: entry_obj = op.module_body(view).entry_by_name(anchor) if before: insert_at = entry_obj.reg_entry_nl.begin() else: insert_at = entry_obj.reg_entry_nl.end() view.insert(edit, insert_at, '{} ::= {}\n'.format(entry, res['newCode'])) op.save_module(view)
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): reg = single_selected_region(self.view) if op.reg_import_section(self.view).contains(reg): self.view.run_command('poli_remove_this_import', { 'force': False }) return loc = op.module_body(self.view).cursor_location_or_stop( reg, require_fully_selected=True ) res = comm.op('removeEntry', { 'module': op.view_module_name(self.view), 'entry': loc.entry.name(), 'force': False }) if not res['removed']: remove_anyway = sublime.ok_cancel_dialog( "Entry \"{}\" is being referred to. Remove it anyway?".format( loc.entry.name() ) ) if not remove_anyway: return res = comm.op('removeEntry', { 'module': op.view_module_name(self.view), 'entry': loc.entry.name(), 'force': True }) if not res['removed']: raise RuntimeError with read_only_set_to(self.view, False): self.view.erase(edit, loc.entry.reg_entry_nl) op.save_module(self.view)
def process_source(view, edit): with regedit.region_editing_suppressed(view): entry_obj = op.module_body(view).entry_by_name(entry) view.erase(edit, entry_obj.reg_entry_nl) op.save_module(view)