4.0.18 ~ pre-optimizations

This commit is contained in:
Allen Webster 2017-03-29 12:32:06 -04:00
parent 25df080f7b
commit 6c1ebcf06e
24 changed files with 654 additions and 608 deletions

View File

@ -562,13 +562,11 @@ STRUCT Buffer_Edit{
DOC_SEE(Access_Flag) DOC_SEE(Access_Flag)
DOC_SEE(Dirty_State) */ DOC_SEE(Dirty_State) */
STRUCT Buffer_Summary{ STRUCT Buffer_Summary{
/* DOC(This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. /* DOC(This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. When this field is false the summary is referred to as a "null summary".) */
When this field is false the summary is referred to as a "null summary".) */
bool32 exists; bool32 exists;
/* DOC(If this is not a null summary, this field indicates whether the buffer has finished loading.) */ /* DOC(If this is not a null summary, this field indicates whether the buffer has finished loading.) */
bool32 ready; bool32 ready;
/* DOC(If this is not a null summary this field is the id of the associated buffer. /* DOC(If this is not a null summary this field is the id of the associated buffer. If this is a null summary then buffer_id is 0.) */
If this is a null summary then buffer_id is 0.) */
int32_t buffer_id; int32_t buffer_id;
/*DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.)*/ /*DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.)*/
Access_Flag lock_flags; Access_Flag lock_flags;
@ -593,10 +591,7 @@ STRUCT Buffer_Summary{
/* DOC(If this is not a null summary, this field indicates whether the buffer is set to lex tokens.) */ /* DOC(If this is not a null summary, this field indicates whether the buffer is set to lex tokens.) */
bool32 is_lexed; bool32 is_lexed;
/* DOC(If this is not a null summary, this field indicates whether the buffer has up to date tokens available. /* DOC(If this is not a null summary, this field indicates whether the buffer has up to date tokens available. If this field is false, it may simply mean the tokens are still being generated in a background task and will be available later. If that is the case, is_lexed will be true to indicate that the buffer is trying to get it's tokens up to date.) */
If this field is false, it may simply mean the tokens are still being generated in a background task and will
be available later. If that is the case, is_lexed will be true to indicate that the buffer is trying to get
it's tokens up to date.) */
bool32 tokens_are_ready; bool32 tokens_are_ready;
/* DOC(If this is not a null summary, this field specifies the id of the command map for this buffer.) */ /* DOC(If this is not a null summary, this field specifies the id of the command map for this buffer.) */
int32_t map_id; int32_t map_id;

View File

@ -575,7 +575,7 @@ CUSTOM_COMMAND_SIG(search);
CUSTOM_COMMAND_SIG(reverse_search); CUSTOM_COMMAND_SIG(reverse_search);
static void static void
isearch(Application_Links *app, int32_t start_reversed){ isearch(Application_Links *app, int32_t start_reversed, String query_init){
uint32_t access = AccessProtected; uint32_t access = AccessProtected;
View_Summary view = get_active_view(app, access); View_Summary view = get_active_view(app, access);
@ -586,98 +586,123 @@ isearch(Application_Links *app, int32_t start_reversed){
Query_Bar bar = {0}; Query_Bar bar = {0};
if (start_query_bar(app, &bar, 0) == 0) return; if (start_query_bar(app, &bar, 0) == 0) return;
int32_t reverse = start_reversed; bool32 reverse = start_reversed;
int32_t pos = view.cursor.pos; int32_t first_pos = view.cursor.pos;
int32_t pos = first_pos;
if (query_init.size != 0){
pos += 2;
}
int32_t start_pos = pos; int32_t start_pos = pos;
int32_t first_pos = pos;
Range match = make_range(pos, pos); Range match = make_range(pos, pos);
char bar_string_space[256]; char bar_string_space[256];
bar.string = make_fixed_width_string(bar_string_space); bar.string = make_fixed_width_string(bar_string_space);
copy_ss(&bar.string, query_init);
String isearch_str = make_lit_string("I-Search: "); String isearch_str = make_lit_string("I-Search: ");
String rsearch_str = make_lit_string("Reverse-I-Search: "); String rsearch_str = make_lit_string("Reverse-I-Search: ");
bool32 first_step = true;
User_Input in = {0}; User_Input in = {0};
for (;;){ for (;;){
view_set_highlight(app, &view, match.start, match.end, true); view_set_highlight(app, &view, match.start, match.end, true);
// NOTE(allen): Change the bar's prompt to match the current direction. // NOTE(allen): Change the bar's prompt to match the current direction.
if (reverse) bar.prompt = rsearch_str; if (reverse){
else bar.prompt = isearch_str; bar.prompt = rsearch_str;
in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton);
if (in.abort) break;
// NOTE(allen): If we're getting mouse events here it's a 4coder bug, because we
// only asked to intercept key events.
Assert(in.type == UserInputKey);
char character = to_writable_char(in.key.character);
int32_t made_change = 0;
if (in.key.keycode == '\n' || in.key.keycode == '\t'){
break;
} }
else if (character && key_is_unmodified(&in.key)){ else{
append_s_char(&bar.string, character); bar.prompt = isearch_str;
made_change = 1;
} }
else if (in.key.keycode == key_back){
if (bar.string.size > 0){ bool32 step_forward = false;
--bar.string.size; bool32 step_backward = false;
made_change = 1; bool32 backspace = false;
if (!first_step){
in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton);
if (in.abort) break;
// NOTE(allen): If we're getting mouse events here it's a 4coder bug, because we only asked to intercept key events.
Assert(in.type == UserInputKey);
char character = to_writable_char(in.key.character);
bool32 made_change = false;
if (in.key.keycode == '\n' || in.key.keycode == '\t'){
break;
}
else if (character && key_is_unmodified(&in.key)){
append_s_char(&bar.string, character);
made_change = true;
}
else if (in.key.keycode == key_back){
if (bar.string.size > 0){
--bar.string.size;
made_change = true;
}
backspace = true;
}
if ((in.command.command == search) || in.key.keycode == key_page_down || in.key.keycode == key_down){
step_forward = true;
}
if ((in.command.command == reverse_search) || in.key.keycode == key_page_up || in.key.keycode == key_up){
step_backward = true;
} }
} }
else{
int32_t step_forward = 0; if (bar.string.size != 0){
int32_t step_backward = 0; step_backward = true;
}
if ((in.command.command == search) || first_step = false;
in.key.keycode == key_page_down || in.key.keycode == key_down) step_forward = 1; }
if ((in.command.command == reverse_search) ||
in.key.keycode == key_page_up || in.key.keycode == key_up) step_backward = 1;
start_pos = pos; start_pos = pos;
if (step_forward && reverse){ if (step_forward && reverse){
start_pos = match.start + 1; start_pos = match.start + 1;
pos = start_pos; pos = start_pos;
reverse = 0; reverse = false;
step_forward = 0; step_forward = false;
} }
if (step_backward && !reverse){ if (step_backward && !reverse){
start_pos = match.start - 1; start_pos = match.start - 1;
pos = start_pos; pos = start_pos;
reverse = 1; reverse = true;
step_backward = 0; step_backward = false;
} }
if (in.key.keycode != key_back){ if (!backspace){
int32_t new_pos;
if (reverse){ if (reverse){
buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, int32_t new_pos = 0;
bar.string.str, bar.string.size, &new_pos); buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, bar.string.str, bar.string.size, &new_pos);
if (new_pos >= 0){ if (new_pos >= 0){
if (step_backward){ if (step_backward){
pos = new_pos; pos = new_pos;
start_pos = new_pos; start_pos = new_pos;
buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, bar.string.str, bar.string.size, &new_pos);
bar.string.str, bar.string.size, &new_pos); if (new_pos < 0){
if (new_pos < 0) new_pos = start_pos; new_pos = start_pos;
}
} }
match.start = new_pos; match.start = new_pos;
match.end = match.start + bar.string.size; match.end = match.start + bar.string.size;
} }
} }
else{ else{
buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, int32_t new_pos = 0;
bar.string.str, bar.string.size, &new_pos); buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, bar.string.str, bar.string.size, &new_pos);
if (new_pos < buffer.size){ if (new_pos < buffer.size){
if (step_forward){ if (step_forward){
pos = new_pos; pos = new_pos;
start_pos = new_pos; start_pos = new_pos;
buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, bar.string.str, bar.string.size, &new_pos);
bar.string.str, bar.string.size, &new_pos); if (new_pos >= buffer.size){
if (new_pos >= buffer.size) new_pos = start_pos; new_pos = start_pos;
}
} }
match.start = new_pos; match.start = new_pos;
match.end = match.start + bar.string.size; match.end = match.start + bar.string.size;
@ -690,6 +715,7 @@ isearch(Application_Links *app, int32_t start_reversed){
} }
} }
} }
view_set_highlight(app, &view, 0, 0, false); view_set_highlight(app, &view, 0, 0, false);
if (in.abort){ if (in.abort){
view_set_cursor(app, &view, seek_pos(first_pos), true); view_set_cursor(app, &view, seek_pos(first_pos), true);
@ -700,11 +726,31 @@ isearch(Application_Links *app, int32_t start_reversed){
} }
CUSTOM_COMMAND_SIG(search){ CUSTOM_COMMAND_SIG(search){
isearch(app, false); String query = {0};
isearch(app, false, query);
} }
CUSTOM_COMMAND_SIG(reverse_search){ CUSTOM_COMMAND_SIG(reverse_search){
isearch(app, true); String query = {0};
isearch(app, true, query);
}
CUSTOM_COMMAND_SIG(search_identifier){
View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
char space[256];
String query = read_identifier_at_pos(app, &buffer, view.cursor.pos, space, sizeof(space), 0);
isearch(app, false, query);
}
CUSTOM_COMMAND_SIG(reverse_search_identifier){
View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
char space[256];
String query = read_identifier_at_pos(app, &buffer, view.cursor.pos, space, sizeof(space), 0);
isearch(app, true, query);
} }
CUSTOM_COMMAND_SIG(replace_in_range){ CUSTOM_COMMAND_SIG(replace_in_range){
@ -745,6 +791,36 @@ CUSTOM_COMMAND_SIG(replace_in_range){
} }
} }
static void
query_replace(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t pos, String r, String w){
int32_t new_pos = 0;
buffer_seek_string_forward(app, buffer, pos, 0, r.str, r.size, &new_pos);
User_Input in = {0};
while (new_pos < buffer->size){
Range match = make_range(new_pos, new_pos + r.size);
view_set_highlight(app, view, match.min, match.max, 1);
in = get_user_input(app, EventOnAnyKey, EventOnButton);
if (in.abort || in.key.keycode == key_esc || !key_is_unmodified(&in.key)) break;
if (in.key.character == 'y' || in.key.character == 'Y' || in.key.character == '\n' || in.key.character == '\t'){
buffer_replace_range(app, buffer, match.min, match.max, w.str, w.size);
pos = match.start + w.size;
}
else{
pos = match.max;
}
buffer_seek_string_forward(app, buffer, pos, 0, r.str, r.size, &new_pos);
}
view_set_highlight(app, view, 0, 0, 0);
if (in.abort) return;
view_set_cursor(app, view, seek_pos(pos), true);
}
CUSTOM_COMMAND_SIG(query_replace){ CUSTOM_COMMAND_SIG(query_replace){
Query_Bar replace; Query_Bar replace;
char replace_space[1024]; char replace_space[1024];
@ -761,55 +837,57 @@ CUSTOM_COMMAND_SIG(query_replace){
if (!query_user_string(app, &with)) return; if (!query_user_string(app, &with)) return;
String r, w; String r = replace.string;
r = replace.string; String w = with.string;
w = with.string;
View_Summary view = get_active_view(app, AccessOpen);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
int32_t pos = view.cursor.pos;
Query_Bar bar; Query_Bar bar;
Buffer_Summary buffer;
View_Summary view;
int32_t pos, new_pos;
bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n"); bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n");
bar.string = null_string; bar.string = null_string;
start_query_bar(app, &bar, 0); start_query_bar(app, &bar, 0);
uint32_t access = AccessOpen; query_replace(app, &view, &buffer, pos, r, w);
view = get_active_view(app, access);
buffer = get_buffer(app, view.buffer_id, access);
pos = view.cursor.pos;
buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos);
User_Input in = {0};
while (new_pos < buffer.size){
Range match = make_range(new_pos, new_pos + r.size);
view_set_highlight(app, &view, match.min, match.max, 1);
in = get_user_input(app, EventOnAnyKey, EventOnButton);
if (in.abort || in.key.keycode == key_esc || !key_is_unmodified(&in.key)) break;
if (in.key.character == 'y' ||
in.key.character == 'Y' ||
in.key.character == '\n' ||
in.key.character == '\t'){
buffer_replace_range(app, &buffer, match.min, match.max, w.str, w.size);
pos = match.start + w.size;
}
else{
pos = match.max;
}
buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos);
}
view_set_highlight(app, &view, 0, 0, 0);
if (in.abort) return;
view_set_cursor(app, &view, seek_pos(pos), 1);
} }
CUSTOM_COMMAND_SIG(query_replace_identifier){
View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
Range range = {0};
char space[256];
String query = read_identifier_at_pos(app, &buffer, view.cursor.pos, space, sizeof(space), &range);
if (query.size != 0){
Query_Bar replace;
replace.prompt = make_lit_string("Replace: ");
replace.string = query;
if (start_query_bar(app, &replace, 0) == 0) return;
Query_Bar with;
char with_space[1024];
with.prompt = make_lit_string("With: ");
with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &with)) return;
String r = replace.string;
String w = with.string;
View_Summary view = get_active_view(app, AccessOpen);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
int32_t pos = range.start;
Query_Bar bar;
bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n");
bar.string = null_string;
start_query_bar(app, &bar, 0);
query_replace(app, &view, &buffer, pos, r, w);
}
}
// //
// File Handling Commands // File Handling Commands

