From 713748c78274a39976a41898eeebf984464fd81d Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 24 Jul 2006 06:52:03 +1000 Subject: [PATCH] Some minor steps towards making vi-mode work darcs-hash:20060723205203-ac50b-8125e733ed92689ba847ccbb9076d05910e701ac.gz --- input.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++----- input.h | 2 + 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/input.c b/input.c index edd8aa200..c057c259c 100644 --- a/input.c +++ b/input.c @@ -121,7 +121,8 @@ static const wchar_t *name_arr[] = L"history-token-search-forward", L"self-insert", L"null", - L"eof" + L"eof", + L"vi-arg-digit" } ; @@ -159,7 +160,8 @@ static const wchar_t *desc_arr[] = L"Search forward through list of previous commands for matching token", L"Insert the pressed key", L"Do nothing", - L"End of file" + L"End of file", + L"Repeat command" } ; */ @@ -196,7 +198,8 @@ static const wchar_t code_arr[] = R_HISTORY_TOKEN_SEARCH_FORWARD, R_SELF_INSERT, R_NULL, - R_EOF + R_EOF, + R_VI_ARG_DIGIT } ; @@ -238,6 +241,19 @@ static int inputrc_error = 0; */ static int is_init = 0; + +/** + This is the variable telling us how many timew the next command + should bne repeated. Only actually used in vi-mode. +*/ +static int repeat_count = 1; + +/** + This is the type of the first command in a vi-mode two-part combo + like 'dw' or '3d3l'. +*/ +static wint_t first_command = 0; + wchar_t input_get_code( const wchar_t *name ) { @@ -255,7 +271,7 @@ wchar_t input_get_code( const wchar_t *name ) /** Returns the function name for the given function code. */ -/* + static const wchar_t *input_get_name( wchar_t c ) { @@ -269,7 +285,7 @@ static const wchar_t *input_get_name( wchar_t c ) } return 0; } -*/ + /** Returns the function description for the given function code. */ @@ -998,7 +1014,7 @@ void input_parse_inputrc_line( wchar_t *cmd ) { if( wcscmp( key, L"editing-mode" ) == 0 ) { -// current_mode_mappings = get_mapping( value ); + current_mode_mappings = get_mapping( value ); } } @@ -1305,12 +1321,29 @@ static void add_vi_bindings() add_mapping( L"vi-command", L"$", L"$", L"end-of-line" ); add_mapping( L"vi-command", L"^", L"^", L"beginning-of-line" ); add_mapping( L"vi-command", L"0", L"0", L"beginning-of-line" ); + add_mapping( L"vi-command", L"b", L"b", L"backward-word" ); add_mapping( L"vi-command", L"B", L"B", L"backward-word" ); add_mapping( L"vi-command", L"w", L"w", L"forward-word" ); add_mapping( L"vi-command", L"W", L"W", L"forward-word" ); + add_mapping( L"vi-command", L"x", L"x", L"delete-char" ); - + + add_mapping( L"vi-command", L"1", L"1", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"2", L"2", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"3", L"3", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"4", L"4", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"5", L"5", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"6", L"6", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"7", L"7", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"8", L"8", L"vi-arg-digit" ); + add_mapping( L"vi-command", L"9", L"9", L"vi-arg-digit" ); + + + add_mapping( L"vi-command", L"d", L"d", L"vi-delete-to" ); + add_mapping( L"vi-command", L"D", L"D", L"vi-delete-to" ); + + /* movement ("h", "l"), word movement ("b", "B", "w", "W", "e", "E"), moving to beginning and end of line @@ -1456,6 +1489,8 @@ void input_destroy() */ static wint_t input_exec_binding( mapping *m, const wchar_t *seq ) { + int i; + // fwprintf( stderr, L"Binding %ls\n", m->command ); wchar_t code = input_get_code( m->command ); if( code != -1 ) @@ -1464,15 +1499,63 @@ static wint_t input_exec_binding( mapping *m, const wchar_t *seq ) { case R_DUMP_FUNCTIONS: { - dump_functions(); + for( i=0; i 0 && repeat <= 9 ) + repeat_count *= repeat; + + return R_NULL; + } + + case R_VI_DELETE_TO: + { + first_command = R_VI_DELETE_TO; + return R_NULL; + } + default: + { + + if( first_command ) + { + switch( first_command ) + { + case R_VI_DELETE_TO: + { + + break; + + } + } + } + else + { + for( i=1; icommand ) ) + { + return input_exec_binding( m, m->seq ); + } + input_unreadch( c ); if( m->seq != 0 ) { @@ -1524,9 +1614,14 @@ static wint_t input_try_mapping( mapping *m) } else { + /* + Return the read characters + */ input_unreadch(c); - for(k=j-1; k>=0; k--) - input_unreadch(m->seq[k]); + for( k=j-1; k>=0; k-- ) + { + input_unreadch( m->seq[k] ); + } } } return 0; diff --git a/input.h b/input.h index ff6bb1cb1..b7b5a61c6 100644 --- a/input.h +++ b/input.h @@ -44,6 +44,8 @@ enum R_HISTORY_TOKEN_SEARCH_BACKWARD, R_HISTORY_TOKEN_SEARCH_FORWARD, R_SELF_INSERT, + R_VI_ARG_DIGIT, + R_VI_DELETE_TO } ;