diff --git a/basis/tools/completion/completion.factor b/basis/tools/completion/completion.factor index 17e617d84b..051152755e 100644 --- a/basis/tools/completion/completion.factor +++ b/basis/tools/completion/completion.factor @@ -15,8 +15,6 @@ IN: tools.completion rot [ ch>lower ] [ ch>upper ] bi '[ dup _ eq? [ drop t ] [ _ eq? ] if ] find-from drop ; -PRIVATE> - :: (fuzzy) ( accum i full ch -- accum i ? ) ch i full smart-index-from [ [ accum push ] @@ -25,10 +23,14 @@ PRIVATE> f -1 f ] if* ; +PRIVATE> + : fuzzy ( full short -- indices ) dup [ length 0 ] curry 2dip [ (fuzzy) ] with all? 2drop ; + ] keep pick last push ] each ; +PRIVATE> + : runs ( seq -- newseq ) [ V{ } clone 1vector ] dip [ first ] keep (runs) drop ; + [ 2drop 1 ] } cond ; +PRIVATE> + : score ( full fuzzy -- n ) dup [ [ [ length ] bi@ - 15 swap [-] 3 /f ] 2keep @@ -72,12 +80,16 @@ PRIVATE> [ ] bi@ dupd fuzzy score max ; + [ , ] [ drop ] if ; +PRIVATE> + : completions ( short candidates -- seq ) [ ] [ [ [ completion, ] with each ] { } make