def write_docstring(self):
        """Write docstring to editor."""
        line_to_cursor = self.code_editor.get_text('sol', 'cursor')
        if self.is_beginning_triple_quotes(line_to_cursor):
            cursor = self.code_editor.textCursor()
            prev_pos = cursor.position()

            quote = line_to_cursor[-1]
            docstring_type = CONF.get('editor', 'docstring_type')
            docstring = self._generate_docstring(docstring_type, quote)

            if docstring:
                self.code_editor.insert_text(docstring)

                cursor = self.code_editor.textCursor()
                cursor.setPosition(prev_pos, QTextCursor.KeepAnchor)
                cursor.movePosition(QTextCursor.NextBlock)
                cursor.movePosition(QTextCursor.EndOfLine,
                                    QTextCursor.KeepAnchor)
                cursor.clearSelection()
                self.code_editor.setTextCursor(cursor)
                return True

        return False
Write docstring to editor.