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,43 +33,49 @@ HOOK_SIG(my_start){
}
HOOK_SIG(my_file_settings){
Buffer_Summary buffer = app->get_active_buffer(app);
// 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;
if (buffer.file_name && buffer.size < (16 << 20)){
String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match(ext, make_lit_string("cpp"))) treat_as_code = 1;
else if (match(ext, make_lit_string("h"))) treat_as_code = 1;
else if (match(ext, make_lit_string("c"))) treat_as_code = 1;
else if (match(ext, make_lit_string("hpp"))) treat_as_code = 1;
}
push_parameter(app, par_lex_as_cpp_file, 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));
exec_command(app, cmdid_set_settings);
}
// 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);
int treat_as_code = 0;
if (buffer.file_name && buffer.size < (16 << 20)){
String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match(ext, make_lit_string("cpp"))) treat_as_code = 1;
else if (match(ext, make_lit_string("h"))) treat_as_code = 1;
else if (match(ext, make_lit_string("c"))) treat_as_code = 1;
else if (match(ext, make_lit_string("hpp"))) treat_as_code = 1;
}
push_parameter(app, par_lex_as_cpp_file, 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));
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){
char text[] = "++";
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);
write_string(app, make_lit_string("++"));
}
CUSTOM_COMMAND_SIG(write_decrement){
char text[] = "--";
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);
write_string(app, make_lit_string("--"));
}
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
@ -137,7 +143,7 @@ CUSTOM_COMMAND_SIG(if0_off){
View_Summary view;
Buffer_Summary buffer;
char text1[] = "#if 0\n";
char text1[] = "\n#if 0";
int size1 = sizeof(text1) - 1;
char text2[] = "#endif\n";
@ -192,8 +198,6 @@ CUSTOM_COMMAND_SIG(switch_to_compilation){
char name[] = "*compilation*";
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);
buffer = app->get_buffer_by_name(app, name, name_size);
@ -446,7 +450,7 @@ CUSTOM_COMMAND_SIG(rewrite_as_single_caps){
// TODO(allen):
// get range by specific "word" type (for example "get token range")
// read range by specific "word" type
// Dream API: for rewrite_as_single_caps
// Dream API for rewrite_as_single_caps:
#if 0
{
rewrite = get_rewrite(app, ByToken);
@ -479,6 +483,8 @@ CUSTOM_COMMAND_SIG(replace_in_range){
with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &replace)) return;
if (replace.string.size == 0) return;
if (!query_user_string(app, &with)) return;
String r, w;
@ -517,6 +523,8 @@ CUSTOM_COMMAND_SIG(query_replace){
with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &replace)) return;
if (replace.string.size == 0) return;
if (!query_user_string(app, &with)) return;
String r, w;
@ -567,11 +575,11 @@ CUSTOM_COMMAND_SIG(query_replace){
CUSTOM_COMMAND_SIG(close_all_code){
String extension;
Buffer_Summary buffer;
int max, i;
max = app->get_buffer_max_index(app);
for (i = 0; i < max; ++i){
buffer = app->get_buffer(app, i);
for (buffer = app->get_buffer_first(app);
buffer.exists;
app->get_buffer_next(app, &buffer)){
extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match(extension, make_lit_string("cpp")) ||
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 = &context_actual;
// 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.
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, 'm', MDFR_ALT, build_search);
bind(context, ',', MDFR_ALT, switch_to_compilation);
bind(context, 'x', MDFR_ALT, execute_arbitrary_command);
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_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_semicolon);
bind(context, '}', MDFR_CTRL, open_long_braces_break);
@ -1039,7 +1051,7 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
end_map(context);
end_bind_helper(context);
return context->write_total;

View File

@ -342,9 +342,12 @@ struct Application_Links;
#define FREE_FILE_LIST_SIG(name) void name(Application_Links *app, File_List list)
// 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_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 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)
// 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_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);
// 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_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 REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
@ -411,7 +419,9 @@ extern "C"{
typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function);
// 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_ACTIVE_VIEW_SIG(Get_Active_View_Function);
@ -448,9 +458,12 @@ struct Application_Links{
Free_File_List_Function *free_file_list;
// 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_Active_Buffer_Function *get_active_buffer;
Get_Parameter_Buffer_Function *get_parameter_buffer;
Get_Buffer_By_Name_Function *get_buffer_by_name;
Refresh_Buffer_Function *refresh_buffer;
@ -461,7 +474,9 @@ struct Application_Links{
Buffer_Set_Pos_Function *buffer_set_pos;
// 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_Active_View_Function *get_active_view;

740
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];
i32 *buffer_param_indices;
i32 buffer_param_count, buffer_param_max;
Font_Set *font_set;
Style_Font global_font;
Style style;

View File

@ -92,14 +92,13 @@ struct Text_Effect{
// file is still streaming in, and all operations except for the
// initial allocation of the file.
struct Editing_File_Settings{
Font_Set *set;
i32 base_map_id;
i32 dos_write_mode;
b32 unwrapped_lines;
b8 tokens_exist;
b8 super_locked;
b8 is_initialized;
b8 unimportant;
b8 read_only;
};
// NOTE(allen): This part of the Editing_File is cleared whenever
@ -142,7 +141,12 @@ struct Editing_File_Name{
String extension;
};
struct File_Node{
File_Node *next, *prev;
};
struct Editing_File{
File_Node node;
Editing_File_Settings settings;
union{
Editing_File_State state;
@ -237,7 +241,9 @@ table_remove(File_Table *table, String name){
struct Working_Set{
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;
@ -418,11 +424,11 @@ working_set_contains(Working_Set *working, String filename){
Editing_File *result = 0;
i32 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;
}
}
return result;
return (result);
}
// 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);
if (!file){
i32 file_i;
i32 end = working_set->file_index_count;
file = working_set->files;
for (file_i = 0; file_i < end; ++file_i, ++file){
if (file->name.live_name.str &&
(string.size == 0 || has_substr(file->name.live_name, string))){
break;
}
}
if (file_i == end) file = 0;
File_Node *node, *used_nodes;
used_nodes = &working_set->used_sentinel;
for (dll_items(node, used_nodes)){
file = (Editing_File*)node;
if (string.size == 0 || has_substr(file->name.live_name, string)){
break;
}
}
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

File diff suppressed because it is too large Load Diff

View File

@ -1461,27 +1461,31 @@ do_live_file_list_box(System_Functions *system, UI_State *state, UI_Layout *layo
Absolutes absolutes;
get_absolutes(*string, &absolutes, 1, 1);
i32 count = working_set->file_index_count;
Editing_File *files = working_set->files;
for (i32 i = 0; i < count; ++i){
Editing_File *file = files + i;
Editing_File *file;
File_Node *node, *used_nodes;
i32 i = 0;
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;
switch (buffer_get_sync(file)){
String message = message_nothing;
switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break;
}
if (filename_match(*string, &absolutes, file->name.live_name, 1)){
if (do_file_option(100+i, state, layout, file->name.live_name, 0, message, system->slash)){
result = 1;
*selected = 1;
copy(string, file->name.source_path);
terminate_with_null(string);
}
}
if (filename_match(*string, &absolutes, file->name.live_name, 1)){
if (do_file_option(100+i, state, layout, file->name.live_name, 0, message, system->slash)){
result = 1;
*selected = 1;
copy(string, file->name.source_path);
terminate_with_null(string);
}
}
++i;
}
}

View File

@ -934,19 +934,19 @@ typedef struct Seek_State{
internal_4tech int
cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width,
float font_height, float *advances, int size, char ch){
float font_height, float *advances, int size, char ch){
Full_Cursor cursor, prev_cursor;
float ch_width;
int result;
float x, px, y;
cursor = state->cursor;
prev_cursor = state->prev_cursor;
result = 1;
prev_cursor = cursor;
switch (ch){
case '\n':
case '\n':
++cursor.line;
cursor.unwrapped_y += font_height;
cursor.wrapped_y += font_height;
@ -954,51 +954,51 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid
cursor.unwrapped_x = 0;
cursor.wrapped_x = 0;
break;
default:
default:
++cursor.character;
if (ch == '\r') ch_width = *(float*)(advances + '\\') + *(float*)(advances + 'r');
else ch_width = *(float*)(advances + ch);
if (cursor.wrapped_x + ch_width >= max_width){
cursor.wrapped_y += font_height;
cursor.wrapped_x = 0;
prev_cursor = cursor;
}
cursor.unwrapped_x += ch_width;
cursor.wrapped_x += ch_width;
break;
}
++cursor.pos;
if (cursor.pos > size){
cursor = prev_cursor;
result = 0;
goto cursor_seek_step_end;
}
x = y = px = 0;
switch (seek.type){
case buffer_seek_pos:
case buffer_seek_pos:
if (cursor.pos > seek.pos){
cursor = prev_cursor;
result = 0;
goto cursor_seek_step_end;
}break;
case buffer_seek_wrapped_xy:
case buffer_seek_wrapped_xy:
x = cursor.wrapped_x; px = prev_cursor.wrapped_x;
y = cursor.wrapped_y; break;
case buffer_seek_unwrapped_xy:
case buffer_seek_unwrapped_xy:
x = cursor.unwrapped_x; px = prev_cursor.unwrapped_x;
y = cursor.unwrapped_y; break;
case buffer_seek_line_char:
case buffer_seek_line_char:
if (cursor.line == seek.line && cursor.character >= seek.character){
result = 0;
goto cursor_seek_step_end;
@ -1009,21 +1009,21 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid
goto cursor_seek_step_end;
}break;
}
if (xy_seek){
if (y > seek.y){
cursor = prev_cursor;
result = 0;
goto cursor_seek_step_end;
}
if (y > seek.y - font_height && x >= seek.x){
if (!seek.round_down){
if (ch != '\n' && (seek.x - px) < (x - seek.x)) cursor = prev_cursor;
result = 0;
goto cursor_seek_step_end;
}
if (x > seek.x){
cursor = prev_cursor;
result = 0;
@ -1031,8 +1031,8 @@ 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->prev_cursor = prev_cursor;
return(result);
@ -1053,8 +1053,21 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
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);
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);
assert_4tech(result == 0);
}
}
buffer_cursor_seek_end:

View File

@ -9,8 +9,10 @@ SET STUFF=/GR- /nologo
SET DEBUG=/Zi
SET EXPORTS=/EXPORT:get_bindings
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
del *.exp