2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
// TOP
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-06-28 22:58:50 +00:00
|
|
|
#include "4coder_default_include.cpp"
|
|
|
|
#include "4coder_default_building.cpp"
|
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
#define NO_BINDING
|
2016-06-21 14:00:07 +00:00
|
|
|
#include "4coder_default_bindings.cpp"
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
CUSTOM_COMMAND_SIG(kill_rect){
|
2016-06-20 20:34:48 +00:00
|
|
|
unsigned int access = AccessOpen;
|
|
|
|
View_Summary view = app->get_active_view(app, access);
|
|
|
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access);
|
2016-05-12 02:15:54 +00:00
|
|
|
|
|
|
|
Buffer_Rect rect = get_rect(&view);
|
|
|
|
|
|
|
|
for (int line = rect.line1; line >= rect.line0; --line){
|
|
|
|
int start = 0;
|
|
|
|
int end = 0;
|
|
|
|
|
2016-06-24 04:02:09 +00:00
|
|
|
int success = true;
|
|
|
|
Full_Cursor cursor = {0};
|
|
|
|
|
|
|
|
success = success &&
|
|
|
|
app->view_compute_cursor(app, &view, seek_line_char(line, rect.char0), &cursor);
|
2016-05-15 22:36:23 +00:00
|
|
|
start = cursor.pos;
|
2016-05-12 02:15:54 +00:00
|
|
|
|
2016-06-24 04:02:09 +00:00
|
|
|
success = success &&
|
|
|
|
app->view_compute_cursor(app, &view, seek_line_char(line, rect.char1), &cursor);
|
2016-05-15 22:36:23 +00:00
|
|
|
end = cursor.pos;
|
2016-05-12 02:15:54 +00:00
|
|
|
|
2016-06-24 04:02:09 +00:00
|
|
|
if (success){
|
|
|
|
app->buffer_replace_range(app, &buffer, start, end, 0, 0);
|
|
|
|
}
|
2016-03-24 01:05:28 +00:00
|
|
|
}
|
2016-05-12 02:15:54 +00:00
|
|
|
}
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-13 19:15:38 +00:00
|
|
|
// TODO(allen): Both of these brace related commands would work better
|
|
|
|
// if the API exposed access to the tokens in a code file.
|
|
|
|
CUSTOM_COMMAND_SIG(mark_matching_brace){
|
2016-06-20 20:34:48 +00:00
|
|
|
unsigned int access = AccessProtected;
|
|
|
|
View_Summary view = app->get_active_view(app, access);
|
|
|
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access);
|
2016-05-13 19:15:38 +00:00
|
|
|
|
|
|
|
int start_pos = view.cursor.pos;
|
|
|
|
|
|
|
|
// NOTE(allen): The user provides the memory that the chunk uses,
|
|
|
|
// this chunk will then be filled at each step of the text stream loop.
|
|
|
|
// This way you can look for something that should be nearby without
|
|
|
|
// having to copy the whole file in at once.
|
|
|
|
Stream_Chunk chunk;
|
|
|
|
char chunk_space[(1 << 10)];
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
int found_result = 0;
|
|
|
|
|
|
|
|
int i = start_pos;
|
|
|
|
int still_looping = 1;
|
|
|
|
int nesting_counter = 0;
|
|
|
|
char at_cursor = 0;
|
|
|
|
|
2016-05-31 01:22:55 +00:00
|
|
|
if (init_stream_chunk(&chunk, app, &buffer, i,
|
|
|
|
chunk_space, sizeof(chunk_space))){
|
2016-05-13 19:15:38 +00:00
|
|
|
|
|
|
|
// NOTE(allen): This is important! The data array is a pointer that is adjusted
|
|
|
|
// so that indexing it with "i" will put it with the chunk that is actually loaded.
|
|
|
|
// If i goes below chunk.start or above chunk.end _that_ is an invalid access.
|
|
|
|
at_cursor = chunk.data[i];
|
|
|
|
if (at_cursor == '{'){
|
|
|
|
do{
|
|
|
|
for (++i; i < chunk.end; ++i){
|
|
|
|
at_cursor = chunk.data[i];
|
|
|
|
if (at_cursor == '{'){
|
|
|
|
++nesting_counter;
|
|
|
|
}
|
|
|
|
else if (at_cursor == '}'){
|
|
|
|
if (nesting_counter == 0){
|
|
|
|
found_result = 1;
|
|
|
|
result = i;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
--nesting_counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&chunk);
|
|
|
|
}
|
|
|
|
while (still_looping);
|
|
|
|
}
|
|
|
|
else if (at_cursor == '}'){
|
|
|
|
do{
|
|
|
|
for (--i; i >= chunk.start; --i){
|
|
|
|
at_cursor = chunk.data[i];
|
|
|
|
if (at_cursor == '}'){
|
|
|
|
++nesting_counter;
|
|
|
|
}
|
|
|
|
else if (at_cursor == '{'){
|
|
|
|
if (nesting_counter == 0){
|
|
|
|
found_result = 1;
|
|
|
|
result = i;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
--nesting_counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&chunk);
|
|
|
|
}
|
|
|
|
while (still_looping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finished:
|
|
|
|
if (found_result){
|
|
|
|
app->view_set_mark(app, &view, seek_pos(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(cursor_to_surrounding_scope){
|
2016-06-20 20:34:48 +00:00
|
|
|
unsigned int access = AccessProtected;
|
|
|
|
View_Summary view = app->get_active_view(app, access);
|
|
|
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access);
|
2016-05-13 19:15:38 +00:00
|
|
|
|
|
|
|
int start_pos = view.cursor.pos - 1;
|
|
|
|
|
|
|
|
Stream_Chunk chunk;
|
|
|
|
char chunk_space[(1 << 10)];
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
int found_result = 0;
|
|
|
|
|
|
|
|
int i = start_pos;
|
|
|
|
int still_looping = 1;
|
|
|
|
int nesting_counter = 0;
|
|
|
|
char at_cursor = 0;
|
|
|
|
|
|
|
|
if (init_stream_chunk(&chunk, app, &buffer, i, chunk_space, sizeof(chunk_space))){
|
|
|
|
do{
|
|
|
|
for (; i >= chunk.start; --i){
|
|
|
|
at_cursor = chunk.data[i];
|
|
|
|
if (at_cursor == '}'){
|
|
|
|
++nesting_counter;
|
|
|
|
}
|
|
|
|
else if (at_cursor == '{'){
|
|
|
|
if (nesting_counter == 0){
|
|
|
|
found_result = 1;
|
|
|
|
result = i;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
--nesting_counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&chunk);
|
|
|
|
} while(still_looping);
|
|
|
|
}
|
|
|
|
|
|
|
|
finished:
|
|
|
|
if (found_result){
|
|
|
|
app->view_set_cursor(app, &view, seek_pos(result), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Incomplete
|
|
|
|
#if 0
|
2016-05-12 02:15:54 +00:00
|
|
|
CUSTOM_COMMAND_SIG(complete_word){
|
|
|
|
app->print_message(app, literal("complete_word\n"));
|
|
|
|
|
|
|
|
View_Summary view = app->get_active_view(app);
|
|
|
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id);
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
int end = 0;
|
|
|
|
|
|
|
|
end = view.cursor.pos;
|
|
|
|
|
|
|
|
push_parameter(app, par_flags, BoundryAlphanumeric);
|
|
|
|
exec_command(app, cmdid_seek_left);
|
|
|
|
|
|
|
|
app->refresh_view(app, &view);
|
|
|
|
start = view.cursor.pos;
|
|
|
|
|
|
|
|
String complete_string;
|
2016-05-13 19:15:38 +00:00
|
|
|
int size = (end - start);
|
2016-05-12 02:15:54 +00:00
|
|
|
char complete_space[256];
|
|
|
|
|
|
|
|
if (size < sizeof(complete_space) - 1){
|
|
|
|
complete_string = make_fixed_width_string(complete_space);
|
|
|
|
app->buffer_read_range(app, &buffer, start, end, complete_space);
|
|
|
|
complete_string.size = size;
|
|
|
|
complete_string.str[size] = 0;
|
|
|
|
|
|
|
|
// TODO(allen): Complete this when the heavy duty coroutine stuff
|
2016-05-13 19:15:38 +00:00
|
|
|
// and the hash table are available.
|
2016-05-12 02:15:54 +00:00
|
|
|
|
|
|
|
app->print_message(app, complete_string.str, complete_string.size);
|
2016-03-24 01:05:28 +00:00
|
|
|
}
|
2016-05-12 02:15:54 +00:00
|
|
|
}
|
2016-05-13 19:15:38 +00:00
|
|
|
#endif
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
// TODO(allen): Query theme settings
|
|
|
|
#if 0
|
|
|
|
CUSTOM_COMMAND_SIG(save_theme_settings){
|
|
|
|
FILE *file = fopen(".4coder_settings", "rb");
|
|
|
|
char theme_name[128];
|
|
|
|
char font_name[128];
|
|
|
|
|
|
|
|
fscanf(file, "%*128s %*128s", theme_name, font_name);
|
|
|
|
|
|
|
|
if (file){
|
|
|
|
replace_char(theme_name, '#', ' ');
|
|
|
|
replace_char(font_name, '#', ' ');
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
app->change_theme(app, theme_name, strlen(theme_name));
|
|
|
|
app->change_font(app, font_name, strlen(font_name));
|
|
|
|
}
|
2016-03-24 01:05:28 +00:00
|
|
|
}
|
2016-05-12 02:15:54 +00:00
|
|
|
#endif
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-19 13:29:38 +00:00
|
|
|
#if 0
|
2016-05-12 02:15:54 +00:00
|
|
|
void experiment_extension(Bind_Helper *context){
|
|
|
|
bind(context, 'k', MDFR_ALT, kill_rect);
|
2016-05-13 19:15:38 +00:00
|
|
|
bind(context, '/', MDFR_ALT, mark_matching_brace);
|
|
|
|
bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
|
2016-03-24 01:05:28 +00:00
|
|
|
}
|
2016-05-19 13:29:38 +00:00
|
|
|
#endif
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-05-17 02:22:57 +00:00
|
|
|
#define SETTINGS_FILE ".4coder_settings"
|
2016-05-12 02:15:54 +00:00
|
|
|
HOOK_SIG(experimental_start_hook){
|
|
|
|
my_start(app);
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
char theme_name[128];
|
|
|
|
char font_name[128];
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-17 02:22:57 +00:00
|
|
|
FILE *file = fopen(SETTINGS_FILE, "rb");
|
|
|
|
|
|
|
|
if (!file){
|
|
|
|
char module_path[512];
|
|
|
|
int len;
|
|
|
|
len = app->get_4ed_path(app, module_path, 448);
|
|
|
|
memcpy(module_path+len, SETTINGS_FILE, sizeof(SETTINGS_FILE));
|
|
|
|
file = fopen(module_path, "rb");
|
|
|
|
}
|
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
if (file){
|
|
|
|
fscanf(file, "%127s\n%127s", theme_name, font_name);
|
|
|
|
|
|
|
|
replace_char(theme_name, '#', ' ');
|
|
|
|
replace_char(font_name, '#', ' ');
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
app->change_theme(app, theme_name, (int)strlen(theme_name));
|
|
|
|
app->change_font(app, font_name, (int)strlen(font_name));
|
|
|
|
}
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2016-05-25 02:12:49 +00:00
|
|
|
extern "C" int
|
|
|
|
get_bindings(void *data, int size){
|
2016-05-12 02:15:54 +00:00
|
|
|
Bind_Helper context_ = begin_bind_helper(data, size);
|
|
|
|
Bind_Helper *context = &context_;
|
|
|
|
|
|
|
|
set_hook(context, hook_start, experimental_start_hook);
|
2016-06-23 23:11:09 +00:00
|
|
|
set_open_file_hook(context, my_file_settings);
|
2016-06-29 18:23:14 +00:00
|
|
|
set_command_caller(context, my_command_caller);
|
2016-05-19 16:23:12 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
set_scroll_rule(context, smooth_scroll_rule);
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-19 16:23:12 +00:00
|
|
|
default_keys(context);
|
2016-05-19 13:29:38 +00:00
|
|
|
|
2016-05-19 16:23:12 +00:00
|
|
|
// NOTE(allen|4.0.6): Command maps can be opened more than
|
|
|
|
// once so that you can extend existing maps very easily.
|
|
|
|
// You can also use the helper "restart_map" instead of
|
|
|
|
// begin_map to clear everything that was in the map and
|
|
|
|
// bind new things instead.
|
2016-06-28 22:58:50 +00:00
|
|
|
begin_map(context, mapid_global);
|
|
|
|
bind(context, ',', MDFR_ALT, close_build_panel);
|
|
|
|
bind(context, 'n', MDFR_ALT, msvc_goto_next_error);
|
|
|
|
bind(context, 'N', MDFR_ALT, msvc_goto_prev_error);
|
|
|
|
bind(context, 'M', MDFR_ALT, msvc_goto_first_error);
|
|
|
|
end_map(context);
|
|
|
|
|
2016-05-19 13:29:38 +00:00
|
|
|
begin_map(context, mapid_file);
|
|
|
|
bind(context, 'k', MDFR_ALT, kill_rect);
|
|
|
|
end_map(context);
|
|
|
|
|
|
|
|
begin_map(context, my_code_map);
|
|
|
|
bind(context, '/', MDFR_ALT, mark_matching_brace);
|
|
|
|
bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
|
|
|
|
end_map(context);
|
2016-05-12 02:15:54 +00:00
|
|
|
|
|
|
|
int result = end_bind_helper(context);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|