diff --git a/4coder_custom.h b/4coder_custom.h index bb5d7455..235013cb 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -368,6 +368,9 @@ extern "C"{ struct Application_Links; +#include "4coder_custom_api.h" + +#if 0 // Command exectuion #define PUSH_PARAMETER_SIG(n) void n(Application_Links *app, Dynamic param, Dynamic value) #define PUSH_MEMORY_SIG(n) char* n(Application_Links *app, int len) @@ -432,30 +435,6 @@ struct Application_Links; #define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int len) #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int count) - - -// Boundry type flags -#define BoundryWhitespace 0x1 -#define BoundryToken 0x2 -#define BoundryAlphanumeric 0x4 -#define BoundryCamelCase 0x8 - - - -// Input type flags -#define EventOnAnyKey 0x1 -#define EventOnEsc 0x2 -#define EventOnLeftButton 0x4 -#define EventOnRightButton 0x8 -#define EventOnWheel 0x10 -#define EventOnButton (EventOnLeftButton | EventOnRightButton | EventOnWheel) - -// NOTE(allen): These don't work so much, so let's pretend they're not here for now. -#define EventOnMouseMove 0x20 -#define EventOnMouse (EventOnButton | EventOnMouseMove) - - - extern "C"{ // Command exectuion typedef EXECUTE_COMMAND_SIG(Exec_Command_Function); @@ -597,6 +576,31 @@ struct Application_Links{ void *current_coroutine; int type_coroutine; }; +#endif + + + +// Boundry type flags +#define BoundryWhitespace 0x1 +#define BoundryToken 0x2 +#define BoundryAlphanumeric 0x4 +#define BoundryCamelCase 0x8 + + + +// Input type flags +#define EventOnAnyKey 0x1 +#define EventOnEsc 0x2 +#define EventOnLeftButton 0x4 +#define EventOnRightButton 0x8 +#define EventOnWheel 0x10 +#define EventOnButton (EventOnLeftButton | EventOnRightButton | EventOnWheel) + +// NOTE(allen): These don't work so much, so let's pretend they're not here for now. +#define EventOnMouseMove 0x20 +#define EventOnMouse (EventOnButton | EventOnMouseMove) + + #define _GET_VERSION_SIG(n) int n(int maj, int min, int patch) typedef _GET_VERSION_SIG(_Get_Version_Function); diff --git a/4coder_custom_api.h b/4coder_custom_api.h new file mode 100644 index 00000000..5903c3df --- /dev/null +++ b/4coder_custom_api.h @@ -0,0 +1,142 @@ +#define PUSH_PARAMETER_SIG(n) void n(Application_Links *app, Dynamic param, Dynamic value) +#define PUSH_MEMORY_SIG(n) char* n(Application_Links *app, int len) +#define EXEC_COMMAND_KEEP_STACK_SIG(n) void n(Application_Links *app, int command_id) +#define CLEAR_PARAMETERS_SIG(n) void n(Application_Links *app) +#define DIRECTORY_GET_HOT_SIG(n) int n(Application_Links *app, char *out, int capacity) +#define GET_4ED_PATH_SIG(n) int n(Application_Links *app, char *out, int capacity) +#define FILE_EXISTS_SIG(n) int n(Application_Links *app, char *filename, int len) +#define DIRECTORY_CD_SIG(n) int n(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len) +#define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int len) +#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list) +#define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app) +#define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer) +#define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int index) +#define GET_ACTIVE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app) +#define GET_PARAMETER_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int param_index) +#define GET_BUFFER_BY_NAME_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int len) +#define BUFFER_SEEK_DELIMITER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out) +#define BUFFER_SEEK_STRING_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) +#define BUFFER_SEEK_STRING_INSENSITIVE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) +#define REFRESH_BUFFER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer) +#define BUFFER_READ_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) +#define BUFFER_REPLACE_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) +#define BUFFER_SET_POS_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int pos) +#define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app) +#define GET_VIEW_NEXT_SIG(n) void n(Application_Links *app, View_Summary *view) +#define GET_VIEW_SIG(n) View_Summary n(Application_Links *app, int index) +#define GET_ACTIVE_VIEW_SIG(n) View_Summary n(Application_Links *app) +#define REFRESH_VIEW_SIG(n) int n(Application_Links *app, View_Summary *view) +#define VIEW_COMPUTE_CURSOR_SIG(n) Full_Cursor n(Application_Links *app, View_Summary *view, Buffer_Seek seek) +#define VIEW_SET_CURSOR_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x) +#define VIEW_SET_MARK_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek) +#define VIEW_SET_HIGHLIGHT_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int turn_on) +#define VIEW_SET_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, int buffer_id) +#define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, unsigned int get_type, unsigned int abort_type) +#define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app) +#define GET_EVENT_MESSAGE_SIG(n) Event_Message n(Application_Links *app) +#define START_QUERY_BAR_SIG(n) int n(Application_Links *app, Query_Bar *bar, unsigned int flags) +#define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, unsigned int flags) +#define PRINT_MESSAGE_SIG(n) void n(Application_Links *app, char *string, int len) +#define GET_GUI_FUNCTIONS_SIG(n) GUI_Functions* n(Application_Links *app) +#define GET_GUI_SIG(n) GUI* n(Application_Links *app, int view_id) +#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int len) +#define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int len) +#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int count) +extern "C"{ + typedef PUSH_PARAMETER_SIG(Push_Parameter_Function); + typedef PUSH_MEMORY_SIG(Push_Memory_Function); + typedef EXEC_COMMAND_KEEP_STACK_SIG(Exec_Command_Keep_Stack_Function); + typedef CLEAR_PARAMETERS_SIG(Clear_Parameters_Function); + typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function); + typedef GET_4ED_PATH_SIG(Get_4ed_Path_Function); + typedef FILE_EXISTS_SIG(File_Exists_Function); + typedef DIRECTORY_CD_SIG(Directory_CD_Function); + typedef GET_FILE_LIST_SIG(Get_File_List_Function); + typedef FREE_FILE_LIST_SIG(Free_File_List_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_SIG(Get_Buffer_By_Name_Function); + typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function); + typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function); + typedef BUFFER_SEEK_STRING_INSENSITIVE_SIG(Buffer_Seek_String_Insensitive_Function); + typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function); + typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function); + typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function); + typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_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); + typedef REFRESH_VIEW_SIG(Refresh_View_Function); + typedef VIEW_COMPUTE_CURSOR_SIG(View_Compute_Cursor_Function); + typedef VIEW_SET_CURSOR_SIG(View_Set_Cursor_Function); + typedef VIEW_SET_MARK_SIG(View_Set_Mark_Function); + typedef VIEW_SET_HIGHLIGHT_SIG(View_Set_Highlight_Function); + typedef VIEW_SET_BUFFER_SIG(View_Set_Buffer_Function); + typedef GET_USER_INPUT_SIG(Get_User_Input_Function); + typedef GET_COMMAND_INPUT_SIG(Get_Command_Input_Function); + typedef GET_EVENT_MESSAGE_SIG(Get_Event_Message_Function); + typedef START_QUERY_BAR_SIG(Start_Query_Bar_Function); + typedef END_QUERY_BAR_SIG(End_Query_Bar_Function); + typedef PRINT_MESSAGE_SIG(Print_Message_Function); + typedef GET_GUI_FUNCTIONS_SIG(Get_GUI_Functions_Function); + typedef GET_GUI_SIG(Get_GUI_Function); + typedef CHANGE_THEME_SIG(Change_Theme_Function); + typedef CHANGE_FONT_SIG(Change_Font_Function); + typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function); +} +struct Application_Links{ + void *memory; + int memory_size; + Push_Parameter_Function *push_parameter; + Push_Memory_Function *push_memory; + Exec_Command_Keep_Stack_Function *exec_command_keep_stack; + Clear_Parameters_Function *clear_parameters; + Directory_Get_Hot_Function *directory_get_hot; + Get_4ed_Path_Function *get_4ed_path; + File_Exists_Function *file_exists; + Directory_CD_Function *directory_cd; + Get_File_List_Function *get_file_list; + Free_File_List_Function *free_file_list; + 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; + Buffer_Seek_Delimiter_Function *buffer_seek_delimiter; + Buffer_Seek_String_Function *buffer_seek_string; + Buffer_Seek_String_Insensitive_Function *buffer_seek_string_insensitive; + Refresh_Buffer_Function *refresh_buffer; + Buffer_Read_Range_Function *buffer_read_range; + Buffer_Replace_Range_Function *buffer_replace_range; + Buffer_Set_Pos_Function *buffer_set_pos; + 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; + Refresh_View_Function *refresh_view; + View_Compute_Cursor_Function *view_compute_cursor; + View_Set_Cursor_Function *view_set_cursor; + View_Set_Mark_Function *view_set_mark; + View_Set_Highlight_Function *view_set_highlight; + View_Set_Buffer_Function *view_set_buffer; + Get_User_Input_Function *get_user_input; + Get_Command_Input_Function *get_command_input; + Get_Event_Message_Function *get_event_message; + Start_Query_Bar_Function *start_query_bar; + End_Query_Bar_Function *end_query_bar; + Print_Message_Function *print_message; + Get_GUI_Functions_Function *get_gui_functions; + Get_GUI_Function *get_gui; + Change_Theme_Function *change_theme; + Change_Font_Function *change_font; + Set_Theme_Colors_Function *set_theme_colors; + void *cmd_context; + void *system_links; + void *current_coroutine; + int type_coroutine; +}; diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 6d9e6d2a..80919503 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -27,19 +27,6 @@ CUSTOM_COMMAND_SIG(write_zero_struct){ write_string(app, make_lit_string(" = {0};")); } -CUSTOM_COMMAND_SIG(write_h){ - write_string(app, make_lit_string("
")); -} - -CUSTOM_COMMAND_SIG(write_div){ - write_string(app, make_lit_string("")); -} - -CUSTOM_COMMAND_SIG(begin_html_mode){ - push_parameter(app, par_key_mapid, my_empty_map1); - exec_command(app, cmdid_set_settings); -} - CUSTOM_COMMAND_SIG(write_capital){ User_Input command_in = app->get_command_input(app); char c = command_in.key.character_no_caps_lock; @@ -103,25 +90,29 @@ CUSTOM_COMMAND_SIG(move_down_10){ CUSTOM_COMMAND_SIG(rewrite_as_single_caps){ View_Summary view; Buffer_Summary buffer; + Full_Cursor cursor; Range range; String string; int is_first, i; - - exec_command(app, seek_token_left); + view = app->get_active_view(app); + cursor = view.cursor; + + exec_command(app, seek_token_left); + app->refresh_view(app, &view); range.min = view.cursor.pos; - + exec_command(app, seek_token_right); app->refresh_view(app, &view); range.max = view.cursor.pos; - + string.str = (char*)app->memory; string.size = range.max - range.min; assert(string.size < app->memory_size); buffer = app->get_buffer(app, view.buffer_id); app->buffer_read_range(app, &buffer, range.min, range.max, string.str); - + is_first = 1; for (i = 0; i < string.size; ++i){ if (char_is_alpha_true(string.str[i])){ @@ -132,8 +123,12 @@ CUSTOM_COMMAND_SIG(rewrite_as_single_caps){ is_first = 1; } } - + app->buffer_replace_range(app, &buffer, range.min, range.max, string.str, string.size); + + app->view_set_cursor(app, &view, + seek_line_char(cursor.line+1, cursor.character), + 1); } CUSTOM_COMMAND_SIG(open_my_files){ @@ -300,13 +295,6 @@ default_keys(Bind_Helper *context){ end_map(context); - - begin_map(context, my_html_map); - inherit_map(context, mapid_file); - bind(context, 'h', MDFR_ALT, write_h); - bind(context, 'd', MDFR_ALT, write_div); - end_map(context); - begin_map(context, my_empty_map1); inherit_map(context, mapid_nomap); end_map(context); @@ -406,6 +394,7 @@ default_keys(Bind_Helper *context){ bind(context, 's', MDFR_ALT, cmdid_show_scrollbar); bind(context, 's', MDFR_CTRL, cmdid_save); bind(context, 'u', MDFR_CTRL, cmdid_to_uppercase); + bind(context, 'U', MDFR_CTRL, rewrite_as_single_caps); bind(context, 'v', MDFR_CTRL, cmdid_paste); bind(context, 'V', MDFR_CTRL, cmdid_paste_next); bind(context, 'w', MDFR_ALT, cmdid_hide_scrollbar); diff --git a/4ed.cpp b/4ed.cpp index 6fdb4252..2cd65d03 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1891,7 +1891,7 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_ } extern "C"{ - EXECUTE_COMMAND_SIG(external_exec_command_keep_stack){ + EXEC_COMMAND_KEEP_STACK_SIG(external_exec_command_keep_stack){ Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Function function = command_table[command_id]; Command_Binding binding = {}; @@ -2022,7 +2022,7 @@ extern "C"{ return(buffer); } - GET_BUFFER_BY_NAME(external_get_buffer_by_name){ + GET_BUFFER_BY_NAME_SIG(external_get_buffer_by_name){ Command_Data *cmd = (Command_Data*)app->cmd_context; Buffer_Summary buffer = {}; Editing_File *file; diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 6232abaf..8ed6c967 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -60,6 +60,7 @@ void to_camel(char *src, char *dst){ #include