Add 'and' input function; fixes a bug with t,T

'and' will prevent later input functions from being executed if the
previous one did not succeed (e.g. a jump to a char not on the command
line)
This commit is contained in:
Julian Aron Prenner 2014-01-23 10:23:04 +01:00
parent 45465e0c45
commit 844b01cb6b
4 changed files with 48 additions and 8 deletions

View file

@ -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;

11
input.h
View file

@ -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.

View file

@ -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;
}

View file

@ -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