-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path4coder_chronal.cpp
104 lines (87 loc) · 3.68 KB
/
4coder_chronal.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//=============================================================================
// >>> my vim-based 4coder custom <<<
// author: chr <chr@chronal.net>
//
// Sample usage of vim functions, from my own 4coder custom.
// Feel free to copy and tweak as you like!
//=============================================================================
#include "4coder_vim.cpp"
// These colors are tuned to work with the Dragonfire color scheme.
// TODO(chr): How to best make this configurable? Can we query for arbitrary
// variables in the theme?
constexpr int_color color_margin_normal = 0xFF341313;
constexpr int_color color_margin_insert = 0xFF5a3619;
constexpr int_color color_margin_replace = 0xFF5a192e;
constexpr int_color color_margin_visual = 0xFF722b04;
START_HOOK_SIG(chronal_init) {
default_4coder_initialize(app);
// NOTE(chr): Be sure to call the vim custom's hook!
return vim_hook_init_func(app, files, file_count, flags, flag_count);
}
// NOTE(chr): Define the four functions that the vim plugin wants in order
// to determine what to do when modes change.
// TODO(chr):
void on_enter_insert_mode(struct Application_Links *app) {
Theme_Color colors[] = {
{ Stag_Bar_Active, color_margin_insert },
{ Stag_Margin_Active, color_margin_insert },
};
set_theme_colors(app, colors, ArrayCount(colors));
}
void on_enter_replace_mode(struct Application_Links *app) {
Theme_Color colors[] = {
{ Stag_Bar_Active, color_margin_replace },
{ Stag_Margin_Active, color_margin_replace },
};
set_theme_colors(app, colors, ArrayCount(colors));
}
void on_enter_normal_mode(struct Application_Links *app) {
Theme_Color colors[] = {
{ Stag_Bar_Active, color_margin_normal },
{ Stag_Margin_Active, color_margin_normal },
};
set_theme_colors(app, colors, ArrayCount(colors));
}
void on_enter_visual_mode(struct Application_Links *app) {
Theme_Color colors[] = {
{ Stag_Bar_Active, color_margin_visual },
{ Stag_Margin_Active, color_margin_visual },
};
set_theme_colors(app, colors, ArrayCount(colors));
}
void chronal_get_bindings(Bind_Helper *context) {
// Set the hooks
set_start_hook(context, chronal_init);
set_open_file_hook(context, vim_hook_open_file_func);
set_new_file_hook(context, vim_hook_new_file_func);
set_render_caller(context, vim_render_caller);
// Call to set the vim bindings
vim_get_bindings(context);
// Since keymaps are re-entrant, I can define my own keybindings below
// here that will apply in the appropriate map:
begin_map(context, mapid_movements);
// For example, I forget to hit shift a lot when typing commands. Since
// semicolon doesn't do much useful in vim by default, I bind it to the
// same command that colon itself does.
bind(context, ';', MDFR_NONE, status_command);
end_map(context);
// I can also define custom commands very simply:
// As an example, suppose we want to be able to use 'save' to write the
// current file:
define_command(make_lit_string("save"), write_file);
define_command(make_lit_string("W"), write_file);
// (In regular vim, :saveas is a valid command, but this hasn't yet
// been defined in the 4coder vim layer. If it were, this definition
// would be pointless, as :save would match as a substring of :saveas
// first.)
// TODO(chr): Make the statusbar commands more intelligent
// so that this isn't an issue.
}
extern "C" int
get_bindings(void *data, int size) {
Bind_Helper context_ = begin_bind_helper(data, size);
Bind_Helper *context = &context_;
chronal_get_bindings(context);
int result = end_bind_helper(context);
return(result);
}