def handle_editor_command(self, cli, document):
<EOL>saved_callables = cli.application.pre_run_callables<EOL>while special.editor_command(document.text):<EOL><INDENT>filename = special.get_filename(document.text)<EOL>query = (special.get_editor_query(document.text) or<EOL>self.get_last_query())<EOL>sql, message = special.open_external_editor(filename, sql=query)<EOL>if message:<EOL><INDENT>raise RuntimeError(message)<EOL><DEDENT>cli.current_buffer.document = Document(sql, cursor_position=len(sql))<EOL>cli.application.pre_run_callables = []<EOL>document = cli.run()<EOL>continue<EOL><DEDENT>cli.application.pre_run_callables = saved_callables<EOL>return document<EOL>
Editor command is any query that is prefixed or suffixed
by a '\e'. The reason for a while loop is because a user
might edit a query multiple times.
For eg:
"select * from \e"<enter> to edit it in vim, then come
back to the prompt with the edited query "select * from
blah where q = 'abc'\e" to edit it again.
:param cli: CommandLineInterface
:param document: Document
:return: Document