Transition integer types over to new config system

master
Allen Webster 2020-11-26 13:12:59 -08:00
parent 46bfdd9bad
commit ed619c7960
8 changed files with 2007 additions and 1979 deletions

View File

@ -389,8 +389,9 @@ auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Inde
function void
auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Indent_Flag flags){
i32 indent_width = global_config.indent_width;
i32 tab_width = global_config.default_tab_width;
i32 indent_width = (i32)def_get_config_u64(app, vars_save_string_lit("indent_width"));
i32 tab_width = (i32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
AddFlag(flags, Indent_FullTokens);
b32 indent_with_tabs = def_get_config_b32(vars_save_string_lit("indent_with_tabs"));
if (indent_with_tabs){

View File

@ -948,9 +948,12 @@ layout_index__inner(Application_Links *app, Arena *arena, Buffer_ID buffer, Rang
Face_Advance_Map advance_map = get_face_advance_map(app, face);
Face_Metrics metrics = get_face_metrics(app, face);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, width);
f32 tab_width = (f32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, tab_width, width);
f32 regular_indent = metrics.space_advance*global_config.virtual_whitespace_regular_indent;
u64 vw_indent = def_get_config_u64(app, vars_save_string_lit("virtual_whitespace_regular_indent"));
f32 regular_indent = metrics.space_advance*vw_indent;
f32 wrap_align_x = width - metrics.normal_advance;
Layout_Reflex reflex = get_layout_reflex(&list, buffer, width, face);

View File

@ -809,6 +809,34 @@ def_set_config_string(String_ID key, String_Const_u8 val){
def_set_config_var(key, vars_save_string(val));
}
function u64
def_get_config_u64(Application_Links *app, String_ID key){
Scratch_Block scratch(app);
Variable_Handle var = def_get_config_var(key);
String_ID val = vars_string_id_from_var(var);
String_Const_u8 string = vars_read_string(scratch, val);
u64 result = 0;
if (string_match(string_prefix(string, 2), string_u8_litinit("0x"))){
String_Const_u8 string_hex = string_skip(string, 2);
if (string_is_integer(string_hex, 0x10)){
result = string_to_integer(string_hex, 0x10);
}
}
else{
if (string_is_integer(string, 10)){
result = string_to_integer(string, 10);
}
}
return(result);
}
function void
def_set_config_u64(Application_Links *app, String_ID key, u64 val){
Scratch_Block scratch(app);
String_Const_u8 val_string = push_stringf(scratch, "%llu", val);
def_set_config_var(key, vars_save_string(val_string));
}
////////////////////////////////
// NOTE(allen): Eval
@ -1341,16 +1369,9 @@ config_init_default(Config_Data *config){
config->mark_thickness = 2.f;
config->lister_roundness = .20f;
config->virtual_whitespace_regular_indent = 4;
config->indent_width = 4;
config->default_tab_width = 4;
config->default_font_size = 16;
}
//parse_extension_line_to_extension_list
function Config*
config_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_name,
String_Const_u8 data, Config_Data *config){
@ -1375,11 +1396,6 @@ config_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_na
}
}
config_int_var(parsed, "virtual_whitespace_regular_indent", 0, &config->virtual_whitespace_regular_indent);
config_int_var(parsed, "indent_width", 0, &config->indent_width);
config_int_var(parsed, "default_tab_width", 0, &config->default_tab_width);
config_int_var(parsed, "default_font_size", 0, &config->default_font_size);
}

View File

@ -182,11 +182,6 @@ struct Config_Data{
f32 mark_thickness;
f32 lister_roundness;
i32 virtual_whitespace_regular_indent;
i32 indent_width;
i32 default_tab_width;
i32 default_font_size;
};
@ -248,6 +243,9 @@ function void def_set_config_b32(String_ID key, b32 val);
function String_Const_u8 def_get_config_string(Arena *arena, String_ID key);
function void def_set_config_string(String_ID key, String_Const_u8 val);
function u64 def_get_config_u64(Application_Links *app, String_ID key);
function void def_set_config_u64(Application_Links *app, String_ID key, u64 val);
#endif
// BOTTOM

View File

