lots of miscellaneous bug fixes

This commit is contained in:
Allen Webster 2016-03-04 16:26:00 -05:00
parent 18eda91724
commit 78653ef118
9 changed files with 897 additions and 822 deletions

View File

@ -33,14 +33,13 @@ HOOK_SIG(my_start){
} }
HOOK_SIG(my_file_settings){ HOOK_SIG(my_file_settings){
Buffer_Summary buffer = app->get_active_buffer(app); // NOTE(allen|a4): In hooks that want parameters, such as this file
// created hook. The file created hook is guaranteed to have only
// and exactly one buffer parameter. In normal command callbacks
// there are no parameter buffers.
Buffer_Summary buffer = app->get_parameter_buffer(app, 0);
assert(buffer.exists);
// NOTE(allen|a3.4.2): Whenever you ask for a buffer, you can check that
// the exists field is set to true. Reasons why the buffer might not exist:
// -The active panel does not contain a buffer and get_active_buffer was used
// -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer
// -The name provided to get_buffer_by_name did not match any of the existing buffers
if (buffer.exists){
int treat_as_code = 0; int treat_as_code = 0;
if (buffer.file_name && buffer.size < (16 << 20)){ if (buffer.file_name && buffer.size < (16 << 20)){
@ -55,21 +54,28 @@ HOOK_SIG(my_file_settings){
push_parameter(app, par_wrap_lines, !treat_as_code); push_parameter(app, par_wrap_lines, !treat_as_code);
push_parameter(app, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file)); push_parameter(app, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file));
exec_command(app, cmdid_set_settings); exec_command(app, cmdid_set_settings);
} }
static void
write_string(Application_Links *app, String string){
Buffer_Summary buffer = app->get_active_buffer(app);
app->buffer_replace_range(app, &buffer, buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, string.str, string.size);
} }
CUSTOM_COMMAND_SIG(write_increment){ CUSTOM_COMMAND_SIG(write_increment){
char text[] = "++"; write_string(app, make_lit_string("++"));
int size = sizeof(text) - 1;
Buffer_Summary buffer = app->get_active_buffer(app);
app->buffer_replace_range(app, &buffer, buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, text, size);
} }
CUSTOM_COMMAND_SIG(write_decrement){ CUSTOM_COMMAND_SIG(write_decrement){
char text[] = "--"; write_string(app, make_lit_string("--"));
int size = sizeof(text) - 1; }
Buffer_Summary buffer = app->get_active_buffer(app);
app->buffer_replace_range(app, &buffer, buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, text, size); CUSTOM_COMMAND_SIG(write_allen_todo){
write_string(app, make_lit_string("// TODO(allen): "));
}
CUSTOM_COMMAND_SIG(write_allen_note){
write_string(app, make_lit_string("// NOTE(allen): "));
} }
static void static void
@ -137,7 +143,7 @@ CUSTOM_COMMAND_SIG(if0_off){
View_Summary view; View_Summary view;
Buffer_Summary buffer; Buffer_Summary buffer;
char text1[] = "#if 0\n"; char text1[] = "\n#if 0";
int size1 = sizeof(text1) - 1; int size1 = sizeof(text1) - 1;
char text2[] = "#endif\n"; char text2[] = "#endif\n";
@ -192,8 +198,6 @@ CUSTOM_COMMAND_SIG(switch_to_compilation){
char name[] = "*compilation*"; char name[] = "*compilation*";
int name_size = sizeof(name)-1; int name_size = sizeof(name)-1;
// TODO(allen): This will only work for file views for now. Fix up this
// view nonsense so that view types aren't such an issue.
view = app->get_active_view(app); view = app->get_active_view(app);
buffer = app->get_buffer_by_name(app, name, name_size); buffer = app->get_buffer_by_name(app, name, name_size);
@ -446,7 +450,7 @@ CUSTOM_COMMAND_SIG(rewrite_as_single_caps){
// TODO(allen): // TODO(allen):
// get range by specific "word" type (for example "get token range") // get range by specific "word" type (for example "get token range")
// read range by specific "word" type // read range by specific "word" type
// Dream API: for rewrite_as_single_caps // Dream API for rewrite_as_single_caps:
#if 0 #if 0
{ {
rewrite = get_rewrite(app, ByToken); rewrite = get_rewrite(app, ByToken);
@ -479,6 +483,8 @@ CUSTOM_COMMAND_SIG(replace_in_range){
with.string = make_fixed_width_string(with_space); with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &replace)) return; if (!query_user_string(app, &replace)) return;
if (replace.string.size == 0) return;
if (!query_user_string(app, &with)) return; if (!query_user_string(app, &with)) return;
String r, w; String r, w;
@ -517,6 +523,8 @@ CUSTOM_COMMAND_SIG(query_replace){
with.string = make_fixed_width_string(with_space); with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &replace)) return; if (!query_user_string(app, &replace)) return;
if (replace.string.size == 0) return;
if (!query_user_string(app, &with)) return; if (!query_user_string(app, &with)) return;
String r, w; String r, w;
@ -567,11 +575,11 @@ CUSTOM_COMMAND_SIG(query_replace){
CUSTOM_COMMAND_SIG(close_all_code){ CUSTOM_COMMAND_SIG(close_all_code){
String extension; String extension;
Buffer_Summary buffer; Buffer_Summary buffer;
int max, i;
max = app->get_buffer_max_index(app); for (buffer = app->get_buffer_first(app);
for (i = 0; i < max; ++i){ buffer.exists;
buffer = app->get_buffer(app, i); app->get_buffer_next(app, &buffer)){
extension = file_extension(make_string(buffer.file_name, buffer.file_name_len)); extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match(extension, make_lit_string("cpp")) || if (match(extension, make_lit_string("cpp")) ||
match(extension, make_lit_string("hpp")) || match(extension, make_lit_string("hpp")) ||
@ -901,6 +909,7 @@ extern "C" GET_BINDING_DATA(get_bindings){
Bind_Helper context_actual = begin_bind_helper(data, size); Bind_Helper context_actual = begin_bind_helper(data, size);
Bind_Helper *context = &context_actual; Bind_Helper *context = &context_actual;
// NOTE(allen|a3.1): Right now hooks have no loyalties to maps, all hooks are // NOTE(allen|a3.1): Right now hooks have no loyalties to maps, all hooks are
// global and once set they always apply, regardless of what map is active. // global and once set they always apply, regardless of what map is active.
set_hook(context, hook_start, my_start); set_hook(context, hook_start, my_start);
@ -921,6 +930,7 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, 'o', MDFR_ALT, open_in_other); bind(context, 'o', MDFR_ALT, open_in_other);
bind(context, 'm', MDFR_ALT, build_search); bind(context, 'm', MDFR_ALT, build_search);
bind(context, ',', MDFR_ALT, switch_to_compilation);
bind(context, 'x', MDFR_ALT, execute_arbitrary_command); bind(context, 'x', MDFR_ALT, execute_arbitrary_command);
bind(context, 'z', MDFR_ALT, execute_any_cli); bind(context, 'z', MDFR_ALT, execute_any_cli);
@ -962,6 +972,8 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, '=', MDFR_CTRL, write_increment); bind(context, '=', MDFR_CTRL, write_increment);
bind(context, '-', MDFR_CTRL, write_decrement); bind(context, '-', MDFR_CTRL, write_decrement);
bind(context, 't', MDFR_ALT, write_allen_todo);
bind(context, 'n', MDFR_ALT, write_allen_note);
bind(context, '[', MDFR_CTRL, open_long_braces); bind(context, '[', MDFR_CTRL, open_long_braces);
bind(context, '{', MDFR_CTRL, open_long_braces_semicolon); bind(context, '{', MDFR_CTRL, open_long_braces_semicolon);
bind(context, '}', MDFR_CTRL, open_long_braces_break); bind(context, '}', MDFR_CTRL, open_long_braces_break);

View File

@ -342,9 +342,12 @@ struct Application_Links;
#define FREE_FILE_LIST_SIG(name) void name(Application_Links *app, File_List list) #define FREE_FILE_LIST_SIG(name) void name(Application_Links *app, File_List list)
// Direct buffer manipulation // Direct buffer manipulation
#define GET_BUFFER_MAX_INDEX_SIG(name) int name(Application_Links *app) #define GET_BUFFER_FIRST_SIG(name) Buffer_Summary name(Application_Links *app)
#define GET_BUFFER_NEXT_SIG(name) void name(Application_Links *app, Buffer_Summary *buffer)
#define GET_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int index) #define GET_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int index)
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app) #define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app)
#define GET_PARAMETER_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int param_index)
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *app, char *filename, int len) #define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *app, char *filename, int len)
#define REFRESH_BUFFER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer) #define REFRESH_BUFFER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer)
@ -355,7 +358,9 @@ struct Application_Links;
#define BUFFER_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos) #define BUFFER_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos)
// File view manipulation // File view manipulation
#define GET_VIEW_MAX_INDEX_SIG(name) int name(Application_Links *app) #define GET_VIEW_FIRST_SIG(name) View_Summary name(Application_Links *app)
#define GET_VIEW_NEXT_SIG(name) void name(Application_Links *app, View_Summary *view)
#define GET_VIEW_SIG(name) View_Summary name(Application_Links *app, int index) #define GET_VIEW_SIG(name) View_Summary name(Application_Links *app, int index)
#define GET_ACTIVE_VIEW_SIG(name) View_Summary name(Application_Links *app) #define GET_ACTIVE_VIEW_SIG(name) View_Summary name(Application_Links *app)
@ -398,9 +403,12 @@ extern "C"{
typedef FREE_FILE_LIST_SIG(Free_File_List_Function); typedef FREE_FILE_LIST_SIG(Free_File_List_Function);
// Buffer manipulation // Buffer manipulation
typedef GET_BUFFER_MAX_INDEX_SIG(Get_Buffer_Max_Index_Function); typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function);
typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function);
typedef GET_BUFFER_SIG(Get_Buffer_Function); typedef GET_BUFFER_SIG(Get_Buffer_Function);
typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function); typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function);
typedef GET_PARAMETER_BUFFER_SIG(Get_Parameter_Buffer_Function);
typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function); typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function);
typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function); typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
@ -411,7 +419,9 @@ extern "C"{
typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function); typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function);
// View manipulation // View manipulation
typedef GET_VIEW_MAX_INDEX_SIG(Get_View_Max_Index_Function); typedef GET_VIEW_FIRST_SIG(Get_View_First_Function);
typedef GET_VIEW_NEXT_SIG(Get_View_Next_Function);
typedef GET_VIEW_SIG(Get_View_Function); typedef GET_VIEW_SIG(Get_View_Function);
typedef GET_ACTIVE_VIEW_SIG(Get_Active_View_Function); typedef GET_ACTIVE_VIEW_SIG(Get_Active_View_Function);
@ -448,9 +458,12 @@ struct Application_Links{
Free_File_List_Function *free_file_list; Free_File_List_Function *free_file_list;
// Buffer manipulation // Buffer manipulation
Get_Buffer_Max_Index_Function *get_buffer_max_index; Get_Buffer_First_Function *get_buffer_first;
Get_Buffer_Next_Function *get_buffer_next;
Get_Buffer_Function *get_buffer; Get_Buffer_Function *get_buffer;
Get_Active_Buffer_Function *get_active_buffer; Get_Active_Buffer_Function *get_active_buffer;
Get_Parameter_Buffer_Function *get_parameter_buffer;
Get_Buffer_By_Name_Function *get_buffer_by_name; Get_Buffer_By_Name_Function *get_buffer_by_name;
Refresh_Buffer_Function *refresh_buffer; Refresh_Buffer_Function *refresh_buffer;
@ -461,7 +474,9 @@ struct Application_Links{
Buffer_Set_Pos_Function *buffer_set_pos; Buffer_Set_Pos_Function *buffer_set_pos;
// View manipulation // View manipulation
Get_View_Max_Index_Function *get_view_max_index; Get_View_First_Function *get_view_first;
Get_View_Next_Function *get_view_next;
Get_View_Function *get_view; Get_View_Function *get_view;
Get_Active_View_Function *get_active_view; Get_Active_View_Function *get_active_view;

618
4ed.cpp

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,9 @@ struct App_Models{
Custom_Command_Function *hooks[hook_type_count]; Custom_Command_Function *hooks[hook_type_count];
i32 *buffer_param_indices;
i32 buffer_param_count, buffer_param_max;
Font_Set *font_set; Font_Set *font_set;
Style_Font global_font; Style_Font global_font;
Style style; Style style;

View File

@ -92,14 +92,13 @@ struct Text_Effect{
// file is still streaming in, and all operations except for the // file is still streaming in, and all operations except for the
// initial allocation of the file. // initial allocation of the file.
struct Editing_File_Settings{ struct Editing_File_Settings{
Font_Set *set;
i32 base_map_id; i32 base_map_id;
i32 dos_write_mode; i32 dos_write_mode;
b32 unwrapped_lines; b32 unwrapped_lines;
b8 tokens_exist; b8 tokens_exist;
b8 super_locked;
b8 is_initialized; b8 is_initialized;
b8 unimportant; b8 unimportant;
b8 read_only;
}; };
// NOTE(allen): This part of the Editing_File is cleared whenever // NOTE(allen): This part of the Editing_File is cleared whenever
@ -142,7 +141,12 @@ struct Editing_File_Name{
String extension; String extension;
}; };
struct File_Node{
File_Node *next, *prev;
};
struct Editing_File{ struct Editing_File{
File_Node node;
Editing_File_Settings settings; Editing_File_Settings settings;
union{ union{
Editing_File_State state; Editing_File_State state;
@ -237,7 +241,9 @@ table_remove(File_Table *table, String name){
struct Working_Set{ struct Working_Set{
Editing_File *files; Editing_File *files;
i32 file_index_count, file_max_count; i32 file_count, file_max;
File_Node free_sentinel;
File_Node used_sentinel;
File_Table table; File_Table table;
@ -418,11 +424,11 @@ working_set_contains(Working_Set *working, String filename){
Editing_File *result = 0; Editing_File *result = 0;
i32 id; i32 id;
if (table_find(&working->table, filename, &id)){ if (table_find(&working->table, filename, &id)){
if (id < working->file_max_count){ if (id >= 0 && id < working->file_max){
result = working->files + id; result = working->files + id;
} }
} }
return result; return (result);
} }
// TODO(allen): Find a way to choose an ordering for these so it picks better first options. // TODO(allen): Find a way to choose an ordering for these so it picks better first options.
@ -431,19 +437,74 @@ working_set_lookup_file(Working_Set *working_set, String string){
Editing_File *file = working_set_contains(working_set, string); Editing_File *file = working_set_contains(working_set, string);
if (!file){ if (!file){
i32 file_i; File_Node *node, *used_nodes;
i32 end = working_set->file_index_count; used_nodes = &working_set->used_sentinel;
file = working_set->files; for (dll_items(node, used_nodes)){
for (file_i = 0; file_i < end; ++file_i, ++file){ file = (Editing_File*)node;
if (file->name.live_name.str && if (string.size == 0 || has_substr(file->name.live_name, string)){
(string.size == 0 || has_substr(file->name.live_name, string))){
break; break;
} }
} }
if (file_i == end) file = 0; if (node == used_nodes) file = 0;
} }
return file; return (file);
}
struct Get_File_Result{
Editing_File *file;
i32 index;
};
internal Get_File_Result
working_set_get_available_file(Working_Set *working_set){
Get_File_Result result = {};
File_Node *node;
if (working_set->file_count < working_set->file_max){
node = working_set->free_sentinel.next;
Assert(node != &working_set->free_sentinel);
result.file = (Editing_File*)node;
result.index = (i32)(result.file - working_set->files);
++working_set->file_count;
dll_remove(node);
*result.file = {};
dll_insert(&working_set->used_sentinel, node);
}
return result;
}
inline void
working_set_free_file(Working_Set *working_set, Editing_File *file){
file->state.is_dummy = 1;
dll_remove(&file->node);
dll_insert(&working_set->free_sentinel, &file->node);
--working_set->file_count;
}
inline Get_File_Result
working_set_get_file(Working_Set *working_set, i32 id, b32 require_active){
Get_File_Result result = {};
if (id > 0 && id <= working_set->file_max){
result.file = working_set->files + id;
result.index = id;
if (result.file->state.is_dummy && require_active){
result.file = 0;
result.index = 0;
}
}
return(result);
}
inline void
file_set_to_loading(Editing_File *file){
file->state = {};
file->settings = {};
file->state.is_loading = 1;
} }
// BOTTOM // BOTTOM

File diff suppressed because it is too large Load Diff

View File

@ -1461,12 +1461,15 @@ do_live_file_list_box(System_Functions *system, UI_State *state, UI_Layout *layo
Absolutes absolutes; Absolutes absolutes;
get_absolutes(*string, &absolutes, 1, 1); get_absolutes(*string, &absolutes, 1, 1);
i32 count = working_set->file_index_count; Editing_File *file;
Editing_File *files = working_set->files; File_Node *node, *used_nodes;
for (i32 i = 0; i < count; ++i){ i32 i = 0;
Editing_File *file = files + i; used_nodes = &working_set->used_sentinel;
for (dll_items(node, used_nodes)){
file = (Editing_File*)node;
Assert(!file->state.is_dummy);
if (!file->state.is_dummy){
String message = message_nothing; String message = message_nothing;
switch (buffer_get_sync(file)){ switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_BEHIND_OS: message = message_unsynced; break;
@ -1481,7 +1484,8 @@ do_live_file_list_box(System_Functions *system, UI_State *state, UI_Layout *layo
terminate_with_null(string); terminate_with_null(string);
} }
} }
}
++i;
} }
} }

View File

@ -1032,7 +1032,7 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid
} }
} }
cursor_seek_step_end: cursor_seek_step_end:
state->cursor = cursor; state->cursor = cursor;
state->prev_cursor = prev_cursor; state->prev_cursor = prev_cursor;
return(result); return(result);
@ -1053,8 +1053,21 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
state.cursor = cursor; state.cursor = cursor;
if (advance_data){ switch(seek.type){
case buffer_seek_pos:
if (cursor.pos >= seek.pos) goto buffer_cursor_seek_end;
case buffer_seek_wrapped_xy:
if (seek.x == 0 && cursor.wrapped_y >= seek.y) goto buffer_cursor_seek_end;
case buffer_seek_unwrapped_xy:
if (seek.x == 0 && cursor.unwrapped_y >= seek.y) goto buffer_cursor_seek_end;
case buffer_seek_line_char:
if (cursor.line >= seek.line && cursor.character >= seek.character) goto buffer_cursor_seek_end;
}
if (advance_data){
size = buffer_size(buffer); size = buffer_size(buffer);
xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy); xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy);
@ -1076,7 +1089,6 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
font_height, advance_data, size, 0); font_height, advance_data, size, 0);
assert_4tech(result == 0); assert_4tech(result == 0);
} }
} }
buffer_cursor_seek_end: buffer_cursor_seek_end:

View File

@ -9,8 +9,10 @@ SET STUFF=/GR- /nologo
SET DEBUG=/Zi SET DEBUG=/Zi
SET EXPORTS=/EXPORT:get_bindings SET EXPORTS=/EXPORT:get_bindings
SET SRC=4coder_custom.cpp SET SRC=4coder_custom.cpp
REM SET LINKS=user32.lib gdi32.lib
SET LINKS=
cl %WARNINGS% %STUFF% %DEBUG% %SRC% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS% cl %WARNINGS% %STUFF% %DEBUG% %SRC% %LINKS% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS%
REM file spammation preventation REM file spammation preventation
del *.exp del *.exp