4coder»Forums
5 posts
Beginner Help. Keybindings
Edited by JustinCase3 on Reason: Initial post
So I'm very new to 4coder and it appears that I'm having trouble rebinding the default keys. I saw the guide that was posted and tried to follow it. I copied the 4coder_default_bindings.cpp to make a custom file tried to messing around with binding things and then building it with ./buildsuper.sh ./custom_bindings2.cpp. But it doesnt seemto be working. I would like to rebind some of the keys in the middle of the keyboard to have the functionality of the arrow keys but I cant figure out how. I was able to rebind a few things however, like the split window key. Can anyone tell me what I might be doing wrong?
Simon Anciaux
1337 posts
Beginner Help. Keybindings
Edited by Simon Anciaux on
Could you post the content of your custom file ? Does buildsuper.sh show any errors ?
5 posts
Beginner Help. Keybindings
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "4coder_default_include.cpp"

extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;
    
    set_all_default_hooks(context);
    
#if defined(__APPLE__) && defined(__MACH__)
    custom_keys_mac(context);
#else
    default_keys(context);
#endif
    begin_map(context, mapid_global);
    bind(context, 'p', MDFR_CTRL, open_panel_vsplit);
    bind(context, 't', MDFR_CTRL, kill_buffer);
    end_map(context);

    
    int32_t result = end_bind_helper(context);
    return(result);
}


This is my custom file for now. Using Ctrl + p works perfectly but CTRL + t is doing nothing. It builds fine and there are no errors. open_panel_vsplit is the only command that I've been able to get to work. I'm not even sure what to write in order to rebind the arrow keys.
Simon Anciaux
1337 posts
Beginner Help. Keybindings
CTRL + 't' is bound to search_identifier in the mapid_file key map. Since mapid_file inherits from mapid_global, it will overwrite your custom keybinding.

You can set that binding in the mapid_file key map.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "4coder_default_include.cpp"

extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;
    
    set_all_default_hooks(context);
    
#if defined(__APPLE__) && defined(__MACH__)
    custom_keys_mac(context);
#else
    default_keys(context);
#endif
    begin_map(context, mapid_global);
    bind(context, 'p', MDFR_CTRL, open_panel_vsplit);
    end_map(context);

    begin_map(context, mapid_file);
    bind(context, 't', MDFR_CTRL, kill_buffer);
    end_map(context);

    
    int32_t result = end_bind_helper(context);
    return(result);
}


Or use the second method described in the wiki and remove or comment the search_identifier binding.

What do you mean by rebinding the arrow keys ? Do you want to bind the arrow keys to something, or move around with a different key ?

To use the arrow keys in a binding:
1
bind(context, key_left, MDFR_NONE, a_command_here);


To find which command is use when you press an arrow key, open this file from the 4coder directory: 4coder_generated\remapping.h
Search for move_left and you'll find all the movement bindings.
5 posts
Beginner Help. Keybindings
Edited by JustinCase3 on
Ooh ok that makes sense. I knew it had to be something like that. And when I say rebind the arrow keys I mean make another key move around the file like the arrow keys do. Edit: so I tried doing what you said and binding it with mapid_file but it still seems to not be working.
Jason
235 posts
Beginner Help. Keybindings
I would try the second method of setting up key bindings that mrmixer linked to in the wiki. This should help reduce any issues of conflicting key bindings between your custom bindings and what 4coder comes with by default by starting with more of a blank slate and only adding in the keybinding you need. So, for example, instead of the 'get_bindings' call looking like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;
    
    set_all_default_hooks(context);
    
#if defined(__APPLE__) && defined(__MACH__)
    custom_keys_mac(context);
#else
    default_keys(context);
#endif
    begin_map(context, mapid_global);
    bind(context, 'p', MDFR_CTRL, open_panel_vsplit);
    end_map(context);

    begin_map(context, mapid_file);
    bind(context, 't', MDFR_CTRL, kill_buffer);
    end_map(context);

    
    int32_t result = end_bind_helper(context);
    return(result);
}


with you calling 4coder's 'default_keys' function, I would set it up to call into your own custom function (we'll call it 'my_custom_key_bindings' or 'my_custom_key_bindings_mac' if you're on a mac) which could look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;
    
    set_all_default_hooks(context);
    
#if defined(__APPLE__) && defined(__MACH__)
    my_custom_key_bindings_mac(context);
#else
    my_custom_key_bindings(context);
#endif
    
    int32_t result = end_bind_helper(context);
    return(result);
}


Now, for a bare bones implementation (meaning no key bindings set at all) you would implement your 'my_custom_key_bindings' function to look something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void my_custom_key_bindings(Bind_Helper* context)
{
    begin_map(context, mapid_global);
    {
        
    }
    end_map(context);

    begin_map(context, mapid_file);
    {
        
    }
    end_map(context);

    begin_map(context, default_code_map);
    {
       
    }
    end_map(context);

    begin_map(context, default_lister_ui_map);
    {
       
    }
    end_map(context);
}


