示例#1
0
文件: all.py 项目: egnartsms/poli
    def on_loaded():
        reg = reg_entry_name(view, entry)
        if reg is None:
            window.focus_view(old_view)
            sublime.status_message("Not found \"{}\" in module \"{}\"".format(
                entry, module))
            return

        set_selection(view, to=reg.begin(), show=True)
示例#2
0
    def run(self, edit):
        loc = op.sel_cursor_location(self.view)
        if not loc.is_def_targeted:
            sublime.status_message("Cursor is not placed over definition")
            return

        op.enter_edit_mode(self.view, loc.entry.reg_def, adding_new=False)

        if loc.is_fully_selected:
            set_selection(self.view, to=loc.entry.reg_def)
示例#3
0
def code_error_source_indication(view, begin_pt):
    try:
        yield
    except CodeError as e:
        row0, col0 = view.rowcol(begin_pt)
        rowe = row0 + e.row
        cole = col0 + e.col if e.row == 0 else e.col
        error_point = view.text_point(rowe, cole)
        set_selection(view, to=error_point)
        sublime.status_message(e.message)
        raise StopCommand
示例#4
0
文件: all.py 项目: egnartsms/poli
def apply_action(view, edit, action, under_edit, is_committing):
    body = module_body(view)

    if is_committing and em.edit_cxt_for[view].adding_new:
        ephemeral_index = body.remove_ephemeral_entry()
    else:
        ephemeral_index = -1

    committed = False

    if action['type'] == 'insert/replace':
        eOnto = body.entries[action['onto']]
        if under_edit and eOnto.is_def_under_edit():
            if is_committing:
                committed = True
            else:
                raise ModificationConflict(view_module_name(view))
        view.replace(edit, eOnto.reg_def, action['def'])
        if not (under_edit and eOnto.is_name_under_edit()):
            view.replace(edit, eOnto.reg_name, action['name'])
    elif action['type'] == 'insert':
        if action['at'] == ephemeral_index:
            point = em.edit_region_for[view].begin()
            view.erase(edit, end_plus_1(em.edit_region_for[view]))
            committed = True
        else:
            point = body.insertion_point(action['at'])

        view.insert(edit, point,
                    '{action[name]} ::= {action[def]}\n'.format(action=action))
    elif action['type'] == 'rename':
        entry = body.entries[action['at']]
        if under_edit and entry.is_name_under_edit():
            if is_committing:
                committed = True
            else:
                raise ModificationConflict(view_module_name(view))
        view.replace(edit, entry.reg_name, action['newName'])
    elif action['type'] == 'delete':
        entry = body.entries[action['at']]
        if under_edit and entry.is_under_edit():
            raise ModificationConflict(view_module_name(view))

        view.erase(edit, entry.reg_nl)
    elif action['type'] == 'move':
        eFrom = body.entries[action['from']]
        to = body.insertion_point(action['to'])

        with body.regions_tracked():
            reg = insert_in(view, edit, to, eFrom.contents_nl())
            if under_edit and eFrom.is_under_edit():
                em.move_edit_region(view, to - eFrom.reg.a)
            if eFrom.is_exclusively_selected():
                set_selection(view, to=end_minus_1(reg), show=True)
            view.erase(edit, eFrom.reg_nl)
    elif action['type'] == 'move/replace':
        if under_edit and eOnto.is_under_edit():
            raise ModificationConflict(view_module_name(view))

        eFrom = body.entries[action['from']]
        eOnto = body.entries[action['onto']]

        with body.regions_tracked():
            view.replace(edit, eOnto.reg_nl, eFrom.contents_nl())
            if under_edit and eFrom.is_under_edit():
                em.move_edit_region(view, eOnto.reg.a - eFrom.reg.a)
            view.erase(edit, eFrom.reg_nl)
    elif action['type'] == 'replace-import-section':
        view.replace(edit, reg_import_section(view), action['with'])
    else:
        raise RuntimeError

    return committed
示例#5
0
 def insert_dummy_def(at):
     reg = insert_in(self.view, edit, at, "name ::= definition")
     self.view.insert(edit, reg.end(), "\n")
     set_selection(self.view, to=reg, show=True)
     return reg
示例#6
0
 def run(self, edit):
     loc = op.sel_cursor_location(self.view)
     set_selection(self.view, to=loc.entry.reg)