code: def open_in_editor(self, cli):
          
          if self.read_only():
              raise EditReadOnlyBuffer()
  
          # Write to temporary file
          descriptor, filename = tempfile.mkstemp(self.tempfile_suffix)
          os.write(descriptor, self.text.encode('utf-8'))
          os.close(descriptor)
  
          # Open in editor
          # (We need to use `cli.run_in_terminal`, because not all editors go to
          # the alternate screen buffer, and some could influence the cursor
          # position.)
          succes = cli.run_in_terminal(lambda: self._open_file_in_editor(filename))
  
          # Read content again.
          if succes:
              with open(filename, 'rb') as f:
                  text = f.read().decode('utf-8')
  
                  # Drop trailing newline. (Editors are supposed to add it at the
                  # end, but we don't need it.)
                  if text.endswith('\n'):
                      text = text[:-1]
  
                  self.document = Document(
                      text=text,
                      cursor_position=len(text))
  
          # Clean up temp file.
          os.remove(filename)
docs: Open code in editor.
  
          :param cli: :class:`~prompt_toolkit.interface.CommandLineInterface`
              instance.