@ -2514,22 +2514,22 @@ exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buff
////////////////////////////////
#if 0
function f32
font_get_glyph_advance(Face_Advance_Map *map, Face_Metrics *metrics, u32 codepoint){
return(font_get_glyph_advance(map, metrics, codepoint, (f32)global_config.default_tab_width));
font_get_glyph_advance(Face_Advance_Map *map, Face_Metrics *metrics, u32 codepoint, f32 tab_width){
return(font_get_glyph_advance(map, metrics, codepoint, tab_width));
}
function f32
font_get_max_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics,
u32 codepoint_first, u32 codepoint_last){
return(font_get_max_glyph_advance_range(map, metrics, codepoint_first, codepoint_last,
(f32)global_config.default_tab_width));
u32 codepoint_first, u32 codepoint_last, f32 tab_width){
return(font_get_max_glyph_advance_range(map, metrics, codepoint_first, codepoint_last, tab_width));
}
function f32
font_get_average_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics,
u32 codepoint_first, u32 codepoint_last){
return(font_get_average_glyph_advance_range(map, metrics, codepoint_first, codepoint_last,
(f32)global_config.default_tab_width));
u32 codepoint_first, u32 codepoint_last, f32 tab_width){
return(font_get_average_glyph_advance_range(map, metrics, codepoint_first, codepoint_last, tab_width));
}
#endif
////////////////////////////////
// NOTE(allen): Layout Invalidate

View File

