finished moving clean all lines

This commit is contained in:
Allen Webster 2016-07-09 00:39:14 -04:00
parent b4e6bd94e5
commit 8258e6c1ab
7 changed files with 34 additions and 93 deletions

View File

@ -380,7 +380,7 @@ default_keys(Bind_Helper *context){
bind(context, '!', MDFR_CTRL, eol_nixify);
bind(context, '?', MDFR_CTRL, toggle_show_whitespace);
bind(context, '~', MDFR_CTRL, cmdid_clean_all_lines);
bind(context, '~', MDFR_CTRL, clean_all_lines);
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
bind(context, ' ', MDFR_SHIFT, write_character);

View File

@ -1462,23 +1462,16 @@ CUSTOM_COMMAND_SIG(clean_all_lines){
char data[1024];
Stream_Chunk chunk = {0};
int i = 0;
if (init_stream_chunk(&chunk, app, &buffer,
0, data, sizeof(data))){
i, data, sizeof(data))){
Buffer_Edit *edit = edits;
int buffer_size = buffer.size;
int still_looping = true;
int need_stopper = true;
int last_hard = buffer_size;
do{
if (need_stopper && !still_looping){
chunk.end = i+1;
chunk.data[0] = '\n';
need_stopper = false;
}
for (; i < chunk.end; ++i){
char at_pos = chunk.data[i];
if (at_pos == '\n'){
@ -1488,7 +1481,7 @@ CUSTOM_COMMAND_SIG(clean_all_lines){
edit->start = last_hard+1;
edit->end = i;
++edit;
i = buffer_size;
last_hard = buffer_size;
}
}
else if (char_is_whitespace(at_pos)){
@ -1499,13 +1492,19 @@ CUSTOM_COMMAND_SIG(clean_all_lines){
}
}
if (still_looping){
still_looping = forward_stream_chunk(&chunk);
}
}while(still_looping && need_stopper);
still_looping = forward_stream_chunk(&chunk);
}while(still_looping);
if (last_hard+1 < buffer_size){
edit->str_start = 0;
edit->len = 0;
edit->start = last_hard+1;
edit->end = buffer_size;
++edit;
}
int edit_count = (int)(edit - edits);
app->buffer_batch_edit(app, &buffer, 0, edits, edit_count, BatchEdit_PreserveTokens);
app->buffer_batch_edit(app, &buffer, 0, 0, edits, edit_count, BatchEdit_PreserveTokens);
}
}
}

View File

