def wrapped(): # if editing the open file if begin_edit: with sublime.Edit(view): f(view) else: f(view)
def run_(self, edit_token, args): def resume(edit_token, args): edit.edit_token = edit_token try: gen.send(args) except (StopIteration, StopCommand): pass except ApiError as e: sublime.error_message(str(e)) finally: edit.edit_token = 0 def callback(*args): if inspect.getgeneratorstate(gen) != 'GEN_SUSPENDED': raise RuntimeError("Generator not in suspended state") call_with_edit_token(self.view, lambda et: resume(et, args)) edit = sublime.Edit(0) gen = self.run(edit, callback, **args) resume(edit_token, None)
def outer_callback(edit_token): edit = sublime.Edit(edit_token) try: return callback(edit) finally: edit.edit_token = 0