condensed API links and data ptrs into one

This commit is contained in:
Allen Webster 2016-02-26 01:26:26 -05:00
parent 362d1ce70c
commit 19e7c96c55
5 changed files with 208 additions and 305 deletions

View File

@ -30,8 +30,8 @@ enum My_Maps{
};
HOOK_SIG(my_start){
exec_command(cmd_context, cmdid_open_panel_vsplit);
exec_command(cmd_context, cmdid_change_active_panel);
exec_command(app, cmdid_open_panel_vsplit);
exec_command(app, cmdid_change_active_panel);
}
char *get_extension(const char *filename, int len, int *extension_len){
@ -55,7 +55,7 @@ bool str_match(const char *a, int len_a, const char *b, int len_b){
}
HOOK_SIG(my_file_settings){
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
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:
@ -74,25 +74,25 @@ HOOK_SIG(my_file_settings){
else if (str_match(extension, extension_len, literal("hpp"))) treat_as_code = 1;
}
push_parameter(app, cmd_context, par_lex_as_cpp_file, treat_as_code);
push_parameter(app, cmd_context, par_wrap_lines, !treat_as_code);
push_parameter(app, cmd_context, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file));
exec_command(cmd_context, cmdid_set_settings);
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);
}
}
CUSTOM_COMMAND_SIG(write_increment){
char text[] = "++";
int size = sizeof(text) - 1;
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
Buffer_Summary buffer = app->get_active_buffer(app);
app->buffer_replace_range(app, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
}
CUSTOM_COMMAND_SIG(write_decrement){
char text[] = "--";
int size = sizeof(text) - 1;
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
Buffer_Summary buffer = app->get_active_buffer(app);
app->buffer_replace_range(app, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
}
CUSTOM_COMMAND_SIG(open_long_braces){
@ -102,18 +102,18 @@ CUSTOM_COMMAND_SIG(open_long_braces){
int size = sizeof(text) - 1;
int pos;
view = app->get_active_file_view(cmd_context);
buffer = app->get_buffer(cmd_context, view.file_id);
view = app->get_active_file_view(app);
buffer = app->get_buffer(app, view.file_id);
pos = view.cursor.pos;
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text, size);
app->view_set_cursor(cmd_context, &view, seek_pos(pos + 2), 1);
app->view_set_mark(cmd_context, &view, seek_pos(pos + 4));
app->buffer_replace_range(app, &buffer, pos, pos, text, size);
app->view_set_cursor(app, &view, seek_pos(pos + 2), 1);
app->view_set_mark(app, &view, seek_pos(pos + 4));
push_parameter(app, cmd_context, par_range_start, pos);
push_parameter(app, cmd_context, par_range_end, pos + size);
push_parameter(app, cmd_context, par_clear_blank_lines, 0);
exec_command(cmd_context, cmdid_auto_tab_range);
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);
}
CUSTOM_COMMAND_SIG(ifdef_off){
@ -129,27 +129,27 @@ CUSTOM_COMMAND_SIG(ifdef_off){
Range range;
int pos;
view = app->get_active_file_view(cmd_context);
buffer = app->get_active_buffer(cmd_context);
view = app->get_active_file_view(app);
buffer = app->get_active_buffer(app);
range = get_range(&view);
pos = range.min;
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text1, size1);
app->buffer_replace_range(app, &buffer, pos, pos, text1, size1);
push_parameter(app, cmd_context, par_range_start, pos);
push_parameter(app, cmd_context, par_range_end, pos);
exec_command(cmd_context, cmdid_auto_tab_range);
push_parameter(app, par_range_start, pos);
push_parameter(app, par_range_end, pos);
exec_command(app, cmdid_auto_tab_range);
app->refresh_file_view(cmd_context, &view);
app->refresh_file_view(app, &view);
range = get_range(&view);
pos = range.max;
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text2, size2);
app->buffer_replace_range(app, &buffer, pos, pos, text2, size2);
push_parameter(app, cmd_context, par_range_start, pos);
push_parameter(app, cmd_context, par_range_end, pos);
exec_command(cmd_context, cmdid_auto_tab_range);
push_parameter(app, par_range_start, pos);
push_parameter(app, par_range_end, pos);
exec_command(app, cmdid_auto_tab_range);
}
CUSTOM_COMMAND_SIG(backspace_word){
@ -157,15 +157,15 @@ CUSTOM_COMMAND_SIG(backspace_word){
Buffer_Summary buffer;
int pos2, pos1;
view = app->get_active_file_view(cmd_context);
view = app->get_active_file_view(app);
pos2 = view.cursor.pos;
exec_command(cmd_context, cmdid_seek_alphanumeric_left);
app->refresh_file_view(cmd_context, &view);
exec_command(app, cmdid_seek_alphanumeric_left);
app->refresh_file_view(app, &view);
pos1 = view.cursor.pos;
buffer = app->get_buffer(cmd_context, view.file_id);
app->buffer_replace_range(cmd_context, &buffer, pos1, pos2, 0, 0);
buffer = app->get_buffer(app, view.file_id);
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
}
CUSTOM_COMMAND_SIG(switch_to_compilation){
@ -179,17 +179,17 @@ CUSTOM_COMMAND_SIG(switch_to_compilation){
// a bit to handle a general view type which can be manipulated at least enough
// to change the specific type of view and set files even when the view didn't
// contain a file.
view = app->get_active_file_view(cmd_context);
buffer = app->get_buffer_by_name(cmd_context, make_string(name, name_size));
view = app->get_active_file_view(app);
buffer = app->get_buffer_by_name(app, make_string(name, name_size));
app->view_set_file(cmd_context, &view, buffer.file_id);
app->view_set_file(app, &view, buffer.file_id);
}
CUSTOM_COMMAND_SIG(move_up_10){
File_View_Summary view;
float x, y;
view = app->get_active_file_view(cmd_context);
view = app->get_active_file_view(app);
x = view.preferred_x;
if (view.unwrapped_lines){
@ -201,14 +201,14 @@ CUSTOM_COMMAND_SIG(move_up_10){
y -= 10*view.line_height;
app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
app->view_set_cursor(app, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
}
CUSTOM_COMMAND_SIG(move_down_10){
File_View_Summary view;
float x, y;
view = app->get_active_file_view(cmd_context);
view = app->get_active_file_view(app);
x = view.preferred_x;
if (view.unwrapped_lines){
@ -220,7 +220,7 @@ CUSTOM_COMMAND_SIG(move_down_10){
y += 10*view.line_height;
app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
app->view_set_cursor(app, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
}
CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
@ -229,13 +229,13 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
char short_file_name[128];
int pos, start, end, size;
view = app->get_active_file_view(cmd_context);
view = app->get_active_file_view(app);
if (view.exists){
buffer = app->get_buffer(cmd_context, view.file_id);
buffer = app->get_buffer(app, view.file_id);
if (buffer.ready){
pos = view.cursor.pos;
app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 1, &end);
app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 0, &start);
app->buffer_seek_delimiter(app, &buffer, pos, '"', 1, &end);
app->buffer_seek_delimiter(app, &buffer, pos, '"', 0, &start);
++start;
@ -244,21 +244,21 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
char file_name_[256];
String file_name = make_fixed_width_string(file_name_);
app->buffer_read_range(cmd_context, &buffer, start, end, short_file_name);
app->buffer_read_range(app, &buffer, start, end, short_file_name);
copy(&file_name, make_string(buffer.file_name, buffer.file_name_len));
truncate_to_path_of_directory(&file_name);
append(&file_name, make_string(short_file_name, size));
buffer = app->get_buffer_by_name(cmd_context, file_name);
exec_command(cmd_context, cmdid_change_active_panel);
view = app->get_active_file_view(cmd_context);
buffer = app->get_buffer_by_name(app, file_name);
exec_command(app, cmdid_change_active_panel);
view = app->get_active_file_view(app);
if (buffer.exists){
app->view_set_file(cmd_context, &view, buffer.file_id);
app->view_set_file(app, &view, buffer.file_id);
}
else{
push_parameter(app, cmd_context, par_name, expand_str(file_name));
exec_command(cmd_context, cmdid_interactive_open);
push_parameter(app, par_name, expand_str(file_name));
exec_command(app, cmdid_interactive_open);
}
}
}
@ -266,18 +266,18 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
}
CUSTOM_COMMAND_SIG(open_in_other){
exec_command(cmd_context, cmdid_change_active_panel);
exec_command(cmd_context, cmdid_interactive_open);
exec_command(app, cmdid_change_active_panel);
exec_command(app, cmdid_interactive_open);
}
CUSTOM_COMMAND_SIG(open_my_files){
// NOTE(allen|a3.1): 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.
push_parameter(app, cmd_context, par_name, literal("w:/4ed/data/test/basic.cpp"));
exec_command(cmd_context, cmdid_interactive_open);
push_parameter(app, par_name, literal("w:/4ed/data/test/basic.cpp"));
exec_command(app, cmdid_interactive_open);
exec_command(cmd_context, cmdid_change_active_panel);
exec_command(app, cmdid_change_active_panel);
char my_file[256];
int my_file_len;
@ -288,21 +288,21 @@ CUSTOM_COMMAND_SIG(open_my_files){
}
// NOTE(allen|a3.1): null terminators are not needed for strings.
push_parameter(app, cmd_context, par_name, my_file, my_file_len);
exec_command(cmd_context, cmdid_interactive_open);
push_parameter(app, par_name, my_file, my_file_len);
exec_command(app, cmdid_interactive_open);
exec_command(cmd_context, cmdid_change_active_panel);
exec_command(app, cmdid_change_active_panel);
}
CUSTOM_COMMAND_SIG(build_at_launch_location){
// NOTE(allen|a3.3): An example of calling build by setting all
// parameters directly. This only works if build.bat can be called
// from the starting directory
push_parameter(app, cmd_context, par_cli_overlap_with_conflict, 1);
push_parameter(app, cmd_context, par_name, literal("*compilation*"));
push_parameter(app, cmd_context, par_cli_path, literal("."));
push_parameter(app, cmd_context, par_cli_command, literal("build"));
exec_command(cmd_context, cmdid_build);
// from the directory the application is launched at.
push_parameter(app, par_cli_overlap_with_conflict, 1);
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_build);
}
CUSTOM_COMMAND_SIG(build_search){
@ -336,34 +336,25 @@ CUSTOM_COMMAND_SIG(build_search){
// It returns true if it can actually move in the specified direction, and false otherwise.
int keep_going = 1;
String dir = push_directory(app, cmd_context);
String dir = push_directory(app);
while (keep_going){
if (app->directory_has_file(dir, "build.bat")){
push_parameter(app, cmd_context, par_cli_overlap_with_conflict, 0);
push_parameter(app, cmd_context, par_name, literal("*compilation*"));
push_parameter(app, cmd_context, par_cli_path, dir.str, dir.size);
if (app->directory_has_file(app, dir, "build.bat")){
push_parameter(app, par_cli_overlap_with_conflict, 0);
push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, dir.str, dir.size);
if (append(&dir, "build")){
#if 1
// NOTE(allen): This version avoids an unecessary copy, both equivalents are
// included to demonstrate how using push_parameter without the helper looks.
app->push_parameter(cmd_context,
dynamic_int(par_cli_command),
dynamic_string(dir.str, dir.size));
#else
push_parameter(cmd_context, par_cli_command, dir.str, dir.size);
#endif
exec_command(cmd_context, cmdid_build);
push_parameter(app, par_cli_command, dir.str, dir.size);
exec_command(app, cmdid_build);
}
else{
clear_parameters(cmd_context);
app->clear_parameters(app);
}
return;
}
if (app->directory_cd(&dir, "..") == 0){
if (app->directory_cd(app, &dir, "..") == 0){
keep_going = 0;
}
}
@ -372,8 +363,8 @@ CUSTOM_COMMAND_SIG(build_search){
}
CUSTOM_COMMAND_SIG(write_and_auto_tab){
exec_command(cmd_context, cmdid_write_character);
exec_command(cmd_context, cmdid_auto_tab_line_at_cursor);
exec_command(app, cmdid_write_character);
exec_command(app, cmdid_auto_tab_line_at_cursor);
}
extern "C" GET_BINDING_DATA(get_bindings){

View File

@ -174,12 +174,6 @@ dynamic_to_bool(Dynamic *dynamic){
return result;
}
struct Extra_Font{
char file_name[256];
char font_name[24];
int size;
};
// NOTE(allen): None of the members of *_Summary structs nor any of the
// data pointed to by the members should be modified, I would have made
// them all const... but that causes a lot problems for C++ reasons.
@ -223,48 +217,49 @@ struct String{
#define GET_BINDING_DATA(name) int name(void *data, int size)
#define SET_EXTRA_FONT_SIG(name) void name(Extra_Font *font_out)
#define CUSTOM_COMMAND_SIG(name) void name(void *cmd_context, struct Application_Links *app)
#define HOOK_SIG(name) void name(void *cmd_context, struct Application_Links *app)
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
#define HOOK_SIG(name) void name(struct Application_Links *app)
extern "C"{
typedef CUSTOM_COMMAND_SIG(Custom_Command_Function);
typedef GET_BINDING_DATA(Get_Binding_Data_Function);
typedef SET_EXTRA_FONT_SIG(Set_Extra_Font_Function);
typedef HOOK_SIG(Hook_Function);
}
struct Application_Links;
// Command exectuion
#define PUSH_PARAMETER_SIG(name) void name(void *cmd_context, Dynamic param, Dynamic value)
#define PUSH_MEMORY_SIG(name) char* name(void *cmd_context, int len)
#define EXECUTE_COMMAND_SIG(name) void name(void *cmd_context, int command_id)
#define CLEAR_PARAMETERS_SIG(name) void name(void *cmd_context)
#define PUSH_PARAMETER_SIG(name) void name(Application_Links *context, Dynamic param, Dynamic value)
#define PUSH_MEMORY_SIG(name) char* name(Application_Links *context, int len)
#define EXECUTE_COMMAND_SIG(name) void name(Application_Links *context, int command_id)
#define CLEAR_PARAMETERS_SIG(name) void name(Application_Links *context)
// File system navigation
#define DIRECTORY_GET_HOT_SIG(name) int name(void *cmd_context, char *buffer, int max)
#define DIRECTORY_HAS_FILE_SIG(name) int name(String dir, char *filename)
#define DIRECTORY_CD_SIG(name) int name(String *dir, char *rel_path)
#define DIRECTORY_GET_HOT_SIG(name) int name(Application_Links *context, char *buffer, int max)
#define DIRECTORY_HAS_FILE_SIG(name) int name(Application_Links *context, String dir, char *filename)
#define DIRECTORY_CD_SIG(name) int name(Application_Links *context, String *dir, char *rel_path)
// Direct buffer manipulation
#define GET_BUFFER_MAX_INDEX_SIG(name) int name(void *cmd_context)
#define GET_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context, int index)
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context)
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(void *cmd_context, String filename)
#define GET_BUFFER_MAX_INDEX_SIG(name) int name(Application_Links *context)
#define GET_BUFFER_SIG(name) Buffer_Summary name(Application_Links *context, int index)
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(Application_Links *context)
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *context, String filename)
#define REFRESH_BUFFER_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer)
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
#define BUFFER_READ_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *str, int len)
#define REFRESH_BUFFER_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer)
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
#define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *str, int len)
// TODO(allen): buffer save
// File view manipulation
#define GET_VIEW_MAX_INDEX_SIG(name) int name(void *cmd_context)
#define GET_FILE_VIEW_SIG(name) File_View_Summary name(void *cmd_context, int index)
#define GET_ACTIVE_FILE_VIEW_SIG(name) File_View_Summary name(void *cmd_context)
#define GET_VIEW_MAX_INDEX_SIG(name) int name(Application_Links *context)
#define GET_FILE_VIEW_SIG(name) File_View_Summary name(Application_Links *context, int index)
#define GET_ACTIVE_FILE_VIEW_SIG(name) File_View_Summary name(Application_Links *context)
#define REFRESH_FILE_VIEW_SIG(name) int name(void *cmd_context, File_View_Summary *view)
#define VIEW_SET_CURSOR_SIG(name) int name(void *cmd_context, File_View_Summary *view, Buffer_Seek seek, int set_preferred_x)
#define VIEW_SET_MARK_SIG(name) int name(void *cmd_context, File_View_Summary *view, Buffer_Seek seek)
#define VIEW_SET_FILE_SIG(name) int name(void *cmd_context, File_View_Summary *view, int file_id)
#define REFRESH_FILE_VIEW_SIG(name) int name(Application_Links *context, File_View_Summary *view)
#define VIEW_SET_CURSOR_SIG(name) int name(Application_Links *context, File_View_Summary *view, Buffer_Seek seek, int set_preferred_x)
#define VIEW_SET_MARK_SIG(name) int name(Application_Links *context, File_View_Summary *view, Buffer_Seek seek)
#define VIEW_SET_FILE_SIG(name) int name(Application_Links *context, File_View_Summary *view, int file_id)
extern "C"{
// Command exectuion
@ -332,6 +327,9 @@ struct Application_Links{
View_Set_Cursor_Function *view_set_cursor;
View_Set_Mark_Function *view_set_mark;
View_Set_File_Function *view_set_file;
// Application data ptr
void *data;
};
struct Custom_API{

View File

@ -172,44 +172,44 @@ end_bind_helper(Bind_Helper *helper){
// NOTE(allen): Useful functions and overloads on app links
inline void
push_parameter(Application_Links *app, void *cmd_context, int param, int value){
app->push_parameter(cmd_context, dynamic_int(param), dynamic_int(value));
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, void *cmd_context, int param, const char *value, int value_len){
char *value_copy = app->push_memory(cmd_context, value_len+1);
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(cmd_context, dynamic_int(param), dynamic_string(value_copy, value_len));
app->push_parameter(app, dynamic_int(param), dynamic_string(value_copy, value_len));
}
inline void
push_parameter(Application_Links *app, void *cmd_context, const char *param, int param_len, int value){
char *param_copy = app->push_memory(cmd_context, param_len+1);
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(cmd_context, dynamic_string(param_copy, param_len), dynamic_int(value));
app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_int(value));
}
inline void
push_parameter(Application_Links *app, void *cmd_context, const char *param, int param_len, const char *value, int value_len){
char *param_copy = app->push_memory(cmd_context, param_len+1);
char *value_copy = app->push_memory(cmd_context, value_len+1);
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(cmd_context, dynamic_string(param_copy, param_len), dynamic_string(value_copy, value_len));
app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_string(value_copy, value_len));
}
inline String
push_directory(Application_Links *app, void *cmd_context){
push_directory(Application_Links *app){
String result;
result.memory_size = 512;
result.str = app->push_memory(cmd_context, result.memory_size);
result.size = app->directory_get_hot(cmd_context, result.str, result.memory_size);
result.str = app->push_memory(app, result.memory_size);
result.size = app->directory_get_hot(app, result.str, result.memory_size);
return(result);
}
@ -229,24 +229,15 @@ get_range(File_View_Summary *view){
return(range);
}
#if DisableMacroTranslations == 0
inline void
exec_command_(Application_Links *app, void *cmd_context, Command_ID id){
app->exec_command_keep_stack(cmd_context, id);
app->clear_parameters(cmd_context);
exec_command(Application_Links *app, Command_ID id){
app->exec_command_keep_stack(app, id);
app->clear_parameters(app);
}
inline void
exec_command_(Application_Links *app, void *cmd_context, Custom_Command_Function *func){
func(cmd_context, app);
app->clear_parameters(cmd_context);
exec_command(Application_Links *app, Custom_Command_Function *func){
func(app);
app->clear_parameters(app);
}
#define exec_command_keep_stack app->exec_command_keep_stack
#define clear_parameters app->clear_parameters
#define exec_command(cmd_context, cmd) exec_command_(app, cmd_context, cmd)
#endif

231
4ed.cpp
View File

@ -47,6 +47,25 @@ struct Complete_State{
b32 initialized;
};
struct Command_Data{
Mem_Options *mem;
Panel *panel;
View *view;
Working_Set *working_set;
Editing_Layout *layout;
Live_Views *live_set;
Style *style;
Delay *delay;
struct App_Vars *vars;
Exchange *exchange;
System_Functions *system;
i32 screen_width, screen_height;
Key_Event_Data key;
Partition part;
};
struct App_Vars{
Mem_Options mem;
@ -97,6 +116,8 @@ struct App_Vars{
Complete_State complete_state;
Panel *prev_mouse_panel;
Command_Data command_data;
Custom_API config_api;
};
@ -167,25 +188,6 @@ globalvar Application_Links app_links;
#define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Command_Data *command, Command_Binding binding)
#define COMPOSE_DECL(n) internal void n(System_Functions *system, Command_Data *command, Command_Binding binding)
struct Command_Data{
Mem_Options *mem;
Panel *panel;
View *view;
Working_Set *working_set;
Editing_Layout *layout;
Live_Views *live_set;
Style *style;
Delay *delay;
App_Vars *vars;
Exchange *exchange;
System_Functions *system;
i32 screen_width, screen_height;
Key_Event_Data key;
Partition part;
};
struct Command_Parameter{
i32 type;
union{
@ -1766,7 +1768,7 @@ COMMAND_DECL(cursor_mark_swap){
COMMAND_DECL(user_callback){
ProfileMomentFunction();
if (binding.custom) binding.custom(command, &app_links);
if (binding.custom) binding.custom(&app_links);
}
COMMAND_DECL(set_settings){
@ -2009,54 +2011,6 @@ COMMAND_DECL(build){
flags);
}
COMMAND_DECL(build_here){
ProfileMomentFunction();
USE_VARS(vars);
USE_MEM(mem);
USE_WORKING_SET(working_set);
USE_STYLE(style);
USE_LIVE_SET(live_set);
USE_PANEL(panel);
USE_EXCHANGE(exchange);
USE_FONT_SET(font_set);
u32 flags = 0;
char *buffer_name = "*compilation*";
int buffer_name_len = sizeof("*compilation*")-1;
char path_space[512];
String path = make_fixed_width_string(path_space);
path.size = app_links.directory_get_hot(command, path.str, path.memory_size);
char dir_space[512];
String dir = make_fixed_width_string(dir_space);
dir.size = app_links.directory_get_hot(command, dir.str, dir.memory_size);
for (;;){
if (app_links.directory_has_file(dir, "build.bat")){
if (append(&dir, "build")){
break;
}
}
if (app_links.directory_cd(&dir, "..") == 0){
copy(&dir, "build");
break;
}
}
terminate_with_null(&dir);
build(system, mem, vars, working_set,
font_set, style, live_set, exchange,
panel, command,
vars->hot_directory.string,
buffer_name, buffer_name_len,
path.str, path.size,
dir.str, dir.size,
flags);
}
internal void
update_command_data(App_Vars *vars, Command_Data *cmd){
Command_Data command_data;
@ -2079,13 +2033,6 @@ update_command_data(App_Vars *vars, Command_Data *cmd){
*cmd = command_data;
}
COMPOSE_DECL(compose_write_auto_tab_line){
command_write_character(system, command, binding);
update_command_data(command->vars, command);
command_auto_tab_line_at_cursor(system, command, binding);
update_command_data(command->vars, command);
}
globalvar Command_Function command_table[cmdid_count];
internal void
@ -2121,7 +2068,7 @@ fill_view_summary(File_View_Summary *view, File_View *file_view, Live_Views *liv
extern "C"{
EXECUTE_COMMAND_SIG(external_exec_command_keep_stack){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Command_Function function = command_table[command_id];
Command_Binding binding;
binding.function = function;
@ -2131,7 +2078,7 @@ extern "C"{
}
PUSH_PARAMETER_SIG(external_push_parameter){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Partition *part = &cmd->part;
Command_Parameter *cmd_param = push_struct(part, Command_Parameter);
cmd_param->type = 0;
@ -2140,7 +2087,7 @@ extern "C"{
}
PUSH_MEMORY_SIG(external_push_memory){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Partition *part = &cmd->part;
Command_Parameter *base = push_struct(part, Command_Parameter);
char *result = push_array(part, char, len);
@ -2154,12 +2101,12 @@ extern "C"{
}
CLEAR_PARAMETERS_SIG(external_clear_parameters){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
cmd->part.pos = 0;
}
DIRECTORY_GET_HOT_SIG(external_directory_get_hot){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Hot_Directory *hot = &cmd->vars->hot_directory;
i32 copy_max = max - 1;
hot_directory_clean_end(hot);
@ -2171,14 +2118,14 @@ extern "C"{
}
GET_BUFFER_MAX_INDEX_SIG(external_get_buffer_max_index){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Working_Set *working_set = cmd->working_set;
int max = working_set->file_index_count;
return(max);
}
GET_BUFFER_SIG(external_get_buffer){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Editing_File *file;
Working_Set *working_set = cmd->working_set;
int max = working_set->file_index_count;
@ -2195,7 +2142,7 @@ extern "C"{
}
GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
File_View *view;
Editing_File *file;
Working_Set *working_set;
@ -2215,7 +2162,7 @@ extern "C"{
}
GET_BUFFER_BY_NAME(external_get_buffer_by_name){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Editing_File *file;
Working_Set *working_set;
i32 index;
@ -2234,13 +2181,13 @@ extern "C"{
REFRESH_BUFFER_SIG(external_refresh_buffer){
int result;
*buffer = external_get_buffer(cmd_context, buffer->file_id);
*buffer = external_get_buffer(context, buffer->file_id);
result = buffer->exists;
return(result);
}
BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Editing_File *file;
Working_Set *working_set;
int result = 0;
@ -2270,7 +2217,7 @@ extern "C"{
}
BUFFER_READ_RANGE_SIG(external_buffer_read_range){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Editing_File *file;
Working_Set *working_set;
int result = 0;
@ -2293,7 +2240,7 @@ extern "C"{
}
BUFFER_REPLACE_RANGE_SIG(external_buffer_replace_range){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Editing_File *file;
Working_Set *working_set;
@ -2333,14 +2280,14 @@ extern "C"{
}
GET_VIEW_MAX_INDEX_SIG(external_get_view_max_index){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Live_Views *live_set = cmd->live_set;
int max = live_set->max;
return(max);
}
GET_FILE_VIEW_SIG(external_get_file_view){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Live_Views *live_set = cmd->live_set;
int max = live_set->max;
View *vptr;
@ -2359,7 +2306,7 @@ extern "C"{
}
GET_ACTIVE_FILE_VIEW_SIG(external_get_active_file_view){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
File_View_Summary view = {};
File_View *file_view;
@ -2373,13 +2320,13 @@ extern "C"{
REFRESH_FILE_VIEW_SIG(external_refresh_file_view){
int result;
*view = external_get_file_view(cmd_context, view->view_id);
*view = external_get_file_view(context, view->view_id);
result = view->exists;
return(result);
}
VIEW_SET_CURSOR_SIG(external_view_set_cursor){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Live_Views *live_set;
View *vptr;
File_View *file_view;
@ -2403,7 +2350,7 @@ extern "C"{
}
VIEW_SET_MARK_SIG(external_view_set_mark){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Live_Views *live_set;
View *vptr;
File_View *file_view;
@ -2431,7 +2378,7 @@ extern "C"{
}
VIEW_SET_FILE_SIG(external_view_set_file){
Command_Data *cmd = (Command_Data*)cmd_context;
Command_Data *cmd = (Command_Data*)context->data;
Live_Views *live_set;
View *vptr;
File_View *file_view;
@ -2856,28 +2803,6 @@ bool _4coder_str_match(const char *a, int len_a, const char *b, int len_b){
return result;
}
HOOK_SIG(default_open_file_hook){
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
int treat_as_code = 0;
if (buffer.file_name && buffer.size < (16 << 20)){
int extension_len;
char *extension = _4coder_get_extension(buffer.file_name, buffer.file_name_len, &extension_len);
if (_4coder_str_match(extension, extension_len, literal("cpp"))) treat_as_code = 1;
else if (_4coder_str_match(extension, extension_len, literal("h"))) treat_as_code = 1;
else if (_4coder_str_match(extension, extension_len, literal("c"))) treat_as_code = 1;
else if (_4coder_str_match(extension, extension_len, literal("hpp"))) treat_as_code = 1;
}
app->push_parameter(cmd_context, dynamic_int(par_lex_as_cpp_file), dynamic_int(treat_as_code));
app->push_parameter(cmd_context, dynamic_int(par_wrap_lines), dynamic_int(!treat_as_code));
app->push_parameter(cmd_context, dynamic_int(par_key_mapid), dynamic_int(mapid_file));
app->exec_command_keep_stack(cmd_context, cmdid_set_settings);
app->clear_parameters(cmd_context);
}
enum Command_Line_Action{
CLAct_Nothing,
CLAct_Ignore,
@ -3044,6 +2969,8 @@ App_Init_Sig(app_init){
App_Vars *vars = (App_Vars*)memory->vars_memory;
vars->config_api = api;
app_links.data = &vars->command_data;
Partition *partition = &vars->mem.part;
target->partition = partition;
@ -3224,10 +3151,6 @@ App_Init_Sig(app_init){
setup_debug_commands(&vars->map_debug, &vars->mem.part, global);
#endif
if (vars->hooks[hook_open_file] == 0){
vars->hooks[hook_open_file] = default_open_file_hook;
}
vars->font_set = &target->font_set;
font_set_init(vars->font_set, partition, 16, 4);
@ -3696,28 +3619,29 @@ App_Step_Sig(app_step){
app_result.redraw = 1;
}
Command_Data command_data;
command_data.mem = &vars->mem;
command_data.panel = active_panel;
command_data.view = active_panel->view;
command_data.working_set = &vars->working_set;
command_data.layout = &vars->layout;
command_data.live_set = &vars->live_set;
command_data.style = &vars->style;
command_data.delay = &vars->delay;
command_data.vars = vars;
command_data.exchange = exchange;
command_data.screen_width = target->width;
command_data.screen_height = target->height;
command_data.system = system;
Command_Data *cmd = &vars->command_data;
cmd->mem = &vars->mem;
cmd->panel = active_panel;
cmd->view = active_panel->view;
cmd->working_set = &vars->working_set;
cmd->layout = &vars->layout;
cmd->live_set = &vars->live_set;
cmd->style = &vars->style;
cmd->delay = &vars->delay;
cmd->vars = vars;
cmd->exchange = exchange;
cmd->screen_width = target->width;
cmd->screen_height = target->height;
cmd->system = system;
Temp_Memory param_stack_temp = begin_temp_memory(&vars->mem.part);
command_data.part = partition_sub_part(&vars->mem.part, 16 << 10);
cmd->part = partition_sub_part(&vars->mem.part, 16 << 10);
if (first_step){
if (vars->hooks[hook_start]){
vars->hooks[hook_start](&command_data, &app_links);
command_data.part.pos = 0;
vars->hooks[hook_start](&app_links);
cmd->part.pos = 0;
}
i32 i;
@ -3729,8 +3653,7 @@ App_Step_Sig(app_step){
file_name = make_string_slowly(vars->settings.init_files[i]);
if (i < vars->layout.panel_count){
fview = app_open_file(system, vars, exchange, &vars->live_set, &vars->working_set, panel,
&command_data, file_name);
fview = app_open_file(system, vars, exchange, &vars->live_set, &vars->working_set, panel, cmd, file_name);
if (i == 0){
if (fview){
@ -3749,12 +3672,12 @@ App_Step_Sig(app_step){
// NOTE(allen): command input to active view
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
Command_Binding cmd = {};
Command_Binding cmd_bind = {};
Command_Map *map = 0;
View *view = active_panel->view;
Key_Event_Data key = get_single_key(&key_data, key_i);
command_data.key = key;
cmd->key = key;
Command_Map *visited_maps[16] = {};
i32 visited_top = 0;
@ -3762,8 +3685,8 @@ App_Step_Sig(app_step){
if (view) map = view->map;
if (map == 0) map = &vars->map_top;
while (map){
cmd = map_extract(map, key);
if (cmd.function == 0){
cmd_bind = map_extract(map, key);
if (cmd_bind.function == 0){
if (visited_top < ArrayCount(visited_maps)){
visited_maps[visited_top++] = map;
map = map->parent;
@ -3785,16 +3708,16 @@ App_Step_Sig(app_step){
Handle_Command_Function *handle_command = 0;
if (view) handle_command = view->handle_command;
if (handle_command){
handle_command(system, view, &command_data, cmd, key);
handle_command(system, view, cmd, cmd_bind, key);
app_result.redraw = 1;
}
else{
if (cmd.function){
cmd.function(system, &command_data, cmd);
if (cmd_bind.function){
cmd_bind.function(system, cmd, cmd_bind);
app_result.redraw = 1;
}
}
vars->prev_command = cmd;
vars->prev_command = cmd_bind;
}break;
case APP_STATE_RESIZING:
@ -3861,10 +3784,10 @@ App_Step_Sig(app_step){
switch (act->type){
case DACT_OPEN:
{
command_data.view = (View*)
cmd->view = (View*)
app_open_file(system, vars, exchange,
live_set, working_set, panel,
&command_data, *string);
cmd, *string);
}break;
case DACT_SAVE_AS:
@ -3902,9 +3825,9 @@ App_Step_Sig(app_step){
view_replace_major(system, exchange, new_view, panel, live_set);
File_View *file_view = file_view_init(new_view, &vars->layout);
command_data.view = (View*)file_view;
cmd->view = (View*)file_view;
view_set_file(system, file_view, file.file, vars->font_set, style,
vars->hooks[hook_open_file], &command_data, &app_links);
vars->hooks[hook_open_file], cmd, &app_links);
new_view->map = app_get_map(vars, file.file->settings.base_map_id);
#if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file.file->settings.tokens_exist)
@ -3920,10 +3843,10 @@ App_Step_Sig(app_step){
view_replace_major(system, exchange, new_view, panel, live_set);
File_View *file_view = file_view_init(new_view, &vars->layout);
command_data.view = (View*)file_view;
cmd->view = (View*)file_view;
view_set_file(system, file_view, file, vars->font_set, style,
vars->hooks[hook_open_file], &command_data, &app_links);
vars->hooks[hook_open_file], cmd, &app_links);
new_view->map = app_get_map(vars, file->settings.base_map_id);
}

View File

@ -1413,7 +1413,7 @@ view_set_file(System_Functions *system, File_View *view,
view->vel_x = 1.f;
if (open_hook && file->settings.is_initialized == 0){
open_hook(cmd_context, app);
open_hook(app);
file->settings.is_initialized = 1;
}
}