1 ! Copyright (C) 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: definitions gadgets gadgets-browser gadgets-dataflow
5 gadgets-help gadgets-listener gadgets-search gadgets-text
6 gadgets-workspace hashtables help inference kernel namespaces
7 parser prettyprint scratchpad sequences strings styles syntax
8 test tools words generic models io modules errors ;
10 V{ } clone operations set-global
19 : (command) ( -- command )
20 +name+ get +keyboard+ get +quot+ get <command> ;
22 C: operation ( predicate hash -- operation )
24 (command) over set-delegate
25 +primary+ get over set-operation-primary?
26 +secondary+ get over set-operation-secondary?
27 +listener+ get over set-operation-listener?
29 [ set-operation-predicate ] keep ;
31 M: operation invoke-command
32 [ operation-hook call ] keep
33 dup command-quot swap operation-listener?
34 [ curry call-listener ] [ call ] if ;
36 : define-operation ( class props -- )
37 <operation> operations get push ;
39 : modify-command ( quot command -- command )
41 [ command-quot append ] keep
42 [ set-command-quot ] keep ;
44 : modify-commands ( commands quot -- commands )
45 swap [ modify-command ] map-with ;
47 : listener-operation ( hook quot operation -- operation )
49 tuck set-operation-hook
50 t over set-operation-listener? ;
52 : listener-operations ( operations hook quot -- operations )
53 rot [ >r 2dup r> listener-operation ] map 2nip ;
59 { +quot+ [ inspect ] }
64 { +name+ "Prettyprint" }
80 { +quot+ [ listener-gadget call-tool ] }
88 { +quot+ [ restart ] }
97 { +quot+ [ pathname-string edit-file ] }
101 { +name+ "Run file" }
102 { +keyboard+ T{ key-down f { A+ } "r" } }
103 { +quot+ [ pathname-string run-file ] }
111 { +keyboard+ T{ key-down f { A+ } "b" } }
112 { +quot+ [ browser call-tool ] }
115 : word-completion-string ( word listener -- string )
116 >r dup word-name swap word-vocabulary dup vocab r>
117 listener-gadget-input interactor-use memq?
118 [ drop ] [ [ "USE: " % % " " % % ] "" make ] if ;
120 : insert-word ( word -- )
121 get-listener [ word-completion-string ] keep
122 listener-gadget-input user-input ;
127 { +quot+ [ insert-word ] }
132 { +keyboard+ T{ key-down f { A+ } "e" } }
137 { +name+ "Documentation" }
138 { +keyboard+ T{ key-down f { A+ } "h" } }
139 { +quot+ [ help-gadget call-tool ] }
144 { +keyboard+ T{ key-down f { A+ } "u" } }
145 { +quot+ [ usage. ] }
151 { +keyboard+ T{ key-down f { A+ } "r" } }
152 { +quot+ [ reload ] }
163 { +quot+ [ forget ] }
167 { +name+ "Word stack effect" }
168 { +quot+ [ word-def infer. ] }
173 { +name+ "Word dataflow" }
174 { +quot+ [ word-def show-dataflow ] }
175 { +keyboard+ T{ key-down f { A+ } "d" } }
182 { +keyboard+ T{ key-down f { A+ } "b" } }
183 { +quot+ [ vocab-link-name get-workspace swap show-vocab-words ] }
187 { +name+ "Enter in" }
188 { +keyboard+ T{ key-down f { A+ } "i" } }
189 { +quot+ [ vocab-link-name set-in ] }
196 { +quot+ [ vocab-link-name use+ ] }
202 { +quot+ [ vocab-link-name forget-vocab ] }
209 { +quot+ [ module-name run-module ] }
215 { +quot+ [ module-name require ] }
220 { +name+ "Documentation" }
221 { +keyboard+ T{ key-down f { A+ } "h" } }
222 { +quot+ [ module-help [ help-gadget call-tool ] when* ] }
227 { +keyboard+ T{ key-down f { A+ } "e" } }
234 { +keyboard+ T{ key-down f { A+ } "b" } }
235 { +quot+ [ get-workspace swap show-module-files ] }
240 { +quot+ [ browser call-tool ] }
245 { +quot+ [ module-name test-module ] }
254 { +quot+ [ module-name run-module ] }
260 { +quot+ [ module-name require ] }
269 { +quot+ [ help-gadget call-tool ] }
274 { +keyboard+ T{ key-down f { A+ } "e" } }
280 { +keyboard+ T{ key-down f { A+ } "r" } }
281 { +quot+ [ reload ] }
285 { +name+ "Definition" }
286 { +keyboard+ T{ key-down f { A+ } "b" } }
287 { +quot+ [ link-name browser call-tool ] }
292 { +name+ "Quotation stack effect" }
293 { +keyboard+ T{ key-down f { C+ } "i" } }
294 { +quot+ [ infer. ] }
299 { +name+ "Quotation dataflow" }
300 { +keyboard+ T{ key-down f { C+ } "d" } }
301 { +quot+ [ show-dataflow ] }
307 { +keyboard+ T{ key-down f { C+ } "w" } }
314 { +keyboard+ T{ key-down f { C+ } "t" } }
322 { +name+ "Show dataflow" }
323 { +quot+ [ dataflow-gadget call-tool ] }
326 ! Define commands in terms of operations
328 ! Interactor commands
329 : quot-action ( interactor -- quot )
330 dup editor-string swap select-all ;
333 { word compound } [ class-operations ] map concat
334 [ selected-word ] [ search ] listener-operations
337 interactor "quotations"
338 quotation class-operations
339 [ quot-action ] [ parse ] listener-operations
342 help-gadget "toolbar" {
343 { "Back" T{ key-down f { C+ } "b" } [ help-gadget-history go-back ] }
344 { "Forward" T{ key-down f { C+ } "f" } [ help-gadget-history go-forward ] }
345 { "Home" T{ key-down f { C+ } "1" } [ go-home ] }
347 link class-operations [ help-action ] modify-commands
348 [ command-name "Follow" = not ] subset