static PyObject * ZenEditor_replace_content(ZenEditor *self, PyObject *args) { gint sel_start = -1, sel_end = -1, ph_pos; gchar *text, *tmp, *tmp2; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "s|ii", &text, &sel_start, &sel_end)) { tmp = ZenEditor_replace_caret_placeholder(self->caret_placeholder, text, &ph_pos); tmp2 = ZenEditor_replace_range(tmp); g_free(tmp); if (sel_start == -1 && sel_end == -1) { /* replace whole editor content */ sci_set_text(sci, tmp2); /* Move cursor to first placeholder position, if found */ if (ph_pos > -1) sci_set_current_position(sci, sel_start + ph_pos, TRUE); } else if (sel_start != -1) { /* replace from sel_start to sel_end */ if (sel_end == -1) { /* insert text at sel_start */ sel_end = sel_start; } sci_set_selection_start(sci, sel_start); sci_set_selection_end(sci, sel_end); sci_replace_sel(sci, ""); editor_insert_text_block(ZenEditor_get_context(self)->editor, tmp2, sel_start, ph_pos, -1, FALSE); } else { dbgf("Invalid arguments were supplied."); g_free(tmp2); Py_RETURN_NONE; } g_free(tmp2); } else { if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } } Py_RETURN_NONE; }
static PyObject * Editor_insert_text_block(Editor *self, PyObject *args, PyObject *kwargs) { gchar *text = NULL; gint insert_pos, cursor_index = -1, newline_indent_size = -1; gint replace_newlines = 0; static gchar *kwlist[] = { "text", "insert_pos", "cursor_index", "newline_indent_size", "replace_newlines", NULL }; if (PyArg_ParseTupleAndKeywords(args, kwargs, "si|iii", kwlist, &text, &insert_pos, &cursor_index, &newline_indent_size, &replace_newlines)) { editor_insert_text_block(self->editor, text, insert_pos, cursor_index, newline_indent_size, (gboolean) replace_newlines); } Py_RETURN_NONE; }