예제 #1
0
static gboolean
automark(gpointer user_data)
{
	GeanyDocument      *doc = (GeanyDocument *)user_data;
	GeanyEditor        *editor = doc->editor;
	static GeanyEditor *editor_cache = NULL;
	ScintillaObject    *sci = editor->sci;
	gchar               text[GEANY_MAX_WORD_LENGTH];
	static gchar        text_cache[GEANY_MAX_WORD_LENGTH] = {0};
	gint                match_flag = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
	struct              Sci_TextToFind ttf;

	source_id = 0;

	/* during timeout document could be destroyed so check everything again */
	if (!DOC_VALID(doc))
		return FALSE;

	/* Do not highlight while selecting text and allow other markers to work */
	if (sci_has_selection(sci))
		return FALSE;

	get_current_word(editor->sci, text, sizeof(text));

	if (!*text)
	{
		editor_indicator_clear(editor, AUTOMARK_INDICATOR);
		return FALSE;
	}

	if (editor_cache != editor || strcmp(text, text_cache) != 0)
	{
		editor_indicator_clear(editor, AUTOMARK_INDICATOR);
		strcpy(text_cache, text);
		editor_cache = editor;
	}
	
	gint vis_first = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
	gint doc_first = SSM(sci, SCI_DOCLINEFROMVISIBLE, vis_first, 0);
	gint vis_last  = SSM(sci, SCI_LINESONSCREEN, 0, 0) + vis_first;
	gint doc_last  = SSM(sci, SCI_DOCLINEFROMVISIBLE, vis_last, 0);
	gint start     = SSM(sci, SCI_POSITIONFROMLINE,   doc_first, 0);
	gint end       = SSM(sci, SCI_GETLINEENDPOSITION, doc_last, 0);

	ttf.chrg.cpMin = start;
	ttf.chrg.cpMax = end;
	ttf.lpstrText  = text;

	search_mark_in_range(editor, match_flag, &ttf);

	return FALSE;
}
예제 #2
0
static void search_current(CmdContext *c, CmdParams *p, gboolean next)
{
	gchar *word = get_current_word(p->sci);
	gint pos;

	g_free(c->search_text);
	if (!word)
		c->search_text = NULL;
	else
	{
		const gchar *prefix = next ? "/" : "?";
		c->search_text = g_strconcat(prefix, word, NULL);
	}
	g_free(word);

	pos = perform_search(p->sci, c->search_text, p->num, FALSE);
	if (pos >= 0)
		SET_POS(c->sci, pos, TRUE);

}
예제 #3
0
void				autocomplete(t_cmd_path *cmds)
{
	int				count;
	char			*word;
	char			*res;

	count = 0;
	if ((word = get_current_word()) == NULL)
		return ;
	while (cmds)
	{
		if (!ft_strncmp(cmds->name, word, ft_strlen(word)))
		{
			res = ft_strdup(cmds->name);
			count++;
		}
		cmds = cmds->next;
	}
	if (count == 1)
		complete_word(res, ft_strlen(word));
}
예제 #4
0
static LocationInfo *
location_query_cb()
{
	GeanyDocument *doc = document_get_current();
	if (!(doc && doc->is_valid))
	{
		return NULL;
	}
	if (doc->file_name)
	{
		LocationInfo *abi;
		gint line;
		abi = g_new0(LocationInfo, 1);
		line = sci_get_current_line(doc->editor->sci);
		abi->filename = g_strdup(doc->file_name);
		if (line >= 0)
		{
			abi->line_num = g_strdup_printf("%d", line + 1);
		}
		abi->symbol = get_current_word();
		return abi;
	}
	return NULL;
}
예제 #5
0
static gchar *
get_next_misspelled_word (GeditView *view)
{
	GeditDocument *doc;
	CheckRange *range;
	gint start, end;
	gchar *word;
	GeditSpellChecker *spell;

	g_return_val_if_fail (view != NULL, NULL);

	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	g_return_val_if_fail (doc != NULL, NULL);

	range = get_check_range (doc);
	g_return_val_if_fail (range != NULL, NULL);

	spell = get_spell_checker_from_document (doc);
	g_return_val_if_fail (spell != NULL, NULL);

	word = get_current_word (doc, &start, &end);
	if (word == NULL)
		return NULL;

	gedit_debug_message (DEBUG_PLUGINS, "Word to check: %s", word);

	while (gedit_spell_checker_check_word (spell, word, -1))
	{
		g_free (word);

		if (!goto_next_word (doc))
			return NULL;

		/* may return null if we reached the end of the selection */
		word = get_current_word (doc, &start, &end);
		if (word == NULL)
			return NULL;

		gedit_debug_message (DEBUG_PLUGINS, "Word to check: %s", word);
	}

	if (!goto_next_word (doc))
		update_current (doc, gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)));

	if (word != NULL)
	{
		GtkTextIter s, e;

		range->mw_start = start;
		range->mw_end = end;

		gedit_debug_message (DEBUG_PLUGINS, "Select [%d, %d]", start, end);

		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &s, start);
		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &e, end);

		gtk_text_buffer_select_range (GTK_TEXT_BUFFER (doc), &s, &e);

		gedit_view_scroll_to_cursor (view);
	}
	else
	{
		range->mw_start = -1;
		range->mw_end = -1;
	}

	return word;
}