diff --git a/4coder_default_framework.h b/4coder_default_framework.h index d41cec31..0b34865a 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -691,13 +691,17 @@ static int32_t named_map_count = 0; static void change_mapping(Application_Links *app, String mapping){ + bool32 did_remap = false; for (int32_t i = 0; i < named_map_count; ++i){ if (match(mapping, named_maps[i].name)){ + did_remap = true; exec_command(app, named_maps[i].remap_command); break; } } - print_message(app, literal("Leaving bindings unaltered.\n")); + if (!did_remap){ + print_message(app, literal("Leaving bindings unaltered.\n")); + } } CUSTOM_COMMAND_SIG(remap_interactive){ diff --git a/4coder_remapping_commands.cpp b/4coder_remapping_commands.cpp index 0a54779e..edef9a15 100644 --- a/4coder_remapping_commands.cpp +++ b/4coder_remapping_commands.cpp @@ -14,618 +14,630 @@ TYPE: 'drop-in-command-pack' // Buffer Filling Helpers // -void -default_keys(Bind_Helper *context){ - // NOTE(allen|a4.0.22): GLOBAL - begin_map(context, mapid_global); - - bind(context, 'p', MDFR_CTRL, open_panel_vsplit); - bind(context, '_', MDFR_CTRL, open_panel_hsplit); - bind(context, 'P', MDFR_CTRL, close_panel); - bind(context, ',', MDFR_CTRL, change_active_panel); - bind(context, '<', MDFR_CTRL, change_active_panel_backwards); - - bind(context, 'n', MDFR_CTRL, interactive_new); - bind(context, 'o', MDFR_CTRL, interactive_open_or_new); - bind(context, 'o', MDFR_ALT, open_in_other); - bind(context, 'k', MDFR_CTRL, interactive_kill_buffer); - bind(context, 'i', MDFR_CTRL, interactive_switch_buffer); - bind(context, 'w', MDFR_CTRL, save_as); - bind(context, 'h', MDFR_CTRL, project_go_to_root_directory); - bind(context, 'S', MDFR_CTRL, save_all_dirty_buffers); - - bind(context, 'c', MDFR_ALT, open_color_tweaker); - bind(context, 'd', MDFR_ALT, open_debug); - - bind(context, '.', MDFR_ALT, change_to_build_panel); - bind(context, ',', MDFR_ALT, close_build_panel); - bind(context, 'n', MDFR_ALT, goto_next_error); - bind(context, 'N', MDFR_ALT, goto_prev_error); - bind(context, 'M', MDFR_ALT, goto_first_error); - bind(context, 'm', MDFR_ALT, build_in_build_panel); - - bind(context, 'z', MDFR_ALT, execute_any_cli); - bind(context, 'Z', MDFR_ALT, execute_previous_cli); - - bind(context, 'x', MDFR_ALT, execute_arbitrary_command); - - bind(context, 's', MDFR_ALT, show_scrollbar); - bind(context, 'w', MDFR_ALT, hide_scrollbar); - bind(context, 'b', MDFR_ALT, toggle_filebar); - - bind(context, '@', MDFR_ALT, toggle_mouse); - bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen); - bind(context, 'E', MDFR_ALT, exit_4coder); - - bind(context, key_f1, MDFR_NONE, project_fkey_command); - bind(context, key_f2, MDFR_NONE, project_fkey_command); - bind(context, key_f3, MDFR_NONE, project_fkey_command); - bind(context, key_f4, MDFR_NONE, project_fkey_command); - - bind(context, key_f5, MDFR_NONE, project_fkey_command); - bind(context, key_f6, MDFR_NONE, project_fkey_command); - bind(context, key_f7, MDFR_NONE, project_fkey_command); - bind(context, key_f8, MDFR_NONE, project_fkey_command); - - bind(context, key_f9, MDFR_NONE, project_fkey_command); - bind(context, key_f10, MDFR_NONE, project_fkey_command); - bind(context, key_f11, MDFR_NONE, project_fkey_command); - bind(context, key_f12, MDFR_NONE, project_fkey_command); - - bind(context, key_f13, MDFR_NONE, project_fkey_command); - bind(context, key_f14, MDFR_NONE, project_fkey_command); - bind(context, key_f15, MDFR_NONE, project_fkey_command); - bind(context, key_f16, MDFR_NONE, project_fkey_command); - - end_map(context); - - // NOTE(allen|a4.0.22): FILE - begin_map(context, mapid_file); - - bind_vanilla_keys(context, write_character); - - bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); - bind(context, key_mouse_right, MDFR_NONE, click_set_mark); - - bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); - - bind(context, key_left, MDFR_NONE, move_left); - bind(context, key_right, MDFR_NONE, move_right); - bind(context, key_del, MDFR_NONE, delete_char); - bind(context, key_del, MDFR_SHIFT, delete_char); - bind(context, key_back, MDFR_NONE, backspace_char); - bind(context, key_back, MDFR_SHIFT, backspace_char); - bind(context, key_up, MDFR_NONE, move_up); - bind(context, key_down, MDFR_NONE, move_down); - bind(context, key_end, MDFR_NONE, seek_end_of_line); - bind(context, key_home, MDFR_NONE, seek_beginning_of_line); - bind(context, key_page_up, MDFR_NONE, page_up); - bind(context, key_page_down, MDFR_NONE, page_down); - - bind(context, key_right, MDFR_CTRL, seek_whitespace_right); - bind(context, key_left, MDFR_CTRL, seek_whitespace_left); - bind(context, key_up, MDFR_CTRL, seek_whitespace_up_end_line); - bind(context, key_down, MDFR_CTRL, seek_whitespace_down_end_line); - - bind(context, key_up, MDFR_ALT, move_up_10); - bind(context, key_down, MDFR_ALT, move_down_10); - - bind(context, key_back, MDFR_CTRL, backspace_word); - bind(context, key_del, MDFR_CTRL, delete_word); - bind(context, key_back, MDFR_ALT, snipe_token_or_word); - bind(context, key_del, MDFR_ALT, snipe_token_or_word_right); - - bind(context, ' ', MDFR_CTRL, set_mark); - bind(context, 'a', MDFR_CTRL, replace_in_range); - bind(context, 'c', MDFR_CTRL, copy); - bind(context, 'd', MDFR_CTRL, delete_range); - bind(context, 'e', MDFR_CTRL, center_view); - bind(context, 'E', MDFR_CTRL, left_adjust_view); - bind(context, 'f', MDFR_CTRL, search); - bind(context, 'F', MDFR_CTRL, list_all_locations); - bind(context, 'F', MDFR_ALT, list_all_substring_locations_case_insensitive); - bind(context, 'g', MDFR_CTRL, goto_line); - bind(context, 'j', MDFR_CTRL, to_lowercase); - bind(context, 'K', MDFR_CTRL, kill_buffer); - bind(context, 'l', MDFR_CTRL, toggle_line_wrap); - bind(context, 'm', MDFR_CTRL, cursor_mark_swap); - bind(context, 'O', MDFR_CTRL, reopen); - bind(context, 'q', MDFR_CTRL, query_replace); - bind(context, 'Q', MDFR_CTRL, query_replace_identifier); - bind(context, 'r', MDFR_CTRL, reverse_search); - bind(context, 's', MDFR_CTRL, save); - bind(context, 't', MDFR_CTRL, search_identifier); - bind(context, 'T', MDFR_CTRL, list_all_locations_of_identifier); - bind(context, 'u', MDFR_CTRL, to_uppercase); - bind(context, 'v', MDFR_CTRL, paste_and_indent); - bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace); - bind(context, 'V', MDFR_CTRL, paste_next_and_indent); - bind(context, 'x', MDFR_CTRL, cut); - bind(context, 'y', MDFR_CTRL, redo); - bind(context, 'z', MDFR_CTRL, undo); - - bind(context, '2', MDFR_CTRL, decrease_line_wrap); - bind(context, '3', MDFR_CTRL, increase_line_wrap); - - bind(context, '?', MDFR_CTRL, toggle_show_whitespace); - bind(context, '~', MDFR_CTRL, clean_all_lines); - bind(context, '\n', MDFR_NONE, newline_or_goto_position); - bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); - bind(context, ' ', MDFR_SHIFT, write_character); - - end_map(context); - - // NOTE(allen|a4.0.22): CODE - begin_map(context, default_code_map); - - inherit_map(context, mapid_file); - - bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right); - bind(context, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left); - - bind(context, '\n', MDFR_NONE, write_and_auto_tab); - bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); - bind(context, '}', MDFR_NONE, write_and_auto_tab); - bind(context, ')', MDFR_NONE, write_and_auto_tab); - bind(context, ']', MDFR_NONE, write_and_auto_tab); - bind(context, ';', MDFR_NONE, write_and_auto_tab); - bind(context, '#', MDFR_NONE, write_and_auto_tab); - - bind(context, '\t', MDFR_NONE, word_complete); - bind(context, '\t', MDFR_CTRL, auto_tab_range); - bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); - - bind(context, 'h', MDFR_ALT, write_hack); - bind(context, 'r', MDFR_ALT, write_block); - bind(context, 't', MDFR_ALT, write_todo); - bind(context, 'y', MDFR_ALT, write_note); - bind(context, '[', MDFR_CTRL, open_long_braces); - bind(context, '{', MDFR_CTRL, open_long_braces_semicolon); - bind(context, '}', MDFR_CTRL, open_long_braces_break); - bind(context, 'i', MDFR_ALT, if0_off); - bind(context, '1', MDFR_ALT, open_file_in_quotes); - bind(context, '2', MDFR_ALT, open_matching_file_cpp); - bind(context, '0', MDFR_CTRL, write_zero_struct); - bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer); - - end_map(context); -} +enum{ + B_None, + B_Major, + B_Minor, + B_Both, +}; void -bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, int32_t command){ - bind(context, code, MDFR_CTRL, command); - bind(context, code, MDFR_CMND, command); -} - -void -bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, Custom_Command_Function *command){ - bind(context, code, MDFR_CTRL, command); - bind(context, code, MDFR_CMND, command); -} - -void -mac_4coder_like_keys(Bind_Helper *context){ - // NOTE(allen|a4.0.22): GLOBAL - begin_map(context, mapid_global); - - bind_ctrl_and_cmnd(context, 'p', open_panel_vsplit); - bind_ctrl_and_cmnd(context, '_', open_panel_hsplit); - bind_ctrl_and_cmnd(context, 'P', close_panel); - bind_ctrl_and_cmnd(context, ',', change_active_panel); - bind_ctrl_and_cmnd(context, '<', change_active_panel_backwards); - - bind_ctrl_and_cmnd(context, 'n', interactive_new); - bind_ctrl_and_cmnd(context, 'o', interactive_open_or_new); - bind(context, 'o', MDFR_ALT, open_in_other); - bind_ctrl_and_cmnd(context, 'k', interactive_kill_buffer); - bind_ctrl_and_cmnd(context, 'i', interactive_switch_buffer); - bind_ctrl_and_cmnd(context, 'w', save_as); - bind_ctrl_and_cmnd(context, 'h', project_go_to_root_directory); - bind_ctrl_and_cmnd(context, 'S', save_all_dirty_buffers); - - bind(context, 'c', MDFR_ALT, open_color_tweaker); - bind(context, 'd', MDFR_ALT, open_debug); - - bind(context, '.', MDFR_ALT, change_to_build_panel); - bind(context, ',', MDFR_ALT, close_build_panel); - bind(context, 'n', MDFR_ALT, goto_next_error); - bind(context, 'N', MDFR_ALT, goto_prev_error); - bind(context, 'M', MDFR_ALT, goto_first_error); - bind(context, 'm', MDFR_ALT, build_in_build_panel); - - bind(context, 'z', MDFR_ALT, execute_any_cli); - bind(context, 'Z', MDFR_ALT, execute_previous_cli); - - bind(context, 'x', MDFR_ALT, execute_arbitrary_command); - - bind(context, 's', MDFR_ALT, show_scrollbar); - bind(context, 'w', MDFR_ALT, hide_scrollbar); - bind(context, 'b', MDFR_ALT, toggle_filebar); - - bind(context, '@', MDFR_ALT, toggle_mouse); - bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen); - bind(context, 'E', MDFR_ALT, exit_4coder); - - bind(context, key_f1, MDFR_NONE, project_fkey_command); - bind(context, key_f2, MDFR_NONE, project_fkey_command); - bind(context, key_f3, MDFR_NONE, project_fkey_command); - bind(context, key_f4, MDFR_NONE, project_fkey_command); - - bind(context, key_f5, MDFR_NONE, project_fkey_command); - bind(context, key_f6, MDFR_NONE, project_fkey_command); - bind(context, key_f7, MDFR_NONE, project_fkey_command); - bind(context, key_f8, MDFR_NONE, project_fkey_command); - - bind(context, key_f9, MDFR_NONE, project_fkey_command); - bind(context, key_f10, MDFR_NONE, project_fkey_command); - bind(context, key_f11, MDFR_NONE, project_fkey_command); - bind(context, key_f12, MDFR_NONE, project_fkey_command); - - bind(context, key_f13, MDFR_NONE, project_fkey_command); - bind(context, key_f14, MDFR_NONE, project_fkey_command); - bind(context, key_f15, MDFR_NONE, project_fkey_command); - bind(context, key_f16, MDFR_NONE, project_fkey_command); - - end_map(context); - - // NOTE(allen|a4.0.22): FILE - begin_map(context, mapid_file); - - bind_vanilla_keys(context, write_character); - - bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); - bind(context, key_mouse_right, MDFR_NONE, click_set_mark); - - bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); - - bind(context, key_left, MDFR_NONE, move_left); - bind(context, key_right, MDFR_NONE, move_right); - bind(context, key_del, MDFR_NONE, delete_char); - bind(context, key_del, MDFR_SHIFT, delete_char); - bind(context, key_back, MDFR_NONE, backspace_char); - bind(context, key_back, MDFR_SHIFT, backspace_char); - bind(context, key_up, MDFR_NONE, move_up); - bind(context, key_down, MDFR_NONE, move_down); - bind(context, key_end, MDFR_NONE, seek_end_of_line); - bind(context, key_home, MDFR_NONE, seek_beginning_of_line); - bind(context, key_page_up, MDFR_NONE, page_up); - bind(context, key_page_down, MDFR_NONE, page_down); - - bind(context, key_right, MDFR_CMND, seek_whitespace_right); - bind(context, key_left, MDFR_CMND, seek_whitespace_left); - bind(context, key_up, MDFR_CMND, seek_whitespace_up_end_line); - bind(context, key_down, MDFR_CMND, seek_whitespace_down_end_line); - - bind(context, key_up, MDFR_ALT, move_up_10); - bind(context, key_down, MDFR_ALT, move_down_10); - - bind_ctrl_and_cmnd(context, key_back, backspace_word); - bind_ctrl_and_cmnd(context, key_del, delete_word); - bind(context, key_back, MDFR_ALT, snipe_token_or_word); - bind(context, key_del, MDFR_ALT, snipe_token_or_word_right); - - bind_ctrl_and_cmnd(context, ' ', set_mark); - bind_ctrl_and_cmnd(context, 'a', replace_in_range); - bind_ctrl_and_cmnd(context, 'c', copy); - bind_ctrl_and_cmnd(context, 'd', delete_range); - bind_ctrl_and_cmnd(context, 'e', center_view); - bind_ctrl_and_cmnd(context, 'E', left_adjust_view); - bind_ctrl_and_cmnd(context, 'f', search); - bind_ctrl_and_cmnd(context, 'F', list_all_locations); - bind(context, 'F', MDFR_ALT, list_all_substring_locations_case_insensitive); - bind_ctrl_and_cmnd(context, 'g', goto_line); - bind_ctrl_and_cmnd(context, 'j', to_lowercase); - bind_ctrl_and_cmnd(context, 'K', kill_buffer); - bind_ctrl_and_cmnd(context, 'l', toggle_line_wrap); - bind_ctrl_and_cmnd(context, 'm', cursor_mark_swap); - bind_ctrl_and_cmnd(context, 'O', reopen); - bind_ctrl_and_cmnd(context, 'q', query_replace); - bind_ctrl_and_cmnd(context, 'Q', query_replace_identifier); - bind_ctrl_and_cmnd(context, 'r', reverse_search); - bind_ctrl_and_cmnd(context, 's', save); - bind_ctrl_and_cmnd(context, 't', search_identifier); - bind_ctrl_and_cmnd(context, 'T', list_all_locations_of_identifier); - bind_ctrl_and_cmnd(context, 'u', to_uppercase); - bind_ctrl_and_cmnd(context, 'v', paste_and_indent); - bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace); - bind_ctrl_and_cmnd(context, 'V', paste_next_and_indent); - bind_ctrl_and_cmnd(context, 'x', cut); - bind_ctrl_and_cmnd(context, 'y', redo); - bind_ctrl_and_cmnd(context, 'z', undo); - - bind_ctrl_and_cmnd(context, '2', decrease_line_wrap); - bind_ctrl_and_cmnd(context, '3', increase_line_wrap); - - bind_ctrl_and_cmnd(context, '?', toggle_show_whitespace); - bind_ctrl_and_cmnd(context, '~', clean_all_lines); - bind(context, '\n', MDFR_NONE, newline_or_goto_position); - bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); - bind(context, ' ', MDFR_SHIFT, write_character); - - end_map(context); - - // NOTE(allen|a4.0.22): CODE - begin_map(context, default_code_map); - - inherit_map(context, mapid_file); - - bind_ctrl_and_cmnd(context, key_right, seek_alphanumeric_or_camel_right); - bind_ctrl_and_cmnd(context, key_left, seek_alphanumeric_or_camel_left); - - bind(context, '\n', MDFR_NONE, write_and_auto_tab); - bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); - bind(context, '}', MDFR_NONE, write_and_auto_tab); - bind(context, ')', MDFR_NONE, write_and_auto_tab); - bind(context, ']', MDFR_NONE, write_and_auto_tab); - bind(context, ';', MDFR_NONE, write_and_auto_tab); - bind(context, '#', MDFR_NONE, write_and_auto_tab); - - bind(context, '\t', MDFR_NONE, word_complete); - bind_ctrl_and_cmnd(context, '\t', auto_tab_range); - bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); - - bind(context, 'h', MDFR_ALT, write_hack); - bind(context, 'r', MDFR_ALT, write_block); - bind(context, 't', MDFR_ALT, write_todo); - bind(context, 'y', MDFR_ALT, write_note); - bind_ctrl_and_cmnd(context, '[', open_long_braces); - bind_ctrl_and_cmnd(context, '{', open_long_braces_semicolon); - bind_ctrl_and_cmnd(context, '}', open_long_braces_break); - bind(context, 'i', MDFR_ALT, if0_off); - bind(context, '1', MDFR_ALT, open_file_in_quotes); - bind(context, '2', MDFR_ALT, open_matching_file_cpp); - bind_ctrl_and_cmnd(context, '0', write_zero_struct); - bind_ctrl_and_cmnd(context, 'I', list_all_functions_current_buffer); - - end_map(context); -} - -void -mac_default_keys(Bind_Helper *context){ - // NOTE(allen|a4.0.22): GLOBAL - begin_map(context, mapid_global); - - bind(context, 'p', MDFR_CMND, open_panel_vsplit); - bind(context, '_', MDFR_CMND, open_panel_hsplit); - bind(context, 'P', MDFR_CMND, close_panel); - bind(context, ',', MDFR_CMND, change_active_panel); - bind(context, '<', MDFR_CMND, change_active_panel_backwards); - - bind(context, 'n', MDFR_CMND, interactive_new); - bind(context, 'o', MDFR_CMND, interactive_open_or_new); - bind(context, 'o', MDFR_CTRL, open_in_other); - bind(context, 'k', MDFR_CMND, interactive_kill_buffer); - bind(context, 'i', MDFR_CMND, interactive_switch_buffer); - bind(context, 'w', MDFR_CMND, save_as); - bind(context, 'h', MDFR_CMND, project_go_to_root_directory); - bind(context, 'S', MDFR_CMND, save_all_dirty_buffers); - - bind(context, 'c', MDFR_CTRL, open_color_tweaker); - bind(context, 'd', MDFR_CTRL, open_debug); - - bind(context, '.', MDFR_CTRL, change_to_build_panel); - bind(context, ',', MDFR_CTRL, close_build_panel); - bind(context, 'n', MDFR_CTRL, goto_next_error); - bind(context, 'N', MDFR_CTRL, goto_prev_error); - bind(context, 'M', MDFR_CTRL, goto_first_error); - bind(context, 'm', MDFR_CTRL, build_in_build_panel); - - bind(context, 'z', MDFR_CTRL, execute_any_cli); - bind(context, 'Z', MDFR_CTRL, execute_previous_cli); - - bind(context, 'x', MDFR_CTRL, execute_arbitrary_command); - - bind(context, 's', MDFR_CTRL, show_scrollbar); - bind(context, 'w', MDFR_CTRL, hide_scrollbar); - bind(context, 'b', MDFR_CTRL, toggle_filebar); - - bind(context, '@', MDFR_CTRL, toggle_mouse); - bind(context, key_page_up, MDFR_CMND, toggle_fullscreen); - bind(context, 'E', MDFR_CTRL, exit_4coder); - - bind(context, key_f1, MDFR_NONE, project_fkey_command); - bind(context, key_f2, MDFR_NONE, project_fkey_command); - bind(context, key_f3, MDFR_NONE, project_fkey_command); - bind(context, key_f4, MDFR_NONE, project_fkey_command); - - bind(context, key_f5, MDFR_NONE, project_fkey_command); - bind(context, key_f6, MDFR_NONE, project_fkey_command); - bind(context, key_f7, MDFR_NONE, project_fkey_command); - bind(context, key_f8, MDFR_NONE, project_fkey_command); - - bind(context, key_f9, MDFR_NONE, project_fkey_command); - bind(context, key_f10, MDFR_NONE, project_fkey_command); - bind(context, key_f11, MDFR_NONE, project_fkey_command); - bind(context, key_f12, MDFR_NONE, project_fkey_command); - - bind(context, key_f13, MDFR_NONE, project_fkey_command); - bind(context, key_f14, MDFR_NONE, project_fkey_command); - bind(context, key_f15, MDFR_NONE, project_fkey_command); - bind(context, key_f16, MDFR_NONE, project_fkey_command); - - end_map(context); - - // NOTE(allen|a4.0.22): FILE - begin_map(context, mapid_file); - - bind_vanilla_keys(context, write_character); - - bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); - bind(context, key_mouse_right, MDFR_NONE, click_set_mark); - - bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); - - bind(context, key_left, MDFR_NONE, move_left); - bind(context, key_right, MDFR_NONE, move_right); - bind(context, key_del, MDFR_NONE, delete_char); - bind(context, key_del, MDFR_SHIFT, delete_char); - bind(context, key_back, MDFR_NONE, backspace_char); - bind(context, key_back, MDFR_SHIFT, backspace_char); - bind(context, key_up, MDFR_NONE, move_up); - bind(context, key_down, MDFR_NONE, move_down); - bind(context, key_end, MDFR_NONE, seek_end_of_line); - bind(context, key_home, MDFR_NONE, seek_beginning_of_line); - bind(context, key_page_up, MDFR_NONE, page_up); - bind(context, key_page_down, MDFR_NONE, page_down); - - bind(context, key_right, MDFR_CMND, seek_whitespace_right); - bind(context, key_left, MDFR_CMND, seek_whitespace_left); - bind(context, key_up, MDFR_CMND, seek_whitespace_up_end_line); - bind(context, key_down, MDFR_CMND, seek_whitespace_down_end_line); - - bind(context, key_up, MDFR_CTRL, move_up_10); - bind(context, key_down, MDFR_CTRL, move_down_10); - - bind(context, key_back, MDFR_CMND, backspace_word); - bind(context, key_del, MDFR_CMND, delete_word); - bind(context, key_back, MDFR_CTRL, snipe_token_or_word); - bind(context, key_del, MDFR_CTRL, snipe_token_or_word_right); - - bind(context, ' ', MDFR_CMND, set_mark); - bind(context, 'a', MDFR_CMND, replace_in_range); - bind(context, 'c', MDFR_CMND, copy); - bind(context, 'd', MDFR_CMND, delete_range); - bind(context, 'e', MDFR_CMND, center_view); - bind(context, 'E', MDFR_CMND, left_adjust_view); - bind(context, 'f', MDFR_CMND, search); - bind(context, 'F', MDFR_CMND, list_all_locations); - bind(context, 'F', MDFR_CTRL, list_all_substring_locations_case_insensitive); - bind(context, 'g', MDFR_CMND, goto_line); - bind(context, 'j', MDFR_CMND, to_lowercase); - bind(context, 'K', MDFR_CMND, kill_buffer); - bind(context, 'l', MDFR_CMND, toggle_line_wrap); - bind(context, 'm', MDFR_CMND, cursor_mark_swap); - bind(context, 'O', MDFR_CMND, reopen); - bind(context, 'q', MDFR_CMND, query_replace); - bind(context, 'Q', MDFR_CMND, query_replace_identifier); - bind(context, 'r', MDFR_CMND, reverse_search); - bind(context, 's', MDFR_CMND, save); - bind(context, 't', MDFR_CMND, search_identifier); - bind(context, 'T', MDFR_CMND, list_all_locations_of_identifier); - bind(context, 'u', MDFR_CMND, to_uppercase); - bind(context, 'v', MDFR_CMND, paste_and_indent); - bind(context, 'v', MDFR_CTRL, toggle_virtual_whitespace); - bind(context, 'V', MDFR_CMND, paste_next_and_indent); - bind(context, 'x', MDFR_CMND, cut); - bind(context, 'y', MDFR_CMND, redo); - bind(context, 'z', MDFR_CMND, undo); - - bind(context, '2', MDFR_CMND, decrease_line_wrap); - bind(context, '3', MDFR_CMND, increase_line_wrap); - - bind(context, '?', MDFR_CMND, toggle_show_whitespace); - bind(context, '~', MDFR_CMND, clean_all_lines); - bind(context, '\n', MDFR_NONE, newline_or_goto_position); - bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); - bind(context, ' ', MDFR_SHIFT, write_character); - - end_map(context); - - // NOTE(allen|a4.0.22): CODE - begin_map(context, default_code_map); - - inherit_map(context, mapid_file); - - bind(context, key_right, MDFR_CMND, seek_alphanumeric_or_camel_right); - bind(context, key_left, MDFR_CMND, seek_alphanumeric_or_camel_left); - - bind(context, '\n', MDFR_NONE, write_and_auto_tab); - bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); - bind(context, '}', MDFR_NONE, write_and_auto_tab); - bind(context, ')', MDFR_NONE, write_and_auto_tab); - bind(context, ']', MDFR_NONE, write_and_auto_tab); - bind(context, ';', MDFR_NONE, write_and_auto_tab); - bind(context, '#', MDFR_NONE, write_and_auto_tab); - - bind(context, '\t', MDFR_NONE, word_complete); - bind(context, '\t', MDFR_CMND, auto_tab_range); - bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); - - bind(context, 'h', MDFR_CTRL, write_hack); - bind(context, 'r', MDFR_CTRL, write_block); - bind(context, 't', MDFR_CTRL, write_todo); - bind(context, 'y', MDFR_CTRL, write_note); - bind(context, '[', MDFR_CMND, open_long_braces); - bind(context, '{', MDFR_CMND, open_long_braces_semicolon); - bind(context, '}', MDFR_CMND, open_long_braces_break); - bind(context, 'i', MDFR_CTRL, if0_off); - bind(context, '1', MDFR_CTRL, open_file_in_quotes); - bind(context, '2', MDFR_CTRL, open_matching_file_cpp); - bind(context, '0', MDFR_CMND, write_zero_struct); - bind(context, 'I', MDFR_CMND, list_all_functions_current_buffer); - - end_map(context); -} - - -// -// Remapping Commands -// - -static Bind_Helper -get_context_on_global_part(void){ - Bind_Helper result = {0}; - int32_t size = (1 << 20); - for (;;){ - void *data = push_array(&global_part, char, size); - if (data != 0){ - result = begin_bind_helper(data, size); - break; - } - size = (size >> 1); - } - return(result); -} - -CUSTOM_COMMAND_SIG(set_bindings_choose){ -#if defined(_WIN32) || defined(__linux__) - - set_bindings_default(app); - -#elif defined(__APPLE__) && defined(__MACH__) - - set_bindings_mac_default(app); - -#endif -} - -CUSTOM_COMMAND_SIG(set_bindings_default){ - Temp_Memory temp = begin_temp_memory(&global_part); - - Bind_Helper context = get_context_on_global_part(); - set_all_default_hooks(&context); - default_keys(&context); - Bind_Buffer result = end_bind_helper_get_buffer(&context); - global_set_mapping(app, result.data, result.size); - - end_temp_memory(temp); -} - -CUSTOM_COMMAND_SIG(set_bindings_mac_4coder_like){ - Temp_Memory temp = begin_temp_memory(&global_part); - - Bind_Helper context = get_context_on_global_part(); - set_all_default_hooks(&context); - mac_4coder_like_keys(&context); - Bind_Buffer result = end_bind_helper_get_buffer(&context); - global_set_mapping(app, result.data, result.size); - - end_temp_memory(temp); -} - -CUSTOM_COMMAND_SIG(set_bindings_mac_default){ - Temp_Memory temp = begin_temp_memory(&global_part); - - Bind_Helper context = get_context_on_global_part(); - set_all_default_hooks(&context); - mac_default_keys(&context); - Bind_Buffer result = end_bind_helper_get_buffer(&context); - global_set_mapping(app, result.data, result.size); - - end_temp_memory(temp); -} - -#endif - -// BOTTOM - +bind(Bind_Helper *context, + + void + default_keys(Bind_Helper *context){ + // NOTE(allen|a4.0.22): GLOBAL + begin_map(context, mapid_global); + + bind(context, 'p', MDFR_CTRL, open_panel_vsplit); + bind(context, '_', MDFR_CTRL, open_panel_hsplit); + bind(context, 'P', MDFR_CTRL, close_panel); + bind(context, ',', MDFR_CTRL, change_active_panel); + bind(context, '<', MDFR_CTRL, change_active_panel_backwards); + + bind(context, 'n', MDFR_CTRL, interactive_new); + bind(context, 'o', MDFR_CTRL, interactive_open_or_new); + bind(context, 'o', MDFR_ALT, open_in_other); + bind(context, 'k', MDFR_CTRL, interactive_kill_buffer); + bind(context, 'i', MDFR_CTRL, interactive_switch_buffer); + bind(context, 'w', MDFR_CTRL, save_as); + bind(context, 'h', MDFR_CTRL, project_go_to_root_directory); + bind(context, 'S', MDFR_CTRL, save_all_dirty_buffers); + + bind(context, 'c', MDFR_ALT, open_color_tweaker); + bind(context, 'd', MDFR_ALT, open_debug); + + bind(context, '.', MDFR_ALT, change_to_build_panel); + bind(context, ',', MDFR_ALT, close_build_panel); + bind(context, 'n', MDFR_ALT, goto_next_error); + bind(context, 'N', MDFR_ALT, goto_prev_error); + bind(context, 'M', MDFR_ALT, goto_first_error); + bind(context, 'm', MDFR_ALT, build_in_build_panel); + + bind(context, 'z', MDFR_ALT, execute_any_cli); + bind(context, 'Z', MDFR_ALT, execute_previous_cli); + + bind(context, 'x', MDFR_ALT, execute_arbitrary_command); + + bind(context, 's', MDFR_ALT, show_scrollbar); + bind(context, 'w', MDFR_ALT, hide_scrollbar); + bind(context, 'b', MDFR_ALT, toggle_filebar); + + bind(context, '@', MDFR_ALT, toggle_mouse); + bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen); + bind(context, 'E', MDFR_ALT, exit_4coder); + + bind(context, key_f1, MDFR_NONE, project_fkey_command); + bind(context, key_f2, MDFR_NONE, project_fkey_command); + bind(context, key_f3, MDFR_NONE, project_fkey_command); + bind(context, key_f4, MDFR_NONE, project_fkey_command); + + bind(context, key_f5, MDFR_NONE, project_fkey_command); + bind(context, key_f6, MDFR_NONE, project_fkey_command); + bind(context, key_f7, MDFR_NONE, project_fkey_command); + bind(context, key_f8, MDFR_NONE, project_fkey_command); + + bind(context, key_f9, MDFR_NONE, project_fkey_command); + bind(context, key_f10, MDFR_NONE, project_fkey_command); + bind(context, key_f11, MDFR_NONE, project_fkey_command); + bind(context, key_f12, MDFR_NONE, project_fkey_command); + + bind(context, key_f13, MDFR_NONE, project_fkey_command); + bind(context, key_f14, MDFR_NONE, project_fkey_command); + bind(context, key_f15, MDFR_NONE, project_fkey_command); + bind(context, key_f16, MDFR_NONE, project_fkey_command); + + end_map(context); + + // NOTE(allen|a4.0.22): FILE + begin_map(context, mapid_file); + + bind_vanilla_keys(context, write_character); + + bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); + bind(context, key_mouse_right, MDFR_NONE, click_set_mark); + + bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); + + bind(context, key_left, MDFR_NONE, move_left); + bind(context, key_right, MDFR_NONE, move_right); + bind(context, key_del, MDFR_NONE, delete_char); + bind(context, key_del, MDFR_SHIFT, delete_char); + bind(context, key_back, MDFR_NONE, backspace_char); + bind(context, key_back, MDFR_SHIFT, backspace_char); + bind(context, key_up, MDFR_NONE, move_up); + bind(context, key_down, MDFR_NONE, move_down); + bind(context, key_end, MDFR_NONE, seek_end_of_line); + bind(context, key_home, MDFR_NONE, seek_beginning_of_line); + bind(context, key_page_up, MDFR_NONE, page_up); + bind(context, key_page_down, MDFR_NONE, page_down); + + bind(context, key_right, MDFR_CTRL, seek_whitespace_right); + bind(context, key_left, MDFR_CTRL, seek_whitespace_left); + bind(context, key_up, MDFR_CTRL, seek_whitespace_up_end_line); + bind(context, key_down, MDFR_CTRL, seek_whitespace_down_end_line); + + bind(context, key_up, MDFR_ALT, move_up_10); + bind(context, key_down, MDFR_ALT, move_down_10); + + bind(context, key_back, MDFR_CTRL, backspace_word); + bind(context, key_del, MDFR_CTRL, delete_word); + bind(context, key_back, MDFR_ALT, snipe_token_or_word); + bind(context, key_del, MDFR_ALT, snipe_token_or_word_right); + + bind(context, ' ', MDFR_CTRL, set_mark); + bind(context, 'a', MDFR_CTRL, replace_in_range); + bind(context, 'c', MDFR_CTRL, copy); + bind(context, 'd', MDFR_CTRL, delete_range); + bind(context, 'e', MDFR_CTRL, center_view); + bind(context, 'E', MDFR_CTRL, left_adjust_view); + bind(context, 'f', MDFR_CTRL, search); + bind(context, 'F', MDFR_CTRL, list_all_locations); + bind(context, 'F', MDFR_ALT, list_all_substring_locations_case_insensitive); + bind(context, 'g', MDFR_CTRL, goto_line); + bind(context, 'j', MDFR_CTRL, to_lowercase); + bind(context, 'K', MDFR_CTRL, kill_buffer); + bind(context, 'l', MDFR_CTRL, toggle_line_wrap); + bind(context, 'm', MDFR_CTRL, cursor_mark_swap); + bind(context, 'O', MDFR_CTRL, reopen); + bind(context, 'q', MDFR_CTRL, query_replace); + bind(context, 'Q', MDFR_CTRL, query_replace_identifier); + bind(context, 'r', MDFR_CTRL, reverse_search); + bind(context, 's', MDFR_CTRL, save); + bind(context, 't', MDFR_CTRL, search_identifier); + bind(context, 'T', MDFR_CTRL, list_all_locations_of_identifier); + bind(context, 'u', MDFR_CTRL, to_uppercase); + bind(context, 'v', MDFR_CTRL, paste_and_indent); + bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace); + bind(context, 'V', MDFR_CTRL, paste_next_and_indent); + bind(context, 'x', MDFR_CTRL, cut); + bind(context, 'y', MDFR_CTRL, redo); + bind(context, 'z', MDFR_CTRL, undo); + + bind(context, '2', MDFR_CTRL, decrease_line_wrap); + bind(context, '3', MDFR_CTRL, increase_line_wrap); + + bind(context, '?', MDFR_CTRL, toggle_show_whitespace); + bind(context, '~', MDFR_CTRL, clean_all_lines); + bind(context, '\n', MDFR_NONE, newline_or_goto_position); + bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); + bind(context, ' ', MDFR_SHIFT, write_character); + + end_map(context); + + // NOTE(allen|a4.0.22): CODE + begin_map(context, default_code_map); + + inherit_map(context, mapid_file); + + bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right); + bind(context, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left); + + bind(context, '\n', MDFR_NONE, write_and_auto_tab); + bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); + bind(context, '}', MDFR_NONE, write_and_auto_tab); + bind(context, ')', MDFR_NONE, write_and_auto_tab); + bind(context, ']', MDFR_NONE, write_and_auto_tab); + bind(context, ';', MDFR_NONE, write_and_auto_tab); + bind(context, '#', MDFR_NONE, write_and_auto_tab); + + bind(context, '\t', MDFR_NONE, word_complete); + bind(context, '\t', MDFR_CTRL, auto_tab_range); + bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); + + bind(context, 'h', MDFR_ALT, write_hack); + bind(context, 'r', MDFR_ALT, write_block); + bind(context, 't', MDFR_ALT, write_todo); + bind(context, 'y', MDFR_ALT, write_note); + bind(context, '[', MDFR_CTRL, open_long_braces); + bind(context, '{', MDFR_CTRL, open_long_braces_semicolon); + bind(context, '}', MDFR_CTRL, open_long_braces_break); + bind(context, 'i', MDFR_ALT, if0_off); + bind(context, '1', MDFR_ALT, open_file_in_quotes); + bind(context, '2', MDFR_ALT, open_matching_file_cpp); + bind(context, '0', MDFR_CTRL, write_zero_struct); + bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer); + + end_map(context); + } + + void + bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, int32_t command){ + bind(context, code, MDFR_CTRL, command); + bind(context, code, MDFR_CMND, command); + } + + void + bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, Custom_Command_Function *command){ + bind(context, code, MDFR_CTRL, command); + bind(context, code, MDFR_CMND, command); + bind(context, code, MDFR_CTRL|MDFR_CMND, command); + } + + void + mac_4coder_like_keys(Bind_Helper *context){ + // NOTE(allen|a4.0.22): GLOBAL + begin_map(context, mapid_global); + + bind_ctrl_and_cmnd(context, 'p', open_panel_vsplit); + bind_ctrl_and_cmnd(context, '_', open_panel_hsplit); + bind_ctrl_and_cmnd(context, 'P', close_panel); + bind_ctrl_and_cmnd(context, ',', change_active_panel); + bind_ctrl_and_cmnd(context, '<', change_active_panel_backwards); + + bind_ctrl_and_cmnd(context, 'n', interactive_new); + bind_ctrl_and_cmnd(context, 'o', interactive_open_or_new); + bind(context, 'o', MDFR_ALT, open_in_other); + bind_ctrl_and_cmnd(context, 'k', interactive_kill_buffer); + bind_ctrl_and_cmnd(context, 'i', interactive_switch_buffer); + bind_ctrl_and_cmnd(context, 'w', save_as); + bind_ctrl_and_cmnd(context, 'h', project_go_to_root_directory); + bind_ctrl_and_cmnd(context, 'S', save_all_dirty_buffers); + + bind(context, 'c', MDFR_ALT, open_color_tweaker); + bind(context, 'd', MDFR_ALT, open_debug); + + bind(context, '.', MDFR_ALT, change_to_build_panel); + bind(context, ',', MDFR_ALT, close_build_panel); + bind(context, 'n', MDFR_ALT, goto_next_error); + bind(context, 'N', MDFR_ALT, goto_prev_error); + bind(context, 'M', MDFR_ALT, goto_first_error); + bind(context, 'm', MDFR_ALT, build_in_build_panel); + + bind(context, 'z', MDFR_ALT, execute_any_cli); + bind(context, 'Z', MDFR_ALT, execute_previous_cli); + + bind(context, 'x', MDFR_ALT, execute_arbitrary_command); + + bind(context, 's', MDFR_ALT, show_scrollbar); + bind(context, 'w', MDFR_ALT, hide_scrollbar); + bind(context, 'b', MDFR_ALT, toggle_filebar); + + bind(context, '@', MDFR_ALT, toggle_mouse); + bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen); + bind(context, 'E', MDFR_ALT, exit_4coder); + + bind(context, key_f1, MDFR_NONE, project_fkey_command); + bind(context, key_f2, MDFR_NONE, project_fkey_command); + bind(context, key_f3, MDFR_NONE, project_fkey_command); + bind(context, key_f4, MDFR_NONE, project_fkey_command); + + bind(context, key_f5, MDFR_NONE, project_fkey_command); + bind(context, key_f6, MDFR_NONE, project_fkey_command); + bind(context, key_f7, MDFR_NONE, project_fkey_command); + bind(context, key_f8, MDFR_NONE, project_fkey_command); + + bind(context, key_f9, MDFR_NONE, project_fkey_command); + bind(context, key_f10, MDFR_NONE, project_fkey_command); + bind(context, key_f11, MDFR_NONE, project_fkey_command); + bind(context, key_f12, MDFR_NONE, project_fkey_command); + + bind(context, key_f13, MDFR_NONE, project_fkey_command); + bind(context, key_f14, MDFR_NONE, project_fkey_command); + bind(context, key_f15, MDFR_NONE, project_fkey_command); + bind(context, key_f16, MDFR_NONE, project_fkey_command); + + end_map(context); + + // NOTE(allen|a4.0.22): FILE + begin_map(context, mapid_file); + + bind_vanilla_keys(context, write_character); + + bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); + bind(context, key_mouse_right, MDFR_NONE, click_set_mark); + + bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); + + bind(context, key_left, MDFR_NONE, move_left); + bind(context, key_right, MDFR_NONE, move_right); + bind(context, key_del, MDFR_NONE, delete_char); + bind(context, key_del, MDFR_SHIFT, delete_char); + bind(context, key_back, MDFR_NONE, backspace_char); + bind(context, key_back, MDFR_SHIFT, backspace_char); + bind(context, key_up, MDFR_NONE, move_up); + bind(context, key_down, MDFR_NONE, move_down); + bind(context, key_end, MDFR_NONE, seek_end_of_line); + bind(context, key_home, MDFR_NONE, seek_beginning_of_line); + bind(context, key_page_up, MDFR_NONE, page_up); + bind(context, key_page_down, MDFR_NONE, page_down); + + bind(context, key_right, MDFR_CMND, seek_whitespace_right); + bind(context, key_left, MDFR_CMND, seek_whitespace_left); + bind(context, key_up, MDFR_CMND, seek_whitespace_up_end_line); + bind(context, key_down, MDFR_CMND, seek_whitespace_down_end_line); + + bind(context, key_up, MDFR_ALT, move_up_10); + bind(context, key_down, MDFR_ALT, move_down_10); + + bind_ctrl_and_cmnd(context, key_back, backspace_word); + bind_ctrl_and_cmnd(context, key_del, delete_word); + bind(context, key_back, MDFR_ALT, snipe_token_or_word); + bind(context, key_del, MDFR_ALT, snipe_token_or_word_right); + + bind_ctrl_and_cmnd(context, ' ', set_mark); + bind_ctrl_and_cmnd(context, 'a', replace_in_range); + bind_ctrl_and_cmnd(context, 'c', copy); + bind_ctrl_and_cmnd(context, 'd', delete_range); + bind_ctrl_and_cmnd(context, 'e', center_view); + bind_ctrl_and_cmnd(context, 'E', left_adjust_view); + bind_ctrl_and_cmnd(context, 'f', search); + bind_ctrl_and_cmnd(context, 'F', list_all_locations); + bind(context, 'F', MDFR_ALT, list_all_substring_locations_case_insensitive); + bind_ctrl_and_cmnd(context, 'g', goto_line); + bind_ctrl_and_cmnd(context, 'j', to_lowercase); + bind_ctrl_and_cmnd(context, 'K', kill_buffer); + bind_ctrl_and_cmnd(context, 'l', toggle_line_wrap); + bind_ctrl_and_cmnd(context, 'm', cursor_mark_swap); + bind_ctrl_and_cmnd(context, 'O', reopen); + bind_ctrl_and_cmnd(context, 'q', query_replace); + bind_ctrl_and_cmnd(context, 'Q', query_replace_identifier); + bind_ctrl_and_cmnd(context, 'r', reverse_search); + bind_ctrl_and_cmnd(context, 's', save); + bind_ctrl_and_cmnd(context, 't', search_identifier); + bind_ctrl_and_cmnd(context, 'T', list_all_locations_of_identifier); + bind_ctrl_and_cmnd(context, 'u', to_uppercase); + bind_ctrl_and_cmnd(context, 'v', paste_and_indent); + bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace); + bind_ctrl_and_cmnd(context, 'V', paste_next_and_indent); + bind_ctrl_and_cmnd(context, 'x', cut); + bind_ctrl_and_cmnd(context, 'y', redo); + bind_ctrl_and_cmnd(context, 'z', undo); + + bind_ctrl_and_cmnd(context, '2', decrease_line_wrap); + bind_ctrl_and_cmnd(context, '3', increase_line_wrap); + + bind_ctrl_and_cmnd(context, '?', toggle_show_whitespace); + bind_ctrl_and_cmnd(context, '~', clean_all_lines); + bind(context, '\n', MDFR_NONE, newline_or_goto_position); + bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); + bind(context, ' ', MDFR_SHIFT, write_character); + + end_map(context); + + // NOTE(allen|a4.0.22): CODE + begin_map(context, default_code_map); + + inherit_map(context, mapid_file); + + bind_ctrl_and_cmnd(context, key_right, seek_alphanumeric_or_camel_right); + bind_ctrl_and_cmnd(context, key_left, seek_alphanumeric_or_camel_left); + + bind(context, '\n', MDFR_NONE, write_and_auto_tab); + bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); + bind(context, '}', MDFR_NONE, write_and_auto_tab); + bind(context, ')', MDFR_NONE, write_and_auto_tab); + bind(context, ']', MDFR_NONE, write_and_auto_tab); + bind(context, ';', MDFR_NONE, write_and_auto_tab); + bind(context, '#', MDFR_NONE, write_and_auto_tab); + + bind(context, '\t', MDFR_NONE, word_complete); + bind_ctrl_and_cmnd(context, '\t', auto_tab_range); + bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); + + bind(context, 'h', MDFR_ALT, write_hack); + bind(context, 'r', MDFR_ALT, write_block); + bind(context, 't', MDFR_ALT, write_todo); + bind(context, 'y', MDFR_ALT, write_note); + bind_ctrl_and_cmnd(context, '[', open_long_braces); + bind_ctrl_and_cmnd(context, '{', open_long_braces_semicolon); + bind_ctrl_and_cmnd(context, '}', open_long_braces_break); + bind(context, 'i', MDFR_ALT, if0_off); + bind(context, '1', MDFR_ALT, open_file_in_quotes); + bind(context, '2', MDFR_ALT, open_matching_file_cpp); + bind_ctrl_and_cmnd(context, '0', write_zero_struct); + bind_ctrl_and_cmnd(context, 'I', list_all_functions_current_buffer); + + end_map(context); + } + + void + mac_default_keys(Bind_Helper *context){ + // NOTE(allen|a4.0.22): GLOBAL + begin_map(context, mapid_global); + + bind(context, 'p', MDFR_CMND, open_panel_vsplit); + bind(context, '_', MDFR_CMND, open_panel_hsplit); + bind(context, 'P', MDFR_CMND, close_panel); + bind(context, ',', MDFR_CMND, change_active_panel); + bind(context, '<', MDFR_CMND, change_active_panel_backwards); + + bind(context, 'n', MDFR_CMND, interactive_new); + bind(context, 'o', MDFR_CMND, interactive_open_or_new); + bind(context, 'o', MDFR_CTRL, open_in_other); + bind(context, 'k', MDFR_CMND, interactive_kill_buffer); + bind(context, 'i', MDFR_CMND, interactive_switch_buffer); + bind(context, 'w', MDFR_CMND, save_as); + bind(context, 'h', MDFR_CMND, project_go_to_root_directory); + bind(context, 'S', MDFR_CMND, save_all_dirty_buffers); + + bind(context, 'c', MDFR_CTRL, open_color_tweaker); + bind(context, 'd', MDFR_CTRL, open_debug); + + bind(context, '.', MDFR_CTRL, change_to_build_panel); + bind(context, ',', MDFR_CTRL, close_build_panel); + bind(context, 'n', MDFR_CTRL, goto_next_error); + bind(context, 'N', MDFR_CTRL, goto_prev_error); + bind(context, 'M', MDFR_CTRL, goto_first_error); + bind(context, 'm', MDFR_CTRL, build_in_build_panel); + + bind(context, 'z', MDFR_CTRL, execute_any_cli); + bind(context, 'Z', MDFR_CTRL, execute_previous_cli); + + bind(context, 'x', MDFR_CTRL, execute_arbitrary_command); + + bind(context, 's', MDFR_CTRL, show_scrollbar); + bind(context, 'w', MDFR_CTRL, hide_scrollbar); + bind(context, 'b', MDFR_CTRL, toggle_filebar); + + bind(context, '@', MDFR_CTRL, toggle_mouse); + bind(context, key_page_up, MDFR_CMND, toggle_fullscreen); + bind(context, 'E', MDFR_CTRL, exit_4coder); + + bind(context, key_f1, MDFR_NONE, project_fkey_command); + bind(context, key_f2, MDFR_NONE, project_fkey_command); + bind(context, key_f3, MDFR_NONE, project_fkey_command); + bind(context, key_f4, MDFR_NONE, project_fkey_command); + + bind(context, key_f5, MDFR_NONE, project_fkey_command); + bind(context, key_f6, MDFR_NONE, project_fkey_command); + bind(context, key_f7, MDFR_NONE, project_fkey_command); + bind(context, key_f8, MDFR_NONE, project_fkey_command); + + bind(context, key_f9, MDFR_NONE, project_fkey_command); + bind(context, key_f10, MDFR_NONE, project_fkey_command); + bind(context, key_f11, MDFR_NONE, project_fkey_command); + bind(context, key_f12, MDFR_NONE, project_fkey_command); + + bind(context, key_f13, MDFR_NONE, project_fkey_command); + bind(context, key_f14, MDFR_NONE, project_fkey_command); + bind(context, key_f15, MDFR_NONE, project_fkey_command); + bind(context, key_f16, MDFR_NONE, project_fkey_command); + + end_map(context); + + // NOTE(allen|a4.0.22): FILE + begin_map(context, mapid_file); + + bind_vanilla_keys(context, write_character); + + bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); + bind(context, key_mouse_right, MDFR_NONE, click_set_mark); + + bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); + + bind(context, key_left, MDFR_NONE, move_left); + bind(context, key_right, MDFR_NONE, move_right); + bind(context, key_del, MDFR_NONE, delete_char); + bind(context, key_del, MDFR_SHIFT, delete_char); + bind(context, key_back, MDFR_NONE, backspace_char); + bind(context, key_back, MDFR_SHIFT, backspace_char); + bind(context, key_up, MDFR_NONE, move_up); + bind(context, key_down, MDFR_NONE, move_down); + bind(context, key_end, MDFR_NONE, seek_end_of_line); + bind(context, key_home, MDFR_NONE, seek_beginning_of_line); + bind(context, key_page_up, MDFR_NONE, page_up); + bind(context, key_page_down, MDFR_NONE, page_down); + + bind(context, key_right, MDFR_CMND, seek_whitespace_right); + bind(context, key_left, MDFR_CMND, seek_whitespace_left); + bind(context, key_up, MDFR_CMND, seek_whitespace_up_end_line); + bind(context, key_down, MDFR_CMND, seek_whitespace_down_end_line); + + bind(context, key_up, MDFR_CTRL, move_up_10); + bind(context, key_down, MDFR_CTRL, move_down_10); + + bind(context, key_back, MDFR_CMND, backspace_word); + bind(context, key_del, MDFR_CMND, delete_word); + bind(context, key_back, MDFR_CTRL, snipe_token_or_word); + bind(context, key_del, MDFR_CTRL, snipe_token_or_word_right); + + bind(context, ' ', MDFR_CMND, set_mark); + bind(context, 'a', MDFR_CMND, replace_in_range); + bind(context, 'c', MDFR_CMND, copy); + bind(context, 'd', MDFR_CMND, delete_range); + bind(context, 'e', MDFR_CMND, center_view); + bind(context, 'E', MDFR_CMND, left_adjust_view); + bind(context, 'f', MDFR_CMND, search); + bind(context, 'F', MDFR_CMND, list_all_locations); + bind(context, 'F', MDFR_CTRL, list_all_substring_locations_case_insensitive); + bind(context, 'g', MDFR_CMND, goto_line); + bind(context, 'j', MDFR_CMND, to_lowercase); + bind(context, 'K', MDFR_CMND, kill_buffer); + bind(context, 'l', MDFR_CMND, toggle_line_wrap); + bind(context, 'm', MDFR_CMND, cursor_mark_swap); + bind(context, 'O', MDFR_CMND, reopen); + bind(context, 'q', MDFR_CMND, query_replace); + bind(context, 'Q', MDFR_CMND, query_replace_identifier); + bind(context, 'r', MDFR_CMND, reverse_search); + bind(context, 's', MDFR_CMND, save); + bind(context, 't', MDFR_CMND, search_identifier); + bind(context, 'T', MDFR_CMND, list_all_locations_of_identifier); + bind(context, 'u', MDFR_CMND, to_uppercase); + bind(context, 'v', MDFR_CMND, paste_and_indent); + bind(context, 'v', MDFR_CTRL, toggle_virtual_whitespace); + bind(context, 'V', MDFR_CMND, paste_next_and_indent); + bind(context, 'x', MDFR_CMND, cut); + bind(context, 'y', MDFR_CMND, redo); + bind(context, 'z', MDFR_CMND, undo); + + bind(context, '2', MDFR_CMND, decrease_line_wrap); + bind(context, '3', MDFR_CMND, increase_line_wrap); + + bind(context, '?', MDFR_CMND, toggle_show_whitespace); + bind(context, '~', MDFR_CMND, clean_all_lines); + bind(context, '\n', MDFR_NONE, newline_or_goto_position); + bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel); + bind(context, ' ', MDFR_SHIFT, write_character); + + end_map(context); + + // NOTE(allen|a4.0.22): CODE + begin_map(context, default_code_map); + + inherit_map(context, mapid_file); + + bind(context, key_right, MDFR_CMND, seek_alphanumeric_or_camel_right); + bind(context, key_left, MDFR_CMND, seek_alphanumeric_or_camel_left); + + bind(context, '\n', MDFR_NONE, write_and_auto_tab); + bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); + bind(context, '}', MDFR_NONE, write_and_auto_tab); + bind(context, ')', MDFR_NONE, write_and_auto_tab); + bind(context, ']', MDFR_NONE, write_and_auto_tab); + bind(context, ';', MDFR_NONE, write_and_auto_tab); + bind(context, '#', MDFR_NONE, write_and_auto_tab); + + bind(context, '\t', MDFR_NONE, word_complete); + bind(context, '\t', MDFR_CMND, auto_tab_range); + bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); + + bind(context, 'h', MDFR_CTRL, write_hack); + bind(context, 'r', MDFR_CTRL, write_block); + bind(context, 't', MDFR_CTRL, write_todo); + bind(context, 'y', MDFR_CTRL, write_note); + bind(context, '[', MDFR_CMND, open_long_braces); + bind(context, '{', MDFR_CMND, open_long_braces_semicolon); + bind(context, '}', MDFR_CMND, open_long_braces_break); + bind(context, 'i', MDFR_CTRL, if0_off); + bind(context, '1', MDFR_CTRL, open_file_in_quotes); + bind(context, '2', MDFR_CTRL, open_matching_file_cpp); + bind(context, '0', MDFR_CMND, write_zero_struct); + bind(context, 'I', MDFR_CMND, list_all_functions_current_buffer); + + end_map(context); + } + + + // + // Remapping Commands + // + + static Bind_Helper + get_context_on_global_part(void){ + Bind_Helper result = {0}; + int32_t size = (1 << 20); + for (;;){ + void *data = push_array(&global_part, char, size); + if (data != 0){ + result = begin_bind_helper(data, size); + break; + } + size = (size >> 1); + } + return(result); + } + + CUSTOM_COMMAND_SIG(set_bindings_choose){ + #if defined(_WIN32) || defined(__linux__) + + set_bindings_default(app); + + #elif defined(__APPLE__) && defined(__MACH__) + + set_bindings_mac_default(app); + + #endif + } + + CUSTOM_COMMAND_SIG(set_bindings_default){ + Temp_Memory temp = begin_temp_memory(&global_part); + + Bind_Helper context = get_context_on_global_part(); + set_all_default_hooks(&context); + default_keys(&context); + Bind_Buffer result = end_bind_helper_get_buffer(&context); + global_set_mapping(app, result.data, result.size); + + end_temp_memory(temp); + } + + CUSTOM_COMMAND_SIG(set_bindings_mac_4coder_like){ + Temp_Memory temp = begin_temp_memory(&global_part); + + Bind_Helper context = get_context_on_global_part(); + set_all_default_hooks(&context); + mac_4coder_like_keys(&context); + Bind_Buffer result = end_bind_helper_get_buffer(&context); + global_set_mapping(app, result.data, result.size); + + end_temp_memory(temp); + } + + CUSTOM_COMMAND_SIG(set_bindings_mac_default){ + Temp_Memory temp = begin_temp_memory(&global_part); + + Bind_Helper context = get_context_on_global_part(); + set_all_default_hooks(&context); + mac_default_keys(&context); + Bind_Buffer result = end_bind_helper_get_buffer(&context); + global_set_mapping(app, result.data, result.size); + + end_temp_memory(temp); + } + + #endif + + // BOTTOM + + \ No newline at end of file diff --git a/4ed.cpp b/4ed.cpp index f8b4db03..1484a947 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -687,6 +687,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ memset(new_mapping.map_id_table, -1, user_map_count*sizeof(i32)); new_mapping.user_maps = push_array(part, Command_Map, user_map_count); + memset(new_mapping.user_maps, 0, user_map_count*sizeof(Command_Map)); // Find the Size of Each Map for (++unit; unit < end; ++unit){ @@ -824,9 +825,10 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ { if (map_ptr != 0){ Command_Function *func = 0; - if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count) + if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count){ func = command_table[unit->binding.command_id]; - if (func){ + } + if (func != 0){ if (unit->binding.code == 0){ u32 index = 0; if (map_get_modifiers_hash(unit->binding.modifiers, &index)){ @@ -846,7 +848,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ if (map_ptr != 0){ Command_Function *func = command_user_callback; Custom_Command_Function *custom = unit->callback.func; - if (func){ + if (func != 0){ if (unit->callback.code == 0){ u32 index = 0; if (map_get_modifiers_hash(unit->binding.modifiers, &index)){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 12af0c85..43be3bd8 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2098,7 +2098,7 @@ DOC_SEE(User_Input) } API_EXPORT User_Input -Get_Command_Input (Application_Links *app) +Get_Command_Input(Application_Links *app) /* DOC_RETURN(This call returns the input that triggered the currently executing command.) DOC_SEE(User_Input) diff --git a/4ed_command.cpp b/4ed_command.cpp index 713fd3d2..21fb99b5 100644 --- a/4ed_command.cpp +++ b/4ed_command.cpp @@ -138,7 +138,7 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f u32 max = map->max; u32 index = hash % max; Command_Binding entry = map->commands[index]; - while (entry.function != 0 && entry.hash != COMMAND_HASH_ERASED){ + for (; entry.function != 0 && entry.hash != COMMAND_HASH_ERASED;){ if (entry.hash == hash){ result = true; break; @@ -148,12 +148,14 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f } if (override_original || !result){ - Command_Binding bind; + Command_Binding bind = {0}; bind.function = function; bind.custom = custom; bind.hash = hash; map->commands[index] = bind; - ++map->count; + if (!result){ + ++map->count; + } } return(result); @@ -171,7 +173,7 @@ map_find_entry(Command_Map *map, Key_Code event_code, u8 modifiers, u32 *index_o u32 index = hash % max; b32 result = false; Command_Binding entry = map->commands[index]; - while (entry.function != 0){ + for (; entry.function != 0;){ if (entry.hash == hash){ *index_out = index; result = true; @@ -222,13 +224,16 @@ map_get_modifiers_hash(u8 modifiers, u32 *hash_out){ b32 result = true; u32 hash = 0; if (modifiers & MDFR_SHIFT){ - hash += 0x1; + hash += MDFR_SHIFT; } if (modifiers & MDFR_CTRL){ - hash += 0x2; + hash += MDFR_CTRL; + } + if (modifiers & MDFR_CMND){ + hash += MDFR_CMND; } if (modifiers & MDFR_ALT){ - hash += 0x4; + hash += MDFR_ALT; } *hash_out = hash; return(result); @@ -253,8 +258,8 @@ map_extract(Command_Map *map, Key_Event_Data key){ u8 mod_flags = MDFR_NONE; if (ctrl) mod_flags |= MDFR_CTRL; - if (command) mod_flags |= MDFR_CMND; if (alt) mod_flags |= MDFR_ALT; + if (command) mod_flags |= MDFR_CMND; if (shift) mod_flags |= MDFR_SHIFT; Key_Code code = key.character_no_caps_lock; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 58991928..9b4930fc 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -4146,10 +4146,14 @@ internal Single_Line_Input_Step app_single_line_input_core(System_Functions *system, Working_Set *working_set, Key_Event_Data key, Single_Line_Mode mode){ Single_Line_Input_Step result = {0}; + b8 ctrl = key.modifiers[MDFR_CONTROL_INDEX]; + b8 cmnd = key.modifiers[MDFR_COMMAND_INDEX]; + b8 alt = key.modifiers[MDFR_ALT_INDEX]; + if (key.keycode == key_back){ - result.hit_backspace = 1; + result.hit_backspace = true; if (mode.string->size > 0){ - result.made_a_change = 1; + result.made_a_change = true; --mode.string->size; switch (mode.type){ case SINGLE_LINE_STRING: @@ -4159,7 +4163,7 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K case SINGLE_LINE_FILE: { - if (!key.modifiers[MDFR_CONTROL_INDEX]){ + if (!ctrl && !cmnd && !alt){ char end_character = mode.string->str[mode.string->size]; if (char_is_slash(end_character)){ mode.string->size = reverse_seek_slash(*mode.string) + 1; @@ -4183,14 +4187,14 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K } else if (key.keycode == key_esc){ - result.hit_esc = 1; - result.made_a_change = 1; + result.hit_esc = true; + result.made_a_change = true; } else if (key.character){ - result.hit_a_character = 1; - if (!key.modifiers[MDFR_CONTROL_INDEX] && !key.modifiers[MDFR_ALT_INDEX]){ - if (mode.string->size+1 < mode.string->memory_size){ + result.hit_a_character = true; + if (!ctrl && !cmnd && !alt){ + if (mode.string->size + 1 < mode.string->memory_size){ u8 new_character = (u8)key.character; mode.string->str[mode.string->size] = new_character; mode.string->size++; @@ -4198,11 +4202,11 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K if (mode.type == SINGLE_LINE_FILE && char_is_slash(new_character)){ hot_directory_set(system, mode.hot_directory, *mode.string); } - result.made_a_change = 1; + result.made_a_change = true; } } else{ - result.did_command = 1; + result.did_command = true; } } diff --git a/buildsuper_x64.sh b/buildsuper_x64.sh index a64415ed..d8d7e939 100755 --- a/buildsuper_x64.sh +++ b/buildsuper_x64.sh @@ -37,7 +37,9 @@ SOURCE=$PHYS_DIR/$TARGET_FILE FLAGS="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -Wno-writable-strings" +DEBUG=-g + cd "$REAL_PWD" echo "Building custom_4coders.so from $SOURCE" -g++ -I"$CODE_HOME" $FLAGS -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC +g++ -I"$CODE_HOME" $FLAGS $DEBUG -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC diff --git a/site/4ed_sitegen.cpp b/site/4ed_sitegen.cpp index 36f09a4a..1a5d5438 100644 --- a/site/4ed_sitegen.cpp +++ b/site/4ed_sitegen.cpp @@ -1,4 +1,3 @@ - /* * Mr. 4th Dimention - Allen Webster *