rad new indent rule
parent
06db721767
commit
f64afa1404
19
4ed.cpp
19
4ed.cpp
|
@ -224,7 +224,7 @@ panel_make_empty(System_Functions *system, Exchange *exchange, App_Vars *vars, P
|
||||||
|
|
||||||
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(new_view.view, 0, models, 0);
|
view_set_file(new_view.view, 0, models);
|
||||||
new_view.view->map = app_get_map(models, mapid_global);
|
new_view.view->map = app_get_map(models, mapid_global);
|
||||||
|
|
||||||
return(new_view.view);
|
return(new_view.view);
|
||||||
|
@ -861,7 +861,6 @@ COMMAND_DECL(interactive_open){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
|
view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
|
||||||
System_Functions *system = cmd->system;
|
|
||||||
Models *models = cmd->models;
|
Models *models = cmd->models;
|
||||||
|
|
||||||
Partition old_part;
|
Partition old_part;
|
||||||
|
@ -878,7 +877,7 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
|
||||||
cmd->part = partition_sub_part(part, Kbytes(16));
|
cmd->part = partition_sub_part(part, Kbytes(16));
|
||||||
|
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
view_set_file(view, file, models, system);
|
view_set_file(view, file, models);
|
||||||
view_show_file(view, 0);
|
view_show_file(view, 0);
|
||||||
|
|
||||||
cmd->part = old_part;
|
cmd->part = old_part;
|
||||||
|
@ -909,7 +908,7 @@ COMMAND_DECL(reopen){
|
||||||
index = file->id.id;
|
index = file->id.id;
|
||||||
app_push_file_binding(vars, file_id, index);
|
app_push_file_binding(vars, file_id, index);
|
||||||
|
|
||||||
view_set_file(view, file, models, system);
|
view_set_file(view, file, models);
|
||||||
view_show_file(view, 0);
|
view_show_file(view, 0);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -2419,7 +2418,7 @@ extern "C"{
|
||||||
if (file){
|
if (file){
|
||||||
result = 1;
|
result = 1;
|
||||||
if (file != vptr->file_data.file){
|
if (file != vptr->file_data.file){
|
||||||
view_set_file(vptr, file, models, cmd->system);
|
view_set_file(vptr, file, models);
|
||||||
view_show_file(vptr, 0);
|
view_show_file(vptr, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3556,7 +3555,7 @@ App_Step_Sig(app_step){
|
||||||
Assert(view);
|
Assert(view);
|
||||||
// TODO(allen): All responses to a panel changing size should
|
// TODO(allen): All responses to a panel changing size should
|
||||||
// be handled in the same place.
|
// be handled in the same place.
|
||||||
view_change_size(system, &models->mem.general, view);
|
view_change_size(&models->mem.general, view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4199,7 +4198,7 @@ App_Step_Sig(app_step){
|
||||||
for (View_Iter iter = file_view_iter_init(&models->layout, ed_file, 0);
|
for (View_Iter iter = file_view_iter_init(&models->layout, ed_file, 0);
|
||||||
file_view_iter_good(iter);
|
file_view_iter_good(iter);
|
||||||
iter = file_view_iter_next(iter)){
|
iter = file_view_iter_next(iter)){
|
||||||
view_measure_wraps(system, general, iter.view);
|
view_measure_wraps(general, iter.view);
|
||||||
view_cursor_move(iter.view, preload_settings.start_line, 0);
|
view_cursor_move(iter.view, preload_settings.start_line, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4388,7 +4387,7 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
|
|
||||||
view_set_file(view, file, models, system);
|
view_set_file(view, file, models);
|
||||||
view_show_file(view, 0);
|
view_show_file(view, 0);
|
||||||
view->map = app_get_map(models, file->settings.base_map_id);
|
view->map = app_get_map(models, file->settings.base_map_id);
|
||||||
|
|
||||||
|
@ -4418,7 +4417,7 @@ App_Step_Sig(app_step){
|
||||||
if (file){
|
if (file){
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
|
|
||||||
view_set_file(view, file, models, system);
|
view_set_file(view, file, models);
|
||||||
view_show_file(view, 0);
|
view_show_file(view, 0);
|
||||||
view->map = app_get_map(models, file->settings.base_map_id);
|
view->map = app_get_map(models, file->settings.base_map_id);
|
||||||
}
|
}
|
||||||
|
@ -4601,6 +4600,8 @@ App_Step_Sig(app_step){
|
||||||
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
|
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
|
||||||
*result = app_result;
|
*result = app_result;
|
||||||
|
|
||||||
|
Assert(general_memory_check(&models->mem.general));
|
||||||
|
|
||||||
// end-of-app_step
|
// end-of-app_step
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
4ed_data.ctm
BIN
4ed_data.ctm
Binary file not shown.
|
@ -407,7 +407,7 @@ file_measure_starts_widths(System_Functions *system, General_Memory *general,
|
||||||
}
|
}
|
||||||
if (!buffer->line_widths){
|
if (!buffer->line_widths){
|
||||||
i32 max = buffer->widths_max = Kbytes(1);
|
i32 max = buffer->widths_max = Kbytes(1);
|
||||||
buffer->line_widths = (f32*)general_memory_allocate(general, max*sizeof(f32), BUBBLE_STARTS);
|
buffer->line_widths = (f32*)general_memory_allocate(general, max*sizeof(f32), BUBBLE_WIDTHS);
|
||||||
TentativeAssert(buffer->line_starts);
|
TentativeAssert(buffer->line_starts);
|
||||||
// TODO(allen): when unable to allocate?
|
// TODO(allen): when unable to allocate?
|
||||||
}
|
}
|
||||||
|
@ -488,8 +488,7 @@ view_compute_lowest_line(View *view){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_measure_wraps(System_Functions *system,
|
view_measure_wraps(General_Memory *general, View *view){
|
||||||
General_Memory *general, View *view){
|
|
||||||
Buffer_Type *buffer;
|
Buffer_Type *buffer;
|
||||||
|
|
||||||
buffer = &view->file_data.file->state.buffer;
|
buffer = &view->file_data.file->state.buffer;
|
||||||
|
@ -1276,12 +1275,7 @@ view_get_cursor_y(View *view){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_set_file(
|
view_set_file(View *view, Editing_File *file, Models *models){
|
||||||
// NOTE(allen): These parameters are always meaningful
|
|
||||||
View *view, Editing_File *file, Models *models,
|
|
||||||
|
|
||||||
// NOTE(allen): Necessary when file != 0
|
|
||||||
System_Functions *system){
|
|
||||||
|
|
||||||
Font_Info *fnt_info;
|
Font_Info *fnt_info;
|
||||||
|
|
||||||
|
@ -1300,7 +1294,7 @@ view_set_file(
|
||||||
view->file_data.unwrapped_lines = file->settings.unwrapped_lines;
|
view->file_data.unwrapped_lines = file->settings.unwrapped_lines;
|
||||||
|
|
||||||
if (file_is_ready(file)){
|
if (file_is_ready(file)){
|
||||||
view_measure_wraps(system, &models->mem.general, view);
|
view_measure_wraps(&models->mem.general, view);
|
||||||
view->file_data.cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos);
|
view->file_data.cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos);
|
||||||
view->reinit_scrolling = 1;
|
view->reinit_scrolling = 1;
|
||||||
}
|
}
|
||||||
|
@ -1605,7 +1599,7 @@ file_edit_cursor_fix(System_Functions *system,
|
||||||
for (dll_items(panel, used_panels)){
|
for (dll_items(panel, used_panels)){
|
||||||
view = panel->view;
|
view = panel->view;
|
||||||
if (view->file_data.file == file){
|
if (view->file_data.file == file){
|
||||||
view_measure_wraps(system, general, view);
|
view_measure_wraps(general, view);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->file_data.cursor.pos);
|
write_cursor_with_index(cursors, &cursor_count, view->file_data.cursor.pos);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->file_data.mark - 1);
|
write_cursor_with_index(cursors, &cursor_count, view->file_data.mark - 1);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->file_data.scroll_i - 1);
|
write_cursor_with_index(cursors, &cursor_count, view->file_data.scroll_i - 1);
|
||||||
|
@ -1715,7 +1709,7 @@ file_do_single_edit(System_Functions *system,
|
||||||
for (dll_items(panel, used_panels)){
|
for (dll_items(panel, used_panels)){
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
if (view->file_data.file == file){
|
if (view->file_data.file == file){
|
||||||
view_measure_wraps(system, general, view);
|
view_measure_wraps(general, view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2192,24 +2186,20 @@ view_clean_whitespace(System_Functions *system, Models *models, View *view){
|
||||||
i32 str_size = 0;
|
i32 str_size = 0;
|
||||||
for (i32 line_i = 0; line_i < line_count; ++line_i){
|
for (i32 line_i = 0; line_i < line_count; ++line_i){
|
||||||
i32 start = file->state.buffer.line_starts[line_i];
|
i32 start = file->state.buffer.line_starts[line_i];
|
||||||
i32 preferred_indentation;
|
Hard_Start_Result hard_start =
|
||||||
b32 all_whitespace = 0;
|
buffer_find_hard_start(&file->state.buffer, start, 4);
|
||||||
b32 all_space = 0;
|
|
||||||
i32 hard_start =
|
|
||||||
buffer_find_hard_start(&file->state.buffer, start, &all_whitespace, &all_space,
|
|
||||||
&preferred_indentation, 4);
|
|
||||||
|
|
||||||
if (all_whitespace) preferred_indentation = 0;
|
if (hard_start.all_whitespace) hard_start.indent_pos = 0;
|
||||||
|
|
||||||
if ((all_whitespace && hard_start > start) || !all_space){
|
if ((hard_start.all_whitespace && hard_start.char_pos > start) || !hard_start.all_space){
|
||||||
Buffer_Edit new_edit;
|
Buffer_Edit new_edit;
|
||||||
new_edit.str_start = str_size;
|
new_edit.str_start = str_size;
|
||||||
str_size += preferred_indentation;
|
str_size += hard_start.indent_pos;
|
||||||
char *str = push_array(part, char, preferred_indentation);
|
char *str = push_array(part, char, hard_start.indent_pos);
|
||||||
for (i32 j = 0; j < preferred_indentation; ++j) str[j] = ' ';
|
for (i32 j = 0; j < hard_start.indent_pos; ++j) str[j] = ' ';
|
||||||
new_edit.len = preferred_indentation;
|
new_edit.len = hard_start.indent_pos;
|
||||||
new_edit.start = start;
|
new_edit.start = start;
|
||||||
new_edit.end = hard_start;
|
new_edit.end = hard_start.char_pos;
|
||||||
edits[edit_count++] = new_edit;
|
edits[edit_count++] = new_edit;
|
||||||
}
|
}
|
||||||
Assert(edit_count <= edit_max);
|
Assert(edit_count <= edit_max);
|
||||||
|
@ -2248,58 +2238,191 @@ struct Make_Batch_Result{
|
||||||
i32 edit_count;
|
i32 edit_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
internal Cpp_Token*
|
||||||
|
get_first_token_at_line(Buffer *buffer, Cpp_Token_Stack tokens, i32 line){
|
||||||
|
Cpp_Token *result = 0;
|
||||||
|
i32 start_pos = 0;
|
||||||
|
Cpp_Get_Token_Result get_token = {0};
|
||||||
|
|
||||||
|
start_pos = buffer->line_starts[line];
|
||||||
|
get_token = cpp_get_token(&tokens, start_pos);
|
||||||
|
if (get_token.in_whitespace) get_token.token_index += 1;
|
||||||
|
result = tokens.tokens + get_token.token_index;
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Cpp_Token*
|
||||||
|
seek_matching_token_backwards(Cpp_Token_Stack tokens, Cpp_Token *token,
|
||||||
|
Cpp_Token_Type open_type, Cpp_Token_Type close_type){
|
||||||
|
int nesting_level = 0;
|
||||||
|
for (; token > tokens.tokens; --token){
|
||||||
|
if (!(token->flags & CPP_TFLAG_PP_BODY)){
|
||||||
|
if (token->type == close_type){
|
||||||
|
++nesting_level;
|
||||||
|
}
|
||||||
|
else if (token->type == open_type){
|
||||||
|
if (nesting_level == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
--nesting_level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Indent_Parse_State{
|
||||||
|
i32 current_indent;
|
||||||
|
i32 previous_line_indent;
|
||||||
|
i32 paren_nesting;
|
||||||
|
i32 paren_anchor_indent[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
|
||||||
|
Cpp_Token T, Cpp_Token prev_token, i32 line_i, i32 tab_width){
|
||||||
|
|
||||||
|
i32 previous_indent = indent.previous_line_indent;
|
||||||
|
i32 this_indent = 0;
|
||||||
|
|
||||||
|
i32 this_line_start = buffer->line_starts[line_i];
|
||||||
|
i32 next_line_start = 0;
|
||||||
|
|
||||||
|
if (line_i+1 < buffer->line_count){
|
||||||
|
next_line_start = buffer->line_starts[line_i+1];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
next_line_start = buffer_size(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev_token.type == CPP_TOKEN_COMMENT &&
|
||||||
|
prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){
|
||||||
|
this_indent = previous_indent;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this_indent = indent.current_indent;
|
||||||
|
if (T.start < next_line_start){
|
||||||
|
if (T.flags & CPP_TFLAG_PP_DIRECTIVE){
|
||||||
|
this_indent = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
switch (T.type){
|
||||||
|
case CPP_TOKEN_BRACKET_CLOSE: this_indent -= tab_width; break;
|
||||||
|
case CPP_TOKEN_BRACE_CLOSE: this_indent -= tab_width; break;
|
||||||
|
case CPP_TOKEN_BRACE_OPEN: break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (indent.current_indent > 0){
|
||||||
|
if (!(prev_token.flags & CPP_TFLAG_PP_BODY ||
|
||||||
|
prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){
|
||||||
|
switch (prev_token.type){
|
||||||
|
case CPP_TOKEN_BRACKET_OPEN:
|
||||||
|
case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE:
|
||||||
|
case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON:
|
||||||
|
case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break;
|
||||||
|
default: this_indent += tab_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this_indent < 0) this_indent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indent.paren_nesting > 0){
|
||||||
|
i32 level = indent.paren_nesting-1;
|
||||||
|
if (level >= ArrayCount(indent.paren_anchor_indent)){
|
||||||
|
level = ArrayCount(indent.paren_anchor_indent)-1;
|
||||||
|
}
|
||||||
|
this_indent = indent.paren_anchor_indent[level];
|
||||||
|
}
|
||||||
|
return(this_indent);
|
||||||
|
}
|
||||||
|
|
||||||
internal i32*
|
internal i32*
|
||||||
get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack tokens,
|
get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack tokens,
|
||||||
i32 line_start, i32 line_end){
|
i32 line_start, i32 line_end, i32 tab_width){
|
||||||
|
|
||||||
i32 indent_mark_count = line_end - line_start;
|
i32 indent_mark_count = line_end - line_start;
|
||||||
i32 *indent_marks = push_array(part, i32, indent_mark_count);
|
i32 *indent_marks = push_array(part, i32, indent_mark_count);
|
||||||
|
|
||||||
i32 current_indent = 0;
|
Indent_Parse_State indent = {0};
|
||||||
i32 token_i;
|
Cpp_Token *token = get_first_token_at_line(buffer, tokens, line_start);
|
||||||
Cpp_Token *token, *self_token;
|
|
||||||
|
|
||||||
{
|
if (token != tokens.tokens){
|
||||||
i32 start_pos = buffer->line_starts[line_start];
|
--token;
|
||||||
Cpp_Get_Token_Result result = cpp_get_token(&tokens, start_pos);
|
for (; token > tokens.tokens; --token){
|
||||||
token_i = result.token_index;
|
if (!(token->flags & CPP_TFLAG_PP_BODY)){
|
||||||
if (result.in_whitespace) token_i += 1;
|
switch(token->type){
|
||||||
self_token = tokens.tokens + token_i;
|
case CPP_TOKEN_BRACE_OPEN:
|
||||||
|
case CPP_TOKEN_BRACE_CLOSE:
|
||||||
|
case CPP_TOKEN_PARENTHESE_OPEN:
|
||||||
|
goto out_of_loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out_of_loop:;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (token = self_token; token_i > 0; --token_i, --token){
|
// TODO(allen): This can maybe be it's own function now, so that we
|
||||||
switch(token->type){
|
// can do the decls in the order we want and avoid the extra binary search.
|
||||||
case CPP_TOKEN_BRACKET_OPEN:
|
i32 found_safe_start_position = 0;
|
||||||
|
do{
|
||||||
|
i32 line = buffer_get_line_index(buffer, token->start);
|
||||||
|
i32 start = buffer->line_starts[line];
|
||||||
|
Hard_Start_Result hard_start = buffer_find_hard_start(buffer, start, tab_width);
|
||||||
|
|
||||||
|
indent.current_indent = hard_start.indent_pos;
|
||||||
|
|
||||||
|
Cpp_Token *start_token = get_first_token_at_line(buffer, tokens, line);
|
||||||
|
Cpp_Token *brace_token = token;
|
||||||
|
|
||||||
|
int close = 0;
|
||||||
|
|
||||||
|
for (token = start_token; token < brace_token; ++token){
|
||||||
|
switch(token->type){
|
||||||
|
case CPP_TOKEN_PARENTHESE_CLOSE:
|
||||||
|
case CPP_TOKEN_BRACKET_CLOSE:
|
||||||
|
case CPP_TOKEN_BRACE_CLOSE:
|
||||||
|
close = token->type;
|
||||||
|
goto out_of_loop2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out_of_loop2:;
|
||||||
|
|
||||||
|
switch (close){
|
||||||
|
case 0: token = start_token; found_safe_start_position = 1; break;
|
||||||
|
|
||||||
|
case CPP_TOKEN_PARENTHESE_CLOSE:
|
||||||
|
token = seek_matching_token_backwards(tokens, token-1,
|
||||||
|
CPP_TOKEN_PARENTHESE_OPEN, CPP_TOKEN_PARENTHESE_CLOSE);
|
||||||
|
break;
|
||||||
|
|
||||||
case CPP_TOKEN_BRACKET_CLOSE:
|
case CPP_TOKEN_BRACKET_CLOSE:
|
||||||
token_i = 0;
|
token = seek_matching_token_backwards(tokens, token-1,
|
||||||
|
CPP_TOKEN_BRACKET_OPEN, CPP_TOKEN_BRACKET_CLOSE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPP_TOKEN_BRACE_CLOSE:
|
||||||
|
token = seek_matching_token_backwards(tokens, token-1,
|
||||||
|
CPP_TOKEN_BRACE_OPEN, CPP_TOKEN_BRACE_CLOSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while(found_safe_start_position == 0);
|
||||||
|
|
||||||
i32 line = 0;
|
// NOTE(allen): Shift the array so that line_i can just operate in
|
||||||
{
|
// it's natural value range.
|
||||||
i32 start = 0;
|
|
||||||
b32 all_whitespace = 0, all_space = 0;
|
|
||||||
|
|
||||||
line = buffer_get_line_index(buffer, token->start);
|
|
||||||
start = buffer->line_starts[line];
|
|
||||||
buffer_find_hard_start(buffer, start, &all_whitespace, &all_space, ¤t_indent, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
i32 start_pos = buffer->line_starts[line];
|
|
||||||
Cpp_Get_Token_Result result = cpp_get_token(&tokens, start_pos);
|
|
||||||
token_i = result.token_index;
|
|
||||||
if (result.in_whitespace) token_i += 1;
|
|
||||||
token = tokens.tokens + token_i;
|
|
||||||
|
|
||||||
// NOTE(allen): Shift the array so that line_i can just take on it's natural value.
|
|
||||||
indent_marks -= line_start;
|
indent_marks -= line_start;
|
||||||
i32 line_i = line_start;
|
|
||||||
|
i32 line_i = buffer_get_line_index(buffer, token->start);
|
||||||
i32 next_line_start = buffer->line_starts[line_i];
|
i32 next_line_start = buffer->line_starts[line_i];
|
||||||
switch (token->type){
|
switch (token->type){
|
||||||
case CPP_TOKEN_BRACKET_OPEN: current_indent += 4; break;
|
case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break;
|
||||||
case CPP_TOKEN_PARENTHESE_OPEN: current_indent += 4; break;
|
case CPP_TOKEN_BRACE_OPEN: indent.current_indent += tab_width; break;
|
||||||
case CPP_TOKEN_BRACE_OPEN: current_indent += 4; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cpp_Token T;
|
Cpp_Token T;
|
||||||
|
@ -2317,7 +2440,6 @@ get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack toke
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; T.start >= next_line_start && line_i < line_end;){
|
for (; T.start >= next_line_start && line_i < line_end;){
|
||||||
i32 this_line_start = next_line_start;
|
|
||||||
if (line_i+1 < buffer->line_count){
|
if (line_i+1 < buffer->line_count){
|
||||||
next_line_start = buffer->line_starts[line_i+1];
|
next_line_start = buffer->line_starts[line_i+1];
|
||||||
}
|
}
|
||||||
|
@ -2325,63 +2447,54 @@ get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack toke
|
||||||
next_line_start = buffer_size(buffer);
|
next_line_start = buffer_size(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 this_indent;
|
// TODO(allen): Since this is called in one place we can probably go back
|
||||||
if (prev_token.type == CPP_TOKEN_COMMENT &&
|
// to directly passing in next_line_start and this_line_start.
|
||||||
prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){
|
i32 this_indent = compute_this_indent(buffer, indent, T, prev_token, line_i, tab_width);
|
||||||
if (line_i > line_start){
|
|
||||||
this_indent = indent_marks[line_i-1];
|
if (line_i >= line_start){
|
||||||
}
|
indent_marks[line_i] = this_indent;
|
||||||
else{
|
|
||||||
this_indent = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
this_indent = current_indent;
|
|
||||||
if (T.start < next_line_start){
|
|
||||||
if (T.flags & CPP_TFLAG_PP_DIRECTIVE){
|
|
||||||
this_indent = 0;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
switch (T.type){
|
|
||||||
case CPP_TOKEN_BRACKET_CLOSE: this_indent -= 4; break;
|
|
||||||
case CPP_TOKEN_PARENTHESE_CLOSE: this_indent -= 4; break;
|
|
||||||
case CPP_TOKEN_BRACE_CLOSE: this_indent -= 4; break;
|
|
||||||
case CPP_TOKEN_BRACE_OPEN: break;
|
|
||||||
default:
|
|
||||||
if (current_indent > 0){
|
|
||||||
if (!(prev_token.flags & CPP_TFLAG_PP_BODY ||
|
|
||||||
prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){
|
|
||||||
switch (prev_token.type){
|
|
||||||
case CPP_TOKEN_BRACKET_OPEN: case CPP_TOKEN_PARENTHESE_OPEN:
|
|
||||||
case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE:
|
|
||||||
case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON: break;
|
|
||||||
case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break;
|
|
||||||
default: this_indent += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this_indent < 0) this_indent = 0;
|
|
||||||
}
|
|
||||||
indent_marks[line_i] = this_indent;
|
|
||||||
++line_i;
|
++line_i;
|
||||||
|
|
||||||
|
indent.previous_line_indent = this_indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (T.type){
|
switch (T.type){
|
||||||
case CPP_TOKEN_BRACKET_OPEN: current_indent += 4; break;
|
case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += 4; break;
|
||||||
case CPP_TOKEN_BRACKET_CLOSE: current_indent -= 4; break;
|
case CPP_TOKEN_BRACKET_CLOSE: indent.current_indent -= 4; break;
|
||||||
case CPP_TOKEN_PARENTHESE_OPEN: current_indent += 4; break;
|
case CPP_TOKEN_BRACE_OPEN: indent.current_indent += 4; break;
|
||||||
case CPP_TOKEN_PARENTHESE_CLOSE: current_indent -= 4; break;
|
case CPP_TOKEN_BRACE_CLOSE: indent.current_indent -= 4; break;
|
||||||
case CPP_TOKEN_BRACE_OPEN: current_indent += 4; break;
|
|
||||||
case CPP_TOKEN_BRACE_CLOSE: current_indent -= 4; break;
|
case CPP_TOKEN_PARENTHESE_OPEN:
|
||||||
|
if (!(T.flags & CPP_TFLAG_PP_BODY)){
|
||||||
|
if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){
|
||||||
|
i32 line = buffer_get_line_index(buffer, T.start);
|
||||||
|
i32 start = buffer->line_starts[line];
|
||||||
|
i32 char_pos = T.start - start;
|
||||||
|
|
||||||
|
Hard_Start_Result hard_start = buffer_find_hard_start(
|
||||||
|
buffer, start, tab_width);
|
||||||
|
|
||||||
|
i32 line_pos = hard_start.char_pos - start;
|
||||||
|
|
||||||
|
indent.paren_anchor_indent[indent.paren_nesting] =
|
||||||
|
char_pos - line_pos + indent.previous_line_indent + 1;
|
||||||
|
}
|
||||||
|
++indent.paren_nesting;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPP_TOKEN_PARENTHESE_CLOSE:
|
||||||
|
if (!(T.flags & CPP_TFLAG_PP_BODY)){
|
||||||
|
--indent.paren_nesting;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
prev_token = T;
|
prev_token = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): Unshift the indent_marks array so that the return value
|
// NOTE(allen): Unshift the indent_marks array so that the return value
|
||||||
// is the exact starting point of the array of indent marks.
|
// is the exact starting point of the array that was actually allocated.
|
||||||
indent_marks += line_start;
|
indent_marks += line_start;
|
||||||
|
|
||||||
return(indent_marks);
|
return(indent_marks);
|
||||||
|
@ -2401,24 +2514,21 @@ make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i3
|
||||||
char *str_base = (char*)part->base + part->pos;
|
char *str_base = (char*)part->base + part->pos;
|
||||||
i32 str_size = 0;
|
i32 str_size = 0;
|
||||||
|
|
||||||
// NOTE(allen): Shift the array so that line_i can just take on it's natural value.
|
// NOTE(allen): Shift the array so that line_i can just operate in
|
||||||
|
// it's natural value range.
|
||||||
indent_marks -= line_start;
|
indent_marks -= line_start;
|
||||||
|
|
||||||
for (i32 line_i = line_start; line_i < line_end; ++line_i){
|
for (i32 line_i = line_start; line_i < line_end; ++line_i){
|
||||||
i32 start = buffer->line_starts[line_i];
|
i32 start = buffer->line_starts[line_i];
|
||||||
i32 preferred_indentation = 0;
|
Hard_Start_Result hard_start =
|
||||||
i32 correct_indentation = 0;
|
buffer_find_hard_start(buffer, start, opts.tab_width);
|
||||||
b32 all_whitespace = 0;
|
|
||||||
b32 all_space = 0;
|
|
||||||
i32 hard_start =
|
|
||||||
buffer_find_hard_start(buffer, start, &all_whitespace, &all_space,
|
|
||||||
&preferred_indentation, opts.tab_width);
|
|
||||||
|
|
||||||
correct_indentation = indent_marks[line_i];
|
i32 correct_indentation = indent_marks[line_i];
|
||||||
if (all_whitespace && opts.empty_blank_lines) correct_indentation = 0;
|
if (hard_start.all_whitespace && opts.empty_blank_lines) correct_indentation = 0;
|
||||||
if (correct_indentation == -1) correct_indentation = preferred_indentation;
|
if (correct_indentation == -1) correct_indentation = hard_start.indent_pos;
|
||||||
|
|
||||||
if ((all_whitespace && hard_start > start) || !all_space || correct_indentation != preferred_indentation){
|
if ((hard_start.all_whitespace && hard_start.char_pos > start) ||
|
||||||
|
!hard_start.all_space || correct_indentation != hard_start.indent_pos){
|
||||||
Buffer_Edit new_edit;
|
Buffer_Edit new_edit;
|
||||||
new_edit.str_start = str_size;
|
new_edit.str_start = str_size;
|
||||||
str_size += correct_indentation;
|
str_size += correct_indentation;
|
||||||
|
@ -2434,7 +2544,7 @@ make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i3
|
||||||
}
|
}
|
||||||
new_edit.len = j;
|
new_edit.len = j;
|
||||||
new_edit.start = start;
|
new_edit.start = start;
|
||||||
new_edit.end = hard_start;
|
new_edit.end = hard_start.char_pos;
|
||||||
edits[edit_count++] = new_edit;
|
edits[edit_count++] = new_edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2470,7 +2580,7 @@ view_auto_tab_tokens(System_Functions *system, Models *models,
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
|
|
||||||
i32 *indent_marks =
|
i32 *indent_marks =
|
||||||
get_line_indentation_marks(part, buffer, tokens, line_start, line_end);
|
get_line_indentation_marks(part, buffer, tokens, line_start, line_end, opts.tab_width);
|
||||||
|
|
||||||
Make_Batch_Result batch =
|
Make_Batch_Result batch =
|
||||||
make_batch_from_indent_marks(part, buffer, line_start, line_end, indent_marks, opts);
|
make_batch_from_indent_marks(part, buffer, line_start, line_end, indent_marks, opts);
|
||||||
|
@ -2493,15 +2603,10 @@ view_auto_tab_tokens(System_Functions *system, Models *models,
|
||||||
end_temp_memory(temp);
|
end_temp_memory(temp);
|
||||||
|
|
||||||
{
|
{
|
||||||
b32 all_whitespace = 0;
|
|
||||||
b32 all_space = 0;
|
|
||||||
i32 preferred_indentation;
|
|
||||||
i32 start = view->file_data.cursor.pos;
|
i32 start = view->file_data.cursor.pos;
|
||||||
i32 hard_start = buffer_find_hard_start(
|
Hard_Start_Result hard_start = buffer_find_hard_start(buffer, start, 4);
|
||||||
buffer, start, &all_whitespace, &all_space,
|
|
||||||
&preferred_indentation, 4);
|
|
||||||
|
|
||||||
view_cursor_move(view, hard_start);
|
view_cursor_move(view, hard_start.char_pos);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -2579,7 +2684,7 @@ internal void
|
||||||
remeasure_file_view(System_Functions *system, View *view, i32_Rect rect){
|
remeasure_file_view(System_Functions *system, View *view, i32_Rect rect){
|
||||||
if (file_is_ready(view->file_data.file)){
|
if (file_is_ready(view->file_data.file)){
|
||||||
Relative_Scrolling relative = view_get_relative_scrolling(view);
|
Relative_Scrolling relative = view_get_relative_scrolling(view);
|
||||||
view_measure_wraps(system, &view->models->mem.general, view);
|
view_measure_wraps(&view->models->mem.general, view);
|
||||||
view_cursor_move(view, view->file_data.cursor.pos);
|
view_cursor_move(view, view->file_data.cursor.pos);
|
||||||
view->file_data.preferred_x = view_get_cursor_x(view);
|
view->file_data.preferred_x = view_get_cursor_x(view);
|
||||||
view_set_relative_scrolling(view, relative);
|
view_set_relative_scrolling(view, relative);
|
||||||
|
@ -4734,12 +4839,12 @@ kill_file(System_Functions *system, Exchange *exchange, Models *models, Editing_
|
||||||
iter = file_view_iter_next(iter)){
|
iter = file_view_iter_next(iter)){
|
||||||
if (node != used){
|
if (node != used){
|
||||||
iter.view->file_data.file = 0;
|
iter.view->file_data.file = 0;
|
||||||
view_set_file(iter.view, (Editing_File*)node, models, system);
|
view_set_file(iter.view, (Editing_File*)node, models);
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
iter.view->file_data.file = 0;
|
iter.view->file_data.file = 0;
|
||||||
view_set_file(iter.view, 0, models, system);
|
view_set_file(iter.view, 0, models);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4945,9 +5050,9 @@ search_next_match(Partition *part, Search_Set *set, Search_Iter *iter_){
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
view_change_size(System_Functions *system, General_Memory *general, View *view){
|
view_change_size(General_Memory *general, View *view){
|
||||||
if (view->file_data.file){
|
if (view->file_data.file){
|
||||||
view_measure_wraps(system, general, view);
|
view_measure_wraps(general, view);
|
||||||
view->file_data.cursor = view_compute_cursor_from_pos(view, view->file_data.cursor.pos);
|
view->file_data.cursor = view_compute_cursor_from_pos(view, view->file_data.cursor.pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ general_memory_open(General_Memory *general, void *memory, i32 size){
|
||||||
insert_bubble(&general->sentinel, first);
|
insert_bubble(&general->sentinel, first);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal b32
|
||||||
general_memory_check(General_Memory *general){
|
general_memory_check(General_Memory *general){
|
||||||
Bubble *sentinel = &general->sentinel;
|
Bubble *sentinel = &general->sentinel;
|
||||||
for (Bubble *bubble = sentinel->next;
|
for (Bubble *bubble = sentinel->next;
|
||||||
|
@ -145,6 +145,7 @@ general_memory_check(General_Memory *general){
|
||||||
Assert(end_ptr == next_ptr);
|
Assert(end_ptr == next_ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BUBBLE_MIN_SIZE 1024
|
#define BUBBLE_MIN_SIZE 1024
|
||||||
|
|
|
@ -470,40 +470,45 @@ buffer_seek_alphanumeric_or_camel_left(Buffer_Type *buffer, int pos){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal_4tech int
|
struct Hard_Start_Result{
|
||||||
buffer_find_hard_start(Buffer_Type *buffer, int line_start, int *all_whitespace,
|
int char_pos;
|
||||||
int *all_space, int *preferred_indent, int tab_width){
|
int indent_pos;
|
||||||
|
int all_whitespace;
|
||||||
|
int all_space;
|
||||||
|
};
|
||||||
|
|
||||||
|
internal_4tech Hard_Start_Result
|
||||||
|
buffer_find_hard_start(Buffer_Type *buffer, int line_start, int tab_width){
|
||||||
|
Hard_Start_Result result = {0};
|
||||||
Buffer_Stringify_Type loop;
|
Buffer_Stringify_Type loop;
|
||||||
char *data;
|
char *data;
|
||||||
int size, end;
|
int size, end;
|
||||||
int result;
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
*all_space = 1;
|
result.all_space = 1;
|
||||||
*preferred_indent = 0;
|
result.indent_pos = 0;
|
||||||
|
|
||||||
size = buffer_size(buffer);
|
size = buffer_size(buffer);
|
||||||
|
|
||||||
tab_width -= 1;
|
tab_width -= 1;
|
||||||
|
|
||||||
result = line_start;
|
result.char_pos = line_start;
|
||||||
for (loop = buffer_stringify_loop(buffer, line_start, size);
|
for (loop = buffer_stringify_loop(buffer, line_start, size);
|
||||||
buffer_stringify_good(&loop);
|
buffer_stringify_good(&loop);
|
||||||
buffer_stringify_next(&loop)){
|
buffer_stringify_next(&loop)){
|
||||||
end = loop.size + loop.absolute_pos;
|
end = loop.size + loop.absolute_pos;
|
||||||
data = loop.data - loop.absolute_pos;
|
data = loop.data - loop.absolute_pos;
|
||||||
for (; result < end; ++result){
|
for (; result.char_pos < end; ++result.char_pos){
|
||||||
c = data[result];
|
c = data[result.char_pos];
|
||||||
|
|
||||||
if (c == '\n' || c == 0){
|
if (c == '\n' || c == 0){
|
||||||
*all_whitespace = 1;
|
result.all_whitespace = 1;
|
||||||
goto buffer_find_hard_start_end;
|
goto buffer_find_hard_start_end;
|
||||||
}
|
}
|
||||||
if (c >= '!' && c <= '~') goto buffer_find_hard_start_end;
|
if (c >= '!' && c <= '~') goto buffer_find_hard_start_end;
|
||||||
if (c == '\t') *preferred_indent += tab_width;
|
if (c == '\t') result.indent_pos += tab_width;
|
||||||
if (c != ' ') *all_space = 0;
|
if (c != ' ') result.all_space = 0;
|
||||||
*preferred_indent += 1;
|
result.indent_pos += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue