-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
81 lines (67 loc) · 1.94 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <geanyplugin.h>
gboolean on_editor_notify();
GeanyPlugin *geany_plugin;
GeanyData *geany_data;
GeanyFunctions *geany_functions;
PLUGIN_VERSION_CHECK(211)
PLUGIN_SET_INFO("Matcher", "Working with braces",
"1.0", "Gordio aka Oleg Gordienko <gordio[at]ya.ru>");
PluginCallback plugin_callbacks[] =
{
{ "editor-notify", (GCallback) &on_editor_notify, FALSE, NULL },
{ NULL, NULL, FALSE, NULL }
};
static void
work_with_match(ScintillaObject *sci, int pressed, char *ch_open, char *ch_close)
{
// save current position
int cur_position = sci_get_current_position(sci);
int open = (int)*ch_open;
int close = (int)*ch_close;
// pressed close
if (pressed == close) {
// check if next character is close
if (sci_get_char_at(sci, cur_position) == close) {
// set remove regions with backward char
sci_set_selection_start(sci, cur_position-1);
sci_set_selection_end(sci, cur_position);
// and remove last char (realy is replace to empty)
sci_replace_sel(sci, "");
// jump cursor to next char
sci_set_current_position(sci, cur_position, FALSE);
} else if (pressed == open) {
// or insert close
sci_insert_text(sci, cur_position, ch_close);
// and jump to center
sci_set_current_position(sci, cur_position, FALSE);
}
// pressed open and NOT close (no equal ;Ъ)
} else if (pressed == open) {
// or insert close
sci_insert_text(sci, cur_position, ch_close);
// and jump to center
sci_set_current_position(sci, cur_position, FALSE);
}
return;
}
gboolean
on_editor_notify(GObject *o, GeanyEditor *e, SCNotification *nt, gpointer d)
{
work_with_match(e->sci, nt->ch, "\"", "\"");
work_with_match(e->sci, nt->ch, "'", "'");
work_with_match(e->sci, nt->ch, "(", ")");
work_with_match(e->sci, nt->ch, "[", "]");
work_with_match(e->sci, nt->ch, "{", "}");
work_with_match(e->sci, nt->ch, "<", ">");
return FALSE;
}
void
plugin_init(GeanyData *data)
{
return;
}
void
plugin_cleanup(void)
{
return;
}