diff options
-rw-r--r-- | builtin.cpp | 42 | ||||
-rw-r--r-- | input.cpp | 29 | ||||
-rw-r--r-- | share/functions/fish_vi_prompt.fish | 4 |
3 files changed, 22 insertions, 53 deletions
diff --git a/builtin.cpp b/builtin.cpp index 589a4730..87f4f406 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -588,8 +588,8 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) const wchar_t *bind_mode = DEFAULT_BIND_MODE; bool bind_mode_given = false; - const wchar_t *new_bind_mode = DEFAULT_BIND_MODE; - bool new_bind_mode_given = false; + const wchar_t *sets_bind_mode = DEFAULT_BIND_MODE; + bool sets_bind_mode_given = false; int use_terminfo = 0; @@ -691,8 +691,8 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) break; case 'm': - new_bind_mode = woptarg; - new_bind_mode_given = true; + sets_bind_mode = woptarg; + sets_bind_mode_given = true; break; case '?': @@ -706,9 +706,9 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) /* * if mode is given, but not new mode, default to new mode to mode */ - if(bind_mode_given && !new_bind_mode_given) + if(bind_mode_given && !sets_bind_mode_given) { - new_bind_mode = bind_mode; + sets_bind_mode = bind_mode; } switch (mode) @@ -739,7 +739,7 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) default: { - builtin_bind_add(argv[woptind], (const wchar_t **)argv + (woptind + 1), argc - (woptind + 1), bind_mode, new_bind_mode, use_terminfo); + builtin_bind_add(argv[woptind], (const wchar_t **)argv + (woptind + 1), argc - (woptind + 1), bind_mode, sets_bind_mode, use_terminfo); break; } @@ -774,33 +774,6 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) /** - The bind mode builtin -*/ -static int builtin_bind_mode(parser_t &parser, wchar_t **argv) -{ - int res = STATUS_BUILTIN_OK; - int argc = builtin_count_args(argv); - - switch (argc) - { - case 1: - { - append_format(stdout_buffer, L"%ls\n", input_get_bind_mode()); - break; - } - - default: - { - res = STATUS_BUILTIN_ERROR; - append_format(stderr_buffer, _(L"%ls: Expected no parameters, got %d"), argv[0], argc); - break; - } - } - return res; -} - - -/** The block builtin, used for temporarily blocking events */ static int builtin_block(parser_t &parser, wchar_t **argv) @@ -4058,7 +4031,6 @@ static const builtin_data_t builtin_datas[]= { L"begin", &builtin_begin, N_(L"Create a block of code") }, { L"bg", &builtin_bg, N_(L"Send job to background") }, { L"bind", &builtin_bind, N_(L"Handle fish key bindings") }, - { L"bind_mode", &builtin_bind_mode, N_(L"Set or get the current bind mode") }, { L"block", &builtin_block, N_(L"Temporarily block delivery of events") }, { L"break", &builtin_break_continue, N_(L"Stop the innermost loop") }, { L"breakpoint", &builtin_breakpoint, N_(L"Temporarily halt execution of a script and launch an interactive debug prompt") }, @@ -61,6 +61,9 @@ #include <vector> #define DEFAULT_TERM L"ansi" + +#define FISH_BIND_MODE_VAR L"fish_bind_mode" + /** Struct representing a keybinding. Returned by input_get_mappings. */ @@ -231,9 +234,6 @@ static const wchar_t code_arr[] = /** Mappings for the current input mode */ static std::vector<input_mapping_t> mapping_list; -#define MAX_BIND_MODE_NAME_SIZE 512 -static wchar_t bind_mode[MAX_BIND_MODE_NAME_SIZE] = DEFAULT_BIND_MODE; - /* Terminfo map list */ static std::vector<terminfo_mapping_t> terminfo_mappings; @@ -261,6 +261,12 @@ static void input_terminfo_init(); */ const wchar_t *input_get_bind_mode() { + const wchar_t *bind_mode = DEFAULT_BIND_MODE; + const env_var_t bind_mode_var = env_get_string(FISH_BIND_MODE_VAR); + if(!bind_mode_var.missing()) + { + bind_mode = bind_mode_var.c_str(); + } return bind_mode; } @@ -269,16 +275,7 @@ const wchar_t *input_get_bind_mode() */ bool input_set_bind_mode(const wchar_t *bm) { - int len = wcslen(bm) * sizeof(wchar_t); - if(len >= MAX_BIND_MODE_NAME_SIZE) - { - debug(0, L"Error: name for bind mode exceeds maximum size\n"); - return false; - } - memset(bind_mode, 0, MAX_BIND_MODE_NAME_SIZE); - memcpy(bind_mode, bm, len); - //debug(0, L"Set bind mode to `%ls'", bind_mode); - + env_set(FISH_BIND_MODE_VAR, bm, ENV_GLOBAL); return true; } @@ -541,6 +538,8 @@ static void input_mapping_execute_matching_or_generic() { const input_mapping_t *generic = NULL; + const wchar_t *bind_mode = input_get_bind_mode(); + for (int i = 0; i < mapping_list.size(); i++) { const input_mapping_t &m = mapping_list.at(i); @@ -548,7 +547,7 @@ static void input_mapping_execute_matching_or_generic() //debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), 1), // m.mode.c_str(), m.sets_mode.c_str()); - if(wcscmp(m.mode.c_str(), input_get_bind_mode())) + if(wcscmp(m.mode.c_str(), bind_mode)) { //debug(0, L"skipping mapping because mode %ls != %ls\n", m.mode.c_str(), input_get_bind_mode()); continue; @@ -581,8 +580,6 @@ static void input_mapping_execute_matching_or_generic() wint_t input_readch() { - size_t i; - CHECK_BLOCK(R_NULL); /* diff --git a/share/functions/fish_vi_prompt.fish b/share/functions/fish_vi_prompt.fish index 8a3fecd1..bae594cf 100644 --- a/share/functions/fish_vi_prompt.fish +++ b/share/functions/fish_vi_prompt.fish @@ -1,9 +1,9 @@ function fish_vi_prompt_cm --description "Displays the current mode" echo -n " " - switch (bind_mode) + switch $fish_bind_mode case default set_color --bold --background green white - echo "[C]" + echo "[N]" case insert set_color --bold --background red white echo "[I]" |