├── 4coder_sandvich_maker.cpp ├── 4coder_vimmish.cpp ├── README.md └── clearfeld_windmove.cpp /4coder_sandvich_maker.cpp: -------------------------------------------------------------------------------- 1 | #include "4coder_default_include.cpp" 2 | 3 | #define VIM_USE_CUSTOM_COLORS 0 4 | #define VIM_CURSOR_ROUNDNESS 0.0f 5 | #define VIM_USE_ECHO_BAR 1 6 | #define VIM_DRAW_PANEL_MARGINS 0 7 | #define VIM_FILE_BAR_ON_BOTTOM 0 8 | #define VIM_KEYBOARD_LAYOUT VIM_KEYBOARD_LAYOUT_US_INTERNATIONAL 9 | 10 | #include "4coder_vimmish.cpp" 11 | 12 | #if !defined(META_PASS) 13 | #include "generated/managed_id_metadata.cpp" 14 | #endif 15 | 16 | CUSTOM_COMMAND_SIG(sandvich_startup) 17 | { 18 | ProfileScope(app, "sandvich startup"); 19 | User_Input input = get_current_input(app); 20 | if (match_core_code(&input, CoreCode_Startup)){ 21 | String_Const_u8_Array file_names = input.event.core.file_names; 22 | load_themes_default_folder(app); 23 | default_4coder_initialize(app, file_names); 24 | default_4coder_side_by_side_panels(app, file_names); 25 | 26 | b32 automatically_load_project = def_get_config_b32(vars_save_string_lit("automatically_load_project")); 27 | if (automatically_load_project){ 28 | load_project(app); 29 | } 30 | toggle_fullscreen(app); 31 | } 32 | 33 | { 34 | def_enable_virtual_whitespace = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace")); 35 | clear_all_layouts(app); 36 | } 37 | } 38 | 39 | void custom_layer_init(Application_Links *app) { 40 | Thread_Context* tctx = get_thread_context(app); 41 | 42 | // 43 | // Base 4coder Initialization 44 | // 45 | 46 | default_framework_init(app); 47 | set_all_default_hooks(app); 48 | mapping_init(tctx, &framework_mapping); 49 | 50 | String_ID global_map_id = vars_save_string_lit("keys_global"); 51 | String_ID file_map_id = vars_save_string_lit("keys_file"); 52 | String_ID code_map_id = vars_save_string_lit("keys_code"); 53 | 54 | #if OS_MAC 55 | setup_mac_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id); 56 | #else 57 | setup_default_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id); 58 | #endif 59 | setup_essential_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id); 60 | 61 | // 62 | // Vim Layer Initialization 63 | // 64 | 65 | vim_init(app); 66 | vim_set_default_hooks(app); 67 | vim_setup_default_mapping(app, &framework_mapping, vim_key(KeyCode_Space)); 68 | 69 | vim_add_abbreviation("breka", "break"); 70 | vim_add_abbreviation("ture", "true"); 71 | 72 | { 73 | MappingScope(); 74 | SelectMapping(&framework_mapping); 75 | SelectMap(global_map_id); 76 | BindCore(sandvich_startup, CoreCode_Startup); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 4coder-vimmish 2 | A pretty feature complete vim layer for 4coder with some bugs. 3 | It's very usable but questionably up to date right now, and no longer maintained. 4 | When using it, please delete or rename your bindings.4coder file as the code has not been updated to use the new bindings system. 5 | 6 | # Try this instead: 7 | https://github.com/B-Y-P/4coder_byp 8 | 9 | The above project is actively maintained and more up to date, so it is probably better to use. 10 | -------------------------------------------------------------------------------- /clearfeld_windmove.cpp: -------------------------------------------------------------------------------- 1 | enum windmove_directions { 2 | windmove_up, 3 | windmove_left, 4 | windmove_down, 5 | windmove_right 6 | }; 7 | 8 | void 9 | windmove_to_panel(Application_Links* app, u8 direction, b32 swap_on_move) 10 | { 11 | View_ID view_id = get_active_view(app, Access_Always); 12 | Buffer_ID cur_buffer = view_get_buffer(app, view_id, Access_Always); 13 | 14 | Panel_ID original_panel = view_get_panel(app, view_id); 15 | Rect_f32 original_rect = view_get_screen_rect(app, view_id); 16 | 17 | Panel_ID current_panel = original_panel; 18 | 19 | Side preferred_side = (direction == windmove_up || direction == windmove_left ? Side_Min : Side_Max); 20 | b32 should_move_horizontal = (direction == windmove_left || direction == windmove_right); 21 | 22 | Panel_ID move_top_node = 0; 23 | if(panel_get_parent(app, original_panel) != 0) { 24 | while(move_top_node == 0) { 25 | Panel_ID parent = panel_get_parent(app, current_panel); 26 | if(!parent) { 27 | break; 28 | } 29 | 30 | Panel_ID min_panel = panel_get_child(app, parent, Side_Min); 31 | Panel_ID max_panel = panel_get_child(app, parent, Side_Max); 32 | 33 | b32 is_on_wrong_side_of_split = ((current_panel == min_panel && preferred_side == Side_Min) || 34 | (current_panel == max_panel && preferred_side == Side_Max)); 35 | 36 | b32 is_wrong_split = false; 37 | 38 | if(!is_on_wrong_side_of_split) { 39 | Panel_ID min_search = min_panel; 40 | while(!panel_is_leaf(app, min_search)) { 41 | min_search = panel_get_child(app, min_search, Side_Min); 42 | } 43 | 44 | Panel_ID max_search = max_panel; 45 | while(!panel_is_leaf(app, max_search)) { 46 | max_search = panel_get_child(app, max_search, Side_Min); 47 | } 48 | 49 | View_ID min_search_view_id = panel_get_view(app, min_search, Access_Always); 50 | View_ID max_search_view_id = panel_get_view(app, max_search, Access_Always); 51 | 52 | Rect_f32 min_origin_rect = view_get_screen_rect(app, min_search_view_id); 53 | Rect_f32 max_origin_rect = view_get_screen_rect(app, max_search_view_id); 54 | 55 | b32 is_vertical = (min_origin_rect.x0 != max_origin_rect.x0 && min_origin_rect.y0 == max_origin_rect.y0); 56 | b32 is_horizontal = (min_origin_rect.y0 != max_origin_rect.y0 && min_origin_rect.x0 == max_origin_rect.x0); 57 | 58 | if(should_move_horizontal && is_horizontal || !should_move_horizontal && is_vertical) { 59 | is_wrong_split = true; 60 | } 61 | } 62 | 63 | if(is_on_wrong_side_of_split || is_wrong_split) { 64 | current_panel = parent; 65 | } else { 66 | move_top_node = parent; 67 | } 68 | } 69 | } 70 | 71 | if(move_top_node != 0) { 72 | current_panel = panel_get_child(app, move_top_node, preferred_side); 73 | 74 | while(!panel_is_leaf(app, current_panel)) { 75 | Panel_ID min_panel = panel_get_child(app, current_panel, Side_Min); 76 | Panel_ID max_panel = panel_get_child(app, current_panel, Side_Max); 77 | 78 | Panel_ID min_search = min_panel; 79 | while(!panel_is_leaf(app, min_search)) { 80 | min_search = panel_get_child(app, min_search, Side_Min); 81 | } 82 | 83 | Panel_ID max_search = max_panel; 84 | while(!panel_is_leaf(app, max_search)) { 85 | max_search = panel_get_child(app, max_search, Side_Min); 86 | } 87 | 88 | Rect_f32 min_origin_rect = view_get_screen_rect(app, panel_get_view(app, min_search, Access_Always)); 89 | Rect_f32 max_origin_rect = view_get_screen_rect(app, panel_get_view(app, max_search, Access_Always)); 90 | 91 | b32 is_vertical = (min_origin_rect.x0 != max_origin_rect.x0 && min_origin_rect.y0 == max_origin_rect.y0); 92 | b32 is_horizontal = (min_origin_rect.y0 != max_origin_rect.y0 && min_origin_rect.x0 == max_origin_rect.x0); 93 | 94 | if(!should_move_horizontal && is_horizontal || should_move_horizontal && is_vertical) { 95 | if(preferred_side == Side_Min) { 96 | current_panel = max_panel; 97 | } else { 98 | current_panel = min_panel; 99 | } 100 | } else { 101 | f32 dist_from_min = 0; 102 | f32 dist_from_max = 0; 103 | 104 | if(should_move_horizontal) { 105 | dist_from_min = original_rect.y0 - min_origin_rect.y0; 106 | dist_from_max = original_rect.y0 - max_origin_rect.y0; 107 | } else { 108 | dist_from_min = original_rect.x0 - min_origin_rect.x0; 109 | dist_from_max = original_rect.x0 - max_origin_rect.x0; 110 | } 111 | 112 | if(dist_from_max < 0 || dist_from_min < dist_from_max) { 113 | current_panel = min_panel; 114 | } else { 115 | current_panel = max_panel; 116 | } 117 | } 118 | } 119 | 120 | View_ID target_view = panel_get_view(app, current_panel, Access_Always); 121 | view_set_active(app, target_view); 122 | 123 | if(swap_on_move) { 124 | Buffer_ID target_buffer = view_get_buffer(app, target_view, Access_Always); 125 | view_set_buffer(app, target_view, cur_buffer, Access_Always); 126 | view_set_buffer(app, view_id, target_buffer, Access_Always); 127 | } 128 | } 129 | } 130 | 131 | CUSTOM_COMMAND_SIG(windmove_panel_up) 132 | CUSTOM_DOC("Move up from the active view.") 133 | { 134 | windmove_to_panel(app, windmove_up, false); 135 | } 136 | 137 | CUSTOM_COMMAND_SIG(windmove_panel_down) 138 | CUSTOM_DOC("Move down from the active view.") 139 | { 140 | windmove_to_panel(app, windmove_down, false); 141 | } 142 | 143 | CUSTOM_COMMAND_SIG(windmove_panel_left) 144 | CUSTOM_DOC("Move left from the active view.") 145 | { 146 | windmove_to_panel(app, windmove_left, false); 147 | } 148 | 149 | CUSTOM_COMMAND_SIG(windmove_panel_right) 150 | CUSTOM_DOC("Move right from the active view.") 151 | { 152 | windmove_to_panel(app, windmove_right, false); 153 | } 154 | 155 | CUSTOM_COMMAND_SIG(windmove_panel_swap_up) 156 | CUSTOM_DOC("Swap buffer up from the active view.") 157 | { 158 | windmove_to_panel(app, windmove_up, true); 159 | } 160 | 161 | CUSTOM_COMMAND_SIG(windmove_panel_swap_down) 162 | CUSTOM_DOC("Swap buffer down from the active view.") 163 | { 164 | windmove_to_panel(app, windmove_down, true); 165 | } 166 | 167 | CUSTOM_COMMAND_SIG(windmove_panel_swap_left) 168 | CUSTOM_DOC("Swap buffer left from the active view.") 169 | { 170 | windmove_to_panel(app, windmove_left, true); 171 | } 172 | 173 | CUSTOM_COMMAND_SIG(windmove_panel_swap_right) 174 | CUSTOM_DOC("Swap buffer right from the active view.") 175 | { 176 | windmove_to_panel(app, windmove_right, true); 177 | } 178 | --------------------------------------------------------------------------------