@ -1,5 +1,6 @@
/* DOC(bool32 is an alias name to signal that an integer parameter or field is for
true/false vales.) */
typedef int32_t bool32;
@ -67,9 +68,6 @@ ENUM(uint64_t, Command_ID){
/* DOC(cmdid_history_forward unperforms the previous cmdid_history_backward step if possib.e) */
cmdid_history_forward,
/* DOC(cmdid_clean_all_lines deletes extra whitespace out the currently active buffer.) */
cmdid_clean_all_lines,
/* DOC(cmdid_interactive_new begins an interactive dialogue to create a new buffer.) */
cmdid_interactive_new,
/* DOC(cmdid_interactive_open begins an interactive dialogue to open a file into a buffer.) */
@ -129,7 +127,7 @@ ENUM(int32_t, Buffer_Batch_Edit_Type){
/* DOC(The BatchEdit_PreserveTokens operation is one in which none of the edits add, delete, or change any tokens.
This usually applies when whitespace is being replaced with whitespace.) */
BatchEdit_PreserveTokens
}
};
/* DOC(A Buffer_Setting_ID names a setting in a buffer.) */
ENUM(int32_t, Buffer_Setting_ID){

View File

@ -1,6 +1,6 @@
#define MAJOR 4
#define MINOR 0
#define PATCH 9
#define PATCH 10
#define VN__(a,b,c) #a"."#b"."#c
#define VN_(a,b,c) VN__(a,b,c)

67
4ed.cpp
View File

@ -739,71 +739,6 @@ COMMAND_DECL(to_lowercase){
case_change_range(system, &models->mem, view, file, 'A', 'Z', (u8)('a' - 'A'));
}
COMMAND_DECL(clean_all_lines){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
Mem_Options *mem = &models->mem;
Editing_File *file = view->file_data.file;
Partition *part = &mem->part;
i32 line_count = file->state.buffer.line_count;
i32 edit_max = line_count * 2;
i32 edit_count = 0;
Assert(file && !file->is_dummy);
Assert(view->edit_pos);
Temp_Memory temp = begin_temp_memory(part);
Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max);
char *str_base = (char*)part->base + part->pos;
i32 str_size = 0;
for (i32 line_i = 0; line_i < line_count; ++line_i){
i32 start = file->state.buffer.line_starts[line_i];
Hard_Start_Result hard_start =
buffer_find_hard_start(&file->state.buffer, start, 4);
if (hard_start.all_whitespace){
hard_start.indent_pos = 0;
}
if ((hard_start.all_whitespace && hard_start.char_pos > start) || !hard_start.all_space){
Buffer_Edit new_edit;
new_edit.str_start = str_size;
str_size += hard_start.indent_pos;
char *str = push_array(part, char, hard_start.indent_pos);
for (i32 j = 0; j < hard_start.indent_pos; ++j) str[j] = ' ';
new_edit.len = hard_start.indent_pos;
new_edit.start = start;
new_edit.end = hard_start.char_pos;
edits[edit_count++] = new_edit;
}
Assert(edit_count <= edit_max);
}
if (edit_count > 0){
Assert(buffer_batch_debug_sort_check(edits, edit_count));
// NOTE(allen): computing edit spec, doing batch edit
Buffer_Edit *inverse_array = push_array(part, Buffer_Edit, edit_count);
Assert(inverse_array);
char *inv_str = (char*)part->base + part->pos;
Edit_Spec spec =
file_compute_whitespace_edit(mem, file,
view->edit_pos->cursor.pos,
edits, str_base, str_size,
inverse_array, inv_str,
part->max - part->pos, edit_count);
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
}
end_temp_memory(temp);
}
COMMAND_DECL(open_panel_vsplit){
USE_VARS(vars);
USE_MODELS(models);
@ -1111,8 +1046,6 @@ setup_command_table(){
SET(save);
SET(kill_buffer);
SET(clean_all_lines);
SET(open_color_tweaker);
SET(open_config);
SET(open_menu);

View File

@ -715,12 +715,23 @@ DOC_SEE(Buffer_Edit)
DOC_SEE(Buffer_Batch_Edit_Type)
*/{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Mem_Options *mem = cmd->models;
Partition *part = &models->mem.part;
Models *models = cmd->models;
Mem_Options *mem = &models->mem;
Partition *part = &mem->part;
Editing_File *file = imp_get_file(cmd, buffer);
bool32 result = false;
app->print_message(app, literal("Buffer_Batch_Edit:\n"));
{
char space[512];
String str = make_fixed_width_string(space);
append(&str, "edit_count: ");
append_int_to_str(&str, edit_count);
append(&str, '\n');
app->print_message(app, str.str, str.size);
}
if (file){
Temp_Memory temp = begin_temp_memory(part);
Buffer_Edit *inverse_edits = push_array(part, Buffer_Edit, edit_count);
@ -742,11 +753,11 @@ DOC_SEE(Buffer_Batch_Edit_Type)
inverse_edits, inv_str, inv_str_max,
edit_count);
file_do_white_batch_edit(system, models, file, spec, hist_normal);
file_do_white_batch_edit(cmd->system, models, file, spec, hist_normal);
}break;
}
end_temp_memory(part);
end_temp_memory(temp);
}
return(result);

View File

@ -2976,7 +2976,7 @@ 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, pos,
file_compute_whitespace_edit(mem, file,
batch.edits, batch.str_base, batch.str_size,
inverse_array, inv_str, part->max - part->pos,
batch.edit_count);