Exemple #1
0
/** 
 * name: cb_eval
 * 
 * This callback function is invoked when the 'LispEdit: eval' menu option is selected.
 * If the cursor is placed after a closing parenthesis the function will look for the matching
 * opening parenthesis. If there is no matching parenthesis it will display a warning dialog box.
 *  
 * If the closing parenthesis has a matching opening parenthesis, all the characters between the parentheses
 * including the parentheses are sent to the child process running in the VTE.
 * 
 * @param menuitem GtkMenuItem.
 * @param gdata gpointer.
 * @return void
 **/
static void cb_eval(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
{
	if (have_vte)
    {
		doc = document_get_current();
		end_pos = sci_get_current_position(doc->editor->sci);
		if (end_pos > 0) end_pos--;
		gchar letter = sci_get_char_at(doc->editor->sci, end_pos);
		
		switch (letter)
		{ 
			case ')':	
						start_pos = sci_find_matching_brace(doc->editor->sci, end_pos);
						if (start_pos < 0)
						{
							dialogs_show_msgbox(GTK_MESSAGE_WARNING, "Found an isolated closing brace!!!");
						}
						else if (start_pos >= 0)
						{
							sci_get_text_range(doc->editor->sci, start_pos, ++end_pos, cmd_string);
							vte_terminal_feed_child(vte, "\n", strlen("\n"));
							vte_terminal_feed_child(vte, cmd_string, strlen(cmd_string));
							vte_terminal_feed_child(vte, "\n", strlen("\n"));
						}
						break;						
		}
    }
	else
	{
		show_error_message();
	}	
}
Exemple #2
0
static gchar *
get_current_word()
{
	gchar *txt;
	GeanyDocument *doc;

	gint pos;
	gint cstart, cend;
	gchar c;
	gint text_len;

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

	text_len = sci_get_selected_text_length(doc->editor->sci);
	if (text_len > 1)
	{
		txt = g_malloc(text_len + 1);
		sci_get_selected_text(doc->editor->sci, txt);
		return txt;
	}

	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;
	txt = g_malloc0(cend - cstart + 1);

	sci_get_text_range(doc->editor->sci, cstart, cend, txt);
	return txt;
}
Exemple #3
0
/** Gets text between @a start and @a end.
 * @param sci Scintilla widget.
 * @param start Start position.
 * @param end End position.
 * @return The text inside the given range. Should be freed when no longer needed.
 *
 * @since 0.17
 */
gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
{
	gchar *text;

	g_return_val_if_fail(start < end, NULL);

	text = g_malloc((gsize) (end - start) + 1);
	sci_get_text_range(sci, start, end, text);
	return text;
}
Exemple #4
0
/* based on editor_find_current_word_sciwc from editor.c */
static void
get_current_word(ScintillaObject *sci, gchar *word, gsize wordlen)
{
	gint pos = sci_get_current_position(sci);
	gint start = SSM(sci, SCI_WORDSTARTPOSITION, pos, TRUE);
	gint end = SSM(sci, SCI_WORDENDPOSITION, pos, TRUE);
	
	if (start == end)
		*word = 0;
	else
	{
		if ((guint)(end - start) >= wordlen)
			end = start + (wordlen - 1);
		sci_get_text_range(sci, start, end, word);
	}
}
Exemple #5
0
static gboolean editor_notify_cb(GObject *object, GeanyEditor *editor,
								SCNotification *nt, gpointer data)
{
	gint lexer, pos, style, min, size;
	gchar sel[512];

	if (nt->nmhdr.code == SCN_CHARADDED && nt->ch == '>')
	{
		lexer = sci_get_lexer(editor->sci);
		if (lexer == SCLEX_XML || lexer == SCLEX_HTML)
		{
			pos = sci_get_current_position(editor->sci);
			style = sci_get_style_at(editor->sci, pos);

			if ((style <= SCE_H_XCCOMMENT || highlighting_is_string_style(lexer, style)) &&
				!highlighting_is_comment_style(lexer, style))
			{
				CompletionInfo c;
				InputInfo i;

				/* Grab the last 512 characters or so */
				min = pos - sizeof(sel);
				if (min < 0) min = 0;
				size = pos - min;

				sci_get_text_range(editor->sci, min, pos, sel);

				if (get_completion(editor, sel, size, &c, &i))
				{
					/* Remove typed opening tag */
					sci_set_selection_start(editor->sci, min + i.tag_start);
					sci_set_selection_end(editor->sci, pos);
					sci_replace_sel(editor->sci, "");
					pos -= (size - i.tag_start); /* pos has changed while deleting */

					/* Insert the completion */
					editor_insert_snippet(editor, pos, c.completion);
					sci_scroll_caret(editor->sci);

					g_free((gchar *)c.completion);
					return TRUE;
				}
			}
		}
	}
	return FALSE;
}
Exemple #6
0
gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line)
{
	gint pos_start, pos_end;
	gint wstart, wend;
	GString *str;
	gint suggestions_found = 0;
	gchar c;

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

	str = g_string_sized_new(256);

	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)
	{
		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;
		c = sci_get_char_at(doc->editor->sci, wstart);
		/* hopefully it's enough to check for these both */
		if (ispunct(c) || isspace(c))
		{
			pos_start++;
			continue;
		}

		/* ensure the string has enough allocated memory */
		if (str->len < (guint)(wend - wstart))
			g_string_set_size(str, wend - wstart);

		sci_get_text_range(doc->editor->sci, wstart, wend, str->str);

		suggestions_found += sc_speller_check_word(doc, line_number, str->str, wstart, wend);

		pos_start = wend + 1;
	}

	g_string_free(str, TRUE);
	return suggestions_found;
}
Exemple #7
0
static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
{
    gint startword, endword, i, doc_len;
    ScintillaObject *sci;
    GString *str;
    gboolean ignore = GPOINTER_TO_INT(gdata);

    if (clickinfo.doc == NULL || clickinfo.word == NULL || clickinfo.pos == -1)
        return;

    /* if we ignore the word, we add it to the current session, to ignore it
     * also for further checks*/
    if (ignore)
        sc_speller_add_word_to_session(clickinfo.word);
    /* if we do not ignore the word, we add the word to the personal dictionary */
    else
        sc_speller_add_word(clickinfo.word);

    /* Remove all indicators on the added/ignored word */
    sci = clickinfo.doc->editor->sci;
    str = g_string_sized_new(256);
    doc_len = sci_get_length(sci);
    for (i = 0; i < doc_len; i++)
    {
        startword = scintilla_send_message(sci, SCI_INDICATORSTART, 0, i);
        if (startword >= 0)
        {
            endword = scintilla_send_message(sci, SCI_INDICATOREND, 0, startword);
            if (startword == endword)
                continue;

            if (str->len < (guint)(endword - startword + 1))
                str = g_string_set_size(str, endword - startword + 1);
            sci_get_text_range(sci, startword, endword, str->str);

            if (strcmp(str->str, clickinfo.word) == 0)
                sci_indicator_clear(sci, startword, endword - startword);

            i = endword;
        }
    }
    g_string_free(str, TRUE);
}