default_tab_width in config.4coder

This commit is contained in:
Allen Webster 2020-05-01 20:59:36 -07:00
parent 4dc4adccf9
commit ca7240f349
10 changed files with 57 additions and 30 deletions

View File

@ -325,15 +325,15 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
{ {
Face_Advance_Map *advance_map = &face->advance_map; Face_Advance_Map *advance_map = &face->advance_map;
met->space_advance = font_get_glyph_advance(advance_map, met, ' '); met->space_advance = font_get_glyph_advance(advance_map, met, ' ', 0);
met->decimal_digit_advance = met->decimal_digit_advance =
font_get_max_glyph_advance_range(advance_map, met, '0', '9'); font_get_max_glyph_advance_range(advance_map, met, '0', '9', 0);
met->hex_digit_advance = met->hex_digit_advance =
font_get_max_glyph_advance_range(advance_map, met, 'A', 'F'); font_get_max_glyph_advance_range(advance_map, met, 'A', 'F', 0);
met->hex_digit_advance = met->hex_digit_advance =
Max(met->hex_digit_advance, met->decimal_digit_advance); Max(met->hex_digit_advance, met->decimal_digit_advance);
met->byte_sub_advances[0] = met->byte_sub_advances[0] =
font_get_glyph_advance(advance_map, met, '\\'); font_get_glyph_advance(advance_map, met, '\\', 0);
met->byte_sub_advances[1] = met->hex_digit_advance; met->byte_sub_advances[1] = met->hex_digit_advance;
met->byte_sub_advances[2] = met->hex_digit_advance; met->byte_sub_advances[2] = met->hex_digit_advance;
met->byte_advance = met->byte_advance =
@ -341,9 +341,9 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
met->byte_sub_advances[1] + met->byte_sub_advances[1] +
met->byte_sub_advances[2]; met->byte_sub_advances[2];
met->normal_lowercase_advance = met->normal_lowercase_advance =
font_get_average_glyph_advance_range(advance_map, met, 'a', 'z'); font_get_average_glyph_advance_range(advance_map, met, 'a', 'z', 0);
met->normal_uppercase_advance = met->normal_uppercase_advance =
font_get_average_glyph_advance_range(advance_map, met, 'A', 'Z'); font_get_average_glyph_advance_range(advance_map, met, 'A', 'Z', 0);
met->normal_advance = (26*met->normal_lowercase_advance + met->normal_advance = (26*met->normal_lowercase_advance +
26*met->normal_uppercase_advance + 26*met->normal_uppercase_advance +
10*met->decimal_digit_advance)/62.f; 10*met->decimal_digit_advance)/62.f;

View File

@ -248,13 +248,14 @@ draw_string(Render_Target *target, Face *face, String_Const_u8 string, Vec2_f32
if (behavior.do_codepoint_advance){ if (behavior.do_codepoint_advance){
u32 codepoint = step.value; u32 codepoint = step.value;
if (color != 0){ if (color != 0){
u32 draw_codepoint = step.value; u32 draw_codepoint = step.value;
if (draw_codepoint == '\t'){ if (draw_codepoint == '\t'){
draw_codepoint = ' '; draw_codepoint = ' ';
} }
draw_font_glyph(target, face, draw_codepoint, point, color, flags); draw_font_glyph(target, face, draw_codepoint, point, color, flags);
} }
f32 d = font_get_glyph_advance(&face->advance_map, &face->metrics, codepoint); local_const f32 internal_tab_width = 4.f;
f32 d = font_get_glyph_advance(&face->advance_map, &face->metrics, codepoint, internal_tab_width);
point += d*delta; point += d*delta;
total_delta += d; total_delta += d;
} }

View File

@ -387,16 +387,15 @@ auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Inde
return(result); return(result);
} }
global_const i32 auto_indent_tab_width = 4;
function void function void
auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Indent_Flag flags){ auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Indent_Flag flags){
i32 indent_width = global_config.indent_width; i32 indent_width = global_config.indent_width;
i32 tab_width = global_config.default_tab_width;
AddFlag(flags, Indent_FullTokens); AddFlag(flags, Indent_FullTokens);
if (global_config.indent_with_tabs){ if (global_config.indent_with_tabs){
AddFlag(flags, Indent_UseTab); AddFlag(flags, Indent_UseTab);
} }
auto_indent_buffer(app, buffer, pos, flags, indent_width, auto_indent_tab_width); auto_indent_buffer(app, buffer, pos, flags, indent_width, tab_width);
} }
function void function void

