rounded out batch edit, tracked down some bugs

master
Allen Webster 2016-07-13 19:19:42 -04:00
parent 1634a65b17
commit dacf7f1675
11 changed files with 188 additions and 164 deletions

View File

@ -11,6 +11,11 @@
#include <assert.h>
#ifndef DEFAULT_INDENT_FLAGS
# define DEFAULT_INDENT_FLAGS 0
#endif
//
// Memory
//
@ -1203,7 +1208,7 @@ long_braces(Application_Links *app, char *text, int size){
app->buffer_auto_indent(app, &buffer,
pos, pos + size,
DEF_TAB_WIDTH,
0);
DEFAULT_INDENT_FLAGS);
move_past_lead_whitespace(app, &view, &buffer);
}
@ -1228,46 +1233,59 @@ CUSTOM_COMMAND_SIG(open_long_braces_break){
// TODO(allen): Have this thing check if it is on
// a blank line and insert newlines as needed.
CUSTOM_COMMAND_SIG(if0_off){
unsigned int access = AccessOpen;
View_Summary view;
Buffer_Summary buffer;
char text1[] = "\n#if 0";
int size1 = sizeof(text1) - 1;
char text2[] = "#endif\n";
int size2 = sizeof(text2) - 1;
Range range;
int pos;
View_Summary view = app->get_active_view(app, AccessOpen);
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, AccessOpen);
view = app->get_active_view(app, access);
buffer = app->get_buffer(app, view.buffer_id, access);
Range range = get_range(&view);
if (range.min < range.max){
Buffer_Edit edits[2];
char *str = 0;
char *base = (char*)partition_current(&global_part);
str = push_array(&global_part, char, size1);
memcpy(str, text1, size1);
edits[0].str_start = (int)(str - base);
edits[0].len = size1;
edits[0].start = range.min;
edits[0].end = range.min;
str = push_array(&global_part, char, size2);
memcpy(str, text2, size2);
edits[1].str_start = (int)(str - base);
edits[1].len = size2;
edits[1].start = range.max;
edits[1].end = range.max;
app->buffer_batch_edit(app,&buffer,
base, global_part.pos,
edits, ArrayCount(edits), BatchEdit_Normal);
view = app->get_view(app, view.view_id, AccessAll);
if (view.cursor.pos > view.mark.pos){
app->view_set_cursor(app, &view,
seek_line_char(view.cursor.line+1, view.cursor.character),
true);
}
else{
app->view_set_mark(app, &view,
seek_line_char(view.mark.line+1, view.mark.character));
}
range = get_range(&view);
pos = range.min;
app->buffer_replace_range(app, &buffer, pos, pos, text1, size1);
app->buffer_auto_indent(app, &buffer,
pos, pos,
range.min, range.max,
DEF_TAB_WIDTH,
0);
move_past_lead_whitespace(app, &view, &buffer);
refresh_view(app, &view);
range = get_range(&view);
pos = range.max;
app->buffer_replace_range(app, &buffer, pos, pos, text2, size2);
app->buffer_auto_indent(app, &buffer,
pos, pos,
DEF_TAB_WIDTH,
0);
DEFAULT_INDENT_FLAGS);
move_past_lead_whitespace(app, &view, &buffer);
}
}
//
@ -1867,7 +1885,7 @@ CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){
app->buffer_auto_indent(app, &buffer,
view.cursor.pos, view.cursor.pos,
DEF_TAB_WIDTH,
0);
DEFAULT_INDENT_FLAGS);
move_past_lead_whitespace(app, &view, &buffer);
}
@ -1879,7 +1897,7 @@ CUSTOM_COMMAND_SIG(auto_tab_whole_file){
app->buffer_auto_indent(app, &buffer,
0, buffer.size,
DEF_TAB_WIDTH,
0);
DEFAULT_INDENT_FLAGS);
}
CUSTOM_COMMAND_SIG(auto_tab_range){
@ -1891,7 +1909,7 @@ CUSTOM_COMMAND_SIG(auto_tab_range){
app->buffer_auto_indent(app, &buffer,
range.min, range.max,
DEF_TAB_WIDTH,
0);
DEFAULT_INDENT_FLAGS);
move_past_lead_whitespace(app, &view, &buffer);
}

View File

