Пример #1
0
static PyObject *
Scintilla_get_contents_range(Scintilla *self, PyObject *args, PyObject *kwargs)
{
	gint start = -1, end = -1;
	gchar *text;
	PyObject *py_text;
	static gchar *kwlist[] = { "start", "end", NULL };

	SCI_RET_IF_FAIL(self);

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "|ii", kwlist, &start, &end))
	{
		if (start == -1)
			start = 0;
		if (end == -1)
			end = sci_get_length(self->sci) + 1;
		text = sci_get_contents_range(self->sci, start, end);
		if (text == NULL)
			Py_RETURN_NONE;
		py_text = PyString_FromString(text);
		g_free(text);
		return py_text;
	}

	Py_RETURN_NONE;
}
Пример #2
0
static gboolean
grind_backend_gnuindent_real_indent (GrindIndenter *base,
                                     GeanyDocument *doc,
                                     gint           start,
                                     gint           end)
{
  ScintillaObject  *sci = doc->editor->sci;
  gchar            *input;
  gchar            *output;
  GError           *err = NULL;
  
  if (! is_language_supported (doc->file_type)) {
    return FALSE;
  }
  
  input = sci_get_contents_range (sci, start, end);
  output = gnuindent (GRIND_BACKEND_GNUINDENT (base), doc, input, &err);
  g_free (input);
  if (! output) {
    g_critical ("GNUIndent failed: %s", err->message);
    g_error_free (err);
  } else {
    sci_set_target_start (sci, start);
    sci_set_target_end (sci, end);
    sci_replace_target (sci, output, FALSE);
  }
  g_free (output);
  
  return output != NULL;
}
Пример #3
0
static char* sci_text_get_range(ScintillaObject* sci, unsigned int i, int n) {
  unsigned int length = (unsigned int) sci_get_length(sci);
  if (i > length) {
    i = length;
  }
  if (n < 0) {
    n = length;
  }
  if (i + n > length) {
    n = length - i;
  }
  return sci_get_contents_range(sci, i, i + n);
}
Пример #4
0
gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
{
	gint pos_start, pos_end;
	gint wstart, wend;
	gint suggestions_found = 0;
	gint wordchars_len;
	gchar *wordchars;

	g_return_val_if_fail(sc_speller_dict != NULL, 0);
	g_return_val_if_fail(doc != NULL, 0);

	/* add ' (single quote) temporarily to wordchars
	 * to be able to check for "doesn't", "isn't" and similar */
	wordchars_len = scintilla_send_message(doc->editor->sci, SCI_GETWORDCHARS, 0, 0);
	wordchars = g_malloc0(wordchars_len + 2); /* 2 = temporarily added "'" and "\0" */
	scintilla_send_message(doc->editor->sci, SCI_GETWORDCHARS, 0, (sptr_t)wordchars);
	if (! strchr(wordchars, '\''))
	{
		/* temporarily add "'" to the wordchars */
		wordchars[wordchars_len] = '\'';
		scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
	}

	pos_start = sci_get_position_from_line(doc->editor->sci, line_number);
	pos_end = sci_get_position_from_line(doc->editor->sci, line_number + 1);

	while (pos_start < pos_end)
	{
		gchar *word;

		wstart = scintilla_send_message(doc->editor->sci, SCI_WORDSTARTPOSITION, pos_start, TRUE);
		wend = scintilla_send_message(doc->editor->sci, SCI_WORDENDPOSITION, wstart, FALSE);
		if (wstart == wend)
			break;

		word = sci_get_contents_range(doc->editor->sci, wstart, wend);

		suggestions_found += sc_speller_check_word(doc, line_number, word, wstart, wend);

		pos_start = wend + 1;

		g_free(word);
	}

	/* reset wordchars for the current document */
	wordchars[wordchars_len] = '\0';
	scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);

	g_free(wordchars);
	return suggestions_found;
}
Пример #5
0
static gchar *
current_word(void)
{
	GeanyDocument *doc;

	gint pos;
	gint cstart, cend;
	gchar c;

	doc = document_get_current();
	g_return_val_if_fail(doc != NULL && doc->file_name != NULL, NULL);

	if (sci_has_selection(doc->editor->sci))
		return sci_get_selection_contents(doc->editor->sci);

	pos = sci_get_current_position(doc->editor->sci);
	if (pos > 0)
		pos--;

	cstart = pos;
	c = sci_get_char_at(doc->editor->sci, cstart);

	if (!word_check_left(c))
		return NULL;

	while (word_check_left(c))
	{
		cstart--;
		if (cstart >= 0)
			c = sci_get_char_at(doc->editor->sci, cstart);
		else
			break;
	}
	cstart++;

	cend = pos;
	c = sci_get_char_at(doc->editor->sci, cend);
	while (word_check_right(c) && cend < sci_get_length(doc->editor->sci))
	{
		cend++;
		c = sci_get_char_at(doc->editor->sci, cend);
	}

	if (cstart == cend)
		return NULL;

	return sci_get_contents_range(doc->editor->sci, cstart, cend);
}
Пример #6
0
static gchar *get_tag_name(ScintillaObject *sci, gint openingBracket, gint closingBracket,
                    gboolean isTagOpening)
{
    gint nameStart = openingBracket + (TRUE == isTagOpening ? 1 : 2);
    gint nameEnd = nameStart;
    gchar charAtCurPosition = sci_get_char_at(sci, nameStart);

    while(' ' != charAtCurPosition && '>' != charAtCurPosition &&
        '\t' != charAtCurPosition && '\r' != charAtCurPosition && '\n' != charAtCurPosition)
    {
        charAtCurPosition = sci_get_char_at(sci, nameEnd);
        nameEnd++;
        if(nameEnd-nameStart > MAX_TAG_NAME)
            break;
    }
    return nameEnd > nameStart ? sci_get_contents_range(sci, nameStart, nameEnd-1) : NULL;
}
gchar *property_helper_get_type(ScintillaObject *current_doc_sci, CXSourceLocation code_source_location) {
	gchar *type_string = NULL;
	gchar current_char, previous_char;
	unsigned int source_offset;
	size_t type_literal_begining = 0;
	size_t type_literal_ending = 0;
	
	gboolean is_edge = FALSE;
	gboolean is_in_type = FALSE;
	
	clang_getInstantiationLocation(code_source_location,NULL,NULL,NULL,&source_offset);
	
	while (is_edge == FALSE) {
		while (isspace((current_char = sci_get_char_at(current_doc_sci,--source_offset))));
		if (current_char == ',' || current_char == '=') {
			while (isspace((current_char = sci_get_char_at(current_doc_sci,--source_offset))));
			while (!isspace((current_char = sci_get_char_at(current_doc_sci,--source_offset))));
			continue;
		}
		
		previous_char = sci_get_char_at(current_doc_sci,source_offset-1);
		if (isedge(current_char,previous_char)) {
			if (type_string == NULL) {
				if (is_in_type == FALSE) {
					type_string = malloc(4 * sizeof(gchar));
					strncpy(type_string,"int",4);
				} else {
					gchar *untrimmed_type_string = NULL;
					
					type_literal_begining = source_offset + 1;
					untrimmed_type_string = sci_get_contents_range(current_doc_sci,type_literal_begining,type_literal_ending);
					type_string = trim_left_string(untrimmed_type_string);
					free (untrimmed_type_string);
				}
				is_edge = TRUE;
			}
		}
		if (is_in_type == FALSE) {
			type_literal_ending = source_offset + 1;
			is_in_type = TRUE;
		}
	}
	return type_string;
}
enum PropertyKind property_helper_get_kind(ScintillaObject *current_doc_sci, CXSourceLocation code_source_location) {
	gchar *kind_keyword = NULL;
	unsigned int source_offset;
	enum PropertyKind property_kind = INVALID_KIND;
	
	clang_getInstantiationLocation(code_source_location,NULL,NULL,NULL,&source_offset);
	kind_keyword = sci_get_contents_range(current_doc_sci,source_offset,source_offset+9);
		
	if (strncmp(kind_keyword,"protected",9) == 0) {
		property_kind = PROTECTED;
	} else if (strncmp(kind_keyword,"private",7) == 0) {
		property_kind = PRIVATE;
	} else if (strncmp(kind_keyword,"public",6) == 0) {
		property_kind = PUBLIC;
	}
	
	free(kind_keyword);
	return property_kind;
}