diff --git a/builtin.cpp b/builtin.cpp index 07d894037..9fc55aa4c 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -404,8 +404,7 @@ int builtin_test(parser_t &parser, wchar_t **argv); static void builtin_bind_list(const wchar_t *bind_mode) { size_t i; - wcstring_list_t lst; - input_mapping_get_names(lst); + const wcstring_list_t lst = input_mapping_get_names(); for (i=0; i commands; /**< commands that should be evaluated by this mapping */ + wcstring_list_t commands; /**< commands that should be evaluated by this mapping */ /* We wish to preserve the user-specified order. This is just an incrementing value. */ unsigned int specification_order; @@ -285,32 +285,25 @@ static bool is_init = false; */ static void input_terminfo_init(); -wchar_t input_function_args[MAX_INPUT_FUNCTION_ARGS]; -bool input_function_status; -int input_function_args_index = 0; +static wchar_t input_function_args[MAX_INPUT_FUNCTION_ARGS]; +static bool input_function_status; +static int input_function_args_index = 0; /** Return the current bind mode */ -const wchar_t *input_get_bind_mode() +wcstring 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; + env_var_t mode = env_get_string(FISH_BIND_MODE_VAR); + return mode.missing() ? DEFAULT_BIND_MODE : mode; } /** Set the current bind mode */ -bool input_set_bind_mode(const wchar_t *bm) +void input_set_bind_mode(const wcstring &bm) { - if(wcscmp(bm, input_get_bind_mode())) - env_set(FISH_BIND_MODE_VAR, bm, ENV_GLOBAL); - return true; + env_set(FISH_BIND_MODE_VAR, bm.c_str(), ENV_GLOBAL); } @@ -323,9 +316,9 @@ int input_function_arity(int function) { case R_FORWARD_JUMP: case R_BACKWARD_JUMP: - return 1; + return 1; default: - return 0; + return 0; } } @@ -375,7 +368,7 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t // debug( 0, L"Add mapping from %ls to %ls in mode %ls", escape(sequence, 1), escape(command, 1 ), mode); // remove existing mappings with this sequence - std::vector commands_vector(commands, commands + commands_len); + const wcstring_list_t commands_vector(commands, commands + commands_len); for (size_t i=0; i= 0; i--) + + size_t idx = m.commands.size(); + while (idx--) { - wcstring command = m.commands.at(i); - wchar_t code = input_function_get_code(command); - if (code != (wchar_t)-1) - { - input_function_push_args(code); - } - } - - for(int i = m.commands.size() - 1; i >= 0; i--) - { - wcstring command = m.commands.at(i); - wchar_t code = input_function_get_code(command); - if (code != (wchar_t)-1) - { - input_unreadch(code); - } - else - { - /* - This key sequence is bound to a command, which - is sent to the parser for evaluation. - */ - int last_status = proc_get_last_status(); - parser_t::principal_parser().eval(command.c_str(), io_chain_t(), TOP); - - proc_set_last_status(last_status); - - input_unreadch(R_NULL); + wcstring command = m.commands.at(idx); + wchar_t code = input_function_get_code(command); + if (code != (wchar_t)-1) + { + input_function_push_args(code); } } - + + idx = m.commands.size(); + while (idx--) + { + wcstring command = m.commands.at(idx); + wchar_t code = input_function_get_code(command); + if (code != (wchar_t)-1) + { + input_unreadch(code); + } + else + { + /* + This key sequence is bound to a command, which + is sent to the parser for evaluation. + */ + int last_status = proc_get_last_status(); + parser_t::principal_parser().eval(command.c_str(), io_chain_t(), TOP); + + proc_set_last_status(last_status); + + input_unreadch(R_NULL); + } + } + input_set_bind_mode(m.sets_mode.c_str()); } @@ -650,7 +648,7 @@ static void input_mapping_execute_matching_or_generic() { const input_mapping_t *generic = NULL; - const wchar_t *bind_mode = input_get_bind_mode(); + const wcstring bind_mode = input_get_bind_mode(); for (int i = 0; i < mapping_list.size(); i++) { @@ -659,7 +657,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(), bind_mode)) + if (m.mode != bind_mode) { //debug(0, L"skipping mapping because mode %ls != %ls\n", m.mode.c_str(), input_get_bind_mode()); continue; @@ -745,18 +743,20 @@ wint_t input_readch() } } -void input_mapping_get_names(wcstring_list_t &lst) +wcstring_list_t input_mapping_get_names() { // Sort the mappings by the user specification order, so we can return them in the same order that the user specified them in std::vector local_list = mapping_list; std::sort(local_list.begin(), local_list.end(), specification_order_is_less_than); + wcstring_list_t result; + result.reserve(local_list.size()); for (size_t i=0; i &cmds, wcstring &mode, wcstring &sets_mode) +bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_sets_mode) { - size_t i, sz = mapping_list.size(); - - for (i=0; i &cmds, wcstring &mode, wcstring &new_mode); +bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_new_mode); /** Return the current bind mode */ -const wchar_t *input_get_bind_mode(); +wcstring input_get_bind_mode(); /** Set the current bind mode */ -bool input_set_bind_mode(const wchar_t *bind_mode); +void input_set_bind_mode(const wcstring &bind_mode); wchar_t input_function_pop_arg(); diff --git a/reader.cpp b/reader.cpp index 243d50aba..357f9a940 100644 --- a/reader.cpp +++ b/reader.cpp @@ -626,9 +626,9 @@ static void reader_repaint() cmd_line->size(), &colors[0], &indents[0], + cursor_position, data->sel_start_pos, data->sel_stop_pos, - cursor_position, data->current_page_rendering, focused_on_pager); @@ -2446,23 +2446,14 @@ size_t reader_get_cursor_pos() bool reader_get_selection(size_t *start, size_t *len) { - if (!data) + bool result = false; + if (data != NULL && data->sel_active) { - return false; - } - else - { - if (! data->sel_active) - { - return false; - } - else - { - *start = data->sel_start_pos; - *len = std::min(data->sel_stop_pos - data->sel_start_pos + 1, data->command_line.size()); - return true; - } + *start = data->sel_start_pos; + *len = std::min(data->sel_stop_pos - data->sel_start_pos + 1, data->command_line.size()); + result = true; } + return result; } @@ -3833,7 +3824,6 @@ const wchar_t *reader_readline(void) line_offset_old = el->position - parse_util_get_offset_from_line(el->text, line_old); total_offset_new = parse_util_get_offset(el->text, line_new, line_offset_old - 4*(indent_new-indent_old)); update_buff_pos(el, total_offset_new); - el->position = total_offset_new; reader_repaint_needed(); } }