Exemplo n.º 1
0
static PyObject *
ZenEditor_get_content(ZenEditor *self, PyObject *args)
{
	PyObject *result;
	gchar *text;
	ScintillaObject *sci;

	print_called();
	py_return_none_if_null(sci = ZenEditor_get_scintilla(self));

	text = sci_get_contents(sci, sci_get_length(sci) + 1);
	py_return_none_if_null(text);

	result = PyString_FromString(text);
	g_free(text);
	py_return_none_if_null(result);

	return result;
}
Exemplo n.º 2
0
static gchar *get_paste_text(GeanyDocument *doc, gsize *text_len)
{
    gsize len;
    gchar *paste_text;

    if (sci_has_selection(doc->editor->sci))
    {
        len = sci_get_selected_text_length(doc->editor->sci) + 1;
        paste_text = sci_get_selection_contents(doc->editor->sci);
    }
    else
    {
        len = sci_get_length(doc->editor->sci) + 1;
        paste_text = sci_get_contents(doc->editor->sci, len);
    }

    if (text_len)
        *text_len = len;

    return paste_text;
}
static void send_complete(GeanyEditor* editor, int flag)
{
	if (completion_framework == NULL) {
		return;
	}
	if (!is_completion_file_now()) {
		return;
	}
	int pos = get_completion_position();
	if (pos == 0) {
		return;
	}  // nothing to complete

	int line = sci_get_line_from_position(editor->sci, pos);
	int ls_pos = sci_get_position_from_line(editor->sci, line);
	int byte_line_len = pos - ls_pos;
	if (byte_line_len < 0) {
		return;
	}

	char* content = sci_get_contents(editor->sci, sci_get_length(editor->sci) + 1 + 1);
	content[sci_get_length(editor->sci)] = ' ';  // replace null -> virtual space for clang
	content[sci_get_length(editor->sci)] = '\0';

	// TODO clang's col is byte? character?
	completion_framework->complete_async(editor->document->file_name, content, line + 1,
	                                     byte_line_len + 1);

	edit_tracker.valid = true;
	edit_tracker.start_pos = pos;
	edit_tracker.text.clear();

	if (pos != sci_get_current_position(editor->sci)) {
		int len = sci_get_current_position(editor->sci) - pos;
		edit_tracker.text.append(content + pos, len);
	}

	g_free(content);
}
Exemplo n.º 4
0
/* Get or Set the entire text of the currently active Geany document */
static gint glspi_text(lua_State* L)
{

    GeanyDocument *doc = document_get_current();

    if (!doc) {
        return 0;
    }
    if (0 == lua_gettop(L)) { /* Called with no args, GET the current text */
        gchar *txt = sci_get_contents(doc->editor->sci, -1);
        lua_pushstring(L, txt ? txt : "");
        g_free(txt);
        return 1;
    } else { /* Called with one arg, SET the current text */
        const gchar*txt;
        if (!lua_isstring(L, 1)) {
            return FAIL_STRING_ARG(1);
        }
        txt = lua_tostring(L, 1);
        sci_set_text(doc->editor->sci, txt);
        return 0;
    }
}
Exemplo n.º 5
0
static PyObject *
Scintilla_get_contents(Scintilla *self, PyObject *args, PyObject *kwargs)
{
	gint len = -1;
	gchar *text;
	PyObject *py_text;
	static gchar *kwlist[] = { "len", NULL };

	SCI_RET_IF_FAIL(self);

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &len))
	{
		if (len == -1)
			len = sci_get_length(self->sci) + 1;
		text = sci_get_contents(self->sci, len);
		if (text == NULL)
			Py_RETURN_NONE;
		py_text = PyString_FromString(text);
		g_free(text);
		return py_text;
	}

	Py_RETURN_NONE;
}