Only compute line indentation info at necessary points in the auto-indent routine

master
Allen Webster 2020-01-11 15:45:28 -08:00
parent 2e21156e66
commit f1dd78f32a
6 changed files with 5030 additions and 5008 deletions

View File

@ -730,7 +730,7 @@ App_Step_Sig(app_step){
// NOTE(allen): if the exit signal has been sent, run the exit hook.
if (!models->keep_playing || input->trying_to_kill){
co_send_core_event(tctx, models, CoreCode_TryExit);
models->keep_playing = true;
models->keep_playing = true;
}
// NOTE(allen): rendering

View File

@ -15,7 +15,7 @@ make_batch_from_indentations(Application_Links *app, Arena *arena, Buffer_ID buf
line_number <= lines.max;
++line_number){
i64 line_start_pos = get_line_start_pos(app, buffer, line_number);
Indent_Info indent_info = get_indent_info_line_start(app, buffer, line_start_pos, tab_width);
Indent_Info indent_info = get_indent_info_line_number_and_start(app, buffer, line_number, line_start_pos, tab_width);
i64 correct_indentation = shifted_indentations[line_number];
if (indent_info.is_blank && HasFlag(flags, Indent_ClearLine)){
@ -63,6 +63,7 @@ set_line_indents(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i
internal Token*
find_anchor_token(Application_Links *app, Buffer_ID buffer, Token_Array *tokens, i64 invalid_line){
ProfileScope(app, "find anchor token");
Token *result = 0;
if (tokens != 0 && tokens->tokens != 0){
@ -148,6 +149,7 @@ indent__unfinished_statement(Token *token, Nest *current_nest){
internal i64*
get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 lines, Indent_Flag flags, i32 tab_width, i32 indent_width){
ProfileScope(app, "get indentation array");
i64 count = lines.max - lines.min + 1;
i64 *indentations = push_array(arena, i64, count);
i64 *shifted_indentations = indentations - lines.first;
@ -174,11 +176,31 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra
i64 actual_indent = 0;
b32 in_unfinished_statement = false;
i64 line_where_token_starts = 0;
i64 line_start_pos = 0;
i64 line_one_past_last_pos = 0;
Indent_Info line_indent_info = {};
for (;;){
Token *token = token_it_read(&token_it);
i64 line_where_token_starts = get_line_number_from_pos(app, buffer, token->pos);
i64 line_start_pos = get_line_start_pos(app, buffer, line_where_token_starts);
Indent_Info line_indent_info = get_indent_info_line_start(app, buffer, line_start_pos, tab_width);
if (line_where_token_starts == 0 ||
token->pos >= line_one_past_last_pos){
{
line_where_token_starts = get_line_number_from_pos(app, buffer, token->pos);
}
{
line_start_pos = get_line_start_pos(app, buffer, line_where_token_starts);
}
{
line_one_past_last_pos = get_line_end_pos(app, buffer, line_where_token_starts);
}
{
Range_i64 range = Ii64(line_start_pos, line_one_past_last_pos);
line_indent_info = get_indent_info_range(app, buffer, range, tab_width);
}
}
i64 current_indent = 0;
if (nest != 0){
@ -255,9 +277,9 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra
}
#define EMIT(N) \
Stmnt(if (lines.first <= line_it){shifted_indentations[line_it]=N;} \
if (line_it == lines.end){goto finished;} \
actual_indent = N; )
Stmnt(if (lines.first <= line_it){shifted_indentations[line_it]=N;} \
if (line_it == lines.end){goto finished;} \
actual_indent = N; )
i64 line_it = line_last_indented;
for (;line_it < line_where_token_starts;){
@ -275,7 +297,7 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra
for (;line_it < line_where_token_ends;){
line_it += 1;
i64 line_it_start_pos = get_line_start_pos(app, buffer, line_it);
Indent_Info line_it_indent_info = get_indent_info_line_start(app, buffer, line_it_start_pos, tab_width);
Indent_Info line_it_indent_info = get_indent_info_line_number_and_start(app, buffer, line_it, line_it_start_pos, tab_width);
i64 new_indent = line_it_indent_info.indent_pos + line_where_token_starts_shift;
new_indent = clamp_bot(0, new_indent);
EMIT(new_indent);
@ -395,6 +417,7 @@ CUSTOM_DOC("Auto-indents the range between the cursor and the mark.")
CUSTOM_COMMAND_SIG(write_text_and_auto_indent)
CUSTOM_DOC("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.")
{
ProfileScope(app, "write and auto indent");
User_Input in = get_current_input(app);
String_Const_u8 insert = to_writable(&in);
if (insert.str != 0 && insert.size > 0){

View File

@ -68,15 +68,15 @@ character_predicate_from_function(Character_Predicate_Function *func){
v[bit_index] = func((u8)i);
}
predicate.b[byte_index] = (
(v[0] << 0) |
(v[1] << 1) |
(v[2] << 2) |
(v[3] << 3) |
(v[4] << 4) |
(v[5] << 5) |
(v[6] << 6) |
(v[7] << 7)
);
(v[0] << 0) |
(v[1] << 1) |
(v[2] << 2) |
(v[3] << 3) |
(v[4] << 4) |
(v[5] << 5) |
(v[6] << 6) |
(v[7] << 7)
);
byte_index += 1;
}
return(predicate);
@ -797,7 +797,7 @@ enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range,
internal Range_i64
left_enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range,
Boundary_Function *func){
Boundary_Function *func){
i64 new_min = func(app, buffer, Side_Min, Scan_Backward, range.min + 1);
i64 new_min_check = func(app, buffer, Side_Max, Scan_Backward, range.min + 1);
if (new_min_check <= new_min && new_min < range.min){
@ -1227,8 +1227,8 @@ get_indent_info_range(Application_Links *app, Buffer_ID buffer, Range_i64 range,
}
internal Indent_Info
get_indent_info_line_start(Application_Links *app, Buffer_ID buffer, i64 line_start, i32 tab_width){
i64 end = get_line_side_pos_from_pos(app, buffer, line_start, Side_Max);
get_indent_info_line_number_and_start(Application_Links *app, Buffer_ID buffer, i64 line_number, i64 line_start, i32 tab_width){
i64 end = get_line_side_pos(app, buffer, line_number, Side_Max);
return(get_indent_info_range(app, buffer, Ii64(line_start, end), tab_width));
}

View File

@ -252,9 +252,9 @@ i32 line_number;
};
static Command_Metadata fcoder_metacmd_table[229] = {
{ 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, 375 },
{ 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, 385 },
{ 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, 366 },
{ 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, 397 },
{ 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, 407 },
{ 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, 388 },
{ 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, 611 },
@ -475,7 +475,7 @@ static Command_Metadata fcoder_metacmd_table[229] = {
{ 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, 395 },
{ 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, 417 },
{ 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 },

File diff suppressed because it is too large Load Diff

View File

@ -1130,7 +1130,6 @@ build_language_model(void){
sm_case_eof_peek(emit);
}
sm_fallback(comment_line);
}
// BOTTOM