示例#1
0
文件: sciwrappers.c 项目: GWRon/geany
void sci_set_lexer(ScintillaObject *sci, guint lexer_id)
{
	gint old = sci_get_lexer(sci);

	SSM(sci, SCI_SETLEXER, lexer_id, 0);

	if (old != (gint)lexer_id)
		SSM(sci, SCI_CLEARDOCUMENTSTYLE, 0, 0);
}
示例#2
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;
}
示例#3
0
static gboolean
inside_define(ScintillaObject *sci, gint line, gboolean newline)
{
	gint    lexer;
	gint    start_pos;
	gint    end_pos;
	gchar   end_char;

	lexer = sci_get_lexer(sci);
	if(lexer != SCLEX_CPP)
		return FALSE;

	end_pos = get_line_end(sci, line);
	end_char = sci_get_char_at(sci, end_pos - 1);
	if(end_char != '\\')
	{
		dprintf("End char is not \\, exit\n");
		return FALSE;
	}
	if(newline)
		line--;
	do {
		line--;
		end_pos = get_line_end(sci, line);
		end_char = sci_get_char_at(sci, end_pos - 1);
	} while(end_char == '\\' && line >= 0);
	line++;
	dprintf("Expecting define on line %d\n", line + 1);
	start_pos = (gint)SSM(sci, SCI_GETLINEINDENTPOSITION, (uptr_t)line, 0);
	end_pos = sci_get_line_end_position(sci, line);
	if(start_pos == end_pos)
	{
		dprintf("line empty, exit\n");
		return FALSE;
	}
	const gchar *start_line = get_char_range(sci, start_pos, 7);
	g_return_val_if_fail(NULL != start_line, FALSE);
	if(0 != strncmp(start_line, "#define ", strlen("#define ")))
	{
		dprintf("Start line is not \"#define\", exit\n");
		return FALSE;
	}
	return TRUE;
}
/* Notification handler for editor-notify */
static gboolean on_editor_notify(GObject *obj, GeanyEditor *editor,
                                SCNotification *nt, gpointer user_data)
{
    gint lexer;

    lexer = sci_get_lexer(editor->sci);
    if((lexer != SCLEX_HTML) && (lexer != SCLEX_XML) && (lexer != SCLEX_PHPSCRIPT))
    {
        return FALSE;
    }

    /* nmhdr is a structure containing information about the event */
    switch (nt->nmhdr.code)
    {
        case SCN_UPDATEUI:
            run_tag_highlighter(editor->sci);
            break;
    }

    /* returning FALSE to allow Geany processing the event */
    return FALSE;
}
示例#5
0
static gboolean
check_chars(
	ScintillaObject *sci,
	gint             ch,
	gchar           *chars_left,
	gchar           *chars_right)
{
	switch (ch)
	{
		case '(':
		case ')':
			if (!ac_info->parenthesis)
				return FALSE;
			*chars_left = '(';
			*chars_right = ')';
			break;
		case ';':
			if (!ac_info->close_functions)
				return FALSE;
			break;
		case '{':
		case '}':
			if (!ac_info->cbracket)
				return FALSE;
			*chars_left = '{';
			*chars_right = '}';
			break;
		case '[':
		case ']':
			if (!ac_info->sbracket)
				return FALSE;
			*chars_left = '[';
			*chars_right = ']';
			break;
		case '<':
		case '>':
			if (!ac_info->abracket)
				return FALSE;
			if (ac_info->abracket_htmlonly &&
					sci_get_lexer(sci) != SCLEX_HTML)
				return FALSE;
			*chars_left = '<';
			*chars_right = '>';
			break;
		case '\'':
			if (!ac_info->squote)
				return FALSE;
			*chars_left = *chars_right = ch;
			break;
		case '"':
			if (!ac_info->dquote)
				return FALSE;
			*chars_left = *chars_right = ch;
			break;
		case '`':
			if (!ac_info->backquote)
				return FALSE;
			if (ac_info->backquote_bashonly &&
					sci_get_lexer(sci) != SCLEX_BASH)
				return FALSE;
			*chars_left = *chars_right = ch;
			break;
		default:
			return FALSE;
	}
	return TRUE;
}