Clean up some messy stack shuffling
parent
00fb6496fb
commit
4513417657
|
@ -3,22 +3,22 @@
|
||||||
USING: accessors arrays assocs calendar combinators
|
USING: accessors arrays assocs calendar combinators
|
||||||
combinators.short-circuit compiler.units concurrency.flags
|
combinators.short-circuit compiler.units concurrency.flags
|
||||||
concurrency.mailboxes continuations destructors documents
|
concurrency.mailboxes continuations destructors documents
|
||||||
documents.elements fry hashtables help help.markup io
|
documents.elements fry hashtables help help.markup io io.styles kernel
|
||||||
io.styles kernel lexer listener math models models.delay models.filter
|
lexer listener math models models.delay models.filter namespaces
|
||||||
namespaces parser prettyprint quotations sequences strings threads
|
parser prettyprint quotations sequences strings threads tools.vocabs
|
||||||
tools.vocabs ui ui.commands ui.gadgets ui.gadgets.buttons
|
vocabs vocabs.loader vocabs.parser words ui ui.commands ui.gadgets
|
||||||
ui.gadgets.editors ui.gadgets.frames ui.gadgets.grids
|
ui.gadgets.buttons ui.gadgets.editors ui.gadgets.frames
|
||||||
ui.gadgets.labelled ui.gadgets.panes ui.gadgets.scrollers
|
ui.gadgets.grids ui.gadgets.labelled ui.gadgets.panes
|
||||||
ui.gadgets.status-bar ui.gadgets.tracks ui.gestures ui.operations
|
ui.gadgets.scrollers ui.gadgets.status-bar ui.gadgets.tracks
|
||||||
ui.tools.browser ui.tools.common ui.tools.debugger
|
ui.gestures ui.operations ui.tools.browser ui.tools.common
|
||||||
ui.tools.listener.completion ui.tools.listener.history vocabs
|
ui.tools.debugger ui.tools.listener.completion
|
||||||
vocabs.parser words ;
|
ui.tools.listener.history ;
|
||||||
IN: ui.tools.listener
|
IN: ui.tools.listener
|
||||||
|
|
||||||
! If waiting is t, we're waiting for user input, and invoking
|
! If waiting is t, we're waiting for user input, and invoking
|
||||||
! evaluate-input resumes the thread.
|
! evaluate-input resumes the thread.
|
||||||
TUPLE: interactor < source-editor
|
TUPLE: interactor < source-editor
|
||||||
output history flag mailbox thread waiting word-model
|
output history flag mailbox thread waiting token-model word-model
|
||||||
completion-popup ;
|
completion-popup ;
|
||||||
|
|
||||||
: register-self ( interactor -- )
|
: register-self ( interactor -- )
|
||||||
|
@ -42,16 +42,23 @@ completion-popup ;
|
||||||
assoc-stack
|
assoc-stack
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: vocab-exists? ( name -- ? )
|
||||||
|
{ [ vocab ] [ find-vocab-root ] } 1|| ;
|
||||||
|
|
||||||
|
: word-at-caret ( token interactor -- word/vocab/f )
|
||||||
|
dup vocab-completion?
|
||||||
|
[ drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ]
|
||||||
|
[ interactor-use assoc-stack ] if ;
|
||||||
|
|
||||||
: <word-model> ( interactor -- model )
|
: <word-model> ( interactor -- model )
|
||||||
[ one-word-elt <element-model> 1/3 seconds <delay> ] keep
|
[ token-model>> 1/3 seconds <delay> ]
|
||||||
'[
|
[ '[ _ word-at-caret ] ] bi
|
||||||
_ dup vocab-completion?
|
<filter> ;
|
||||||
[ drop >vocab-link ] [ interactor-use assoc-stack ] if
|
|
||||||
] <filter> ;
|
|
||||||
|
|
||||||
: <interactor> ( output -- gadget )
|
: <interactor> ( output -- gadget )
|
||||||
interactor new-editor
|
interactor new-editor
|
||||||
<flag> >>flag
|
<flag> >>flag
|
||||||
|
dup one-word-elt <element-model> >>token-model
|
||||||
dup <word-model> >>word-model
|
dup <word-model> >>word-model
|
||||||
dup model>> <history> >>history
|
dup model>> <history> >>history
|
||||||
swap >>output ;
|
swap >>output ;
|
||||||
|
@ -332,15 +339,14 @@ M: interactor stream-read-quot
|
||||||
completion-popup>> focusable-child resend-gesture ;
|
completion-popup>> focusable-child resend-gesture ;
|
||||||
|
|
||||||
: interactor-operation ( gesture interactor -- ? )
|
: interactor-operation ( gesture interactor -- ? )
|
||||||
word-model>> value>>
|
[ token-model>> value>> ] keep word-at-caret
|
||||||
[ nip ] [ gesture>operation ] 2bi
|
[ nip ] [ gesture>operation ] 2bi dup [ invoke-command f ] [ 2drop t ] if ;
|
||||||
dup [ invoke-command f ] [ 2drop t ] if ;
|
|
||||||
|
|
||||||
M: interactor handle-gesture
|
M: interactor handle-gesture
|
||||||
{
|
{
|
||||||
{ [ over key-gesture? not ] [ call-next-method ] }
|
{ [ over key-gesture? not ] [ call-next-method ] }
|
||||||
{ [ dup completion-popup>> ] [ { [ pass-to-popup ] [ call-next-method ] } 2&& ] }
|
{ [ dup completion-popup>> ] [ { [ pass-to-popup ] [ call-next-method ] } 2&& ] }
|
||||||
{ [ dup word-model>> value>> ] [ { [ interactor-operation ] [ call-next-method ] } 2&& ] }
|
{ [ dup token-model>> value>> ] [ { [ interactor-operation ] [ call-next-method ] } 2&& ] }
|
||||||
[ call-next-method ]
|
[ call-next-method ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ DEFER: if
|
||||||
|
|
||||||
! Default
|
! Default
|
||||||
: ?if ( default cond true false -- )
|
: ?if ( default cond true false -- )
|
||||||
pick [ roll 2drop call ] [ 2nip call ] if ; inline
|
pick [ drop [ drop ] 2dip call ] [ 2nip call ] if ; inline
|
||||||
|
|
||||||
! Slippers and dippers.
|
! Slippers and dippers.
|
||||||
! Not declared inline because the compiler special-cases them
|
! Not declared inline because the compiler special-cases them
|
||||||
|
|
|
@ -280,7 +280,7 @@ INSTANCE: repetition immutable-sequence
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: subseq ( from to seq -- subseq )
|
: subseq ( from to seq -- subseq )
|
||||||
[ check-slice prepare-subseq (copy) ] [ like ] bi ;
|
[ check-slice prepare-subseq (copy) ] keep like ;
|
||||||
|
|
||||||
: head ( seq n -- headseq ) (head) subseq ;
|
: head ( seq n -- headseq ) (head) subseq ;
|
||||||
|
|
||||||
|
@ -386,9 +386,6 @@ PRIVATE>
|
||||||
[ 2drop f f ]
|
[ 2drop f f ]
|
||||||
if ; inline
|
if ; inline
|
||||||
|
|
||||||
: (interleave) ( n elt between quot -- )
|
|
||||||
roll 0 = [ nip ] [ swapd 2slip ] if call ; inline
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: each ( seq quot -- )
|
: each ( seq quot -- )
|
||||||
|
@ -475,9 +472,6 @@ PRIVATE>
|
||||||
: partition ( seq quot -- trueseq falseseq )
|
: partition ( seq quot -- trueseq falseseq )
|
||||||
over [ 2pusher [ each ] 2dip ] dip tuck [ like ] 2bi@ ; inline
|
over [ 2pusher [ each ] 2dip ] dip tuck [ like ] 2bi@ ; inline
|
||||||
|
|
||||||
: interleave ( seq between quot -- )
|
|
||||||
[ (interleave) ] 2curry [ [ length ] keep ] dip 2each ; inline
|
|
||||||
|
|
||||||
: accumulator ( quot -- quot' vec )
|
: accumulator ( quot -- quot' vec )
|
||||||
V{ } clone [ [ push ] curry compose ] keep ; inline
|
V{ } clone [ [ push ] curry compose ] keep ; inline
|
||||||
|
|
||||||
|
@ -496,6 +490,11 @@ PRIVATE>
|
||||||
: each-index ( seq quot -- )
|
: each-index ( seq quot -- )
|
||||||
prepare-index 2each ; inline
|
prepare-index 2each ; inline
|
||||||
|
|
||||||
|
: interleave ( seq between quot -- )
|
||||||
|
swap [ drop ] [ [ 2dip call ] 2curry ] 2bi
|
||||||
|
[ [ 0 = ] 2dip if ] 2curry
|
||||||
|
each-index ; inline
|
||||||
|
|
||||||
: map-index ( seq quot -- )
|
: map-index ( seq quot -- )
|
||||||
prepare-index 2map ; inline
|
prepare-index 2map ; inline
|
||||||
|
|
||||||
|
@ -700,8 +699,10 @@ PRIVATE>
|
||||||
|
|
||||||
: join ( seq glue -- newseq )
|
: join ( seq glue -- newseq )
|
||||||
[
|
[
|
||||||
2dup joined-length over new-resizable spin
|
2dup joined-length over new-resizable [
|
||||||
[ dup pick push-all ] [ pick push-all ] interleave drop
|
[ [ push-all ] 2curry ] [ [ nip push-all ] 2curry ] 2bi
|
||||||
|
interleave
|
||||||
|
] keep
|
||||||
] keep like ;
|
] keep like ;
|
||||||
|
|
||||||
: padding ( seq n elt quot -- newseq )
|
: padding ( seq n elt quot -- newseq )
|
||||||
|
|
Loading…
Reference in New Issue