@ -142,13 +142,14 @@ newline_layout_consume_finish(Newline_Layout_Vars *vars){
////
function LefRig_TopBot_Layout_Vars
get_lr_tb_layout_vars(Face_Advance_Map *advance_map, Face_Metrics *metrics, f32 width){
get_lr_tb_layout_vars(Face_Advance_Map *advance_map, Face_Metrics *metrics, f32 tab_width, f32 width){
f32 text_height = metrics->text_height;
f32 line_height = metrics->line_height;
LefRig_TopBot_Layout_Vars result = {};
result.advance_map = advance_map;
result.metrics = metrics;
result.tab_width = tab_width;
result.line_to_text_shift = text_height - line_height;
result.blank_dim = V2f32(metrics->space_advance, text_height);
@ -171,7 +172,7 @@ lr_tb_crosses_width(LefRig_TopBot_Layout_Vars *vars, f32 advance){
function f32
lr_tb_advance(LefRig_TopBot_Layout_Vars *vars, Face_ID face, u32 codepoint){
return(font_get_glyph_advance(vars->advance_map, vars->metrics, codepoint));
return(font_get_glyph_advance(vars->advance_map, vars->metrics, codepoint, vars->tab_width));
}
function void
@ -292,7 +293,9 @@ layout_unwrapped_small_blank_lines(Application_Links *app, Arena *arena, Buffer_
Face_Advance_Map advance_map = get_face_advance_map(app, face);
Face_Metrics metrics = get_face_metrics(app, face);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, width);
f32 tab_width = (f32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, tab_width, width);
pos_vars.blank_dim = V2f32(metrics.space_advance, metrics.text_height*0.5f);
@ -386,7 +389,9 @@ layout_wrap_anywhere(Application_Links *app, Arena *arena, Buffer_ID buffer, Ran
Face_Advance_Map advance_map = get_face_advance_map(app, face);
Face_Metrics metrics = get_face_metrics(app, face);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, width);
f32 tab_width = (f32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, tab_width, width);
if (text.size == 0){
lr_tb_write_blank(&pos_vars, face, arena, &list, range.first);
@ -459,7 +464,9 @@ layout_unwrapped__inner(Application_Links *app, Arena *arena, Buffer_ID buffer,
Face_Advance_Map advance_map = get_face_advance_map(app, face);
Face_Metrics metrics = get_face_metrics(app, face);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, width);
f32 tab_width = (f32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, tab_width, width);
if (text.size == 0){
lr_tb_write_blank(&pos_vars, face, arena, &list, range.first);
@ -537,7 +544,9 @@ layout_wrap_whitespace__inner(Application_Links *app, Arena *arena, Buffer_ID bu
Face_Advance_Map advance_map = get_face_advance_map(app, face);
Face_Metrics metrics = get_face_metrics(app, face);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, width);
f32 tab_width = (f32)def_get_config_u64(app, vars_save_string_lit("default_tab_width"));
tab_width = clamp_bot(1, tab_width);
LefRig_TopBot_Layout_Vars pos_vars = get_lr_tb_layout_vars(&advance_map, &metrics, tab_width, width);
if (text.size == 0){
lr_tb_write_blank(&pos_vars, face, arena, &list, range.first);

View File

@ -16,6 +16,7 @@ struct Newline_Layout_Vars{
struct LefRig_TopBot_Layout_Vars{
Face_Advance_Map *advance_map;
Face_Metrics *metrics;
f32 tab_width;
f32 line_to_text_shift;
Vec2_f32 blank_dim;

View File

@ -273,9 +273,9 @@ i32 line_number;
};
static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(allow_mouse, 0), false, "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 481 },
{ PROC_LINKS(auto_indent_line_at_cursor, 0), false, "auto_indent_line_at_cursor", 26, "Auto-indents the line on which the cursor sits.", 47, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 418 },
{ PROC_LINKS(auto_indent_range, 0), false, "auto_indent_range", 17, "Auto-indents the range between the cursor and the mark.", 55, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 428 },
{ PROC_LINKS(auto_indent_whole_file, 0), false, "auto_indent_whole_file", 22, "Audo-indents the entire current buffer.", 39, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 409 },
{ PROC_LINKS(auto_indent_line_at_cursor, 0), false, "auto_indent_line_at_cursor", 26, "Auto-indents the line on which the cursor sits.", 47, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 419 },
{ PROC_LINKS(auto_indent_range, 0), false, "auto_indent_range", 17, "Auto-indents the range between the cursor and the mark.", 55, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 429 },
{ PROC_LINKS(auto_indent_whole_file, 0), false, "auto_indent_whole_file", 22, "Audo-indents the entire current buffer.", 39, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 410 },
{ PROC_LINKS(backspace_alpha_numeric_boundary, 0), false, "backspace_alpha_numeric_boundary", 32, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 154 },
{ PROC_LINKS(backspace_char, 0), false, "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 96 },
{ PROC_LINKS(basic_change_active_panel, 0), false, "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 666 },
@ -372,7 +372,7 @@ static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 972 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1609 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1625 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 547 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 },
@ -503,7 +503,7 @@ static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(toggle_mouse, 0), false, "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 487 },
{ PROC_LINKS(toggle_paren_matching_helper, 0), false, "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 521 },
{ PROC_LINKS(toggle_show_whitespace, 0), false, "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 816 },
{ PROC_LINKS(toggle_virtual_whitespace, 0), false, "toggle_virtual_whitespace", 25, "Toggles virtual whitespace for all files.", 41, "W:\\4ed\\code\\custom\\4coder_code_index.cpp", 40, 1235 },
{ PROC_LINKS(toggle_virtual_whitespace, 0), false, "toggle_virtual_whitespace", 25, "Toggles virtual whitespace for all files.", 41, "W:\\4ed\\code\\custom\\4coder_code_index.cpp", 40, 1238 },
{ PROC_LINKS(tutorial_maximize, 0), false, "tutorial_maximize", 17, "Expand the tutorial window", 26, "W:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 20 },
{ PROC_LINKS(tutorial_minimize, 0), false, "tutorial_minimize", 17, "Shrink the tutorial window", 26, "W:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 34 },
{ PROC_LINKS(uncomment_line, 0), false, "uncomment_line", 14, "If present, delete '//' at the beginning of the line after leading whitespace.", 78, "W:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 137 },
@ -517,7 +517,7 @@ static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(write_hack, 0), false, "write_hack", 10, "At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.", 99, "W:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 82 },
{ PROC_LINKS(write_note, 0), false, "write_note", 10, "At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.", 99, "W:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 88 },
{ PROC_LINKS(write_space, 0), false, "write_space", 11, "Inserts a space.", 16, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 67 },
{ PROC_LINKS(write_text_and_auto_indent, 0), false, "write_text_and_auto_indent", 26, "Inserts text and auto-indents the line on which the cursor sits if any of the text contains 'layout punctuation' such as ;:{}()[]# and new lines.", 145, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 438 },
{ PROC_LINKS(write_text_and_auto_indent, 0), false, "write_text_and_auto_indent", 26, "Inserts text and auto-indents the line on which the cursor sits if any of the text contains 'layout punctuation' such as ;:{}()[]# and new lines.", 145, "W:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 439 },
{ PROC_LINKS(write_text_input, 0), false, "write_text_input", 16, "Inserts whatever text was used to trigger this command.", 55, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 59 },
{ PROC_LINKS(write_todo, 0), false, "write_todo", 10, "At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.", 99, "W:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 76 },
{ PROC_LINKS(write_underscore, 0), false, "write_underscore", 16, "Inserts an underscore.", 22, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 73 },