diff --git a/4coder_custom.h b/4coder_custom.h index 80c30359..70a6a859 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -10,6 +10,11 @@ #include "4coder_buffer_types.h" #include "4coder_gui.h" +#define MDFR_NONE 0x0 +#define MDFR_CTRL 0x1 +#define MDFR_ALT 0x2 +#define MDFR_SHIFT 0x4 + #ifndef FRED_STRING_STRUCT #define FRED_STRING_STRUCT typedef struct String{ @@ -40,7 +45,6 @@ typedef struct Key_Event_Data{ Code keycode; Code character; Code character_no_caps_lock; - char modifiers[MDFR_INDEX_COUNT]; } Key_Event_Data; inline Key_Event_Data @@ -58,7 +62,6 @@ typedef struct Mouse_State{ int x, y; } Mouse_State; - typedef union Range{ struct{ int min, max; @@ -83,72 +86,6 @@ make_range(int p1, int p2){ } -typedef enum Dynamic_Type{ - dynamic_type_int, - dynamic_type_string, - // never below this - dynamic_type_count -} Dynamic_Type; - -typedef struct Dynamic{ - int type; - union{ - struct{ - int str_len; - char *str_value; - }; - int int_value; - }; -} Dynamic; - -inline Dynamic -dynamic_int(int x){ - Dynamic result; - result.type = dynamic_type_int; - result.int_value = x; - return result; -} - -inline Dynamic -dynamic_string(const char *string, int len){ - Dynamic result; - result.type = dynamic_type_string; - result.str_len = len; - result.str_value = (char*)(string); - return result; -} - -inline int -dynamic_to_int(Dynamic *dynamic){ - int result = 0; - if (dynamic->type == dynamic_type_int){ - result = dynamic->int_value; - } - return result; -} - -inline char* -dynamic_to_string(Dynamic *dynamic, int *len){ - char *result = 0; - if (dynamic->type == dynamic_type_string){ - result = dynamic->str_value; - *len = dynamic->str_len; - } - return result; -} - -inline int -dynamic_to_bool(Dynamic *dynamic){ - int result = 0; - if (dynamic->type == dynamic_type_int){ - result = (dynamic->int_value != 0); - } - else{ - result = 1; - } - return result; -} - typedef struct File_Info{ String filename; int folder; @@ -166,17 +103,18 @@ typedef struct File_List{ int block_size; } File_List; -#define MDFR_NONE 0x0 -#define MDFR_CTRL 0x1 -#define MDFR_ALT 0x2 -#define MDFR_SHIFT 0x4 +// NOTE(allen|a4.0.7): This is used to identify which buffer +// an operation should work on when you might want to +// identify it by id or by name. +typedef struct Buffer_Identifier{ + char *name; + int name_len; + int id; +} Buffer_Identifier; enum Command_ID{ cmdid_null, - cmdid_seek_left, - cmdid_seek_right, - cmdid_center_view, cmdid_left_adjust_view, @@ -196,6 +134,7 @@ enum Command_ID{ cmdid_interactive_open, cmdid_reopen, cmdid_save, + cmdid_save_as, cmdid_interactive_switch_buffer, cmdid_interactive_kill_buffer, cmdid_kill_buffer, @@ -207,7 +146,6 @@ enum Command_ID{ cmdid_toggle_show_whitespace, cmdid_clean_all_lines, - cmdid_auto_tab_range, cmdid_eol_dosify, cmdid_eol_nixify, @@ -227,36 +165,26 @@ enum Command_ID{ cmdid_hide_scrollbar, cmdid_show_scrollbar, - cmdid_set_settings, - - cmdid_command_line, // cmdid_count }; -enum Param_ID{ - par_range_start, - par_range_end, - par_name, - par_buffer_id, - par_do_in_background, - par_flags, - par_lex_as_cpp_file, - par_wrap_lines, - par_key_mapid, - par_show_whitespace, - par_cli_path, - par_cli_command, - par_clear_blank_lines, - par_use_tabs, - par_save_update_name, - - // never below this - par_type_count +enum{ + CLI_OverlapWithConflict = 0x1, + CLI_AlwaysBindToView = 0x2, }; -#define CLI_OverlapWithConflict 0x1 -#define CLI_AlwaysBindToView 0x2 +enum{ + BufferSetting_Null, + BufferSetting_Lex, + BufferSetting_WrapLine, + BufferSetting_MapID, +}; + +enum{ + AutoTab_ClearLine = 0x1, + AutoTab_UseTab = 0x2 +}; // These are regular hooks, any of them can be set to any function // that matches the HOOK_SIG pattern. diff --git a/4coder_custom_api.h b/4coder_custom_api.h index f0468850..26763c67 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -1,7 +1,5 @@ -#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 EXEC_COMMAND_SIG(n) void n(Application_Links *app, int command_id) +#define EXEC_SYSTEM_COMMAND_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int path_len, char *command, int command_len, unsigned int flags) #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) @@ -16,17 +14,21 @@ #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 BUFFER_SEEK_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start_pos, int seek_forward, unsigned int flags) +#define BUFFER_SET_SETTING_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int setting, int value) #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_AUTO_TAB_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int tab_width, unsigned int flags) #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 VIEW_OPEN_FILE_SIG(n) int n(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background) +#define VIEW_KILL_FILE_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer) #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) @@ -34,16 +36,12 @@ #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 EXEC_COMMAND_SIG(Exec_Command_Function); + typedef EXEC_SYSTEM_COMMAND_SIG(Exec_System_Command_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); @@ -58,17 +56,21 @@ extern "C"{ 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 BUFFER_SEEK_SIG(Buffer_Seek_Function); + typedef BUFFER_SET_SETTING_SIG(Buffer_Set_Setting_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_AUTO_TAB_SIG(View_Auto_Tab_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 VIEW_OPEN_FILE_SIG(View_Open_File_Function); + typedef VIEW_KILL_FILE_SIG(View_Kill_File_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); @@ -76,8 +78,6 @@ extern "C"{ 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); @@ -85,10 +85,8 @@ extern "C"{ 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; + Exec_Command_Function *exec_command; + Exec_System_Command_Function *exec_system_command; Directory_Get_Hot_Function *directory_get_hot; Get_4ed_Path_Function *get_4ed_path; File_Exists_Function *file_exists; @@ -103,17 +101,21 @@ struct Application_Links{ 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; + Buffer_Seek_Function *buffer_seek; + Buffer_Set_Setting_Function *buffer_set_setting; 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_Auto_Tab_Function *view_auto_tab; 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; + View_Open_File_Function *view_open_file; + View_Kill_File_Function *view_kill_file; Get_User_Input_Function *get_user_input; Get_Command_Input_Function *get_command_input; Get_Event_Message_Function *get_event_message; @@ -121,8 +123,6 @@ struct Application_Links{ 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; @@ -131,3 +131,45 @@ struct Application_Links{ void *current_coroutine; int type_coroutine; }; +#define FillAppLinksAPI(app_links) do{\ +app_links->exec_command = external_exec_command;\ +app_links->exec_system_command = external_exec_system_command;\ +app_links->directory_get_hot = external_directory_get_hot;\ +app_links->get_4ed_path = external_get_4ed_path;\ +app_links->file_exists = external_file_exists;\ +app_links->directory_cd = external_directory_cd;\ +app_links->get_file_list = external_get_file_list;\ +app_links->free_file_list = external_free_file_list;\ +app_links->get_buffer_first = external_get_buffer_first;\ +app_links->get_buffer_next = external_get_buffer_next;\ +app_links->get_buffer = external_get_buffer;\ +app_links->get_parameter_buffer = external_get_parameter_buffer;\ +app_links->get_buffer_by_name = external_get_buffer_by_name;\ +app_links->refresh_buffer = external_refresh_buffer;\ +app_links->buffer_read_range = external_buffer_read_range;\ +app_links->buffer_replace_range = external_buffer_replace_range;\ +app_links->buffer_seek = external_buffer_seek;\ +app_links->buffer_set_setting = external_buffer_set_setting;\ +app_links->get_view_first = external_get_view_first;\ +app_links->get_view_next = external_get_view_next;\ +app_links->get_view = external_get_view;\ +app_links->get_active_view = external_get_active_view;\ +app_links->refresh_view = external_refresh_view;\ +app_links->view_auto_tab = external_view_auto_tab;\ +app_links->view_compute_cursor = external_view_compute_cursor;\ +app_links->view_set_cursor = external_view_set_cursor;\ +app_links->view_set_mark = external_view_set_mark;\ +app_links->view_set_highlight = external_view_set_highlight;\ +app_links->view_set_buffer = external_view_set_buffer;\ +app_links->view_open_file = external_view_open_file;\ +app_links->view_kill_file = external_view_kill_file;\ +app_links->get_user_input = external_get_user_input;\ +app_links->get_command_input = external_get_command_input;\ +app_links->get_event_message = external_get_event_message;\ +app_links->get_mouse_state = external_get_mouse_state;\ +app_links->start_query_bar = external_start_query_bar;\ +app_links->end_query_bar = external_end_query_bar;\ +app_links->print_message = external_print_message;\ +app_links->change_theme = external_change_theme;\ +app_links->change_font = external_change_font;\ +app_links->set_theme_colors = external_set_theme_colors; } while(false) diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index fbd95755..e2a8559f 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -94,78 +94,21 @@ CUSTOM_COMMAND_SIG(rewrite_as_single_caps){ } CUSTOM_COMMAND_SIG(open_my_files){ - // NOTE(allen|a3.1): EXAMPLE probably not useful in practice. - // - // The command cmdid_interactive_open can now open - // a file specified on the parameter stack. If the file does not exist - // cmdid_interactive_open behaves as usual. If par_do_in_background - // is set to true the command is prevented from changing the view under - // any circumstance. - push_parameter(app, par_name, literal("w:/4ed/data/test/basic.cpp")); - exec_command(app, cmdid_interactive_open); - -#if 0 - exec_command(app, cmdid_change_active_panel); - - char my_file[256]; - int my_file_len; - - my_file_len = sizeof("w:/4ed/data/test/basic.txt") - 1; - for (int i = 0; i < my_file_len; ++i){ - my_file[i] = ("w:/4ed/data/test/basic.txt")[i]; - } - - // NOTE(allen|a3.1): null terminators are not needed for strings. - push_parameter(app, par_name, my_file, my_file_len); - exec_command(app, cmdid_interactive_open); - - exec_command(app, cmdid_change_active_panel); -#endif + // TODO(allen|a4.0.8): comment + View_Summary view = app->get_active_view(app); + app->view_open_file(app, &view, literal("w:/4ed/data/test/basic.cpp"), false); } CUSTOM_COMMAND_SIG(build_at_launch_location){ - // NOTE(allen|a3.3): EXAMPLE probably not all that useful in practice. - // - // An example of calling build by setting all - // parameters directly. This only works if build.bat can be called - // from the directory the application is launched at. - push_parameter(app, par_flags, CLI_OverlapWithConflict); - push_parameter(app, par_name, literal("*compilation*")); - push_parameter(app, par_cli_path, literal(".")); - push_parameter(app, par_cli_command, literal("build")); - exec_command(app, cmdid_command_line); + // TODO(allen|a4.0.8): comment + View_Summary view = app->get_active_view(app); + app->exec_system_command(app, &view, + buffer_identifier(literal("*compilation*")), + literal("."), + literal("build"), + CLI_OverlapWithConflict); } -#if 0 -// NOTE(allen|a4) See 4coder_styles.h for a list of available style tags. -// There are style tags corresponding to every color in the theme editor. -CUSTOM_COMMAND_SIG(improve_theme){ - Theme_Color colors[] = { - {Stag_Bar, 0xFF0088}, - {Stag_Margin, 0x880088}, - {Stag_Margin_Hover, 0xAA0088}, - {Stag_Margin_Active, 0xDD0088}, - {Stag_Cursor, 0xFF0000}, - }; - int count = ArrayCount(colors); - - app->set_theme_colors(app, colors, count); -} - -CUSTOM_COMMAND_SIG(ruin_theme){ - Theme_Color colors[] = { - {Stag_Bar, 0x888888}, - {Stag_Margin, 0x181818}, - {Stag_Margin_Hover, 0x252525}, - {Stag_Margin_Active, 0x323232}, - {Stag_Cursor, 0x00EE00}, - }; - int count = ArrayCount(colors); - - app->set_theme_colors(app, colors, count); -} -#endif - HOOK_SIG(my_start){ exec_command(app, cmdid_open_panel_vsplit); exec_command(app, cmdid_change_active_panel); @@ -220,12 +163,11 @@ HOOK_SIG(my_file_settings){ // NOTE(allen|a4.0.5): Unlike previous versions the command cmdid_set_settings // no longer automatically effects the active buffer. This command will actually be // phased out in favor of an app call soon. - push_parameter(app, par_buffer_id, buffer.buffer_id); - push_parameter(app, par_lex_as_cpp_file, treat_as_code); - push_parameter(app, par_wrap_lines, wrap_lines); - push_parameter(app, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file)); - exec_command(app, cmdid_set_settings); + // TODO(allen): also eliminate this hook if you can. + app->buffer_set_setting(app, &buffer, BufferSetting_Lex, treat_as_code); + app->buffer_set_setting(app, &buffer, BufferSetting_WrapLine, wrap_lines); + app->buffer_set_setting(app, &buffer, BufferSetting_MapID, (treat_as_code)?((int)my_code_map):((int)mapid_file)); // no meaning for return return(0); @@ -292,7 +234,7 @@ default_keys(Bind_Helper *context){ bind(context, '#', MDFR_NONE, write_and_auto_tab); bind(context, '\t', MDFR_NONE, cmdid_word_complete); - bind(context, '\t', MDFR_CTRL, cmdid_auto_tab_range); + bind(context, '\t', MDFR_CTRL, auto_tab_range); bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); bind(context, '=', MDFR_CTRL, write_increment); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index ed8828de..2307e9bd 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -443,24 +443,32 @@ CUSTOM_COMMAND_SIG(seek_beginning_of_line){ } static void -basic_seek(Application_Links *app, Command_ID seek_type, unsigned int flags){ - push_parameter(app, par_flags, flags); - exec_command(app, seek_type); +basic_seek(Application_Links *app, int seek_type, unsigned int flags){ + View_Summary view = app->get_active_view(app); + Buffer_Summary buffer = app->get_buffer(app, view.locked_buffer_id); + int pos = app->buffer_seek(app, &buffer, view.cursor.pos, seek_type, flags); + app->view_set_cursor(app, &view, seek_pos(pos), true); } #define SEEK_COMMAND(n, dir, flags)\ -CUSTOM_COMMAND_SIG(seek_##n##_##dir){ basic_seek(app, cmdid_seek_##dir, flags); } +CUSTOM_COMMAND_SIG(seek_##n##_##dir){ basic_seek(app, dir, flags); } -SEEK_COMMAND(whitespace, right, BoundryWhitespace) -SEEK_COMMAND(whitespace, left, BoundryWhitespace) -SEEK_COMMAND(token, right, BoundryToken) -SEEK_COMMAND(token, left, BoundryToken) -SEEK_COMMAND(white_or_token, right, BoundryToken | BoundryWhitespace) -SEEK_COMMAND(white_or_token, left, BoundryToken | BoundryWhitespace) -SEEK_COMMAND(alphanumeric, right, BoundryAlphanumeric) -SEEK_COMMAND(alphanumeric, left, BoundryAlphanumeric) +#define right true +#define left false + +SEEK_COMMAND(whitespace, right, BoundryWhitespace) +SEEK_COMMAND(whitespace, left, BoundryWhitespace) +SEEK_COMMAND(token, right, BoundryToken) +SEEK_COMMAND(token, left, BoundryToken) +SEEK_COMMAND(white_or_token, right, BoundryToken | BoundryWhitespace) +SEEK_COMMAND(white_or_token, left, BoundryToken | BoundryWhitespace) +SEEK_COMMAND(alphanumeric, right, BoundryAlphanumeric) +SEEK_COMMAND(alphanumeric, left, BoundryAlphanumeric) SEEK_COMMAND(alphanumeric_or_camel, right, BoundryAlphanumeric | BoundryCamelCase) -SEEK_COMMAND(alphanumeric_or_camel, left, BoundryAlphanumeric | BoundryCamelCase) +SEEK_COMMAND(alphanumeric_or_camel, left, BoundryAlphanumeric | BoundryCamelCase) + +#undef right +#undef left // @@ -479,23 +487,27 @@ CUSTOM_COMMAND_SIG(write_increment){ write_string(app, make_lit_string("++")); } +#ifndef DEF_TAB_WIDTH +# define DEF_TAB_WIDTH 4 +#endif + static void long_braces(Application_Links *app, char *text, int size){ View_Summary view; Buffer_Summary buffer; int pos; - + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); - + pos = view.cursor.pos; app->buffer_replace_range(app, &buffer, pos, pos, text, size); - app->view_set_cursor(app, &view, seek_pos(pos + 2), 1); - - push_parameter(app, par_range_start, pos); - push_parameter(app, par_range_end, pos + size); - push_parameter(app, par_clear_blank_lines, 0); - exec_command(app, cmdid_auto_tab_range); + app->view_set_cursor(app, &view, seek_pos(pos + 2), true); + + app->view_auto_tab(app, &view, + pos, pos + size, + DEF_TAB_WIDTH, + 0); } CUSTOM_COMMAND_SIG(open_long_braces){ @@ -539,9 +551,10 @@ CUSTOM_COMMAND_SIG(if0_off){ app->buffer_replace_range(app, &buffer, pos, pos, text1, size1); - push_parameter(app, par_range_start, pos); - push_parameter(app, par_range_end, pos); - exec_command(app, cmdid_auto_tab_range); + app->view_auto_tab(app, &view, + pos, pos, + DEF_TAB_WIDTH, + 0); app->refresh_view(app, &view); range = get_range(&view); @@ -549,9 +562,10 @@ CUSTOM_COMMAND_SIG(if0_off){ app->buffer_replace_range(app, &buffer, pos, pos, text2, size2); - push_parameter(app, par_range_start, pos); - push_parameter(app, par_range_end, pos); - exec_command(app, cmdid_auto_tab_range); + app->view_auto_tab(app, &view, + pos, pos, + DEF_TAB_WIDTH, + 0); } CUSTOM_COMMAND_SIG(backspace_word){ @@ -592,19 +606,13 @@ CUSTOM_COMMAND_SIG(snipe_token_or_word){ int pos1, pos2; view = app->get_active_view(app); + buffer = app->get_buffer(app, view.buffer_id); - push_parameter(app, par_flags, BoundryToken | BoundryWhitespace); - exec_command(app, cmdid_seek_left); - app->refresh_view(app, &view); - pos1 = view.cursor.pos; + pos1 = app->buffer_seek(app, &buffer, view.cursor.pos, false, BoundryToken | BoundryWhitespace); - push_parameter(app, par_flags, BoundryToken | BoundryWhitespace); - exec_command(app, cmdid_seek_right); - app->refresh_view(app, &view); - pos2 = view.cursor.pos; + pos2 = app->buffer_seek(app, &buffer, pos1, true, BoundryToken | BoundryWhitespace); Range range = make_range(pos1, pos2); - buffer = app->get_buffer(app, view.buffer_id); app->buffer_replace_range(app, &buffer, range.start, range.end, 0, 0); } @@ -636,14 +644,12 @@ CUSTOM_COMMAND_SIG(open_file_in_quotes){ append(&file_name, make_string(short_file_name, size)); exec_command(app, cmdid_change_active_panel); - push_parameter(app, par_name, expand_str(file_name)); - exec_command(app, cmdid_interactive_open); + app->view_open_file(app, &view, expand_str(file_name), false); } } CUSTOM_COMMAND_SIG(save_as){ - push_parameter(app, par_save_update_name, 1); - exec_command(app, cmdid_save); + exec_command(app, cmdid_save_as); } CUSTOM_COMMAND_SIG(goto_line){ @@ -919,9 +925,10 @@ CUSTOM_COMMAND_SIG(close_all_code){ } } + View_Summary view = app->get_active_view(app); + for (int i = 0; i < buffers_to_close_count; ++i){ - push_parameter(app, par_buffer_id, buffers_to_close[i]); - exec_command(app, cmdid_kill_buffer); + app->view_kill_file(app, &view, buffer_identifier(buffers_to_close[i])); } } @@ -953,8 +960,6 @@ CUSTOM_COMMAND_SIG(open_all_code){ // was originally, so that new appends overwrite old ones. dir.size = dir_size; append(&dir, info->filename); - push_parameter(app, par_name, dir.str, dir.size); - //push_parameter(app, par_do_in_background, 1); exec_command(app, cmdid_interactive_open); } } @@ -968,27 +973,32 @@ char out_buffer_space[1024], command_space[1024], hot_directory_space[1024]; CUSTOM_COMMAND_SIG(execute_any_cli){ Query_Bar bar_out, bar_cmd; String hot_directory; - + bar_out.prompt = make_lit_string("Output Buffer: "); bar_out.string = make_fixed_width_string(out_buffer_space); if (!query_user_string(app, &bar_out)) return; - + bar_cmd.prompt = make_lit_string("Command: "); bar_cmd.string = make_fixed_width_string(command_space); if (!query_user_string(app, &bar_cmd)) return; - + hot_directory = make_fixed_width_string(hot_directory_space); hot_directory.size = app->directory_get_hot(app, hot_directory.str, hot_directory.memory_size); - - push_parameter(app, par_flags, CLI_OverlapWithConflict); - push_parameter(app, par_name, bar_out.string.str, bar_out.string.size); - push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size); - push_parameter(app, par_cli_command, bar_cmd.string.str, bar_cmd.string.size); - exec_command(app, cmdid_command_line); + // TODO(allen): provide command line call + View_Summary view = app->get_active_view(app); + + // TODO(allen): Make this work without null terminators terminate_with_null(&bar_out.string); terminate_with_null(&bar_cmd.string); terminate_with_null(&hot_directory); + + app->exec_system_command(app, &view, + buffer_identifier(bar_out.string.str, bar_out.string.size), + hot_directory.str, hot_directory.size, + bar_cmd.string.str, bar_cmd.string.size, + CLI_OverlapWithConflict); + } CUSTOM_COMMAND_SIG(execute_previous_cli){ @@ -999,11 +1009,13 @@ CUSTOM_COMMAND_SIG(execute_previous_cli){ hot_directory = make_string_slowly(hot_directory_space); if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){ - push_parameter(app, par_flags, CLI_OverlapWithConflict); - push_parameter(app, par_name, out_buffer.str, out_buffer.size); - push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size); - push_parameter(app, par_cli_command, cmd.str, cmd.size); - exec_command(app, cmdid_command_line); + View_Summary view = app->get_active_view(app); + + app->exec_system_command(app, &view, + buffer_identifier(out_buffer.str, out_buffer.size), + hot_directory.str, hot_directory.size, + cmd.str, cmd.size, + CLI_OverlapWithConflict); } } @@ -1088,32 +1100,40 @@ CUSTOM_COMMAND_SIG(build_search){ int keep_going = 1; int old_size; - String dir = make_string(app->memory, 0, app->memory_size); + int size = app->memory_size/2; + + String dir = make_string(app->memory, 0, size); dir.size = app->directory_get_hot(app, dir.str, dir.memory_size); - + + String command = make_string((char*)app->memory + size, 0, size); + append(&command, '"'); + while (keep_going){ + append(&command, dir); + old_size = dir.size; append(&dir, "build.bat"); - + if (app->file_exists(app, dir.str, dir.size)){ dir.size = old_size; - - push_parameter(app, par_flags, CLI_OverlapWithConflict); - push_parameter(app, par_name, literal("*compilation*")); - push_parameter(app, par_cli_path, dir.str, dir.size); - - if (append(&dir, "build")){ - push_parameter(app, par_cli_command, dir.str, dir.size); - exec_command(app, cmdid_command_line); - } - else{ - app->clear_parameters(app); - } - + append(&command, "build"); + append(&command, '"'); + + View_Summary view = app->get_active_view(app); + + terminate_with_null(&dir); + terminate_with_null(&command); + + app->exec_system_command(app, &view, + buffer_identifier(literal("*compilation*")), + dir.str, dir.size, + command.str, command.size, + CLI_OverlapWithConflict); + return; } dir.size = old_size; - + if (app->directory_cd(app, dir.str, &dir.size, dir.memory_size, literal("..")) == 0){ keep_going = 0; } @@ -1124,17 +1144,31 @@ CUSTOM_COMMAND_SIG(build_search){ CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){ View_Summary view = app->get_active_view(app); - push_parameter(app, par_range_start, view.cursor.pos); - push_parameter(app, par_range_end, view.cursor.pos); - push_parameter(app, par_clear_blank_lines, 0); - exec_command(app, cmdid_auto_tab_range); + + app->view_auto_tab(app, &view, + view.cursor.pos, view.cursor.pos, + DEF_TAB_WIDTH, + 0); } CUSTOM_COMMAND_SIG(auto_tab_whole_file){ - Buffer_Summary buffer = get_active_buffer(app); - push_parameter(app, par_range_start, 0); - push_parameter(app, par_range_end, buffer.size); - exec_command(app, cmdid_auto_tab_range); + View_Summary view = app->get_active_view(app); + Buffer_Summary buffer = app->get_buffer(app, view.buffer_id); + + app->view_auto_tab(app, &view, + 0, buffer.size, + DEF_TAB_WIDTH, + 0); +} + +CUSTOM_COMMAND_SIG(auto_tab_range){ + View_Summary view = app->get_active_view(app); + Range range = get_range(&view); + + app->view_auto_tab(app, &view, + range.min, range.max, + DEF_TAB_WIDTH, + 0); } CUSTOM_COMMAND_SIG(write_and_auto_tab){ diff --git a/4coder_helper.h b/4coder_helper.h index 54e7960a..f5cefcdb 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -194,40 +194,6 @@ end_bind_helper(Bind_Helper *helper){ return(result); } -// NOTE(allen): Useful functions and overloads on app links -inline void -push_parameter(Application_Links *app, int param, int value){ - app->push_parameter(app, dynamic_int(param), dynamic_int(value)); -} - -inline void -push_parameter(Application_Links *app, int param, const char *value, int value_len){ - char *value_copy = app->push_memory(app, value_len+1); - copy(value_copy, value, value_len); - value_copy[value_len] = 0; - app->push_parameter(app, dynamic_int(param), dynamic_string(value_copy, value_len)); -} - -inline void -push_parameter(Application_Links *app, const char *param, int param_len, int value){ - char *param_copy = app->push_memory(app, param_len+1); - copy(param_copy, param, param_len); - param_copy[param_len] = 0; - app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_int(value)); -} - -inline void -push_parameter(Application_Links *app, const char *param, int param_len, const char *value, int value_len){ - char *param_copy = app->push_memory(app, param_len+1); - char *value_copy = app->push_memory(app, value_len+1); - copy(param_copy, param, param_len); - copy(value_copy, value, value_len); - value_copy[value_len] = 0; - param_copy[param_len] = 0; - - app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_string(value_copy, value_len)); -} - inline Range get_range(View_Summary *view){ Range range; @@ -266,14 +232,12 @@ get_rect(View_Summary *view){ inline void exec_command(Application_Links *app, Command_ID id){ - app->exec_command_keep_stack(app, id); - app->clear_parameters(app); + app->exec_command(app, id); } inline void exec_command(Application_Links *app, Custom_Command_Function *func){ func(app); - app->clear_parameters(app); } inline void @@ -743,4 +707,22 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * } } +inline Buffer_Identifier +buffer_identifier(char *str, int len){ + Buffer_Identifier identifier; + identifier.name = str; + identifier.name_len = len; + identifier.id = 0; + return(identifier); +} + +inline Buffer_Identifier +buffer_identifier(int id){ + Buffer_Identifier identifier; + identifier.name = 0; + identifier.name_len = 0; + identifier.id = id; + return(identifier); +} + diff --git a/4coder_version.h b/4coder_version.h index 1baec73c..9fa0ac48 100644 --- a/4coder_version.h +++ b/4coder_version.h @@ -1,6 +1,6 @@ #define MAJOR 4 #define MINOR 0 -#define PATCH 7 +#define PATCH 8 #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) diff --git a/4ed.cpp b/4ed.cpp index d31e71f5..ff6a974b 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -53,8 +53,6 @@ struct Command_Data{ i32 screen_width, screen_height; Key_Event_Data key; - - Partition part; }; enum Input_Types{ @@ -269,47 +267,6 @@ do_feedback_message(System_Functions *system, Models *models, String value){ #define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Command_Data *command, Command_Binding binding) -struct Command_Parameter{ - i32 type; - union{ - struct{ - Dynamic param; - Dynamic value; - } param; - struct{ - i32 len; - char *str; - } inline_string; - }; -}; - -inline Command_Parameter* -param_next(Command_Parameter *param, Command_Parameter *end){ - Command_Parameter *result = param; - if (result->type == 0){ - ++result; - } - while (result->type != 0 && result < end){ - i32 len = result->inline_string.len; - len += sizeof(*result) - 1; - len -= (len % sizeof(*result)); - result = (Command_Parameter*)((char*)result + len + sizeof(*result)); - } - return result; -} - -inline Command_Parameter* -param_stack_first(Partition *part, Command_Parameter *end){ - Command_Parameter *result = (Command_Parameter*)part->base; - if (result->type != 0) result = param_next(result, end); - return result; -} - -inline Command_Parameter* -param_stack_end(Partition *part){ - return (Command_Parameter*)((char*)part->base + part->pos); -} - internal View* panel_make_empty(System_Functions *system, App_Vars *vars, Panel *panel){ Models *models = &vars->models; @@ -356,112 +313,6 @@ seek_token_right(Cpp_Token_Stack *tokens, i32 pos){ return token->start + token->size; } -COMMAND_DECL(seek_left){ - REQ_READABLE_VIEW(view); - REQ_FILE(file, view); - - u32 flags = BoundryWhitespace; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_flags: - flags = dynamic_to_int(¶m->param.value); - break; - } - } - - i32 pos[4] = {0}; - - if (flags & (1)){ - pos[0] = buffer_seek_whitespace_left(&file->state.buffer, view->recent->cursor.pos); - } - - if (flags & (1 << 1)){ - if (file->state.tokens_complete){ - pos[1] = seek_token_left(&file->state.token_stack, view->recent->cursor.pos); - } - else{ - pos[1] = buffer_seek_whitespace_left(&file->state.buffer, view->recent->cursor.pos); - } - } - - if (flags & (1 << 2)){ - pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, view->recent->cursor.pos); - if (flags & (1 << 3)){ - pos[3] = buffer_seek_range_camel_left(&file->state.buffer, view->recent->cursor.pos, pos[2]); - } - } - else{ - if (flags & (1 << 3)){ - pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, view->recent->cursor.pos); - } - } - - i32 new_pos = 0; - for (i32 i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] > new_pos) new_pos = pos[i]; - } - - view_cursor_move(view, new_pos); -} - -COMMAND_DECL(seek_right){ - REQ_READABLE_VIEW(view); - REQ_FILE(file, view); - - u32 flags = BoundryWhitespace; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_flags: - flags = dynamic_to_int(¶m->param.value); - break; - } - } - - i32 size = buffer_size(&file->state.buffer); - i32 pos[4]; - for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size; - - if (flags & (1)){ - pos[0] = buffer_seek_whitespace_right(&file->state.buffer, view->recent->cursor.pos); - } - - if (flags & (1 << 1)){ - if (file->state.tokens_complete){ - pos[1] = seek_token_right(&file->state.token_stack, view->recent->cursor.pos); - } - else{ - pos[1] = buffer_seek_whitespace_right(&file->state.buffer, view->recent->cursor.pos); - } - } - - if (flags & (1 << 2)){ - pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, view->recent->cursor.pos); - if (flags & (1 << 3)){ - pos[3] = buffer_seek_range_camel_right(&file->state.buffer, view->recent->cursor.pos, pos[2]); - } - } - else{ - if (flags & (1 << 3)){ - pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, view->recent->cursor.pos); - } - } - - i32 new_pos = size; - for (i32 i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] < new_pos) new_pos = pos[i]; - } - - view_cursor_move(view, new_pos); -} - COMMAND_DECL(center_view){ REQ_READABLE_VIEW(view); REQ_FILE(file, view); @@ -685,30 +536,7 @@ COMMAND_DECL(copy){ REQ_READABLE_VIEW(view); REQ_FILE(file, view); - // TODO(allen): deduplicate - int r_start = 0, r_end = 0; - int start_set = 0, end_set = 0; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_range_start: - start_set = 1; - r_start = dynamic_to_int(¶m->param.value); - break; - - case par_range_end: - end_set = 1; - r_end = dynamic_to_int(¶m->param.value); - break; - } - } - Range range = make_range(view->recent->cursor.pos, view->recent->mark); - if (start_set) range.start = r_start; - if (end_set) range.end = r_end; if (range.start < range.end){ clipboard_copy(system, &models->mem.general, &models->working_set, range, file); } @@ -719,30 +547,7 @@ COMMAND_DECL(cut){ REQ_OPEN_VIEW(view); REQ_FILE(file, view); - // TODO(allen): deduplicate - int r_start = 0, r_end = 0; - int start_set = 0, end_set = 0; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_range_start: - start_set = 1; - r_start = dynamic_to_int(¶m->param.value); - break; - - case par_range_end: - end_set = 1; - r_end = dynamic_to_int(¶m->param.value); - break; - } - } - Range range = make_range(view->recent->cursor.pos, view->recent->mark); - if (start_set) range.start = r_start; - if (end_set) range.end = r_end; if (range.start < range.end){ i32 next_cursor_pos = range.start; @@ -868,42 +673,11 @@ COMMAND_DECL(interactive_new){ } COMMAND_DECL(interactive_open){ - USE_MODELS(models); USE_VIEW(view); - char *filename = 0; - int filename_len = 0; - int do_in_background = 0; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - if (param->param.param.type == dynamic_type_int){ - if (param->param.param.int_value == par_name && - param->param.value.type == dynamic_type_string){ - filename = param->param.value.str_value; - filename_len = param->param.value.str_len; - } - else if (param->param.param.int_value == par_do_in_background){ - do_in_background = dynamic_to_int(¶m->param.value); - } - } - } - - if (filename){ - String string = make_string(filename, filename_len); - if (do_in_background){ - view_open_file(system, models, 0, string); - } - else{ - view_open_file(system, models, view, string); - } - } - else{ - view_show_interactive(system, view, - IAct_Open, IInt_Sys_File_List, - make_lit_string("Open: ")); - } + view_show_interactive(system, view, + IAct_Open, IInt_Sys_File_List, + make_lit_string("Open: ")); } // TODO(allen): Improvements to reopen @@ -939,72 +713,21 @@ COMMAND_DECL(reopen){ COMMAND_DECL(save){ USE_MODELS(models); USE_VIEW(view); - USE_FILE(file, view); + REQ_FILE(file, view); - char *filename = 0; - int filename_len = 0; - int buffer_id = -1; - int update_names = 0; + if (!file->is_dummy && file_is_ready(file)){ + String name = file->name.source_path; + view_save_file(system, models, file, 0, name, 0); + } +} + +COMMAND_DECL(save_as){ + USE_VIEW(view); + REQ_FILE(file, view); - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int v = dynamic_to_int(¶m->param.param); - if (v == par_name && param->param.value.type == dynamic_type_string){ - filename = param->param.value.str_value; - filename_len = param->param.value.str_len; - } - else if (v == par_buffer_id && param->param.value.type == dynamic_type_int){ - buffer_id = dynamic_to_int(¶m->param.value); - } - else if (v == par_save_update_name){ - update_names = dynamic_to_bool(¶m->param.value); - } - } - - if (buffer_id != -1){ - file = working_set_get_active_file(&models->working_set, buffer_id); - } - - if (update_names){ - String name = {}; - if (filename){ - name = make_string(filename, filename_len); - } - - if (file){ - if (name.str){ - if (!file->is_dummy && file_is_ready(file)){ - view_save_file(system, models, file, 0, name, 1); - } - } - else{ - view_show_interactive(system, view, - IAct_Save_As, IInt_Sys_File_List, - make_lit_string("Save As: ")); - } - } - } - else{ - String name = {0}; - if (filename){ - name = make_string(filename, filename_len); - } - else if (file){ - name = file->name.source_path; - } - - if (name.size != 0){ - if (file){ - if (!file->is_dummy && file_is_ready(file)){ - view_save_file(system, models, file, 0, name, 0); - } - } - else{ - view_save_file(system, models, 0, 0, name, 0); - } - } - } + view_show_interactive(system, view, + IAct_Save_As, IInt_Sys_File_List, + make_lit_string("Save As: ")); } COMMAND_DECL(change_active_panel){ @@ -1037,29 +760,9 @@ COMMAND_DECL(interactive_kill_buffer){ COMMAND_DECL(kill_buffer){ USE_MODELS(models); USE_VIEW(view); - USE_FILE(file, view); + REQ_FILE(file, view); - int buffer_id = 0; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int v = dynamic_to_int(¶m->param.param); - if (v == par_buffer_id && param->param.value.type == dynamic_type_int){ - buffer_id = dynamic_to_int(¶m->param.value); - } - } - - if (buffer_id != 0){ - file = working_set_get_active_file(&models->working_set, buffer_id); - if (file){ - kill_file(system, models, file, string_zero()); - } - } - else if (file){ - try_kill_file(system, models, - file, view, string_zero()); - } + try_kill_file(system, models, file, view, string_zero()); } COMMAND_DECL(toggle_line_wrap){ @@ -1176,52 +879,6 @@ COMMAND_DECL(eol_nixify){ file->state.last_4ed_edit_time = system->now_time_stamp(); } -COMMAND_DECL(auto_tab_range){ - USE_MODELS(models); - REQ_OPEN_VIEW(view); - REQ_FILE(file, view); - - int r_start = 0, r_end = 0; - int start_set = 0, end_set = 0; - Indent_Options opts; - opts.empty_blank_lines = 0; - opts.use_tabs = 0; - opts.tab_width = 4; - - // TODO(allen): deduplicate - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_range_start: - start_set = 1; - r_start = dynamic_to_int(¶m->param.value); - break; - - case par_range_end: - end_set = 1; - r_end = dynamic_to_int(¶m->param.value); - break; - - case par_clear_blank_lines: - opts.empty_blank_lines = dynamic_to_bool(¶m->param.value); - break; - - case par_use_tabs: - opts.use_tabs = dynamic_to_bool(¶m->param.value); - break; - } - } - - if (file->state.token_stack.tokens && file->state.tokens_complete && !file->state.still_lexing){ - Range range = make_range(view->recent->cursor.pos, view->recent->mark); - if (start_set) range.start = r_start; - if (end_set) range.end = r_end; - view_auto_tab_tokens(system, models, view, range.start, range.end, opts); - } -} - COMMAND_DECL(open_panel_vsplit){ USE_VARS(vars); USE_MODELS(models); @@ -1414,284 +1071,6 @@ COMMAND_DECL(show_scrollbar){ view->hide_scrollbar = 0; } -COMMAND_DECL(set_settings){ - USE_MODELS(models); - - Editing_File *file = 0; - b32 set_mapid = 0; - i32 new_mapid = 0; - b32 set_show_whitespace = 0; - b32 show_whitespace = 0; - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_buffer_id: - { - int v = dynamic_to_int(¶m->param.value); - file = working_set_get_active_file(&models->working_set, v); - }break; - - case par_lex_as_cpp_file: - { -#if BUFFER_EXPERIMENT_SCALPEL <= 0 - if (file){ - int v = dynamic_to_bool(¶m->param.value); - if (file->settings.tokens_exist){ - if (!v) file_kill_tokens(system, &models->mem.general, file); - } - else{ - if (v) file_first_lex_parallel(system, &models->mem.general, file); - } - } -#endif - }break; - - case par_wrap_lines: - { - int v = dynamic_to_bool(¶m->param.value); - if (file){ - file->settings.unwrapped_lines = !v; - } - }break; - - case par_key_mapid: - { - if (file){ - set_mapid = 1; - int v = dynamic_to_int(¶m->param.value); - if (v == mapid_global) file->settings.base_map_id = mapid_global; - else if (v == mapid_file) file->settings.base_map_id = mapid_file; - else if (v < mapid_global){ - new_mapid = get_map_index(models, v); - if (new_mapid < models->user_map_count) file->settings.base_map_id = v; - else file->settings.base_map_id = mapid_file; - } - } - }break; - - case par_show_whitespace: - { - set_show_whitespace = 1; - show_whitespace = dynamic_to_bool(¶m->param.value); - }break; - } - } - - if (set_mapid){ - for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); - file_view_iter_good(iter); - iter = file_view_iter_next(iter)){ - iter.view->map = get_map(models, file->settings.base_map_id); - } - } -} - -COMMAND_DECL(command_line){ - USE_VARS(vars); - USE_MODELS(models); - USE_VIEW(view); - - Partition *part = &models->mem.part; - - char *buffer_name = 0; - char *path = 0; - char *script = 0; - - i32 buffer_id = 0; - i32 buffer_name_len = 0; - i32 path_len = 0; - i32 script_len = 0; - u32 flags = CLI_OverlapWithConflict; - b32 do_in_background = 0; - - char feedback_space[256]; - String feedback_str = make_fixed_width_string(feedback_space); - - Command_Parameter *end = param_stack_end(&command->part); - Command_Parameter *param = param_stack_first(&command->part, end); - for (; param < end; param = param_next(param, end)){ - int p = dynamic_to_int(¶m->param.param); - switch (p){ - case par_name: - { - char *new_buffer_name = dynamic_to_string(¶m->param.value, &buffer_name_len); - if (new_buffer_name){ - buffer_name = new_buffer_name; - } - }break; - - case par_buffer_id: - { - buffer_id = dynamic_to_int(¶m->param.value); - }break; - - case par_do_in_background: - { - do_in_background = 1; - }break; - - case par_cli_path: - { - char *new_cli_path = dynamic_to_string(¶m->param.value, &path_len); - if (new_cli_path){ - path = new_cli_path; - } - }break; - - case par_cli_command: - { - char *new_command = dynamic_to_string(¶m->param.value, &script_len); - if (new_command){ - script = new_command; - } - }break; - - case par_flags: - { - flags = (u32)dynamic_to_int(¶m->param.value); - }break; - } - } - - { - Working_Set *working_set = &models->working_set; - CLI_Process *procs = vars->cli_processes.procs, *proc = 0; - Editing_File *file = 0; - b32 bind_to_new_view = !do_in_background; - General_Memory *general = &models->mem.general; - - if (vars->cli_processes.count < vars->cli_processes.max){ - if (buffer_id){ - file = working_set_get_active_file(working_set, buffer_id); - if (file && file->settings.read_only == 0){ - append(&feedback_str, "ERROR: "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not a read-only buffer\n"); - do_feedback_message(system, models, feedback_str); - return; - } - if (file->settings.never_kill){ - append(&feedback_str, "The buffer "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not killable"); - do_feedback_message(system, models, feedback_str); - return; - } - } - else if (buffer_name){ - file = working_set_contains(system, working_set, make_string(buffer_name, buffer_name_len)); - if (file){ - if (file->settings.read_only == 0){ - append(&feedback_str, "ERROR: "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not a read-only buffer\n"); - do_feedback_message(system, models, feedback_str); - return; - } - if (file->settings.never_kill){ - append(&feedback_str, "The buffer "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not killable"); - do_feedback_message(system, models, feedback_str); - return; - } - } - else{ - file = working_set_alloc_always(working_set, general); - if (file == 0){ - append(&feedback_str, "ERROR: unable to allocate a new buffer\n"); - do_feedback_message(system, models, feedback_str); - return; - } - file_create_read_only(system, models, file, buffer_name); - working_set_add(system, working_set, file, general); - } - } - - if (file){ - i32 proc_count = vars->cli_processes.count; - View_Iter iter; - i32 i; - - for (i = 0; i < proc_count; ++i){ - if (procs[i].out_file == file){ - if (flags & CLI_OverlapWithConflict) - procs[i].out_file = 0; - else - file = 0; - break; - } - } - - if (file){ - file_clear(system, models, file, 1); - file->settings.unimportant = 1; - - if (!(flags & CLI_AlwaysBindToView)){ - iter = file_view_iter_init(&models->layout, file, 0); - if (file_view_iter_good(iter)){ - bind_to_new_view = 0; - } - } - } - else{ - append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); - do_feedback_message(system, models, feedback_str); - return; - } - } - - if (!path){ - path = models->hot_directory.string.str; - terminate_with_null(&models->hot_directory.string); - } - - { - Temp_Memory temp; - Range range; - Editing_File *file2; - i32 size; - - temp = begin_temp_memory(part); - if (!script){ - file2 = view->file_data.file; - if (file2){ - range = make_range(view->recent->cursor.pos, view->recent->mark); - size = range.end - range.start; - script = push_array(part, char, size + 1); - buffer_stringify(&file2->state.buffer, range.start, range.end, script); - script[size] = 0; - } - else{ - script = " echo no script specified"; - } - } - - if (bind_to_new_view){ - view_set_file(view, file, models); - view_show_file(view); - } - - proc = procs + vars->cli_processes.count++; - proc->out_file = file; - - if (!system->cli_call(path, script, &proc->cli)){ - --vars->cli_processes.count; - } - end_temp_memory(temp); - } - } - else{ - append(&feedback_str, "ERROR: no available process slot\n"); - do_feedback_message(system, models, feedback_str); - return; - } - } -} - internal void update_command_data(App_Vars *vars, Command_Data *cmd){ cmd->panel = cmd->models->layout.panels + cmd->models->layout.active_panel; @@ -1770,8 +1149,26 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_ } } +internal Editing_File* +get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){ + i32 buffer_id = buffer.id; + i32 buffer_name_len = buffer.name_len; + char *buffer_name = buffer.name; + + Editing_File *file = 0; + + if (buffer_id){ + file = working_set_get_active_file(working_set, buffer_id); + } + else if (buffer_name){ + file = working_set_contains(system, working_set, make_string(buffer_name, buffer_name_len)); + } + + return(file); +} + extern "C"{ - EXEC_COMMAND_KEEP_STACK_SIG(external_exec_command_keep_stack){ + EXEC_COMMAND_SIG(external_exec_command){ Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Function function = command_table[command_id]; Command_Binding binding = {}; @@ -1781,32 +1178,150 @@ extern "C"{ update_command_data(cmd->vars, cmd); } - PUSH_PARAMETER_SIG(external_push_parameter){ + EXEC_SYSTEM_COMMAND_SIG(external_exec_system_command){ Command_Data *cmd = (Command_Data*)app->cmd_context; - Partition *part = &cmd->part; - Command_Parameter *cmd_param = push_struct(part, Command_Parameter); - cmd_param->type = 0; - cmd_param->param.param = param; - cmd_param->param.value = value; - } - - PUSH_MEMORY_SIG(external_push_memory){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Partition *part = &cmd->part; - Command_Parameter *base = push_struct(part, Command_Parameter); - char *result = push_array(part, char, len); - int full_len = len + sizeof(Command_Parameter) - 1; - full_len -= (full_len % sizeof(Command_Parameter)); - part->pos += full_len - len; - base->type = 1; - base->inline_string.str = result; - base->inline_string.len = len; - return(result); - } - - CLEAR_PARAMETERS_SIG(external_clear_parameters){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - cmd->part.pos = 0; + System_Functions *system = cmd->system; + App_Vars *vars = cmd->vars; + Models *models = cmd->models; + + char feedback_space[256]; + String feedback_str = make_fixed_width_string(feedback_space); + + Working_Set *working_set = &models->working_set; + CLI_Process *procs = vars->cli_processes.procs, *proc = 0; + Editing_File *file = 0; + b32 bind_to_new_view = true; + General_Memory *general = &models->mem.general; + + View *vptr = 0; + + if (view->exists){ + Live_Views *live_set = cmd->live_set; + i32 view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + } + } + + if (vptr == 0){ + return(0); + } + + if (vars->cli_processes.count < vars->cli_processes.max){ + file = get_file_from_identifier(system, working_set, buffer); + if (file){ + if (file->settings.read_only == 0){ + append(&feedback_str, "ERROR: "); + append(&feedback_str, file->name.live_name); + append(&feedback_str, " is not a read-only buffer\n"); + do_feedback_message(system, models, feedback_str); + return(0); + } + if (file->settings.never_kill){ + append(&feedback_str, "The buffer "); + append(&feedback_str, file->name.live_name); + append(&feedback_str, " is not killable"); + do_feedback_message(system, models, feedback_str); + return(0); + } + } + else if (buffer.name){ + file = working_set_alloc_always(working_set, general); + if (file == 0){ + append(&feedback_str, "ERROR: unable to allocate a new buffer\n"); + do_feedback_message(system, models, feedback_str); + return(0); + } + file_create_read_only(system, models, file, buffer.name); + working_set_add(system, working_set, file, general); + } + + if (file){ + i32 proc_count = vars->cli_processes.count; + View_Iter iter; + i32 i; + + for (i = 0; i < proc_count; ++i){ + if (procs[i].out_file == file){ + if (flags & CLI_OverlapWithConflict){ + procs[i].out_file = 0; + } + else{ + file = 0; + } + break; + } + } + + if (file){ + file_clear(system, models, file, 1); + file->settings.unimportant = 1; + + if (!(flags & CLI_AlwaysBindToView)){ + iter = file_view_iter_init(&models->layout, file, 0); + if (file_view_iter_good(iter)){ + bind_to_new_view = 0; + } + } + } + else{ + append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); + do_feedback_message(system, models, feedback_str); + return(0); + } + } + + if (!path){ + path = models->hot_directory.string.str; + terminate_with_null(&models->hot_directory.string); + } + + { + Range range; + Editing_File *file2; + i32 size; + + Partition *part = &models->mem.part; + Temp_Memory temp = begin_temp_memory(part); + if (!command){ + file2 = vptr->file_data.file; + if (file2){ + range = make_range(vptr->recent->cursor.pos, vptr->recent->mark); + size = range.end - range.start; + command = push_array(part, char, size + 1); + buffer_stringify(&file2->state.buffer, range.start, range.end, command); + command[size] = 0; + command_len = size; + } + else{ +#define NO_SCRIPT " echo no script specified" + command = NO_SCRIPT; + command_len = sizeof(NO_SCRIPT)-1; +#undef NO_SCRIPT + } + } + + if (bind_to_new_view){ + view_set_file(vptr, file, models); + view_show_file(vptr); + } + + proc = procs + vars->cli_processes.count++; + proc->out_file = file; + + if (!system->cli_call(path, command, &proc->cli)){ + --vars->cli_processes.count; + } + end_temp_memory(temp); + } + } + else{ + append(&feedback_str, "ERROR: no available process slot\n"); + do_feedback_message(system, models, feedback_str); + return(0); + } + + return(1); } DIRECTORY_GET_HOT_SIG(external_directory_get_hot){ @@ -1907,6 +1422,103 @@ extern "C"{ return(result); } + BUFFER_SEEK_SIG(external_buffer_seek){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file; + Working_Set *working_set; + int result = 0; + + if (buffer->exists){ + working_set = &cmd->models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + // TODO(allen): reduce duplication? + { + i32 size = buffer_size(&file->state.buffer); + i32 pos[4] = {0}; + i32 new_pos = 0; + + if (start_pos < 0){ + start_pos = 0; + } + else if (start_pos > size){ + start_pos = size; + } + + if (seek_forward){ + for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size; + + if (flags & (1)){ + pos[0] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); + } + + if (flags & (1 << 1)){ + if (file->state.tokens_complete){ + pos[1] = seek_token_right(&file->state.token_stack, start_pos); + } + else{ + pos[1] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); + } + } + + if (flags & (1 << 2)){ + pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, start_pos); + if (flags & (1 << 3)){ + pos[3] = buffer_seek_range_camel_right(&file->state.buffer, start_pos, pos[2]); + } + } + else{ + if (flags & (1 << 3)){ + pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, start_pos); + } + } + + new_pos = size; + for (i32 i = 0; i < ArrayCount(pos); ++i){ + if (pos[i] < new_pos) new_pos = pos[i]; + } + } + else{ + if (flags & (1)){ + pos[0] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); + } + + if (flags & (1 << 1)){ + if (file->state.tokens_complete){ + pos[1] = seek_token_left(&file->state.token_stack, start_pos); + } + else{ + pos[1] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); + } + } + + if (flags & (1 << 2)){ + pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, start_pos); + if (flags & (1 << 3)){ + pos[3] = buffer_seek_range_camel_left(&file->state.buffer, start_pos, pos[2]); + } + } + else{ + if (flags & (1 << 3)){ + pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, start_pos); + } + } + + new_pos = 0; + for (i32 i = 0; i < ArrayCount(pos); ++i){ + if (pos[i] > new_pos) new_pos = pos[i]; + } + } + result = new_pos; + } + + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); + } + BUFFER_READ_RANGE_SIG(external_buffer_read_range){ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file; @@ -1964,6 +1576,7 @@ extern "C"{ return(result); } +#if 0 BUFFER_SET_POS_SIG(external_buffer_set_pos){ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file; @@ -1987,6 +1600,79 @@ extern "C"{ return(result); } +#endif + + BUFFER_SET_SETTING_SIG(external_buffer_set_setting){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + + Editing_File *file; + Working_Set *working_set; + + int result = false; + + i32 new_mapid = 0; + + if (buffer->exists){ + working_set = &models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + result = true; + switch (setting){ + case BufferSetting_Lex: + { +#if BUFFER_EXPERIMENT_SCALPEL <= 0 + if (file->settings.tokens_exist){ + if (!value){ + file_kill_tokens(system, &models->mem.general, file); + } + } + else{ + if (value){ + file_first_lex_parallel(system, &models->mem.general, file); + } + } +#endif + }break; + + case BufferSetting_WrapLine: + { + file->settings.unwrapped_lines = !value; + }break; + + case BufferSetting_MapID: + { + if (value == mapid_global){ + file->settings.base_map_id = mapid_global; + } + else if (value == mapid_file){ + file->settings.base_map_id = mapid_file; + } + else if (value < mapid_global){ + new_mapid = get_map_index(models, value); + if (new_mapid < models->user_map_count){ + file->settings.base_map_id = value; + } + else{ + file->settings.base_map_id = mapid_file; + } + } + + for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); + file_view_iter_good(iter); + iter = file_view_iter_next(iter)){ + iter.view->map = get_map(models, file->settings.base_map_id); + } + }break; + } + } + + fill_buffer_summary(buffer, file, working_set); + } + + return(result); + } GET_VIEW_FIRST_SIG(external_get_view_first){ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -2055,6 +1741,42 @@ extern "C"{ return(result); } + VIEW_AUTO_TAB_SIG(external_view_auto_tab){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + + int result = false; + + Live_Views *live_set; + Editing_File *file; + View *vptr; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + file = vptr->file_data.file; + + if (file && file->state.token_stack.tokens && + file->state.tokens_complete && !file->state.still_lexing){ + result = true; + + Indent_Options opts; + opts.empty_blank_lines = (flags & AutoTab_ClearLine); + opts.use_tabs = (flags & AutoTab_UseTab); + opts.tab_width = tab_width; + + view_auto_tab_tokens(system, models, vptr, start, end, opts); + } + } + } + + return(result); + } + VIEW_COMPUTE_CURSOR_SIG(external_view_compute_cursor){ Command_Data *cmd = (Command_Data*)app->cmd_context; Live_Views *live_set; @@ -2202,6 +1924,73 @@ extern "C"{ return(result); } + VIEW_OPEN_FILE_SIG(external_view_open_file){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + + System_Functions *system = cmd->system; + Models *models = cmd->models; + + Working_Set *working_set = &models->working_set; + + Live_Views *live_set = cmd->live_set; + + int result = false; + + // TODO(allen): do in background option + + if (do_in_background){ + result = true; + view_open_file(system, models, 0, + make_string(filename, filename_len)); + } + else if (view){ + View *vptr = 0; + int view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + result = true; + + view_open_file(system, models, 0, + make_string(filename, filename_len)); + + fill_view_summary(view, vptr, live_set, working_set); + } + } + + return(result); + } + + VIEW_KILL_FILE_SIG(external_view_kill_file){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Live_Views *live_set; + View *vptr; + Editing_File *file; + Working_Set *working_set; + Models *models; + int result = false; + int view_id; + + if (view->exists){ + models = cmd->models; + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + working_set = &models->working_set; + file = get_file_from_identifier(system, working_set, buffer); + + if (file){ + result = true; + try_kill_file(system, models, file, vptr, string_zero()); + fill_view_summary(view, vptr, live_set, working_set); + } + } + } + + return(result); + } + GET_USER_INPUT_SIG(external_get_user_input){ Command_Data *cmd = (Command_Data*)app->cmd_context; System_Functions *system = cmd->system; @@ -2278,6 +2067,7 @@ extern "C"{ do_feedback_message(cmd->system, models, make_string(string, len)); } +#if 0 GET_GUI_FUNCTIONS_SIG(external_get_gui_functions){ GUI_Functions *guifn = 0; NotImplemented; @@ -2289,7 +2079,8 @@ extern "C"{ NotImplemented; return(gui); } - +#endif + CHANGE_THEME_SIG(external_change_theme){ Command_Data *cmd = (Command_Data*)app->cmd_context; Style_Library *styles = &cmd->models->styles; @@ -2365,57 +2156,11 @@ app_links_init(System_Functions *system, Application_Links *app_links, void *dat app_links->memory = data; app_links->memory_size = size; - app_links->exec_command_keep_stack = external_exec_command_keep_stack; - app_links->push_parameter = external_push_parameter; - app_links->push_memory = external_push_memory; - app_links->clear_parameters = external_clear_parameters; +#define external_get_4ed_path system->get_4ed_path +#define external_file_exists system->file_exists +#define external_directory_cd system->directory_cd - app_links->directory_get_hot = external_directory_get_hot; - app_links->get_4ed_path = system->get_4ed_path; - app_links->file_exists = system->file_exists; - app_links->directory_cd = system->directory_cd; - app_links->get_file_list = external_get_file_list; - app_links->free_file_list = external_free_file_list; - - app_links->get_buffer_first = external_get_buffer_first; - app_links->get_buffer_next = external_get_buffer_next; - - app_links->get_buffer = external_get_buffer; - app_links->get_parameter_buffer = external_get_parameter_buffer; - app_links->get_buffer_by_name = external_get_buffer_by_name; - - app_links->refresh_buffer = external_refresh_buffer; - - app_links->buffer_read_range = external_buffer_read_range; - app_links->buffer_replace_range = external_buffer_replace_range; - - app_links->get_view_first = external_get_view_first; - app_links->get_view_next = external_get_view_next; - - app_links->get_view = external_get_view; - app_links->get_active_view = external_get_active_view; - - app_links->refresh_view = external_refresh_view; - app_links->view_compute_cursor = external_view_compute_cursor; - app_links->view_set_cursor = external_view_set_cursor; - app_links->view_set_mark = external_view_set_mark; - app_links->view_set_highlight = external_view_set_highlight; - app_links->view_set_buffer = external_view_set_buffer; - - app_links->get_user_input = external_get_user_input; - app_links->get_command_input = external_get_command_input; - app_links->get_event_message = external_get_event_message; - app_links->get_mouse_state = external_get_mouse_state; - - app_links->start_query_bar = external_start_query_bar; - app_links->end_query_bar = external_end_query_bar; - app_links->print_message = external_print_message; - app_links->get_gui_functions = external_get_gui_functions; - app_links->get_gui = external_get_gui; - - app_links->change_theme = external_change_theme; - app_links->change_font = external_change_font; - app_links->set_theme_colors = external_set_theme_colors; + FillAppLinksAPI(app_links); app_links->current_coroutine = 0; app_links->system_links = system; @@ -2457,9 +2202,6 @@ setup_command_table(){ #define SET(n) command_table[cmdid_##n] = command_##n SET(null); - SET(seek_left); - SET(seek_right); - SET(center_view); SET(left_adjust_view); @@ -2479,6 +2221,7 @@ setup_command_table(){ SET(interactive_open); SET(reopen); SET(save); + SET(save_as); SET(interactive_switch_buffer); SET(interactive_kill_buffer); SET(kill_buffer); @@ -2490,7 +2233,7 @@ setup_command_table(){ SET(toggle_show_whitespace); SET(clean_all_lines); - SET(auto_tab_range); + //SET(auto_tab_range); SET(eol_dosify); SET(eol_nixify); @@ -2510,10 +2253,6 @@ setup_command_table(){ SET(hide_scrollbar); SET(show_scrollbar); - SET(set_settings); - - SET(command_line); - #undef SET } @@ -3538,7 +3277,6 @@ App_Step_Sig(app_step){ cmd->key = key_event_data_zero(); Temp_Memory param_stack_temp = begin_temp_memory(&models->mem.part); - cmd->part = partition_sub_part(&models->mem.part, 16 << 10); if (input->first_step){ @@ -3581,7 +3319,6 @@ App_Step_Sig(app_step){ if (models->hooks[hook_start]){ models->hooks[hook_start](&models->app_links); - cmd->part.pos = 0; } i32 i; @@ -4058,6 +3795,9 @@ App_Step_Sig(app_step){ "and if you load README.txt you'll find all the key combos there are.\n" "\n" "Newest features:\n" + "-Eliminated the parameter stack\n" + "\n" + "New in alpha 4.0.7:\n" "-Right click sets the mark\n" "-Clicks are now have key codes so they can have event bound in customizations\n" "- opens a debug view, see more in README.txt\n" diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 478b5930..4a0ffcdb 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -500,9 +500,8 @@ generate_custom_headers(){ ); fprintf(file, "};\n"); - // TODO(allen): Generate app->function(app, ...) to function(app, ...) wrappers. - // Need to parse parameter names to do this. -#if 0 + fprintf(file, + "#define FillAppLinksAPI(app_links) do{"); for (int i = 0; i < sig_count; ++i){ Function_Signature *sig = sigs + i; @@ -511,12 +510,12 @@ generate_custom_headers(){ to_lower(name_buffer, name_buffer); fprintf(file, - "inline %.*s\n" - "%s%.*s{ app->%s(", - sig->name.size, sig->name.str, - name_buffer); + "\\\n" + "app_links->%s = external_%s;", + name_buffer, name_buffer + ); } -#endif + fprintf(file," } while(false)\n"); fclose(file); diff --git a/custom_api_spec.txt b/custom_api_spec.txt index d419868c..c0028671 100644 --- a/custom_api_spec.txt +++ b/custom_api_spec.txt @@ -1,9 +1,7 @@ // Command exectuion -void Push_Parameter(Application_Links *app, Dynamic param, Dynamic value) -char* Push_Memory(Application_Links *app, int len) -void Exec_Command_Keep_Stack(Application_Links *app, int command_id) -void Clear_Parameters(Application_Links *app) +void Exec_Command(Application_Links *app, int command_id) +int Exec_System_Command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int path_len, char *command, int command_len, unsigned int flags) // File system navigation int Directory_Get_Hot(Application_Links *app, char *out, int capacity) @@ -21,16 +19,15 @@ Buffer_Summary Get_Buffer(Application_Links *app, int index) Buffer_Summary Get_Parameter_Buffer(Application_Links *app, int param_index) Buffer_Summary Get_Buffer_By_Name(Application_Links *app, char *filename, int len) -//int Buffer_Seek_Delimiter(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out) -//int Buffer_Seek_String(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) -//int Buffer_Seek_String_Insensitive(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) - int Refresh_Buffer(Application_Links *app, Buffer_Summary *buffer) int Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) int Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) -int Buffer_Set_Pos(Application_Links *app, Buffer_Summary *buffer, int pos) +//int Buffer_Set_Pos(Application_Links *app, Buffer_Summary *buffer, int pos) -// File view manipulation +int Buffer_Seek(Application_Links *app, Buffer_Summary *buffer, int start_pos, int seek_forward, unsigned int flags) +int Buffer_Set_Setting(Application_Links *app, Buffer_Summary *buffer, int setting, int value) + +// View manipulation View_Summary Get_View_First(Application_Links *app) void Get_View_Next(Application_Links *app, View_Summary *view) @@ -38,12 +35,17 @@ View_Summary Get_View(Application_Links *app, int index) View_Summary Get_Active_View(Application_Links *app) int Refresh_View(Application_Links *app, View_Summary *view) + +int View_Auto_Tab(Application_Links *app, View_Summary *view, int start, int end, int tab_width, unsigned int flags) Full_Cursor View_Compute_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek) int View_Set_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x) int View_Set_Mark(Application_Links *app, View_Summary *view, Buffer_Seek seek) int View_Set_Highlight(Application_Links *app, View_Summary *view, int start, int end, int turn_on) int View_Set_Buffer(Application_Links *app, View_Summary *view, int buffer_id) +int View_Open_File(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background) +int View_Kill_File(Application_Links *app, View_Summary *view, Buffer_Identifier buffer) + // Directly get user input User_Input Get_User_Input(Application_Links *app, unsigned int get_type, unsigned int abort_type) User_Input Get_Command_Input(Application_Links *app) @@ -54,8 +56,8 @@ Mouse_State Get_Mouse_State(Application_Links *app) int Start_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags) void End_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags) void Print_Message(Application_Links *app, char *string, int len) -GUI_Functions* Get_GUI_Functions(Application_Links *app) -GUI* Get_GUI(Application_Links *app, int view_id) +//GUI_Functions* Get_GUI_Functions(Application_Links *app) +//GUI* Get_GUI(Application_Links *app, int view_id) // Color settings void Change_Theme(Application_Links *app, char *name, int len)