--- gforth/utf-8.fs 2004/12/12 20:24:00 1.2 +++ gforth/utf-8.fs 2004/12/12 22:20:00 1.3 @@ -78,9 +78,11 @@ : .all ( span addr pos1 -- span addr pos1 ) restore-cursor >r 2dup swap type r> ; -: (u8ins) ( max span addr pos1 u8char -- max span addr pos2 ) +: ( max span addr pos1 u8char -- max span addr pos2 ) >r >string over r@ u8len + swap move 2dup chars + r@ swap u8!+ drop - r> u8len >r rot r@ chars + -rot r> chars + .all .rest ; + r> u8len >r rot r@ chars + -rot r> chars + ; +: (u8ins) ( max span addr pos1 u8char -- max span addr pos2 ) + .all .rest ; : u8back ( max span addr pos1 -- max span addr pos2 f ) dup IF over + u8<< over - 0 max .all .rest ELSE #bell emit THEN 0 ; @@ -89,21 +91,64 @@ : (u8del) ( max span addr pos1 -- max span addr pos2 ) over + dup u8<< tuck - >r over - >string over r@ + -rot move - rot r> - -rot .all 2 spaces .rest ; + rot r> - -rot ; : ?u8del ( max span addr pos1 -- max span addr pos2 0 ) - dup IF (u8del) THEN 0 ; + dup IF (u8del) .all 2 spaces .rest THEN 0 ; : ( max span addr pos1 -- max span addr pos2 0 ) 2 pick over <> - IF u8forw drop (u8del) ELSE #bell emit THEN 0 ; + IF u8forw drop (u8del) .all 2 spaces .rest + ELSE #bell emit THEN 0 ; : u8eof 2 pick over or 0= IF bye ELSE THEN ; -' u8forw ctrl F bindkey -' u8back ctrl B bindkey -' ?u8del ctrl H bindkey -' u8eof ctrl D bindkey -' ctrl X bindkey +: u8first-pos ( max span addr pos1 -- max span addr 0 0 ) + drop 0 .all .rest 0 ; +: u8end-pos ( max span addr pos1 -- max span addr span 0 ) + drop over .all 0 ; + + +: u8clear-line ( max span addr pos1 -- max addr ) + drop restore-cursor swap spaces restore-cursor ; +: u8clear-tib ( max span addr pos -- max 0 addr 0 false ) + u8clear-line 0 tuck dup ; + +: (u8enter) ( max span addr pos1 -- max span addr pos2 true ) + >r end^ 2@ hist-setpos + 2dup swap history write-line drop ( throw ) \ don't worry about errors + hist-pos 2dup backward^ 2! end^ 2! + r> .all space true ; + +: u8kill-expand ( max span addr pos1 -- max span addr pos2 ) + prefix-found cell+ @ ?dup IF >r + r@ - >string over r@ + -rot move + rot r@ - -rot .all r> spaces .rest THEN ; + +: insert ( string length buffer size -- ) + rot over min >r r@ - ( left over ) + over dup r@ + rot move r> move ; + +: u8tab-expand ( max span addr pos1 -- max span addr pos2 0 ) + key? IF #tab (u8ins) 0 EXIT THEN + u8kill-expand 2dup extract-word dup 0= IF nip EXIT THEN + search-prefix tib-full? + IF 7 emit 2drop 0 0 prefix-found 2! + ELSE dup >r + 2>r >string r@ + 2r> 2swap insert + r@ + rot r> + -rot + THEN + prefix-found @ IF bl (u8ins) THEN 0 ; + +' u8forw ctrl F bindkey +' u8back ctrl B bindkey +' ?u8del ctrl H bindkey +' u8eof ctrl D bindkey +' ctrl X bindkey +' u8clear-tib ctrl K bindkey +' u8first-pos ctrl A bindkey +' u8end-pos ctrl E bindkey +' (u8enter) #lf bindkey +' (u8enter) #cr bindkey +' u8tab-expand #tab bindkey ' (u8ins) IS insert-char -' noop IS everychar ' save-cursor IS everyline ' u8key IS key ' u8emit IS emit