API tweaks

This commit is contained in:
Allen Webster 2016-02-25 07:12:09 -05:00
parent 3a03c6dbb0
commit 9c6fdde85d
8 changed files with 662 additions and 730 deletions

View File

@ -12,6 +12,15 @@
#ifndef FRED_BUFFER_TYPES_H #ifndef FRED_BUFFER_TYPES_H
#define FRED_BUFFER_TYPES_H #define FRED_BUFFER_TYPES_H
typedef union Range{
struct{
int min, max;
};
struct{
int start, end;
};
} Range;
typedef struct Full_Cursor{ typedef struct Full_Cursor{
int pos; int pos;
int line, character; int line, character;
@ -66,12 +75,10 @@ seek_unwrapped_xy(float x, float y, int round_down){
static Buffer_Seek static Buffer_Seek
seek_xy(float x, float y, int round_down, int unwrapped){ seek_xy(float x, float y, int round_down, int unwrapped){
Buffer_Seek result; Buffer_Seek result;
if (unwrapped){ result.type = unwrapped?buffer_seek_unwrapped_xy:buffer_seek_wrapped_xy;
result = seek_unwrapped_xy(x,y,round_down); result.x = x;
} result.y = y;
else{ result.round_down = round_down;
result = seek_wrapped_xy(x,y,round_down);
}
return(result); return(result);
} }

View File

@ -57,7 +57,7 @@ bool str_match(const char *a, int len_a, const char *b, int len_b){
HOOK_SIG(my_file_settings){ HOOK_SIG(my_file_settings){
Buffer_Summary buffer = app->get_active_buffer(cmd_context); Buffer_Summary buffer = app->get_active_buffer(cmd_context);
// NOTE(allen|a3.4.2): Whenever you ask for a buffer, you should first check that // NOTE(allen|a3.4.2): Whenever you ask for a buffer, you can check that
// the exists field is set to true. Reasons why the buffer might not exist: // the exists field is set to true. Reasons why the buffer might not exist:
// -The active panel does not contain a buffer and get_active_buffer was used // -The active panel does not contain a buffer and get_active_buffer was used
// -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer // -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer
@ -84,40 +84,27 @@ HOOK_SIG(my_file_settings){
CUSTOM_COMMAND_SIG(write_increment){ CUSTOM_COMMAND_SIG(write_increment){
char text[] = "++"; char text[] = "++";
int size = sizeof(text) - 1; int size = sizeof(text) - 1;
// NOTE(allen|a3.4.2): In addition to checking whether the buffer exists after a query,
// if you're going to read from or write to the buffer, you should check ready. A buffer
// is usually ready, but when a buffer has just been opened it is possible that the contents
// haven't been filled yet. If the buffer is not ready trying to read or write it is invalid.
// (See my_file_settings for comments on the exists field).
Buffer_Summary buffer = app->get_active_buffer(cmd_context); Buffer_Summary buffer = app->get_active_buffer(cmd_context);
if (buffer.exists && buffer.ready){
app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size); app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
} }
}
CUSTOM_COMMAND_SIG(write_decrement){ CUSTOM_COMMAND_SIG(write_decrement){
char text[] = "--"; char text[] = "--";
int size = sizeof(text) - 1; int size = sizeof(text) - 1;
Buffer_Summary buffer = app->get_active_buffer(cmd_context); Buffer_Summary buffer = app->get_active_buffer(cmd_context);
if (buffer.exists && buffer.ready){
app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size); app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, text, size);
} }
}
CUSTOM_COMMAND_SIG(open_long_braces){ CUSTOM_COMMAND_SIG(open_long_braces){
File_View_Summary view; File_View_Summary view;
Buffer_Summary buffer; Buffer_Summary buffer;
view = app->get_active_file_view(cmd_context);
if (view.exists){
buffer = app->get_active_buffer(cmd_context);
char text[] = "{\n\n}"; char text[] = "{\n\n}";
int size = sizeof(text) - 1; int size = sizeof(text) - 1;
int pos; int pos;
if (buffer.exists && buffer.ready){ view = app->get_active_file_view(cmd_context);
buffer = app->get_buffer(cmd_context, view.file_id);
pos = view.cursor.pos; pos = view.cursor.pos;
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text, size); 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_cursor(cmd_context, &view, seek_pos(pos + 2), 1);
@ -128,29 +115,25 @@ CUSTOM_COMMAND_SIG(open_long_braces){
push_parameter(app, cmd_context, par_clear_blank_lines, 0); push_parameter(app, cmd_context, par_clear_blank_lines, 0);
exec_command(cmd_context, cmdid_auto_tab_range); exec_command(cmd_context, cmdid_auto_tab_range);
} }
}
}
CUSTOM_COMMAND_SIG(ifdef_off){ CUSTOM_COMMAND_SIG(ifdef_off){
File_View_Summary view; File_View_Summary view;
Buffer_Summary buffer; Buffer_Summary buffer;
view = app->get_active_file_view(cmd_context);
if (view.exists){
buffer = app->get_active_buffer(cmd_context);
char text1[] = "#if 0\n"; char text1[] = "#if 0\n";
int size1 = sizeof(text1) - 1; int size1 = sizeof(text1) - 1;
char text2[] = "#endif\n"; char text2[] = "#endif\n";
int size2 = sizeof(text2) - 1; int size2 = sizeof(text2) - 1;
int pos, c, m; Range range;
int pos;
if (buffer.exists && buffer.ready){ view = app->get_active_file_view(cmd_context);
c = view.cursor.pos; buffer = app->get_active_buffer(cmd_context);
m = view.mark.pos;
pos = (c<m)?(c):(m); range = get_range(&view);
pos = range.min;
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text1, size1); app->buffer_replace_range(cmd_context, &buffer, pos, pos, text1, size1);
@ -158,12 +141,9 @@ CUSTOM_COMMAND_SIG(ifdef_off){
push_parameter(app, cmd_context, par_range_end, pos); push_parameter(app, cmd_context, par_range_end, pos);
exec_command(cmd_context, cmdid_auto_tab_range); exec_command(cmd_context, cmdid_auto_tab_range);
app->refresh_file_view(cmd_context, &view); app->refresh_file_view(cmd_context, &view);
c = view.cursor.pos; range = get_range(&view);
m = view.mark.pos; pos = range.max;
pos = (c>m)?(c):(m);
app->buffer_replace_range(cmd_context, &buffer, pos, pos, text2, size2); app->buffer_replace_range(cmd_context, &buffer, pos, pos, text2, size2);
@ -171,8 +151,6 @@ CUSTOM_COMMAND_SIG(ifdef_off){
push_parameter(app, cmd_context, par_range_end, pos); push_parameter(app, cmd_context, par_range_end, pos);
exec_command(cmd_context, cmdid_auto_tab_range); exec_command(cmd_context, cmdid_auto_tab_range);
} }
}
}
CUSTOM_COMMAND_SIG(backspace_word){ CUSTOM_COMMAND_SIG(backspace_word){
File_View_Summary view; File_View_Summary view;
@ -180,18 +158,15 @@ CUSTOM_COMMAND_SIG(backspace_word){
int pos2, pos1; int pos2, pos1;
view = app->get_active_file_view(cmd_context); view = app->get_active_file_view(cmd_context);
if (view.exists){
pos2 = view.cursor.pos; pos2 = view.cursor.pos;
exec_command(cmd_context, cmdid_seek_alphanumeric_left); exec_command(cmd_context, cmdid_seek_alphanumeric_left);
app->refresh_file_view(cmd_context, &view); app->refresh_file_view(cmd_context, &view);
pos1 = view.cursor.pos; pos1 = view.cursor.pos;
if (pos1 < pos2){
buffer = app->get_buffer(cmd_context, view.file_id); buffer = app->get_buffer(cmd_context, view.file_id);
app->buffer_replace_range(cmd_context, &buffer, pos1, pos2, 0, 0); app->buffer_replace_range(cmd_context, &buffer, pos1, pos2, 0, 0);
} }
}
}
CUSTOM_COMMAND_SIG(switch_to_compilation){ CUSTOM_COMMAND_SIG(switch_to_compilation){
File_View_Summary view; File_View_Summary view;
@ -205,20 +180,16 @@ CUSTOM_COMMAND_SIG(switch_to_compilation){
// to change the specific type of view and set files even when the view didn't // to change the specific type of view and set files even when the view didn't
// contain a file. // contain a file.
view = app->get_active_file_view(cmd_context); view = app->get_active_file_view(cmd_context);
if (view.exists){
buffer = app->get_buffer_by_name(cmd_context, make_string(name, name_size)); buffer = app->get_buffer_by_name(cmd_context, make_string(name, name_size));
if (buffer.exists){
app->view_set_file(cmd_context, &view, buffer.file_id); app->view_set_file(cmd_context, &view, buffer.file_id);
} }
}
}
CUSTOM_COMMAND_SIG(move_up_10){ CUSTOM_COMMAND_SIG(move_up_10){
File_View_Summary view; File_View_Summary view;
float x, y; float x, y;
view = app->get_active_file_view(cmd_context); view = app->get_active_file_view(cmd_context);
if (view.exists){
x = view.preferred_x; x = view.preferred_x;
if (view.unwrapped_lines){ if (view.unwrapped_lines){
@ -232,14 +203,12 @@ CUSTOM_COMMAND_SIG(move_up_10){
app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0); app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
} }
}
CUSTOM_COMMAND_SIG(move_down_10){ CUSTOM_COMMAND_SIG(move_down_10){
File_View_Summary view; File_View_Summary view;
float x, y; float x, y;
view = app->get_active_file_view(cmd_context); view = app->get_active_file_view(cmd_context);
if (view.exists){
x = view.preferred_x; x = view.preferred_x;
if (view.unwrapped_lines){ if (view.unwrapped_lines){
@ -253,7 +222,6 @@ CUSTOM_COMMAND_SIG(move_down_10){
app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0); app->view_set_cursor(cmd_context, &view, seek_xy(x, y, 0, view.unwrapped_lines), 0);
} }
}
CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
File_View_Summary view; File_View_Summary view;
@ -264,7 +232,7 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
view = app->get_active_file_view(cmd_context); view = app->get_active_file_view(cmd_context);
if (view.exists){ if (view.exists){
buffer = app->get_buffer(cmd_context, view.file_id); buffer = app->get_buffer(cmd_context, view.file_id);
if (buffer.exists && buffer.ready){ if (buffer.ready){
pos = view.cursor.pos; pos = view.cursor.pos;
app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 1, &end); app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 1, &end);
app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 0, &start); app->buffer_seek_delimiter(cmd_context, &buffer, pos, '"', 0, &start);
@ -283,6 +251,8 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
append(&file_name, make_string(short_file_name, size)); append(&file_name, make_string(short_file_name, size));
buffer = app->get_buffer_by_name(cmd_context, file_name); 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);
if (buffer.exists){ if (buffer.exists){
app->view_set_file(cmd_context, &view, buffer.file_id); app->view_set_file(cmd_context, &view, buffer.file_id);
} }

View File

@ -215,6 +215,21 @@ push_directory(Application_Links *app, void *cmd_context){
#define expand_string(d) ((d).str), ((d).size) #define expand_string(d) ((d).str), ((d).size)
inline Range
get_range(File_View_Summary *view){
Range range;
if (view->cursor.pos < view->mark.pos){
range.min = view->cursor.pos;
range.max = view->mark.pos;
}
else{
range.max = view->cursor.pos;
range.min = view->mark.pos;
}
return(range);
}
#if DisableMacroTranslations == 0 #if DisableMacroTranslations == 0
inline void inline void

View File

@ -273,6 +273,9 @@ tailstr(String str){
#ifdef FCPP_STRING_IMPLEMENTATION #ifdef FCPP_STRING_IMPLEMENTATION
#ifndef FCPP_DID_STRING_IMPLEMENTATION
#define FCPP_DID_STRING_IMPLEMENTATION
FCPP_LINK int FCPP_LINK int
str_size(char *str){ str_size(char *str){
int i = 0; int i = 0;
@ -1171,6 +1174,8 @@ wildcard_match(Absolutes *absolutes, String x, int case_sensitive){
return wildcard_match(absolutes, x.str, case_sensitive); return wildcard_match(absolutes, x.str, case_sensitive);
} }
#endif // #ifndef FCPP_DID_STRING_IMPLEMENTATION
#undef FCPP_STRING_IMPLEMENTATION #undef FCPP_STRING_IMPLEMENTATION
#endif // #ifdef FCPP_STRING_IMPLEMENTATION #endif // #ifdef FCPP_STRING_IMPLEMENTATION

114
4ed.cpp
View File

@ -1086,13 +1086,6 @@ COMMAND_DECL(save){
USE_PANEL(panel); USE_PANEL(panel);
delayed_action(delay, DACT_SAVE, file->name.source_path, panel); delayed_action(delay, DACT_SAVE, file->name.source_path, panel);
#if 0
String *file_path = &file->name.source_path;
if (file_path->size > 0){
i32 sys_id = file_save(system, exchange, mem, file, file_path->str);
app_push_file_binding(vars, sys_id, get_file_id(working_set, file));
}
#endif
} }
COMMAND_DECL(interactive_save_as){ COMMAND_DECL(interactive_save_as){
@ -2533,92 +2526,12 @@ setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Comm
internal void internal void
setup_file_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ setup_file_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){
map_init(commands, part, 101, parent); map_init(commands, part, 10, parent);
commands->vanilla_keyboard_default.function = command_write_character;
map_add(commands, codes->left, MDFR_NONE, command_move_left);
map_add(commands, codes->right, MDFR_NONE, command_move_right);
map_add(commands, codes->del, MDFR_NONE, command_delete);
map_add(commands, codes->back, MDFR_NONE, command_backspace);
map_add(commands, codes->up, MDFR_NONE, command_move_up);
map_add(commands, codes->down, MDFR_NONE, command_move_down);
map_add(commands, codes->end, MDFR_NONE, command_seek_end_of_line);
map_add(commands, codes->home, MDFR_NONE, command_seek_beginning_of_line);
map_add(commands, codes->page_up, MDFR_NONE, command_page_up);
map_add(commands, codes->page_down, MDFR_NONE, command_page_down);
map_add(commands, codes->right, MDFR_CTRL, command_seek_alphanumeric_or_camel_right);
map_add(commands, codes->left, MDFR_CTRL, command_seek_alphanumeric_or_camel_left);
map_add(commands, codes->up, MDFR_CTRL, command_seek_whitespace_up);
map_add(commands, codes->down, MDFR_CTRL, command_seek_whitespace_down);
map_add(commands, ' ', MDFR_CTRL, command_set_mark);
map_add(commands, 'm', MDFR_CTRL, command_cursor_mark_swap);
map_add(commands, 'c', MDFR_CTRL, command_copy);
map_add(commands, 'x', MDFR_CTRL, command_cut);
map_add(commands, 'v', MDFR_CTRL, command_paste);
map_add(commands, 'V', MDFR_CTRL, command_paste_next);
map_add(commands, 'z', MDFR_CTRL, command_undo);
map_add(commands, 'y', MDFR_CTRL, command_redo);
map_add(commands, 'Z', MDFR_CTRL, command_timeline_scrub);
map_add(commands, codes->left, MDFR_ALT, command_increase_rewind_speed);
map_add(commands, codes->right, MDFR_ALT, command_increase_fastforward_speed);
map_add(commands, codes->down, MDFR_ALT, command_stop_rewind_fastforward);
map_add(commands, 'h', MDFR_CTRL, command_history_backward);
map_add(commands, 'H', MDFR_CTRL, command_history_forward);
map_add(commands, 'd', MDFR_CTRL, command_delete_range);
map_add(commands, 'l', MDFR_CTRL, command_toggle_line_wrap);
map_add(commands, '?', MDFR_CTRL, command_toggle_show_whitespace);
map_add(commands, '|', MDFR_CTRL, command_toggle_tokens);
map_add(commands, 'u', MDFR_CTRL, command_to_uppercase);
map_add(commands, 'j', MDFR_CTRL, command_to_lowercase);
map_add(commands, '~', MDFR_CTRL, command_clean_all_lines);
map_add(commands, 'f', MDFR_CTRL, command_search);
map_add(commands, 'r', MDFR_CTRL, command_reverse_search);
map_add(commands, 'g', MDFR_CTRL, command_goto_line);
map_add(commands, '\n', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '}', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ')', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ']', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ';', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '#', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '\t', MDFR_NONE, command_word_complete);
map_add(commands, '\t', MDFR_CTRL, command_auto_tab_range);
map_add(commands, '\t', MDFR_SHIFT, command_auto_tab_line_at_cursor);
map_add(commands, 'K', MDFR_CTRL, command_kill_buffer);
map_add(commands, 'O', MDFR_CTRL, command_reopen);
map_add(commands, 's', MDFR_CTRL, command_save);
map_add(commands, 'w', MDFR_CTRL, command_interactive_save_as);
#if UseFileHistoryDump
map_add(commands, 'h', MDFR_ALT, command_save_history);
#endif
} }
internal void internal void
setup_top_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ setup_top_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){
map_init(commands, part, 51, parent); map_init(commands, part, 5, parent);
#if FRED_INTERNAL
map_add(commands, 'd', MDFR_ALT, command_open_debug_view);
#endif
map_add(commands, 'p', MDFR_CTRL, command_open_panel_vsplit);
map_add(commands, '-', MDFR_CTRL, command_open_panel_hsplit);
map_add(commands, 'P', MDFR_CTRL, command_close_panel);
map_add(commands, 'n', MDFR_CTRL, command_interactive_new);
map_add(commands, 'o', MDFR_CTRL, command_interactive_open);
map_add(commands, ',', MDFR_CTRL, command_change_active_panel);
map_add(commands, 'k', MDFR_CTRL, command_interactive_kill_buffer);
map_add(commands, 'i', MDFR_CTRL, command_interactive_switch_buffer);
map_add(commands, 'c', MDFR_ALT, command_open_color_tweaker);
map_add(commands, 'x', MDFR_ALT, command_open_menu);
map_add(commands, 'm', MDFR_ALT, command_build_here);
} }
internal void internal void
@ -3091,9 +3004,16 @@ app_setup_memory(Application_Memory *memory){
internal i32 internal i32
execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){ execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){
char message[] = "Hell World!"; i32 result;
i32 result = sizeof(message) - 1; char message[] = "tool was not specified or is invalid";
result = sizeof(message) - 1;
memcpy(memory, message, result); memcpy(memory, message, result);
if (clparams.argc > 2){
if (match(clparams.argv[2], "version")){
result = sizeof(VERSION) - 1;
memcpy(memory, VERSION, result);
}
}
return(result); return(result);
} }
@ -3179,7 +3099,8 @@ App_Init_Sig(app_init){
setup_command_table(); setup_command_table();
Command_Map *global = &vars->map_top; Command_Map *global = &vars->map_top;
if (vars->config_api.get_bindings){ Assert(vars->config_api.get_bindings != 0);
i32 size = partition_remaining(partition); i32 size = partition_remaining(partition);
void *data = partition_current(partition); void *data = partition_current(partition);
@ -3293,11 +3214,10 @@ App_Init_Sig(app_init){
if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, codes, global); if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, codes, global);
if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, codes, global); if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, codes, global);
}
else{ #if !defined(FRED_SUPER)
setup_top_commands(&vars->map_top, &vars->mem.part, codes, global); vars->hooks[hook_start] = 0;
setup_file_commands(&vars->map_file, &vars->mem.part, codes, global); #endif
}
setup_ui_commands(&vars->map_ui, &vars->mem.part, codes, global); setup_ui_commands(&vars->map_ui, &vars->mem.part, codes, global);
#if FRED_INTERNAL #if FRED_INTERNAL

View File

@ -9,6 +9,16 @@
// TOP // TOP
#define VERSION_NUMBER "alpha 3.4.3"
#ifdef FRED_SUPER
#define VERSION_TYPE " super!"
#else
#define VERSION_TYPE ""
#endif
#define VERSION VERSION_NUMBER VERSION_TYPE
#include "4ed_config.h" #include "4ed_config.h"
#define BUFFER_EXPERIMENT_SCALPEL 0 #define BUFFER_EXPERIMENT_SCALPEL 0

View File

@ -9,10 +9,6 @@
// TOP // TOP
struct Range{
i32 start, end;
};
struct File_View_Mode{ struct File_View_Mode{
b8 rewrite; b8 rewrite;
}; };

View File

@ -24,7 +24,12 @@
#include "4ed_dll_reader.h" #include "4ed_dll_reader.h"
#include "4coder_custom.h" #include "4coder_custom.cpp"
#undef exec_command
#undef exec_command_keep_stack
#undef clear_parameters
#include "4ed_system.h" #include "4ed_system.h"
#include "4ed_rendering.h" #include "4ed_rendering.h"
#include "4ed.h" #include "4ed.h"
@ -1602,6 +1607,10 @@ main(int argc, char **argv){
} }
#endif #endif
if (win32vars.custom_api.get_bindings == 0){
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings;
}
Thread_Context background[4]; Thread_Context background[4];
memset(background, 0, sizeof(background)); memset(background, 0, sizeof(background));
win32vars.groups[BACKGROUND_THREADS].threads = background; win32vars.groups[BACKGROUND_THREADS].threads = background;