again, in this current state 4coder will not respond to any key bindings cause you haven't set any (obviously) but you can now go to 'remapping.h' and just start copying over the bind() calls you want and changing them if necessary. This should help ensure no inheritance issues are tripping you up and you have an explicit idea from this one file what bindings you are supporting. This is some of what my current custom function looks like with me only setting the bindings I want:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
void my_custom_key_bindings(Bind_Helper* context)
{
    begin_map(context, mapid_global);
    {
        bind(context, ',', MDFR_CTRL, change_active_panel);
        bind(context, 'n', MDFR_CTRL, interactive_new);
        bind(context, 'o', MDFR_CTRL, interactive_open_or_new);
        bind(context, 'O', MDFR_CTRL, jason_open_in_other);
        bind(context, 'i', MDFR_NONE, jason_enter_insert_mode);
        bind(context, '`', MDFR_NONE, jason_enter_command_mode);
        bind(context, '/', MDFR_NONE, jason_search_from_top_of_buffer);
        bind(context, 'z', MDFR_CTRL, undo);
        bind(context, 'y', MDFR_CTRL, redo);
        bind(context, 's', MDFR_CTRL, jason_save);
        bind(context, 'p', MDFR_CTRL, command_lister);
        bind(context, ',', MDFR_ALT, change_active_panel);
        bind(context, key_f4, MDFR_NONE, jason_project_fkey_command);
        bind(context, key_f5, MDFR_NONE, jason_project_fkey_command);
        bind(context, key_f6, MDFR_NONE, jason_project_fkey_command);
        bind(context, key_f7, MDFR_NONE, jason_project_fkey_command);
        bind(context, key_f4, MDFR_ALT, exit_4coder);
        bind(context, key_mouse_wheel, MDFR_NONE, mouse_wheel_scroll);
        bind(context, key_mouse_wheel, MDFR_CTRL, mouse_wheel_change_face_size);
    }
    end_map(context);

    begin_map(context, mapid_file);
    {
        bind(context, key_mouse_left, MDFR_NONE, click_set_cursor_and_mark);
        bind(context, key_click_activate_view, MDFR_NONE, click_set_cursor_and_mark);
        bind(context, key_mouse_left_release, MDFR_NONE, click_set_cursor);
        bind(context, key_mouse_move, MDFR_NONE, click_set_cursor_if_lbutton);
        bind(context, 'G', MDFR_NONE, goto_end_of_file);
        bind(context, 'g', MDFR_NONE, jason_interpret_command);
    }
    end_map(context);

    begin_map(context, default_code_map);
    {
        inherit_map(context, mapid_file);
        bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right);
        bind(context, 'm', MDFR_CTRL, jason_display_definition);
        bind(context, 'M', MDFR_CTRL, test);
        bind(context, 's', MDFR_NONE, place_in_scope);
        bind(context, '[', MDFR_CTRL, goto_next_error);
        bind(context, ']', MDFR_CTRL, goto_prev_error);
    }
    end_map(context);

    begin_map(context, default_lister_ui_map);
    {
        bind_vanilla_keys(context, lister__write_character);
        bind(context, key_esc, MDFR_NONE, lister__quit);
        bind(context, '\n', MDFR_NONE, lister__activate);
        bind(context, '\t', MDFR_NONE, lister__activate);
        bind(context, key_back, MDFR_NONE, lister__backspace_text_field);
        bind(context, key_up, MDFR_NONE, lister__move_up);
        bind(context, 'k', MDFR_ALT, lister__move_up);
        bind(context, key_page_up, MDFR_NONE, lister__move_up);
        bind(context, key_down, MDFR_NONE, lister__move_down);
        bind(context, 'j', MDFR_ALT, lister__move_down);
        bind(context, key_page_down, MDFR_NONE, lister__move_down);
        bind(context, key_mouse_wheel, MDFR_NONE, lister__wheel_scroll);
        bind(context, key_mouse_left, MDFR_NONE, lister__mouse_press);
        bind(context, key_mouse_left_release, MDFR_NONE, lister__mouse_release);
        bind(context, key_mouse_move, MDFR_NONE, lister__repaint);
        bind(context, key_animate, MDFR_NONE, lister__repaint);
    }
    end_map(context);
}
Simon Anciaux
1337 posts
Beginner Help. Keybindings
@JustinCase3 Are you sure you're compiling the right file by calling
1
./buildsuper.sh custom_layer.cpp

(if that's the name of your custom layer file) ?
5 posts
Beginner Help. Keybindings
Edited by JustinCase3 on
Yea I'm pretty sure I'm compiling correctly because the CTRL + p is working perfectly.
Edit: I did what Boagz57 suggested and made a function. I copied over his bindings just to test them and some of the work like CTRL + , changes the selected window but when I try and add CTRL + t to kill the buffer it still just does nothing.
Edi2: I just tried going into remapping.h and changing the binding for t from search_identifier to kill_buffer and that doesnt work either. This doesnt make any sense.
Simon Anciaux
1337 posts
Beginner Help. Keybindings
In your original test, does CTRL + 't' does nothing at all or does it start a search ?

If it does nothing, that might mean that your OS or window manager is using that shortcut and that it doesn't pass the messages to 4coder. On what operating system are you ?
5 posts
Beginner Help. Keybindings
Edited by JustinCase3 on
It does do a search but when I try and replace it with kill_buffer it doesnt work. Im using linux.
Simon Anciaux
1337 posts
Beginner Help. Keybindings
I don't have any more ideas. Try to contact Allen by e-mail (the e-mail is in the read me) or report a bug.