From b1439075c6c6691d7b595f949391e5f4d5947ad7 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 31 Aug 2006 10:45:25 +1000 Subject: [PATCH] Updated definiton of move_word, more intuitive behaviour when a token consists only of non-alphanumerics darcs-hash:20060831004525-ac50b-aa6675809f0f17fa266982374700a8a4ce6b2f5a.gz --- reader.c | 83 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/reader.c b/reader.c index 5ba2d6a63..5d44bf1b1 100644 --- a/reader.c +++ b/reader.c @@ -1984,11 +1984,25 @@ static void handle_token_history( int forward, int reset ) static void move_word( int dir, int erase ) { int end_buff_pos=data->buff_pos; - int mode=0; int step = dir?1:-1; - while( mode < 2 ) + /* + If we are beyond the last character and moving left, start by + moving one step, since otehrwise we'll start on the \0, which + should be ignored. + */ + if( !dir && (end_buff_pos == data->buff_len) ) { + if( !end_buff_pos ) + return; + + end_buff_pos--; + } + + while( 1 ) + { + wchar_t c; + if( !dir ) { if( end_buff_pos == 0 ) @@ -1999,41 +2013,46 @@ static void move_word( int dir, int erase ) if( end_buff_pos == data->buff_len ) break; } - end_buff_pos+=step; - if( end_buff_pos < data->buff_len ) + c = data->buff[end_buff_pos]; + + if( !iswspace( c ) ) { - switch( mode ) - { - case 0: - if( iswalnum(data->buff[end_buff_pos] ) ) - mode++; - break; - - case 1: - if( !iswalnum(data->buff[end_buff_pos] ) ) - { - if( !dir ) - end_buff_pos -= step; - mode++; - } - break; -/* - case 2: - if( !iswspace(data->buff[end_buff_pos] ) ) - { - mode++; - if( !dir ) - end_buff_pos-=step; - } - break; -*/ - } + break; + } + + end_buff_pos+=step; + } + + while( 1 ) + { + wchar_t c; + + if( !dir ) + { + if( end_buff_pos == 0 ) + break; + } + else + { + if( end_buff_pos == data->buff_len ) + break; } - if( mode==2) - break; + c = data->buff[end_buff_pos]; + if( !iswalnum( c ) ) + { + /* + Don't gobble the boundary character if it was a + whitespace, but do for all other non-alphabetic + characters + */ + if( iswspace( c ) ) + end_buff_pos -= step; + break; + } + end_buff_pos+=step; } if( erase )