finished moving clean all lines
parent
b4e6bd94e5
commit
8258e6c1ab
|
@ -380,7 +380,7 @@ default_keys(Bind_Helper *context){
|
||||||
bind(context, '!', MDFR_CTRL, eol_nixify);
|
bind(context, '!', MDFR_CTRL, eol_nixify);
|
||||||
|
|
||||||
bind(context, '?', MDFR_CTRL, toggle_show_whitespace);
|
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, '\n', MDFR_SHIFT, write_and_auto_tab);
|
||||||
bind(context, ' ', MDFR_SHIFT, write_character);
|
bind(context, ' ', MDFR_SHIFT, write_character);
|
||||||
|
|
||||||
|
|
|
@ -1465,20 +1465,13 @@ CUSTOM_COMMAND_SIG(clean_all_lines){
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (init_stream_chunk(&chunk, app, &buffer,
|
if (init_stream_chunk(&chunk, app, &buffer,
|
||||||
0, data, sizeof(data))){
|
i, data, sizeof(data))){
|
||||||
Buffer_Edit *edit = edits;
|
Buffer_Edit *edit = edits;
|
||||||
|
|
||||||
int buffer_size = buffer.size;
|
int buffer_size = buffer.size;
|
||||||
int still_looping = true;
|
int still_looping = true;
|
||||||
int need_stopper = true;
|
|
||||||
int last_hard = buffer_size;
|
int last_hard = buffer_size;
|
||||||
do{
|
do{
|
||||||
if (need_stopper && !still_looping){
|
|
||||||
chunk.end = i+1;
|
|
||||||
chunk.data[0] = '\n';
|
|
||||||
need_stopper = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i < chunk.end; ++i){
|
for (; i < chunk.end; ++i){
|
||||||
char at_pos = chunk.data[i];
|
char at_pos = chunk.data[i];
|
||||||
if (at_pos == '\n'){
|
if (at_pos == '\n'){
|
||||||
|
@ -1488,7 +1481,7 @@ CUSTOM_COMMAND_SIG(clean_all_lines){
|
||||||
edit->start = last_hard+1;
|
edit->start = last_hard+1;
|
||||||
edit->end = i;
|
edit->end = i;
|
||||||
++edit;
|
++edit;
|
||||||
i = buffer_size;
|
last_hard = buffer_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (char_is_whitespace(at_pos)){
|
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);
|
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;
|
||||||
}
|
}
|
||||||
}while(still_looping && need_stopper);
|
|
||||||
|
|
||||||
int edit_count = (int)(edit - edits);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DOC(bool32 is an alias name to signal that an integer parameter or field is for
|
/* DOC(bool32 is an alias name to signal that an integer parameter or field is for
|
||||||
true/false vales.) */
|
true/false vales.) */
|
||||||
typedef int32_t bool32;
|
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) */
|
/* DOC(cmdid_history_forward unperforms the previous cmdid_history_backward step if possib.e) */
|
||||||
cmdid_history_forward,
|
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.) */
|
/* DOC(cmdid_interactive_new begins an interactive dialogue to create a new buffer.) */
|
||||||
cmdid_interactive_new,
|
cmdid_interactive_new,
|
||||||
/* DOC(cmdid_interactive_open begins an interactive dialogue to open a file into a buffer.) */
|
/* 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.
|
/* 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.) */
|
This usually applies when whitespace is being replaced with whitespace.) */
|
||||||
BatchEdit_PreserveTokens
|
BatchEdit_PreserveTokens
|
||||||
}
|
};
|
||||||
|
|
||||||
/* DOC(A Buffer_Setting_ID names a setting in a buffer.) */
|
/* DOC(A Buffer_Setting_ID names a setting in a buffer.) */
|
||||||
ENUM(int32_t, Buffer_Setting_ID){
|
ENUM(int32_t, Buffer_Setting_ID){
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define MAJOR 4
|
#define MAJOR 4
|
||||||
#define MINOR 0
|
#define MINOR 0
|
||||||
#define PATCH 9
|
#define PATCH 10
|
||||||
|
|
||||||
#define VN__(a,b,c) #a"."#b"."#c
|
#define VN__(a,b,c) #a"."#b"."#c
|
||||||
#define VN_(a,b,c) VN__(a,b,c)
|
#define VN_(a,b,c) VN__(a,b,c)
|
||||||
|
|
67
4ed.cpp
67
4ed.cpp
|
@ -739,71 +739,6 @@ COMMAND_DECL(to_lowercase){
|
||||||
case_change_range(system, &models->mem, view, file, 'A', 'Z', (u8)('a' - 'A'));
|
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){
|
COMMAND_DECL(open_panel_vsplit){
|
||||||
USE_VARS(vars);
|
USE_VARS(vars);
|
||||||
USE_MODELS(models);
|
USE_MODELS(models);
|
||||||
|
@ -1111,8 +1046,6 @@ setup_command_table(){
|
||||||
SET(save);
|
SET(save);
|
||||||
SET(kill_buffer);
|
SET(kill_buffer);
|
||||||
|
|
||||||
SET(clean_all_lines);
|
|
||||||
|
|
||||||
SET(open_color_tweaker);
|
SET(open_color_tweaker);
|
||||||
SET(open_config);
|
SET(open_config);
|
||||||
SET(open_menu);
|
SET(open_menu);
|
||||||
|
|
|
@ -715,12 +715,23 @@ DOC_SEE(Buffer_Edit)
|
||||||
DOC_SEE(Buffer_Batch_Edit_Type)
|
DOC_SEE(Buffer_Batch_Edit_Type)
|
||||||
*/{
|
*/{
|
||||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||||
Mem_Options *mem = cmd->models;
|
Models *models = cmd->models;
|
||||||
Partition *part = &models->mem.part;
|
Mem_Options *mem = &models->mem;
|
||||||
|
Partition *part = &mem->part;
|
||||||
Editing_File *file = imp_get_file(cmd, buffer);
|
Editing_File *file = imp_get_file(cmd, buffer);
|
||||||
|
|
||||||
bool32 result = false;
|
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){
|
if (file){
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
Buffer_Edit *inverse_edits = push_array(part, Buffer_Edit, edit_count);
|
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,
|
inverse_edits, inv_str, inv_str_max,
|
||||||
edit_count);
|
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;
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
end_temp_memory(part);
|
end_temp_memory(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
|
|
|
@ -2976,7 +2976,7 @@ file_auto_tab_tokens(System_Functions *system, Models *models,
|
||||||
|
|
||||||
char *inv_str = (char*)part->base + part->pos;
|
char *inv_str = (char*)part->base + part->pos;
|
||||||
Edit_Spec spec =
|
Edit_Spec spec =
|
||||||
file_compute_whitespace_edit(mem, file, pos,
|
file_compute_whitespace_edit(mem, file,
|
||||||
batch.edits, batch.str_base, batch.str_size,
|
batch.edits, batch.str_base, batch.str_size,
|
||||||
inverse_array, inv_str, part->max - part->pos,
|
inverse_array, inv_str, part->max - part->pos,
|
||||||
batch.edit_count);
|
batch.edit_count);
|
||||||
|
|
Loading…
Reference in New Issue