@ -46,7 +46,7 @@ parse_error(String line, Jump_Location *location,
if (colon_pos < line.size){
String location_str = substr(line, 0, colon_pos);
if (!(skip_sub_errors && location_str.str[0] == ' ')){
if (!(skip_sub_errors && line.str[0] == ' ')){
location_str = skip_chop_whitespace(location_str);
int paren_pos = find(location_str, 0, '(');
@ -61,9 +61,7 @@ parse_error(String line, Jump_Location *location,
close_pos-paren_pos-2);
line_number = skip_chop_whitespace(line_number);
if (line_number.size > 0){
//copy(&location->file, file);
location->file = file;
int comma_pos = find(line_number, 0, ',');
@ -102,7 +100,6 @@ parse_error(String line, Jump_Location *location,
int colon_pos2 = find(line, colon_pos1+1, ':');
int colon_pos3 = find(line, colon_pos2+1, ':');
if (gcc_style_verify(line, colon_pos3)){
String filename = substr(line, 0, colon_pos1);
String line_number = substr(line, colon_pos1+1, colon_pos2 - colon_pos1 - 1);
@ -111,7 +108,6 @@ parse_error(String line, Jump_Location *location,
if (filename.size > 0 &&
line_number.size > 0 &&
column_number.size > 0){
//copy(&location->file, filename);
location->file = filename;
location->line = str_to_int(line_number);
location->column = str_to_int(column_number);
@ -127,7 +123,6 @@ parse_error(String line, Jump_Location *location,
String line_number = substr(line, colon_pos1+1, colon_pos2 - colon_pos1 - 1);
if (filename.size > 0 && line_number.size > 0){
//copy(&location->file, filename);
location->file = filename;
location->line = str_to_int(line_number);
location->column = 0;
@ -190,6 +185,7 @@ struct Prev_Jump{
static Prev_Jump null_location = {0};
static Prev_Jump prev_location = {0};
// TODO(allen): GIVE THESE THINGS NAMES I CAN FUCKING UNDERSTAND
static int
next_error(Application_Links *app,
Partition *part,

11
4ed.cpp
View File

@ -2461,6 +2461,17 @@ App_Step_Sig(app_step){
"and if you load README.txt you'll find all the key combos there are.\n"
"\n"
"Newest features:\n"
"-<control F> list all locations of a string across all open buffers\n"
"-Build now finds build.sh and Makefile on Linux\n"
"-<alt n> goes to the next error if the *compilation* buffer is open\n"
"-<alt N> goes to the previous error\n"
"-<alt M> goes to the first error\n"
"-<alt .> switch to the compilation buffer\n"
"-<alt ,> close the panel viewing the compilation buffer\n"
"-New documentation for the 4coder string library included in 4coder_API.html\n"
"-Low level allocation calls available in custom API\n"
"\n"
"New in alpha 4.0.9:\n"
"-A scratch buffer is now opened with 4coder automatically\n"
"-A new mouse suppression mode toggled by <F2>\n"
"-Hinting is disabled by default, a -h flag on the command line enables it\n"

View File

@ -808,23 +808,13 @@ DOC_SEE(Buffer_Batch_Edit_Type)
int inv_str_max = part->max - part->pos;
Assert(inverse_edits);
switch (type){
case BatchEdit_Normal:
{
// TODO(allen):
}break;
case BatchEdit_PreserveTokens:
{
Edit_Spec spec =
file_compute_whitespace_edit(mem, file,
file_compute_edit(mem, file,
edits, str, str_len,
inverse_edits, inv_str, inv_str_max,
edit_count);
edit_count, type);
file_do_white_batch_edit(cmd->system, models, file, spec, hist_normal);
}break;
}
file_do_batch_edit(cmd->system, models, file, spec, hist_normal, type);
end_temp_memory(temp);
}

View File

@ -60,7 +60,8 @@ struct Edit_Step{
struct{
b32 can_merge;
Buffer_Edit edit;
i32 next_block, prev_block;
i32 next_block;
i32 prev_block;
};
struct{
i32 first_child;

View File

@ -249,7 +249,6 @@ struct View{
i32 color_cursor;
// misc
i32 font_advance;
i32 line_height;
View_Mode mode, next_mode;
@ -1345,17 +1344,19 @@ file_first_lex_parallel(System_Functions *system,
}
#endif
internal void
internal b32
file_relex_parallel(System_Functions *system,
Mem_Options *mem, Editing_File *file,
i32 start_i, i32 end_i, i32 amount){
General_Memory *general = &mem->general;
Partition *part = &mem->part;
if (file->state.token_stack.tokens == 0){
file_first_lex_parallel(system, general, file);
return;
return(false);
}
b32 result = true;
b32 inline_lex = !file->state.still_lexing;
if (inline_lex){
Cpp_File cpp_file;
@ -1436,7 +1437,10 @@ file_relex_parallel(System_Functions *system,
job.data[0] = file;
job.data[1] = general;
file->state.lex_job = system->post_job(BACKGROUND_THREADS, job);
result = false;
}
return(result);
}
internal void
@ -2138,6 +2142,7 @@ file_do_single_edit(System_Functions *system,
if (old_data) general_memory_free(general, old_data);
}
// NOTE(allen): meta data
Buffer_Type *buffer = &file->state.buffer;
i32 line_start = buffer_get_line_index(&file->state.buffer, start);
i32 line_end = buffer_get_line_index(&file->state.buffer, end);
@ -2163,23 +2168,25 @@ file_do_single_edit(System_Functions *system,
}
}
#if BUFFER_EXPERIMENT_SCALPEL <= 0
// NOTE(allen): fixing stuff afterwards
if (file->settings.tokens_exist)
file_relex_parallel(system, mem, file, start, end, shift_amount);
#endif
// NOTE(allen): cursor fixing
Cursor_Fix_Descriptor desc = {};
desc.start = start;
desc.end = end;
desc.shift_amount = shift_amount;
file_edit_cursor_fix(system, part, general, file, layout, desc);
#if BUFFER_EXPERIMENT_SCALPEL <= 0
// NOTE(allen): token fixing
if (file->settings.tokens_exist){
file_relex_parallel(system, mem, file, start, end, shift_amount);
}
#endif
}
internal void
file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File *file,
Edit_Spec spec, History_Mode history_mode){
file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file,
Edit_Spec spec, History_Mode history_mode, i32 batch_type){
Mem_Options *mem = &models->mem;
Editing_Layout *layout = &models->layout;
@ -2235,6 +2242,24 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
}
// NOTE(allen): token fixing
switch (batch_type){
case BatchEdit_Normal:
{
if (file->settings.tokens_exist){
Buffer_Edit *edit = batch;
for (i32 i = 0; i < batch_size; ++i, ++edit){
i32 start = edit->start;
i32 end = edit->end;
i32 shift_amount = edit->len - (end - start);
if (!file_relex_parallel(system, mem, file, start, end, shift_amount)){
break;
}
}
}
}break;
case BatchEdit_PreserveTokens:
{
if (file->state.tokens_complete){
Cpp_Token_Stack tokens = file->state.token_stack;
Cpp_Token *token = tokens.tokens;
@ -2262,6 +2287,8 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
shift_amount += local_shift;
}
}
}break;
}
}
inline void
@ -2309,6 +2336,34 @@ main_style(Models *models){
return (get_style(models, 0));
}
internal void
apply_history_edit(System_Functions *system, Models *models,
Editing_File *file, View *view,
Edit_Stack *stack, Edit_Step step, History_Mode history_mode){
Edit_Spec spec = {};
spec.step = step;
if (step.child_count == 0){
spec.step.edit.str_start = 0;
spec.str = stack->strings + step.edit.str_start;
file_do_single_edit(system, models, file, spec, history_mode);
if (view){
view_cursor_move(view, step.edit.start + step.edit.len);
view->edit_pos->mark = view->edit_pos->cursor.pos;
Style *style = main_style(models);
view_post_paste_effect(view, 0.333f,
step.edit.start, step.edit.len,
style->main.undo_color);
}
}
else{
file_do_batch_edit(system, models, view->file_data.file, spec, hist_normal, spec.step.special_type);
}
}
internal void
view_undo_redo(System_Functions *system,
Models *models, View *view,
@ -2323,27 +2378,9 @@ view_undo_redo(System_Functions *system,
Assert(step.type == expected_type);
Edit_Spec spec = {};
spec.step = step;
if (step.child_count == 0){
spec.step.edit.str_start = 0;
spec.str = stack->strings + step.edit.str_start;
file_do_single_edit(system, models, file, spec, hist_normal);
view_cursor_move(view, step.edit.start + step.edit.len);
view->edit_pos->mark = view->edit_pos->cursor.pos;
Style *style = main_style(models);
view_post_paste_effect(view, 0.333f,
step.edit.start, step.edit.len,
style->main.undo_color);
}
else{
TentativeAssert(spec.step.special_type == 1);
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
}
apply_history_edit(system, models,
file, view,
stack, step, hist_normal);
}
}
@ -2449,32 +2486,9 @@ view_history_step(System_Functions *system, Models *models, View *view, History_
}
if (do_history_step){
Edit_Spec spec = {0};
spec.step = step;
if (spec.step.child_count == 0){
spec.step.edit.str_start = 0;
spec.str = file->state.undo.history.strings + step.edit.str_start;
file_do_single_edit(system, models, file, spec, history_mode);
switch (spec.step.type){
case ED_NORMAL:
case ED_REDO:
view_cursor_move(view, step.edit.start + step.edit.len);
break;
case ED_REVERSE_NORMAL:
case ED_UNDO:
view_cursor_move(view, step.edit.start + step.edit.len);
break;
}
view->edit_pos->mark = view->edit_pos->cursor.pos;
}
else{
TentativeAssert(spec.step.special_type == 1);
file_do_white_batch_edit(system, models, view->file_data.file, spec, history_mode);
}
apply_history_edit(system, models,
file, view,
&file->state.undo.history, step, history_mode);
}
}
@ -2556,10 +2570,10 @@ clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *w
}
internal Edit_Spec
file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file,
file_compute_edit(Mem_Options *mem, Editing_File *file,
Buffer_Edit *edits, char *str_base, i32 str_size,
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max,
i32 edit_count){
i32 edit_count, i32 batch_type){
General_Memory *general = &mem->general;
i32 inv_str_pos = 0;
@ -2580,7 +2594,7 @@ file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file,
spec.step.type = ED_NORMAL;
spec.step.first_child = first_child;
spec.step.inverse_first_child = inverse_first_child;
spec.step.special_type = 1;
spec.step.special_type = batch_type;
spec.step.child_count = edit_count;
spec.step.inverse_child_count = edit_count;
@ -3000,12 +3014,12 @@ file_auto_tab_tokens(System_Functions *system, Models *models,
char *inv_str = (char*)part->base + part->pos;
Edit_Spec spec =
file_compute_whitespace_edit(mem, file,
file_compute_edit(mem, file,
batch.edits, batch.str_base, batch.str_size,
inverse_array, inv_str, part->max - part->pos,
batch.edit_count);
batch.edit_count, BatchEdit_PreserveTokens);
file_do_white_batch_edit(system, models, file, spec, hist_normal);
file_do_batch_edit(system, models, file, spec, hist_normal, BatchEdit_PreserveTokens);
}
end_temp_memory(temp);
#endif
@ -3067,7 +3081,6 @@ style_get_color(Style *style, Cpp_Token token){
internal void
update_view_line_height(Models *models, View *view){
Font_Info *fnt_info = get_font_info(models->font_set, models->global_font.font_id);
view->font_advance = fnt_info->advance;
view->line_height = fnt_info->height;
}

View File

@ -146,8 +146,7 @@ font_set_evict_lru(Font_Set *set){
internal void
font_set_use(Partition *partition, Font_Set *set, i16 font_id){
b8 already_used;
already_used = set->font_used_flags[font_id-1];
b8 already_used = set->font_used_flags[font_id-1];
if (!already_used){
if (set->used_this_frame < set->live_max){

View File

@ -673,10 +673,10 @@ font_load_freetype(Partition *part,
f32 space_width = rf->advance_data[' '];
rf->glyphs['\r'] = space_glyph;
rf->advance_data['\r'] = space_width*tab_width;
rf->advance_data['\r'] = space_width;
rf->glyphs['\n'] = space_glyph;
rf->advance_data['\n'] = space_width*tab_width;
rf->advance_data['\n'] = space_width;
rf->glyphs['\t'] = space_glyph;
rf->advance_data['\t'] = space_width*tab_width;

View File

@ -1177,11 +1177,8 @@ buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_d
internal_4tech void
buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings,
int *str_pos, int max, int shift_amount){
int pos;
int len;
pos = *str_pos;
len = edit.end - edit.start;
int pos = *str_pos;
int len = edit.end - edit.start;
assert_4tech(pos >= 0);
assert_4tech(pos + len <= max);
*str_pos = pos + len;

View File

@ -1267,7 +1267,6 @@ Win32LoadRenderCode(){
win32vars.target.pop_clip = draw_pop_clip;
win32vars.target.push_piece = draw_push_piece;
//win32vars.target.font_set.font_info_load = draw_font_info_load;
win32vars.target.font_set.font_load = system_draw_font_load;
win32vars.target.font_set.release_font = draw_release_font;
}