View File

@ -25,10 +25,10 @@ codepoint_index_map_count(Codepoint_Index_Map *map){
} }
function f32 function f32
font_get_glyph_advance(Face_Advance_Map *map, Face_Metrics *metrics, u32 codepoint){ font_get_glyph_advance(Face_Advance_Map *map, Face_Metrics *metrics, u32 codepoint, f32 tab_multiplier){
f32 result = 0.f; f32 result = 0.f;
if (codepoint == '\t'){ if (codepoint == '\t'){
result = metrics->space_advance*4.f; result = metrics->space_advance*tab_multiplier;
} }
else{ else{
if (character_is_whitespace(codepoint)){ if (character_is_whitespace(codepoint)){
@ -46,10 +46,11 @@ font_get_glyph_advance(Face_Advance_Map *map, Face_Metrics *metrics, u32 codepoi
function f32 function f32
font_get_max_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics, font_get_max_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics,
u32 codepoint_first, u32 codepoint_last){ u32 codepoint_first, u32 codepoint_last,
f32 result = font_get_glyph_advance(map, metrics, codepoint_first); f32 tab_multiplier){
f32 result = font_get_glyph_advance(map, metrics, codepoint_first, tab_multiplier);
for (u32 i = codepoint_first + 1; i <= codepoint_last; i += 1){ for (u32 i = codepoint_first + 1; i <= codepoint_last; i += 1){
f32 a = font_get_glyph_advance(map, metrics, i); f32 a = font_get_glyph_advance(map, metrics, i, tab_multiplier);
result = Max(a, result); result = Max(a, result);
} }
return(result); return(result);
@ -57,10 +58,11 @@ font_get_max_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics,
function f32 function f32
font_get_average_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics, font_get_average_glyph_advance_range(Face_Advance_Map *map, Face_Metrics *metrics,
u32 codepoint_first, u32 codepoint_last){ u32 codepoint_first, u32 codepoint_last,
f32 tab_multiplier){
f32 result = 0.f; f32 result = 0.f;
for (u32 i = codepoint_first; i <= codepoint_last; i += 1){ for (u32 i = codepoint_first; i <= codepoint_last; i += 1){
result += font_get_glyph_advance(map, metrics, i); result += font_get_glyph_advance(map, metrics, i, tab_multiplier);
} }
result /= (f32)(codepoint_last - codepoint_first + 1); result /= (f32)(codepoint_last - codepoint_first + 1);
return(result); return(result);

View File

@ -1247,6 +1247,7 @@ config_init_default(Config_Data *config){
config->indent_with_tabs = false; config->indent_with_tabs = false;
config->indent_width = 4; config->indent_width = 4;
config->default_tab_width = 4;
config->default_theme_name = SCu8(config->default_theme_name_space, sizeof("4coder") - 1); config->default_theme_name = SCu8(config->default_theme_name_space, sizeof("4coder") - 1);
block_copy(config->default_theme_name.str, "4coder", config->default_theme_name.size); block_copy(config->default_theme_name.str, "4coder", config->default_theme_name.size);
@ -1315,6 +1316,7 @@ config_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_na
config_bool_var(parsed, "indent_with_tabs", 0, &config->indent_with_tabs); config_bool_var(parsed, "indent_with_tabs", 0, &config->indent_with_tabs);
config_int_var(parsed, "indent_width", 0, &config->indent_width); config_int_var(parsed, "indent_width", 0, &config->indent_width);
config_int_var(parsed, "default_tab_width", 0, &config->default_tab_width);
config_fixed_string_var(parsed, "default_theme_name", 0, config_fixed_string_var(parsed, "default_theme_name", 0,
&config->default_theme_name, config->default_theme_name_space); &config->default_theme_name, config->default_theme_name_space);
@ -1565,6 +1567,7 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *con
config_feedback_bool(scratch, &list, "indent_with_tabs", config->indent_with_tabs); config_feedback_bool(scratch, &list, "indent_with_tabs", config->indent_with_tabs);
config_feedback_int(scratch, &list, "indent_width", config->indent_width); config_feedback_int(scratch, &list, "indent_width", config->indent_width);
config_feedback_int(scratch, &list, "default_tab_width", config->default_tab_width);
config_feedback_string(scratch, &list, "default_theme_name", config->default_theme_name); config_feedback_string(scratch, &list, "default_theme_name", config->default_theme_name);
config_feedback_bool(scratch, &list, "highlight_line_at_cursor", config->highlight_line_at_cursor); config_feedback_bool(scratch, &list, "highlight_line_at_cursor", config->highlight_line_at_cursor);

View File

@ -202,6 +202,7 @@ struct Config_Data{
b8 lister_whole_word_backspace_when_modified; b8 lister_whole_word_backspace_when_modified;
b8 show_line_number_margins; b8 show_line_number_margins;
b8 enable_output_wrapping; b8 enable_output_wrapping;
b8 indent_with_tabs;
b8 enable_virtual_whitespace; b8 enable_virtual_whitespace;
b8 enable_code_wrapping; b8 enable_code_wrapping;
@ -211,8 +212,8 @@ struct Config_Data{
i32 virtual_whitespace_regular_indent; i32 virtual_whitespace_regular_indent;
b8 indent_with_tabs;
i32 indent_width; i32 indent_width;
i32 default_tab_width;
u8 default_theme_name_space[256]; u8 default_theme_name_space[256];
String_Const_u8 default_theme_name; String_Const_u8 default_theme_name;

View File

@ -2475,5 +2475,24 @@ exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buff
// TODO(allen): --- end --- // TODO(allen): --- end ---
////////////////////////////////
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));
}
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));
}
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));
}
// BOTTOM // BOTTOM

View File

@ -267,9 +267,9 @@ i32 line_number;
}; };
static Command_Metadata fcoder_metacmd_table[244] = { static Command_Metadata fcoder_metacmd_table[244] = {
{ 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, 409 }, { 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, 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, 418 }, { 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, 417 },
{ 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_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, 427 },
{ 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_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, 408 },
{ 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_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(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, 663 }, { 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, 663 },
@ -363,7 +363,7 @@ static Command_Metadata fcoder_metacmd_table[244] = {
{ 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, 171 }, { 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, 171 },
{ 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, 183 }, { 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, 183 },
{ 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, 864 }, { 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, 864 },
{ 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, 1630 }, { 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, 1633 },
{ 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, 457 }, { 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, 457 },
{ 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, 469 }, { 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, 469 },
{ 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, 1451 }, { 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, 1451 },
@ -505,7 +505,7 @@ static Command_Metadata fcoder_metacmd_table[244] = {
{ 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_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_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_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, 437 },
{ 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_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_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 }, { PROC_LINKS(write_underscore, 0), false, "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 73 },

View File

@ -1,10 +1,11 @@
4.1.5 4.1.5
+ MAJOR: Scratch_Blocks now take arena pointer parameters in their constructor to specify arenas that should be treated as having distinct lifetimes, without doing this it is possible that a local scratch and another arena will actually refer to the same allocator and freeing the local scratch will also free memory that was meant to be in a separate arena. + MAJOR: Scratch_Blocks now take arena pointer parameters in their constructor to specify arenas that should be treated as having distinct lifetimes, without doing this it is possible that a local scratch and another arena will actually refer to the same allocator and freeing the local scratch will also free memory that was meant to be in a separate arena.
+ New Date_Time system APIs, and Date_Time string formatting + Date_Time system APIs, and Date_Time string formatting
+ clean_all_lines remves trailing whitespace and removes blank lines + 'clean_all_lines' removes trailing whitespace and removes blank lines
+ New command, clean_trailing_whitespace leaves blank lines + 'clean_trailing_whitespace' leaves blank lines
+ In config.4coder "enable_output_wrapping" determine whether to wrap buffers like *compilation*, *search*, etc. + In config.4coder "enable_output_wrapping" determine whether to wrap buffers like *compilation*, *search*, etc.
+ In config.4coder "default_tab_width" determines the width of a tab character in number of spaces
+ Fix: when generated/metadata* files are missing buildsuper still succeeds + Fix: when generated/metadata* files are missing buildsuper still succeeds
+ Fix: mac does not hang opening multiple files + Fix: mac does not hang opening multiple files
+ Fix: line number margin performance + Fix: line number margin performance

View File

@ -41,6 +41,7 @@ automatically_load_project = false;
// Indentation // Indentation
indent_with_tabs = false; indent_with_tabs = false;
indent_width = 4; indent_width = 4;
default_tab_width = 4;
// Theme // Theme
default_theme_name = "4coder"; default_theme_name = "4coder";