View File

@ -177,8 +177,10 @@ default_keys(Bind_Helper *context){
bind(context, 'm', MDFR_CTRL, cursor_mark_swap); bind(context, 'm', MDFR_CTRL, cursor_mark_swap);
bind(context, 'O', MDFR_CTRL, reopen); bind(context, 'O', MDFR_CTRL, reopen);
bind(context, 'q', MDFR_CTRL, query_replace); bind(context, 'q', MDFR_CTRL, query_replace);
bind(context, 'Q', MDFR_CTRL, query_replace_identifier);
bind(context, 'r', MDFR_CTRL, reverse_search); bind(context, 'r', MDFR_CTRL, reverse_search);
bind(context, 's', MDFR_CTRL, save); bind(context, 's', MDFR_CTRL, save);
bind(context, 't', MDFR_CTRL, search_identifier);
bind(context, 'T', MDFR_CTRL, list_all_locations_of_identifier); bind(context, 'T', MDFR_CTRL, list_all_locations_of_identifier);
bind(context, 'u', MDFR_CTRL, to_uppercase); bind(context, 'u', MDFR_CTRL, to_uppercase);
bind(context, 'v', MDFR_CTRL, paste_and_indent); bind(context, 'v', MDFR_CTRL, paste_and_indent);
@ -194,7 +196,7 @@ default_keys(Bind_Helper *context){
bind(context, '?', MDFR_CTRL, toggle_show_whitespace); bind(context, '?', MDFR_CTRL, toggle_show_whitespace);
bind(context, '~', MDFR_CTRL, clean_all_lines); bind(context, '~', MDFR_CTRL, clean_all_lines);
bind(context, '\n', MDFR_NONE, newline_or_goto_position); bind(context, '\n', MDFR_NONE, newline_or_goto_position);
bind(context, '\n', MDFR_SHIFT, newline_or_goto_position); bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel);
bind(context, ' ', MDFR_SHIFT, write_character); bind(context, ' ', MDFR_SHIFT, write_character);
end_map(context); end_map(context);

View File

@ -36,6 +36,12 @@ static General_Memory global_general;
// Jump Buffer Locking // Jump Buffer Locking
// //
#if !defined(AUTO_CENTER_AFTER_JUMPS)
static bool32 auto_center_after_jumps = true;
#else
static bool32 auto_center_after_jumps = AUTO_CENTER_AFTER_JUMPS;
#endif
static char locked_buffer_space[256]; static char locked_buffer_space[256];
static String locked_buffer = make_fixed_width_string(locked_buffer_space); static String locked_buffer = make_fixed_width_string(locked_buffer_space);
@ -361,9 +367,9 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
if (i < array.count){ if (i < array.count){
Cpp_Token token = read_config_token(array, &i); Cpp_Token token = read_config_token(array, &i);
bool32 subscript_success = 1; bool32 subscript_success = true;
if (token.type == CPP_TOKEN_BRACKET_OPEN){ if (token.type == CPP_TOKEN_BRACKET_OPEN){
subscript_success = 0; subscript_success = false;
++i; ++i;
if (i < array.count){ if (i < array.count){
config_line.subscript_token = read_config_token(array, &i); config_line.subscript_token = read_config_token(array, &i);
@ -375,7 +381,7 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
++i; ++i;
if (i < array.count){ if (i < array.count){
token = read_config_token(array, &i); token = read_config_token(array, &i);
subscript_success = 1; subscript_success = true;
} }
} }
} }
@ -390,9 +396,9 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
if (i < array.count){ if (i < array.count){
Cpp_Token val_token = read_config_token(array, &i); Cpp_Token val_token = read_config_token(array, &i);
bool32 array_success = 1; bool32 array_success = true;
if (val_token.type == CPP_TOKEN_BRACE_OPEN){ if (val_token.type == CPP_TOKEN_BRACE_OPEN){
array_success = 0; array_success = false;
++i; ++i;
if (i < array.count){ if (i < array.count){
config_line.val_array_start = i; config_line.val_array_start = i;
@ -405,13 +411,13 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
} }
if (array_token.type == CPP_TOKEN_BRACE_CLOSE){ if (array_token.type == CPP_TOKEN_BRACE_CLOSE){
config_line.val_array_end = i; config_line.val_array_end = i;
array_success = 1; array_success = true;
break; break;
} }
else{ else{
if (array_token.type == CPP_TOKEN_COMMA){ if (array_token.type == CPP_TOKEN_COMMA){
if (!expecting_array_item){ if (!expecting_array_item){
expecting_array_item = 1; expecting_array_item = true;
} }
else{ else{
break; break;
@ -419,7 +425,7 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
} }
else{ else{
if (expecting_array_item){ if (expecting_array_item){
expecting_array_item = 0; expecting_array_item = false;
++config_line.val_array_count; ++config_line.val_array_count;
} }
} }

View File

@ -75,12 +75,11 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
// NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated // NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated
// and instead the buffer is passed as an explicit parameter through // and instead the buffer is passed as an explicit parameter through
// the function call. That is where buffer_id comes from here. // the function call. That is where buffer_id comes from here.
uint32_t access = AccessAll; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
Buffer_Summary buffer = get_buffer(app, buffer_id, access);
Assert(buffer.exists); Assert(buffer.exists);
int32_t treat_as_code = false; bool32 treat_as_code = false;
int32_t wrap_lines = true; bool32 wrap_lines = true;
int32_t extension_count = 0; int32_t extension_count = 0;
char **extension_list = get_current_code_extensions(&extension_count); char **extension_list = get_current_code_extensions(&extension_count);
@ -102,9 +101,11 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
wrap_lines = false; wrap_lines = false;
} }
int32_t map_id = (treat_as_code)?((int32_t)default_code_map):((int32_t)mapid_file);
buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, default_wrap_width); buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, default_wrap_width);
buffer_set_setting(app, &buffer, BufferSetting_MinimumBaseWrapPosition, default_min_base_width); buffer_set_setting(app, &buffer, BufferSetting_MinimumBaseWrapPosition, default_min_base_width);
buffer_set_setting(app, &buffer, BufferSetting_MapID, (treat_as_code)?((int32_t)default_code_map):((int32_t)mapid_file)); buffer_set_setting(app, &buffer, BufferSetting_MapID, map_id);
if (treat_as_code && enable_code_wrapping && buffer.size < (1 << 18)){ if (treat_as_code && enable_code_wrapping && buffer.size < (1 << 18)){
// NOTE(allen|a4.0.12): There is a little bit of grossness going on here. // NOTE(allen|a4.0.12): There is a little bit of grossness going on here.

View File

@ -49,11 +49,10 @@ buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t sta
} }
static void static void
basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ basic_seek(Application_Links *app, bool32 seek_forward, uint32_t flags){
uint32_t access = AccessProtected; View_Summary view = get_active_view(app, AccessProtected);
View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_forward, flags);
int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags);
view_set_cursor(app, &view, seek_pos(pos), true); view_set_cursor(app, &view, seek_pos(pos), true);
} }

View File

@ -31,45 +31,27 @@ TYPE: 'drop-in-command-pack'
// Declaration list // Declaration list
// //
static void struct Function_Positions{
list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buffer){ int32_t sig_start_index;
String search_name = make_lit_string("*decls*"); int32_t sig_end_index;
Buffer_Summary decls_buffer = get_buffer_by_name(app, search_name.str, search_name.size, AccessAll); int32_t open_paren_pos;
if (!decls_buffer.exists){ };
decls_buffer = create_buffer(app, search_name.str, search_name.size, BufferCreate_AlwaysNew);
buffer_set_setting(app, &decls_buffer, BufferSetting_Unimportant, true);
buffer_set_setting(app, &decls_buffer, BufferSetting_ReadOnly, true);
buffer_set_setting(app, &decls_buffer, BufferSetting_WrapLine, false);
}
else{
buffer_replace_range(app, &decls_buffer, 0, decls_buffer.size, 0, 0);
}
Temp_Memory temp = begin_temp_memory(part); struct Get_Positions_Results{
int32_t positions_count;
int32_t next_token_index;
bool32 still_looping;
};
struct Function_Positions{ static Get_Positions_Results
int32_t sig_start_index; get_function_positions(Application_Links *app, Buffer_Summary *buffer, int32_t token_index, Function_Positions *positions_array, int32_t positions_max){
int32_t sig_end_index; Get_Positions_Results result = {0};
int32_t open_paren_pos;
};
Function_Positions *positions_array = push_array(part, Function_Positions, (4<<10)/sizeof(Function_Positions));
int32_t positions_count = 0;
Partition extra_memory_ = partition_sub_part(part, (4<<10));
Partition *extra_memory = &extra_memory_;
char *str = (char*)partition_current(part);
int32_t part_size = 0;
int32_t size = 0;
static const int32_t token_chunk_size = 512; static const int32_t token_chunk_size = 512;
Cpp_Token token_chunk[token_chunk_size]; Cpp_Token token_chunk[token_chunk_size];
Stream_Tokens token_stream = {0}; Stream_Tokens token_stream = {0};
if (init_stream_tokens(&token_stream, app, buffer, 0, token_chunk, token_chunk_size)){ if (init_stream_tokens(&token_stream, app, buffer, token_index, token_chunk, token_chunk_size)){
Stream_Tokens start_position_stream_temp = begin_temp_stream_token(&token_stream);
int32_t token_index = 0;
int32_t nest_level = 0; int32_t nest_level = 0;
int32_t paren_nest_level = 0; int32_t paren_nest_level = 0;
@ -80,7 +62,14 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
bool32 still_looping = false; bool32 still_looping = false;
// Look for the next token at global scope that might need to be printed. // Look for the next token at global scope that might need to be printed.
mode1: do{ mode1:
Assert(nest_level == 0);
Assert(paren_nest_level == 0);
first_paren_index = 0;
first_paren_position = 0;
last_paren_index = 0;
do{
for (; token_index < token_stream.end; ++token_index){ for (; token_index < token_stream.end; ++token_index){
Cpp_Token *token = &token_stream.tokens[token_index]; Cpp_Token *token = &token_stream.tokens[token_index];
@ -168,76 +157,110 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
positions.sig_start_index = signature_start_index; positions.sig_start_index = signature_start_index;
positions.sig_end_index = last_paren_index; positions.sig_end_index = last_paren_index;
positions.open_paren_pos = first_paren_position; positions.open_paren_pos = first_paren_position;
positions_array[positions_count++] = positions; positions_array[result.positions_count++] = positions;
} }
end_temp_stream_token(&token_stream, backward_stream_temp); end_temp_stream_token(&token_stream, backward_stream_temp);
if (result.positions_count >= positions_max){
result.next_token_index = token_index;
result.still_looping = true;
goto end;
}
goto mode1; goto mode1;
} }
end:; end:;
end_temp_stream_token(&token_stream, start_position_stream_temp); }
// Print the results
String buffer_name = make_string(buffer->buffer_name, buffer->buffer_name_len);
for (int32_t i = 0; i < positions_count; ++i){
Function_Positions *positions = &positions_array[i];
Temp_Memory extra_temp = begin_temp_memory(extra_memory);
int32_t local_index = positions->sig_start_index; return(result);
int32_t end_index = positions->sig_end_index; }
int32_t open_paren_pos = positions->open_paren_pos;
static void
print_positions(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, int32_t positions_count, Buffer_Summary *output_buffer, Partition *part){
Temp_Memory temp = begin_temp_memory(part);
Partition extra_memory_ = partition_sub_part(part, (4<<10));
Partition *extra_memory = &extra_memory_;
char *str_ptr = (char*)partition_current(part);
int32_t part_size = 0;
String buffer_name = make_string(buffer->buffer_name, buffer->buffer_name_len);
int32_t size = output_buffer->size;
for (int32_t i = 0; i < positions_count; ++i){
Function_Positions *positions = &positions_array[i];
Temp_Memory extra_temp = begin_temp_memory(extra_memory);
int32_t local_index = positions->sig_start_index;
int32_t end_index = positions->sig_end_index;
int32_t open_paren_pos = positions->open_paren_pos;
Assert(end_index > local_index);
static const int32_t sig_chunk_size = 64;
Cpp_Token sig_chunk[sig_chunk_size];
Stream_Tokens sig_stream = {0};
if (init_stream_tokens(&sig_stream, app, buffer, local_index, sig_chunk, sig_chunk_size)){
bool32 still_looping = false;
do{ do{
for (; local_index < token_stream.end; ++local_index){ for (; local_index < sig_stream.end; ++local_index){
Cpp_Token *token = &token_stream.tokens[local_index]; Cpp_Token *token = &sig_stream.tokens[local_index];
if (!(token->flags & CPP_TFLAG_PP_BODY)){ if (!(token->flags & CPP_TFLAG_PP_BODY) && token->type != CPP_TOKEN_COMMENT){
if (token->type != CPP_TOKEN_COMMENT){ bool32 delete_space_before = false;
bool32 delete_space_before = false; bool32 space_after = false;
bool32 space_after = false;
switch (token->type){ switch (token->type){
case CPP_TOKEN_COMMA: case CPP_TOKEN_PARENTHESE_OPEN:
case CPP_TOKEN_PARENTHESE_OPEN: case CPP_TOKEN_PARENTHESE_CLOSE:
case CPP_TOKEN_PARENTHESE_CLOSE: {
{ delete_space_before = true;
delete_space_before = true; }break;
}break;
}
switch (token->type){ case CPP_TOKEN_IDENTIFIER:
case CPP_TOKEN_IDENTIFIER: case CPP_TOKEN_STAR:
case CPP_TOKEN_COMMA: {
case CPP_TOKEN_STAR:
{
space_after = true;
}break;
}
if (token->flags & CPP_TFLAG_IS_KEYWORD){
space_after = true; space_after = true;
}break;
case CPP_TOKEN_COMMA:
{
delete_space_before = true;
space_after = true;
}break;
}
if (token->flags & CPP_TFLAG_IS_KEYWORD){
space_after = true;
}
if (delete_space_before){
int32_t pos = extra_memory->pos - 1;
char *base = ((char*)(extra_memory->base));
if (pos >= 0 && base[pos] == ' '){
extra_memory->pos = pos;
} }
}
if (delete_space_before){ char *token_str = push_array(extra_memory, char, token->size + space_after);
int32_t pos = extra_memory->pos - 1; if (token_str != 0){
char *base = ((char*)(extra_memory->base));
if (pos >= 0 && base[pos] == ' '){
extra_memory->pos = pos;
}
}
char *token_str = push_array(extra_memory, char, token->size + space_after);
buffer_read_range(app, buffer, token->start, token->start + token->size, token_str); buffer_read_range(app, buffer, token->start, token->start + token->size, token_str);
if (space_after){ if (space_after){
token_str[token->size] = ' '; token_str[token->size] = ' ';
} }
} }
else{
goto finish_print;
}
} }
if (local_index == end_index){ if (local_index == end_index){
goto finish_print; goto finish_print;
} }
} }
still_looping = forward_stream_tokens(&token_stream); still_looping = forward_stream_tokens(&sig_stream);
}while(still_looping); }while(still_looping);
finish_print:; finish_print:;
@ -252,7 +275,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
char *out_space = push_array(part, char, append_len); char *out_space = push_array(part, char, append_len);
if (out_space == 0){ if (out_space == 0){
buffer_replace_range(app, &decls_buffer, size, size, str, part_size); buffer_replace_range(app, output_buffer, size, size, str_ptr, part_size);
size += part_size; size += part_size;
end_temp_memory(temp); end_temp_memory(temp);
@ -272,19 +295,53 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
append(&out, sig); append(&out, sig);
append(&out, '\n'); append(&out, '\n');
} }
end_temp_memory(extra_temp);
} }
buffer_replace_range(app, &decls_buffer, size, size, str, part_size); end_temp_memory(extra_temp);
View_Summary view = get_active_view(app, AccessAll);
view_set_buffer(app, &view, decls_buffer.buffer_id, 0);
lock_jump_buffer(search_name.str, search_name.size);
end_temp_memory(temp);
} }
buffer_replace_range(app, output_buffer, size, size, str_ptr, part_size);
end_temp_memory(temp);
}
static void
list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buffer){
String search_name = make_lit_string("*decls*");
Buffer_Summary decls_buffer = get_buffer_by_name(app, search_name.str, search_name.size, AccessAll);
if (!decls_buffer.exists){
decls_buffer = create_buffer(app, search_name.str, search_name.size, BufferCreate_AlwaysNew);
buffer_set_setting(app, &decls_buffer, BufferSetting_Unimportant, true);
buffer_set_setting(app, &decls_buffer, BufferSetting_ReadOnly, true);
buffer_set_setting(app, &decls_buffer, BufferSetting_WrapLine, false);
}
else{
buffer_replace_range(app, &decls_buffer, 0, decls_buffer.size, 0, 0);
}
Temp_Memory temp = begin_temp_memory(part);
int32_t positions_max = (4<<10)/sizeof(Function_Positions);
Function_Positions *positions_array = push_array(part, Function_Positions, positions_max);
int32_t token_index = 0;
bool32 still_looping = false;
do{
Get_Positions_Results get_positions_results = get_function_positions(app, buffer, token_index, positions_array, positions_max);
int32_t positions_count = get_positions_results.positions_count;
token_index = get_positions_results.next_token_index;
still_looping = get_positions_results.still_looping;
print_positions(app, buffer, positions_array, positions_count, &decls_buffer, part);
}while(still_looping);
View_Summary view = get_active_view(app, AccessAll);
view_set_buffer(app, &view, decls_buffer.buffer_id, 0);
lock_jump_buffer(search_name.str, search_name.size);
end_temp_memory(temp);
} }
CUSTOM_COMMAND_SIG(list_all_functions_current_buffer){ CUSTOM_COMMAND_SIG(list_all_functions_current_buffer){

View File

@ -22,29 +22,6 @@ exec_command(Application_Links *app, Generic_Command cmd){
} }
} }
static View_Summary
get_first_view_with_buffer(Application_Links *app, int32_t buffer_id){
View_Summary result = {};
View_Summary test = {};
if (buffer_id != 0){
uint32_t access = AccessAll;
for(test = get_view_first(app, access);
test.exists;
get_view_next(app, &test, access)){
Buffer_Summary buffer = get_buffer(app, test.buffer_id, access);
if(buffer.buffer_id == buffer_id){
result = test;
break;
}
}
}
return(result);
}
static int32_t static int32_t
key_is_unmodified(Key_Event_Data *key){ key_is_unmodified(Key_Event_Data *key){
char *mods = key->modifiers; char *mods = key->modifiers;
@ -69,10 +46,9 @@ to_writable_char(Key_Code long_character){
return(character); return(character);
} }
static int32_t static bool32
query_user_general(Application_Links *app, Query_Bar *bar, bool32 force_number){ query_user_general(Application_Links *app, Query_Bar *bar, bool32 force_number){
User_Input in; bool32 success = true;
int32_t success = 1;
// NOTE(allen|a3.4.4): It will not cause an *error* if we continue on after failing to. // NOTE(allen|a3.4.4): It will not cause an *error* if we continue on after failing to.
// start a query bar, but it will be unusual behavior from the point of view of the // start a query bar, but it will be unusual behavior from the point of view of the
@ -86,12 +62,12 @@ query_user_general(Application_Links *app, Query_Bar *bar, bool32 force_number){
// types specified in the flags. The first set of flags are inputs you'd like to intercept // types specified in the flags. The first set of flags are inputs you'd like to intercept
// that you don't want to abort on. The second set are inputs that you'd like to cause // that you don't want to abort on. The second set are inputs that you'd like to cause
// the command to abort. If an event satisfies both flags, it is treated as an abort. // the command to abort. If an event satisfies both flags, it is treated as an abort.
in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton); User_Input in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton);
// NOTE(allen|a3.4.4): The responsible thing to do on abort is to end the command // NOTE(allen|a3.4.4): The responsible thing to do on abort is to end the command
// without waiting on get_user_input again. // without waiting on get_user_input again.
if (in.abort){ if (in.abort){
success = 0; success = false;
break; break;
} }
@ -276,13 +252,38 @@ get_line_x_rect(View_Summary *view){
return(rect); return(rect);
} }
static View_Summary
get_first_view_with_buffer(Application_Links *app, int32_t buffer_id){
View_Summary result = {0};
View_Summary test = {0};
if (buffer_id != 0){
uint32_t access = AccessAll;
for(test = get_view_first(app, access);
test.exists;
get_view_next(app, &test, access)){
Buffer_Summary buffer = get_buffer(app, test.buffer_id, access);
if(buffer.buffer_id == buffer_id){
result = test;
break;
}
}
}
return(result);
}
static bool32 static bool32
open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, int32_t filename_len, bool32 background, bool32 never_new){ open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, int32_t filename_len, bool32 background, bool32 never_new){
bool32 result = false; bool32 result = false;
Buffer_Summary buffer = get_buffer_by_name(app, filename, filename_len, AccessProtected|AccessHidden); Buffer_Summary buffer = get_buffer_by_name(app, filename, filename_len, AccessProtected|AccessHidden);
if (buffer.exists){ if (buffer.exists){
if (buffer_out) *buffer_out = buffer; if (buffer_out){
*buffer_out = buffer;
}
result = true; result = true;
} }
else{ else{
@ -295,7 +296,9 @@ open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, in
} }
buffer = create_buffer(app, filename, filename_len, flags); buffer = create_buffer(app, filename, filename_len, flags);
if (buffer.exists){ if (buffer.exists){
if (buffer_out) *buffer_out = buffer; if (buffer_out){
*buffer_out = buffer;
}
result = true; result = true;
} }
} }
@ -303,15 +306,15 @@ open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, in
return(result); return(result);
} }
static int32_t static bool32
view_open_file(Application_Links *app, View_Summary *view, char *filename, int32_t filename_len, int32_t never_new){ view_open_file(Application_Links *app, View_Summary *view, char *filename, int32_t filename_len, bool32 never_new){
int32_t result = 0; bool32 result = false;
if (view){ if (view != 0){
Buffer_Summary buffer = {0}; Buffer_Summary buffer = {0};
if (open_file(app, &buffer, filename, filename_len, false, never_new)){ if (open_file(app, &buffer, filename, filename_len, false, never_new)){
view_set_buffer(app, view, buffer.buffer_id, 0); view_set_buffer(app, view, buffer.buffer_id, 0);
result = 1; result = true;
} }
} }

View File

@ -20,15 +20,27 @@ struct Name_Based_Jump_Location{
static void static void
jump_to_location(Application_Links *app, View_Summary *view, Name_Based_Jump_Location *l){ jump_to_location(Application_Links *app, View_Summary *view, Name_Based_Jump_Location *l){
Buffer_Summary buffer = {0};
if (open_file(app, &buffer, l->file.str, l->file.size, false, true)){
View_Summary target_view = get_first_view_with_buffer(app, buffer.buffer_id);
if (!target_view.exists){
view_set_buffer(app, view, buffer.buffer_id, 0);
target_view = *view;
}
view_set_cursor(app, &target_view, seek_line_char(l->line, l->column), true);
}
}
static void
jump_to_location_always_use_view(Application_Links *app, View_Summary *view, Name_Based_Jump_Location *l){
if (view_open_file(app, view, l->file.str, l->file.size, true)){ if (view_open_file(app, view, l->file.str, l->file.size, true)){
view_set_cursor(app, view, seek_line_char(l->line, l->column), true); view_set_cursor(app, view, seek_line_char(l->line, l->column), true);
} }
} }
static int32_t static bool32
ms_style_verify(String line, int32_t paren_pos){ ms_style_verify(String line, int32_t paren_pos){
int32_t result = false; int32_t result = false;
String line_part = substr_tail(line, paren_pos); String line_part = substr_tail(line, paren_pos);
if (match_part_sc(line_part, ") : ")){ if (match_part_sc(line_part, ") : ")){
result = true; result = true;
@ -36,7 +48,6 @@ ms_style_verify(String line, int32_t paren_pos){
else if (match_part_sc(line_part, "): ")){ else if (match_part_sc(line_part, "): ")){
result = true; result = true;
} }
return(result); return(result);
} }

View File

@ -170,18 +170,13 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3
int32_t chunk_size = sizeof(chunk); int32_t chunk_size = sizeof(chunk);
Stream_Chunk stream = {0}; Stream_Chunk stream = {0};
int32_t no_hard;
int32_t prev_endline;
int32_t still_looping;
char at_pos;
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
// step 1: find the first non-whitespace character // step 1: find the first non-whitespace character
// ahead of the current position. // ahead of the current position.
still_looping = true; bool32 still_looping = true;
do{ do{
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
at_pos = stream.data[pos]; char at_pos = stream.data[pos];
if (!char_is_whitespace(at_pos)){ if (!char_is_whitespace(at_pos)){
goto double_break_1; goto double_break_1;
} }
@ -195,11 +190,11 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3
// the prev_endline value. if another '\n' is found // the prev_endline value. if another '\n' is found
// with non-whitespace then the previous line was // with non-whitespace then the previous line was
// all whitespace. // all whitespace.
no_hard = false; bool32 no_hard = false;
prev_endline = -1; int32_t prev_endline = -1;
while(still_looping){ while(still_looping){
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
at_pos = stream.data[pos]; char at_pos = stream.data[pos];
if (at_pos == '\n'){ if (at_pos == '\n'){
if (no_hard){ if (no_hard){
goto double_break_2; goto double_break_2;
@ -232,10 +227,9 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int
char data_chunk[1024]; char data_chunk[1024];
Stream_Chunk stream = {0}; Stream_Chunk stream = {0};
if (init_stream_chunk(&stream, app, buffer, if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = 1; bool32 still_looping = true;
do{ do{
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
if (!char_is_whitespace(stream.data[pos])){ if (!char_is_whitespace(stream.data[pos])){
@ -246,7 +240,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int
}while(still_looping); }while(still_looping);
double_break1:; double_break1:;
still_looping = 1; still_looping = true;
do{ do{
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
if (char_is_whitespace(stream.data[pos])){ if (char_is_whitespace(stream.data[pos])){
@ -311,10 +305,9 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i
char data_chunk[1024]; char data_chunk[1024];
Stream_Chunk stream = {0}; Stream_Chunk stream = {0};
if (init_stream_chunk(&stream, app, buffer, if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = 1; bool32 still_looping = true;
do{ do{
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){ if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
@ -325,7 +318,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i
}while(still_looping); }while(still_looping);
double_break1:; double_break1:;
still_looping = 1; still_looping = true;
do{ do{
for (; pos < stream.end; ++pos){ for (; pos < stream.end; ++pos){
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){ if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
@ -348,8 +341,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in
--pos; --pos;
if (pos > 0){ if (pos > 0){
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){ if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
bool32 still_looping = 1;
do{ do{
for (; pos >= stream.start; --pos){ for (; pos >= stream.start; --pos){
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){ if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
@ -360,7 +352,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in
}while(still_looping); }while(still_looping);
double_break1:; double_break1:;
still_looping = 1; still_looping = true;
do{ do{
for (; pos >= stream.start; --pos){ for (; pos >= stream.start; --pos){
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){ if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
@ -380,6 +372,78 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in
return(pos); return(pos);
} }
static int32_t
buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
char data_chunk[1024];
Stream_Chunk stream = {0};
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (char_is_alpha_numeric_utf8(stream.data[pos])){
goto double_break1;
}
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break1:;
still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
goto double_break2;
}
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break2:;
}
return(pos);
}
static int32_t
buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
char data_chunk[1024];
Stream_Chunk stream = {0};
--pos;
if (pos > 0){
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (char_is_alpha_numeric_utf8(stream.data[pos])){
goto double_break1;
}
}
still_looping = backward_stream_chunk(&stream);
}while(still_looping);
double_break1:;
still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
++pos;
goto double_break2;
}
}
still_looping = backward_stream_chunk(&stream);
}while(still_looping);
double_break2:;
}
}
else{
pos = 0;
}
return(pos);
}
static int32_t static int32_t
buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){
char data_chunk[1024]; char data_chunk[1024];
@ -982,6 +1046,31 @@ get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Toke
return(result); return(result);
} }
static String
read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char *space, int32_t max, Range *range_out){
String query = {0};
int32_t start = buffer_seek_alphanumeric_or_underscore_left(app, buffer, pos);
int32_t end = buffer_seek_alphanumeric_or_underscore_right(app, buffer, start);
if (!(start <= pos && pos < end)){
end = buffer_seek_alphanumeric_or_underscore_right(app, buffer, pos);
start = buffer_seek_alphanumeric_or_underscore_left(app, buffer, end);
}
if (start <= pos && pos < end){
int32_t size = end - start;
if (size <= max){
if (range_out != 0){
*range_out = make_range(start, end);
}
buffer_read_range(app, buffer, start, end, space);
query = make_string_cap(space, size, max);
}
}
return(query);
}
#endif #endif

View File

@ -22,29 +22,44 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){
View_Summary view = get_active_view(app, AccessProtected); View_Summary view = get_active_view(app, AccessProtected);
Name_Based_Jump_Location location = {0}; Name_Based_Jump_Location location = {0};
if (parse_jump_from_buffer_line(app, &global_part, if (parse_jump_from_buffer_line(app, &global_part, view.buffer_id, view.cursor.line, false, &location)){
view.buffer_id, view.cursor.line, false,
&location)){
exec_command(app, change_active_panel); exec_command(app, change_active_panel);
view = get_active_view(app, AccessAll); view = get_active_view(app, AccessAll);
jump_to_location(app, &view, &location); jump_to_location(app, &view, &location);
if (auto_center_after_jumps){
center_view(app);
}
} }
end_temp_memory(temp); end_temp_memory(temp);
} }
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel){
Temp_Memory temp = begin_temp_memory(&global_part);
View_Summary view = get_active_view(app, AccessProtected);
Name_Based_Jump_Location location = {0};
if (parse_jump_from_buffer_line(app, &global_part, view.buffer_id, view.cursor.line, false, &location)){
view = get_active_view(app, AccessAll);
jump_to_location(app, &view, &location);
if (auto_center_after_jumps){
center_view(app);
}
}
end_temp_memory(temp);
}
// //
// Error Jumping // Error Jumping
// //
static int32_t static bool32
seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){
Assert(direction == 1 || direction == -1); Assert(direction == 1 || direction == -1);
int32_t result = false; bool32 result = false;
int32_t line = first_line; int32_t line = first_line;
String line_str = {0}; String line_str = {0};
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
@ -146,23 +161,22 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summar
return(result); return(result);
} }
static int32_t static bool32
seek_jump(Application_Links *app, Partition *part, int32_t skip_repeats, int32_t skip_sub_errors, int32_t direction){ seek_jump(Application_Links *app, Partition *part, bool32 skip_repeats, bool32 skip_sub_errors, int32_t direction){
int32_t result = 0; bool32 result = false;
View_Summary view = get_view_for_locked_jump_buffer(app); View_Summary view = get_view_for_locked_jump_buffer(app);
if (view.exists){ if (view.exists){
Name_Based_Jump_Location location = {0}; Name_Based_Jump_Location location = {0};
if (advance_cursor_in_jump_view(app, &global_part, &view, skip_repeats, skip_sub_errors, direction, &location)){ if (advance_cursor_in_jump_view(app, &global_part, &view, skip_repeats, skip_sub_errors, direction, &location)){
View_Summary active_view = get_active_view(app, AccessAll); View_Summary active_view = get_active_view(app, AccessAll);
if (active_view.view_id == view.view_id){ if (active_view.view_id == view.view_id){
exec_command(app, change_active_panel); change_active_panel(app);
active_view = get_active_view(app, AccessAll); active_view = get_active_view(app, AccessAll);
} }
jump_to_location(app, &active_view, &location); jump_to_location(app, &active_view, &location);
result = 1; result = true;
} }
} }
@ -171,29 +185,29 @@ seek_jump(Application_Links *app, Partition *part, int32_t skip_repeats, int32_t
CUSTOM_COMMAND_SIG(goto_next_jump){ CUSTOM_COMMAND_SIG(goto_next_jump){
int32_t skip_repeats = true; bool32 skip_repeats = true;
int32_t skip_sub_errors = true; bool32 skip_sub_errors = true;
int32_t dir = 1; int32_t dir = 1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
} }
CUSTOM_COMMAND_SIG(goto_prev_jump){ CUSTOM_COMMAND_SIG(goto_prev_jump){
int32_t skip_repeats = true; bool32 skip_repeats = true;
int32_t skip_sub_errors = true; bool32 skip_sub_errors = true;
int32_t dir = -1; int32_t dir = -1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
} }
CUSTOM_COMMAND_SIG(goto_next_jump_no_skips){ CUSTOM_COMMAND_SIG(goto_next_jump_no_skips){
int32_t skip_repeats = false; bool32 skip_repeats = false;
int32_t skip_sub_errors = true; bool32 skip_sub_errors = true;
int32_t dir = 1; int32_t dir = 1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
} }
CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips){ CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips){
int32_t skip_repeats = false; bool32 skip_repeats = false;
int32_t skip_sub_errors = true; bool32 skip_sub_errors = true;
int32_t dir = -1; int32_t dir = -1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
} }
@ -218,11 +232,24 @@ CUSTOM_COMMAND_SIG(newline_or_goto_position){
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
if (buffer.lock_flags & AccessProtected){ if (buffer.lock_flags & AccessProtected){
exec_command(app, goto_jump_at_cursor); goto_jump_at_cursor(app);
lock_jump_buffer(buffer); lock_jump_buffer(buffer);
} }
else{ else{
exec_command(app, write_character); write_character(app);
}
}
CUSTOM_COMMAND_SIG(newline_or_goto_position_same_panel){
View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
if (buffer.lock_flags & AccessProtected){
goto_jump_at_cursor_same_panel(app);
lock_jump_buffer(buffer);
}
else{
write_character(app);
} }
} }

View File

@ -684,14 +684,14 @@ list_all_locations_of_identifier_parameters(Application_Links *app, bool32 subst
bool32 success = buffer_get_token_index(app, &buffer, view.cursor.pos, &get_result); bool32 success = buffer_get_token_index(app, &buffer, view.cursor.pos, &get_result);
if (success && !get_result.in_whitespace){ if (success && !get_result.in_whitespace){
char space[128]; char space[256];
int32_t size = get_result.token_end - get_result.token_start; int32_t size = get_result.token_end - get_result.token_start;
if (size > 0 && size <= sizeof(space)){ if (size > 0 && size <= sizeof(space)){
success = buffer_read_range(app, &buffer, get_result.token_start, get_result.token_end, space); success = buffer_read_range(app, &buffer, get_result.token_start, get_result.token_end, space);
if (success){ if (success){
String str = make_string(space, size); String str = make_string(space, size);
exec_command(app, change_active_panel); change_active_panel(app);
uint32_t flags = 0; uint32_t flags = 0;
if (substrings){ if (substrings){

View File

@ -1,198 +0,0 @@
/*
4coder_windows_bindings.cpp - Supplies bindings very similar to the bindings in modern style editors like notepad.
TYPE: 'build-target'
*/
// TOP
#if !defined(FCODER_WINDOWS_BINDINGS_CPP)
#define FCODER_WINDOWS_BINDINGS_CPP
#include "4coder_default_include.cpp"
void
default_keys(Bind_Helper *context){
begin_map(context, mapid_global);
bind(context, 't', MDFR_CTRL, open_panel_vsplit);
bind(context, 'T', MDFR_CTRL, open_panel_hsplit);
bind(context, 'w', MDFR_CTRL, close_panel);
bind(context, '\t', MDFR_CTRL, change_active_panel);
bind(context, '\t', MDFR_CTRL | MDFR_SHIFT, change_active_panel_backwards);
bind(context, 'n', MDFR_CTRL, interactive_new);
bind(context, 'n', MDFR_ALT, new_in_other);
bind(context, 'o', MDFR_CTRL, interactive_open);
bind(context, 'o', MDFR_ALT, open_in_other);
bind(context, 'k', MDFR_CTRL, interactive_kill_buffer);
bind(context, 'i', MDFR_CTRL, interactive_switch_buffer);
bind(context, 'S', MDFR_CTRL, save_all_dirty_buffers);
bind(context, 'c', MDFR_ALT, open_color_tweaker);
bind(context, 'd', MDFR_ALT, open_debug);
bind(context, '\\', MDFR_CTRL, change_to_build_panel);
bind(context, '|', MDFR_CTRL, close_build_panel);
bind(context, key_down, MDFR_ALT, goto_next_error);
bind(context, key_up, MDFR_ALT, goto_prev_error);
bind(context, key_up, MDFR_ALT | MDFR_SHIFT, goto_first_error);
bind(context, 'z', MDFR_ALT, execute_any_cli);
bind(context, 'Z', MDFR_ALT, execute_previous_cli);
bind(context, 'x', MDFR_ALT, execute_arbitrary_command);
bind(context, 's', MDFR_ALT, show_scrollbar);
bind(context, 'w', MDFR_ALT, hide_scrollbar);
bind(context, '@', MDFR_ALT, toggle_mouse);
bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen);
bind(context, 'W', MDFR_CTRL, exit_4coder);
bind(context, key_f4, MDFR_ALT, exit_4coder);
bind(context, key_f1, MDFR_NONE, project_fkey_command);
bind(context, key_f2, MDFR_NONE, project_fkey_command);
bind(context, key_f3, MDFR_NONE, project_fkey_command);
bind(context, key_f4, MDFR_NONE, project_fkey_command);
bind(context, key_f5, MDFR_NONE, project_fkey_command);
bind(context, key_f6, MDFR_NONE, project_fkey_command);
bind(context, key_f7, MDFR_NONE, project_fkey_command);
bind(context, key_f8, MDFR_NONE, project_fkey_command);
bind(context, key_f9, MDFR_NONE, project_fkey_command);
bind(context, key_f10, MDFR_NONE, project_fkey_command);
bind(context, key_f11, MDFR_NONE, project_fkey_command);
bind(context, key_f12, MDFR_NONE, project_fkey_command);
bind(context, key_f13, MDFR_NONE, project_fkey_command);
bind(context, key_f14, MDFR_NONE, project_fkey_command);
bind(context, key_f15, MDFR_NONE, project_fkey_command);
bind(context, key_f16, MDFR_NONE, project_fkey_command);
end_map(context);
begin_map(context, default_code_map);
inherit_map(context, mapid_file);
bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right);
bind(context, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left);
bind(context, key_right, MDFR_ALT, seek_whitespace_right);
bind(context, key_left, MDFR_ALT, seek_whitespace_left);
bind(context, '\n', MDFR_NONE, write_and_auto_tab);
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
bind(context, '}', MDFR_NONE, write_and_auto_tab);
bind(context, ')', MDFR_NONE, write_and_auto_tab);
bind(context, ']', MDFR_NONE, write_and_auto_tab);
bind(context, ';', MDFR_NONE, write_and_auto_tab);
bind(context, '#', MDFR_NONE, write_and_auto_tab);
bind(context, ' ', MDFR_ALT, word_complete);
bind(context, '\t', MDFR_NONE, auto_tab_line_at_cursor);
bind(context, '\t', MDFR_SHIFT, auto_tab_range);
bind(context, 't', MDFR_ALT, write_todo);
bind(context, 'y', MDFR_ALT, write_note);
bind(context, 'r', MDFR_ALT, write_block);
bind(context, '[', MDFR_CTRL, open_long_braces);
bind(context, '{', MDFR_CTRL, open_long_braces_semicolon);
bind(context, '}', MDFR_CTRL, open_long_braces_break);
bind(context, 'i', MDFR_ALT, if0_off);
bind(context, '1', MDFR_ALT, open_file_in_quotes);
bind(context, '2', MDFR_ALT, open_matching_file_cpp);
bind(context, '0', MDFR_CTRL, write_zero_struct);
bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer);
end_map(context);
begin_map(context, mapid_file);
bind_vanilla_keys(context, write_character);
bind(context, key_mouse_left, MDFR_NONE, click_set_cursor);
bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark);
bind(context, key_mouse_right, MDFR_NONE, click_set_mark);
bind(context, key_left, MDFR_NONE, move_left);
bind(context, key_right, MDFR_NONE, move_right);
bind(context, key_del, MDFR_NONE, delete_char);
bind(context, key_del, MDFR_SHIFT, delete_char);
bind(context, key_back, MDFR_NONE, backspace_char);
bind(context, key_back, MDFR_SHIFT, backspace_char);
bind(context, key_up, MDFR_NONE, move_up);
bind(context, key_down, MDFR_NONE, move_down);
bind(context, key_end, MDFR_NONE, seek_end_of_line);
bind(context, key_home, MDFR_NONE, seek_beginning_of_line);
bind(context, key_page_up, MDFR_NONE, page_up);
bind(context, key_page_down, MDFR_NONE, page_down);
bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right);
bind(context, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left);
bind(context, key_right, MDFR_ALT, seek_whitespace_right);
bind(context, key_left, MDFR_ALT, seek_whitespace_left);
bind(context, key_up, MDFR_CTRL, seek_whitespace_up_end_line);
bind(context, key_down, MDFR_CTRL, seek_whitespace_down_end_line);
bind(context, key_back, MDFR_CTRL, backspace_word);
bind(context, key_del, MDFR_CTRL, delete_word);
bind(context, key_back, MDFR_ALT, snipe_token_or_word);
bind(context, ' ', MDFR_CTRL, set_mark);
bind(context, 'a', MDFR_CTRL, select_all);
bind(context, 'c', MDFR_CTRL, copy);
bind(context, 'd', MDFR_CTRL, duplicate_line);
bind(context, 'f', MDFR_ALT, list_all_locations);
bind(context, 'f', MDFR_CTRL, list_all_substring_locations_case_insensitive);
bind(context, 'F', MDFR_CTRL, list_all_locations_of_identifier);
bind(context, 'F', MDFR_ALT, list_all_locations_of_identifier_case_insensitive);
bind(context, 'e', MDFR_CTRL, center_view);
bind(context, 'E', MDFR_CTRL, left_adjust_view);
bind(context, 'g', MDFR_CTRL, goto_line);
bind(context, 'h', MDFR_CTRL, query_replace);
bind(context, 'H', MDFR_CTRL, replace_in_range);
bind(context, 'i', MDFR_CTRL, search);
bind(context, 'I', MDFR_CTRL, reverse_search);
bind(context, 'K', MDFR_CTRL, kill_buffer);
bind(context, 'l', MDFR_CTRL, delete_line);
bind(context, 'L', MDFR_ALT, toggle_line_wrap);
bind(context, 'O', MDFR_CTRL, reopen);
bind(context, 's', MDFR_CTRL, save);
bind(context, 'S', MDFR_ALT, save_as);
bind(context, 'v', MDFR_CTRL, paste_and_indent);
bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace);
bind(context, 'V', MDFR_CTRL, paste_next_and_indent);
bind(context, 'x', MDFR_CTRL, cut);
bind(context, 'y', MDFR_CTRL, redo);
bind(context, 'z', MDFR_CTRL, undo);
bind(context, '2', MDFR_CTRL, decrease_line_wrap);
bind(context, '3', MDFR_CTRL, increase_line_wrap);
bind(context, '?', MDFR_CTRL, toggle_show_whitespace);
bind(context, '~', MDFR_CTRL, clean_all_lines);
bind(context, '\n', MDFR_NONE, newline_or_goto_position);
bind(context, '\n', MDFR_SHIFT, newline_or_goto_position);
bind(context, ' ', MDFR_SHIFT, write_character);
end_map(context);
}
#ifndef NO_BINDING
extern "C" int32_t
get_bindings(void *data, int32_t size){
Bind_Helper context_ = begin_bind_helper(data, size);
Bind_Helper *context = &context_;
set_all_default_hooks(context);
default_keys(context);
int32_t result = end_bind_helper(context);
return(result);
}
#endif //NO_BINDING
#endif
// BOTTOM

57
4ed.cpp
View File

@ -275,7 +275,7 @@ panel_make_empty(System_Functions *system, App_Vars *vars, Panel *panel){
Assert(panel->view == 0); Assert(panel->view == 0);
new_view = live_set_alloc_view(&vars->live_set, panel, models); new_view = live_set_alloc_view(&vars->live_set, panel, models);
view_set_file(system, new_view.view, models->scratch_buffer, models); view_set_file(system, new_view.view, models->scratch_buffer, models);
new_view.view->map = get_map(models, mapid_file); new_view.view->map = get_map(models, models->scratch_buffer->settings.base_map_id);
return(new_view.view); return(new_view.view);
} }
@ -965,7 +965,7 @@ enum Command_Line_Action{
CLAct_WindowFullscreen, CLAct_WindowFullscreen,
CLAct_WindowStreamMode, CLAct_WindowStreamMode,
CLAct_FontSize, CLAct_FontSize,
CLAct_FontStartHinting, CLAct_FontUseHinting,
CLAct_Count CLAct_Count
}; };
@ -1010,9 +1010,6 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
if (arg[0] == '-'){ if (arg[0] == '-'){
action = CLAct_Ignore; action = CLAct_Ignore;
switch (arg[1]){ switch (arg[1]){
case 'u': action = CLAct_UserFile; strict = 0; break;
case 'U': action = CLAct_UserFile; strict = 1; break;
case 'd': action = CLAct_CustomDLL; strict = 0; break; case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break; case 'D': action = CLAct_CustomDLL; strict = 1; break;
@ -1025,7 +1022,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'S': action = CLAct_WindowStreamMode; break; case 'S': action = CLAct_WindowStreamMode; break;
case 'f': action = CLAct_FontSize; break; case 'f': action = CLAct_FontSize; break;
case 'h': action = CLAct_FontStartHinting; --i; break; case 'h': action = CLAct_FontUseHinting; --i; break;
} }
} }
else if (arg[0] != 0){ else if (arg[0] != 0){
@ -1036,18 +1033,9 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
} }
}break; }break;
case CLAct_UserFile:
{
settings->user_file_is_strict = strict;
if (i < clparams.argc){
settings->user_file = clparams.argv[i];
}
action = CLAct_Nothing;
}break;
case CLAct_CustomDLL: case CLAct_CustomDLL:
{ {
plat_settings->custom_dll_is_strict = strict; plat_settings->custom_dll_is_strict = (b8)strict;
if (i < clparams.argc){ if (i < clparams.argc){
plat_settings->custom_dll = clparams.argv[i]; plat_settings->custom_dll = clparams.argv[i];
} }
@ -1065,7 +1053,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case CLAct_WindowSize: case CLAct_WindowSize:
{ {
if (i + 1 < clparams.argc){ if (i + 1 < clparams.argc){
plat_settings->set_window_size = 1; plat_settings->set_window_size = true;
plat_settings->window_w = str_to_int_c(clparams.argv[i]); plat_settings->window_w = str_to_int_c(clparams.argv[i]);
plat_settings->window_h = str_to_int_c(clparams.argv[i+1]); plat_settings->window_h = str_to_int_c(clparams.argv[i+1]);
@ -1077,14 +1065,14 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case CLAct_WindowMaximize: case CLAct_WindowMaximize:
{ {
--i; --i;
plat_settings->maximize_window = 1; plat_settings->maximize_window = true;
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_WindowPosition: case CLAct_WindowPosition:
{ {
if (i + 1 < clparams.argc){ if (i + 1 < clparams.argc){
plat_settings->set_window_pos = 1; plat_settings->set_window_pos = true;
plat_settings->window_x = str_to_int_c(clparams.argv[i]); plat_settings->window_x = str_to_int_c(clparams.argv[i]);
plat_settings->window_y = str_to_int_c(clparams.argv[i+1]); plat_settings->window_y = str_to_int_c(clparams.argv[i+1]);
@ -1096,29 +1084,29 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case CLAct_WindowFullscreen: case CLAct_WindowFullscreen:
{ {
--i; --i;
plat_settings->fullscreen_window = 1; plat_settings->fullscreen_window = true;
plat_settings->stream_mode = 1; plat_settings->stream_mode = true;
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_WindowStreamMode: case CLAct_WindowStreamMode:
{ {
--i; --i;
plat_settings->stream_mode = 1; plat_settings->stream_mode = true;
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_FontSize: case CLAct_FontSize:
{ {
if (i < clparams.argc){ if (i < clparams.argc){
settings->font_size = str_to_int_c(clparams.argv[i]); plat_settings->font_size = str_to_int_c(clparams.argv[i]);
} }
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_FontStartHinting: case CLAct_FontUseHinting:
{ {
plat_settings->use_hinting = 1; plat_settings->use_hinting = true;
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
} }
@ -1155,7 +1143,7 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Settings *settings = &vars->models.settings; App_Settings *settings = &vars->models.settings;
*settings = null_app_settings; *settings = null_app_settings;
settings->font_size = 16; plat_settings->font_size = 16;
if (clparams.argc > 1){ if (clparams.argc > 1){
init_command_line_settings(&vars->models.settings, plat_settings, clparams); init_command_line_settings(&vars->models.settings, plat_settings, clparams);
@ -1480,7 +1468,7 @@ App_Init_Sig(app_init){
struct File_Init{ struct File_Init{
String name; String name;
Editing_File **ptr; Editing_File **ptr;
i32 type; b32 read_only;
}; };
File_Init init_files[] = { File_Init init_files[] = {
@ -1492,16 +1480,11 @@ App_Init_Sig(app_init){
Editing_File *file = working_set_alloc_always(&models->working_set, general); Editing_File *file = working_set_alloc_always(&models->working_set, general);
buffer_bind_name(general, &models->working_set, file, init_files[i].name); buffer_bind_name(general, &models->working_set, file, init_files[i].name);
switch (init_files[i].type){ if (init_files[i].read_only){
case 0: init_read_only_file(system, models, file);
{ }
init_normal_file(system, models, file, 0, 0); else{
}break; init_normal_file(system, models, file, 0, 0);
case 1:
{
init_read_only_file(system, models, file);
}break;
} }
file->settings.never_kill = true; file->settings.never_kill = true;

20
4ed.h
View File

@ -38,30 +38,32 @@ get_single_key(Key_Input_Data *data, i32 index){
return(key); return(key);
} }
typedef struct Input_Summary{ struct Input_Summary{
Mouse_State mouse; Mouse_State mouse;
Key_Input_Data keys; Key_Input_Data keys;
f32 dt; f32 dt;
} Input_Summary; };
typedef struct Command_Line_Parameters{ struct Command_Line_Parameters{
char **argv; char **argv;
int32_t argc; int32_t argc;
} Command_Line_Parameters; };
typedef struct Plat_Settings{ struct Plat_Settings{
char *custom_dll; char *custom_dll;
b32 custom_dll_is_strict; b8 custom_dll_is_strict;
b32 fullscreen_window; b8 fullscreen_window;
b32 stream_mode; b8 stream_mode;
i32 window_w, window_h; i32 window_w, window_h;
i32 window_x, window_y; i32 window_x, window_y;
b8 set_window_pos; b8 set_window_pos;
b8 set_window_size; b8 set_window_size;
b8 maximize_window; b8 maximize_window;
b8 use_hinting; b8 use_hinting;
} Plat_Settings; i32 font_size;
};
#define App_Read_Command_Line_Sig(name) \ #define App_Read_Command_Line_Sig(name) \
i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, Command_Line_Parameters clparams) i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, Command_Line_Parameters clparams)

View File

@ -900,13 +900,7 @@ DOC_SEE(Buffer_Setting_ID)
case BufferSetting_MapID: case BufferSetting_MapID:
{ {
if (value == mapid_global){ if (value < mapid_global){
file->settings.base_map_id = mapid_global;
}
else if (value == mapid_file){
file->settings.base_map_id = mapid_file;
}
else if (value < mapid_global){
new_mapid = get_map_index(models, value); new_mapid = get_map_index(models, value);
if (new_mapid < models->user_map_count){ if (new_mapid < models->user_map_count){
file->settings.base_map_id = value; file->settings.base_map_id = value;
@ -915,6 +909,9 @@ DOC_SEE(Buffer_Setting_ID)
file->settings.base_map_id = mapid_file; file->settings.base_map_id = mapid_file;
} }
} }
else if (value <= mapid_nomap){
file->settings.base_map_id = value;
}
for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); for (View_Iter iter = file_view_iter_init(&models->layout, file, 0);
file_view_iter_good(iter); file_view_iter_good(iter);
@ -2076,11 +2073,9 @@ DOC(This call changes 4coder's color pallet to one of the built in themes.)
Style_Library *styles = &cmd->models->styles; Style_Library *styles = &cmd->models->styles;
String theme_name = make_string(name, len); String theme_name = make_string(name, len);
i32 i = 0;
i32 count = styles->count; i32 count = styles->count;
Style *s = styles->styles; Style *s = styles->styles;
for (i32 i = 0; i < count; ++i, ++s){
for (i = 0; i < count; ++i, ++s){
if (match_ss(s->name, theme_name)){ if (match_ss(s->name, theme_name)){
style_copy(main_style(cmd->models), s); style_copy(main_style(cmd->models), s);
break; break;
@ -2093,29 +2088,22 @@ Change_Font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all
/* /*
DOC_PARAM(name, The name parameter specifies the name of the font to begin using; it need not be null terminated.) DOC_PARAM(name, The name parameter specifies the name of the font to begin using; it need not be null terminated.)
DOC_PARAM(len, The len parameter specifies the length of the name string.) DOC_PARAM(len, The len parameter specifies the length of the name string.)
DOC_PARAM(apply_to_all_files, If this is set all open files change to this font. Usually this should be true DOC_PARAM(apply_to_all_files, If this is set all open files change to this font. Usually this should be true durring the start hook because several files already exist at that time.)
durring the start hook because several files already exist at that time.)
DOC(This call changes 4coder's default font to one of the built in fonts.) DOC(This call changes 4coder's default font to one of the built in fonts.)
*/{ */{
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Font_Set *set = cmd->models->font_set; Models *models = cmd->models;
System_Functions *system = cmd->system;
Style_Font *global_font = &cmd->models->global_font;
String font_name = make_string(name, len); String font_name = make_string(name, len);
i16 font_id = 0; Font_ID font_id = font_get_id_by_name(system, font_name);
if (font_set_extract(set, font_name, &font_id)){ if (apply_to_all_files){
if (apply_to_all_files){ global_set_font(system, models, font_id);
global_set_font(cmd->models, font_id); }
} else{
else{ models->global_font_id = font_id;
global_font->font_id = font_id;
}
} }
#endif
} }
API_EXPORT void API_EXPORT void
@ -2127,22 +2115,16 @@ DOC_PARAM(len, The len parameter specifies the length of the name string.)
DOC(This call sets the display font of a particular buffer.) DOC(This call sets the display font of a particular buffer.)
*/{ */{
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models; Models *models = cmd->models;
System_Functions *system = cmd->system;
Editing_File *file = imp_get_file(cmd, buffer); Editing_File *file = imp_get_file(cmd, buffer);
if (file){ if (file != 0){
Font_Set *set = models->font_set;
String font_name = make_string(name, len); String font_name = make_string(name, len);
i16 font_id = 0; Font_ID font_id = font_get_id_by_name(system, font_name);
file_set_font(system, models, file, font_id);
if (font_set_extract(set, font_name, &font_id)){
file_set_font(models, file, font_id);
}
} }
#endif
} }
API_EXPORT bool32 API_EXPORT bool32
@ -2152,23 +2134,21 @@ DOC_PARAM(buffer, the buffer from which to get the font name)
DOC_PARAM(name_out, a character array in which to write the name of the font) DOC_PARAM(name_out, a character array in which to write the name of the font)
DOC_PARAM(name_max, the capacity of name_out) DOC_PARAM(name_max, the capacity of name_out)
DOC_RETURN(returns non-zero on success) DOC_RETURN(returns non-zero on success)
*/ */{
{
bool32 result = false;
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models; System_Functions *system = cmd->system;
Editing_File *file = imp_get_file(cmd, buffer); Editing_File *file = imp_get_file(cmd, buffer);
if (file){ bool32 result = false;
Font_Set *set = models->font_set;
if (file != 0){
String name = make_string_cap(name_out, 0, name_max); String name = make_string_cap(name_out, 0, name_max);
if (font_set_get_name(set, file->settings.font_id, &name)){ Font_ID font_id = file->settings.font_id;
result = (name.size > 0); name.size = system->font.get_name_by_id(font_id, name_out, name_max);
if (name.size > 0){
result = true;
} }
} }
#endif
return(result); return(result);
} }
@ -2178,8 +2158,7 @@ Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count)
/* /*
DOC_PARAM(colors, The colors pointer provides an array of color structs pairing differet style tags to color codes.) DOC_PARAM(colors, The colors pointer provides an array of color structs pairing differet style tags to color codes.)
DOC_PARAM(count, The count parameter specifies the number of Theme_Color structs in the colors array.) DOC_PARAM(count, The count parameter specifies the number of Theme_Color structs in the colors array.)
DOC( DOC(For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid no change is made to the color pallet.)
For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid no change is made to the color pallet.)
DOC_SEE(Theme_Color) DOC_SEE(Theme_Color)
*/{ */{
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;

View File

@ -10,9 +10,6 @@
// TOP // TOP
struct App_Settings{ struct App_Settings{
char *user_file;
b32 user_file_is_strict;
char *init_files[8]; char *init_files[8];
i32 init_files_count; i32 init_files_count;
i32 init_files_max; i32 init_files_max;
@ -20,8 +17,6 @@ struct App_Settings{
i32 initial_line; i32 initial_line;
b32 lctrl_lalt_is_altgr; b32 lctrl_lalt_is_altgr;
i32 font_size;
char *custom_font_file; char *custom_font_file;
char *custom_font_name; char *custom_font_name;
i32 custom_font_size; i32 custom_font_size;

View File

@ -1966,7 +1966,6 @@ file_set_min_base_width(System_Functions *system, Models *models, Editing_File *
internal void internal void
file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){
//Font_Set *font_set = models->font_set;
General_Memory *general = &models->mem.general; General_Memory *general = &models->mem.general;
Partition *part = &models->mem.part; Partition *part = &models->mem.part;
Open_File_Hook_Function *hook_open_file = models->hook_open_file; Open_File_Hook_Function *hook_open_file = models->hook_open_file;
@ -2037,7 +2036,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
if (hook_open_file){ if (hook_open_file){
hook_open_file(app_links, file->id.id); hook_open_file(app_links, file->id.id);
} }
file->settings.is_initialized = 1; file->settings.is_initialized = true;
} }
internal void internal void
@ -5437,9 +5436,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
SHOW_GUI_BLANK(0); SHOW_GUI_BLANK(0);
{ {
Command_Map *map = view_ptr->map; Command_Map *map = view_ptr->map;
#define MAP_LABEL "command map" #define MAP_LABEL "command map"
if (map == &models->map_top){ if (map == &models->map_top){
SHOW_GUI_STRING(1, h_align, MAP_LABEL, "global"); SHOW_GUI_STRING(1, h_align, MAP_LABEL, "global");
} }
@ -5449,10 +5446,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
else if (map == &models->map_ui){ else if (map == &models->map_ui){
SHOW_GUI_STRING(1, h_align, MAP_LABEL, "gui"); SHOW_GUI_STRING(1, h_align, MAP_LABEL, "gui");
} }
else{ else if (map == 0){
SHOW_GUI_STRING(1, h_align, MAP_LABEL, "nomap");
}
else if (map >= models->user_maps){
i32 map_index = (i32)(view_ptr->map - models->user_maps); i32 map_index = (i32)(view_ptr->map - models->user_maps);
i32 map_id = models->map_id_table[map_index]; i32 map_id = models->map_id_table[map_index];
SHOW_GUI_STRING(1, h_align, MAP_LABEL, "user"); SHOW_GUI_STRING(1, h_align, MAP_LABEL, "user");
SHOW_GUI_INT(2, h_align, "custom map id", map_id); SHOW_GUI_INT(2, h_align, "custom map id", map_id);
} }

View File

@ -20,16 +20,16 @@ struct Glyph_Page;
#define Sys_Font_Get_Count_Sig(name_) u32 (name_)(void) #define Sys_Font_Get_Count_Sig(name_) u32 (name_)(void)
typedef Sys_Font_Get_Count_Sig(Font_Get_Count_Function); typedef Sys_Font_Get_Count_Sig(Font_Get_Count_Function);
#define Sys_Font_Get_IDs_By_Index_Sig(name_) b32 (name_)(u32 first_index, u32 index_count, u32 *id_out) #define Sys_Font_Get_IDs_By_Index_Sig(name_) b32 (name_)(Font_ID first_index, u32 index_count, u32 *id_out)
typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function); typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function);
#define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) #define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap)
typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function); typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function);
#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_id, char *str_out, u32 str_out_cap) #define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(Font_ID font_id, char *str_out, u32 str_out_cap)
typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function); typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function);
#define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id) #define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(Font_ID font_id)
typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function); typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function);
#define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number) #define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number)
@ -53,6 +53,8 @@ struct Font_Functions{
Font_Free_Function *free; Font_Free_Function *free;
}; };
internal u32 font_get_id_by_name(struct System_Functions *system, String name);
internal f32 font_get_byte_advance(Render_Font *font); internal f32 font_get_byte_advance(Render_Font *font);
internal f32*font_get_byte_sub_advances(Render_Font *font); internal f32*font_get_byte_sub_advances(Render_Font *font);
internal i32 font_get_height(Render_Font *font); internal i32 font_get_height(Render_Font *font);

View File

@ -11,6 +11,22 @@
#include "4ed_font_data.h" #include "4ed_font_data.h"
internal u32
font_get_id_by_name(System_Functions *system, String name){
u32 id = 0;
u32 count = system->font.get_count();
for (u32 index = 0; index < count; ++index){
char str[256];
u32 str_len = system->font.get_name_by_index(index, str, sizeof(str));
String font_name = make_string(str, str_len);
if (match_ss(font_name, name)){
system->font.get_ids_by_index(index, 1, &id);
break;
}
}
return(id);
}
internal f32 internal f32
font_get_byte_advance(Render_Font *font){ font_get_byte_advance(Render_Font *font){
return(font->byte_advance); return(font->byte_advance);

View File

@ -3162,7 +3162,7 @@ main(int argc, char **argv)
// Font System Init // Font System Init
// //
system_font_init(&linuxvars.system.font, 0, 0, 16, true); system_font_init(&linuxvars.system.font, 0, 0, linuxvars.settings.font_size, linuxvars.settings.use_hinting);
// //
// Epoll init // Epoll init

View File

@ -71,7 +71,7 @@ Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){
internal internal
Sys_Font_Load_Page_Sig(system_font_load_page){ Sys_Font_Load_Page_Sig(system_font_load_page){
system_set_page(&linuxvars.system, &linux_fonts.part, font, page, page_number, 16, true); system_set_page(&linuxvars.system, &linux_fonts.part, font, page, page_number, linuxvars.settings.font_size, linuxvars.settings.use_hinting);
} }
internal internal

View File

@ -2197,7 +2197,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// Font System Init // Font System Init
// //
system_font_init(&win32vars.system.font, 0, 0, 16, true); system_font_init(&win32vars.system.font, 0, 0, win32vars.settings.font_size, win32vars.settings.use_hinting);
// //
// Misc System Initializations // Misc System Initializations

View File

@ -71,7 +71,7 @@ Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){
internal internal
Sys_Font_Load_Page_Sig(system_font_load_page){ Sys_Font_Load_Page_Sig(system_font_load_page){
system_set_page(&win32vars.system, &win32_fonts.part, font, page, page_number, 16, true); system_set_page(&win32vars.system, &win32_fonts.part, font, page, page_number, win32vars.settings.font_size, win32vars.settings.use_hinting);
} }
internal internal