diff --git a/input.cpp b/input.cpp index 576d7d560..d6b7edad7 100644 --- a/input.cpp +++ b/input.cpp @@ -141,7 +141,8 @@ static const wchar_t * const name_arr[] = L"end-selection", L"kill-selection", L"forward-jump", - L"backward-jump" + L"backward-jump", + L"and" } ; @@ -236,7 +237,8 @@ static const wchar_t code_arr[] = R_END_SELECTION, R_KILL_SELECTION, R_FORWARD_JUMP, - R_BACKWARD_JUMP + R_BACKWARD_JUMP, + R_AND } ; @@ -266,6 +268,7 @@ 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; /** @@ -308,6 +311,14 @@ int input_function_arity(int function) } } +/** + Sets the return status of the most recently executed input function +*/ +void input_function_set_status(bool status) +{ + input_function_status = status; +} + /** Returns the nth argument for a given input function */ @@ -511,6 +522,9 @@ void input_function_push_args(int code) */ static void input_mapping_execute(const input_mapping_t &m) { + /* By default input functions always succeed */ + input_function_status = true; + for(int i = m.commands.size() - 1; i >= 0; i--) { wcstring command = m.commands.at(i); @@ -647,12 +661,12 @@ wint_t input_readch() /* Clear the interrupted flag - */ + */ reader_reset_interrupted(); /* Search for sequence in mapping tables - */ + */ while (1) { @@ -670,6 +684,19 @@ wint_t input_readch() { return input_common_readch(0); } + case R_AND: + { + if(input_function_status) + { + return input_readch(); + } + else + { + while((c = input_common_readch(0)) && c >= R_MIN && c <= R_MAX); + input_unreadch(c); + return input_readch(); + } + } default: { return c; diff --git a/input.h b/input.h index a8e2dffb7..e29b08829 100644 --- a/input.h +++ b/input.h @@ -66,12 +66,13 @@ enum R_END_SELECTION, R_KILL_SELECTION, R_FORWARD_JUMP, - R_BACKWARD_JUMP + R_BACKWARD_JUMP, + R_AND } ; #define R_MIN R_NULL -#define R_MAX R_BACKWARD_JUMP +#define R_MAX R_AND /** Initialize the terminal by calling setupterm, and set up arrays @@ -150,6 +151,12 @@ bool input_set_bind_mode(const wchar_t *bind_mode); wchar_t input_function_pop_arg(); + +/** + Sets the return status of the most recently executed input function +*/ +void input_function_set_status(bool status); + /** Return the sequence for the terminfo variable of the specified name. diff --git a/reader.cpp b/reader.cpp index 1e629af17..e02cfc543 100644 --- a/reader.cpp +++ b/reader.cpp @@ -3865,15 +3865,18 @@ const wchar_t *reader_readline(void) { wchar_t target = input_function_pop_arg(); size_t len = data->command_length(); + bool status = false; for(int i = data->buff_pos + 1; i < len; i++) { if(buff[i] == target) { update_buff_pos(i); + status = true; break; } } + input_function_set_status(status); reader_repaint(); break; } @@ -3882,15 +3885,18 @@ const wchar_t *reader_readline(void) { wchar_t target = input_function_pop_arg(); size_t len = data->command_length(); + bool status = false; for(int i = data->buff_pos - 1; i >= 0; i--) { if(buff[i] == target) { update_buff_pos(i); + status = true; break; } } + input_function_set_status(status); reader_repaint(); break; } diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 122d1fb79..fceca4f75 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -131,8 +131,8 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish" bind f forward-jump bind F backward-jump - bind t forward-jump backward-char - bind T backward-jump forward-char + bind t forward-jump and backward-char + bind T backward-jump and forward-char # in emacs yank means paste bind p yank