1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays io io.styles kernel namespaces make
4 parser prettyprint sequences words words.symbol assocs
5 definitions generic quotations effects slots continuations
6 classes.tuple debugger combinators vocabs help.stylesheet
7 help.topics help.crossref help.markup sorting classes
11 GENERIC: word-help* ( word -- content )
13 : word-help ( word -- content )
14 dup "help" word-prop [ ] [
16 [ swap 2array 1array ] [ 2drop f ] if
19 : $predicate ( element -- )
20 { { "object" object } { "?" "a boolean" } } $values
22 "Tests if the object is an instance of the " ,
23 first "predicating" word-prop <$link> ,
25 ] { } make $description ;
27 M: word word-help* drop f ;
29 M: predicate word-help* drop \ $predicate ;
31 : all-articles ( -- seq )
33 all-words [ word-help ] filter append ;
35 : orphan-articles ( -- seq )
37 [ article-parent not ] filter ;
40 all-articles [ xref-article ] each ;
42 : error? ( word -- ? )
43 \ $error-description swap word-help elements empty? not ;
45 : sort-articles ( seq -- newseq )
46 [ dup article-title ] { } map>assoc sort-values keys ;
48 : all-errors ( -- seq )
49 all-words [ error? ] filter sort-articles ;
51 M: word article-name name>> ;
54 dup [ parsing-word? ] [ symbol? ] bi or [
58 [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
64 : (word-help) ( word -- element )
67 [ \ $vocabulary swap 2array , ]
69 [ \ $related swap 2array , ]
70 [ get-global [ \ $value swap 2array , ] when* ]
71 [ \ $definition swap 2array , ]
75 M: word article-content (word-help) ;
79 : word-with-methods ( word -- elements )
82 [ \ $methods swap 2array , ]
88 M: generic article-content word-with-methods ;
90 M: class article-content word-with-methods ;
92 M: word article-parent "help-parent" word-prop ;
94 M: word set-article-parent swap "help-parent" set-word-prop ;
96 : $doc-path ( article -- )
100 "Parent topics: " write $links
105 : $title ( topic -- )
109 dup article-title swap >link write-object
114 : print-topic ( topic -- )
116 last-element off dup $title
117 article-content print-content nl ;
121 help-hook global [ [ print-topic ] or ] change-at
129 "No such vocabulary: " prepend throw
134 "The " write vocab-name write
135 " vocabulary does not define a main help article." print
136 "To define one, refer to \\ ABOUT: help" print
139 : ($index) ( articles -- )
140 sort-articles [ \ $subsection swap 2array ] map print-element ;
142 : $index ( element -- )
143 first call [ ($index) ] unless-empty ;
145 : $about ( element -- )
146 first vocab-help [ 1array $subsection ] when* ;
148 : :help-debugger ( -- )
150 "Debugger commands:" print
152 ":s - data stack at error time" print
153 ":r - retain stack at error time" print
154 ":c - call stack at error time" print
155 ":edit - jump to source location (parse errors only)" print
157 ":get ( var -- value ) accesses variables at time of the error" print
158 ":vars - list all variables at error time" print ;
160 : (:help) ( error -- )
161 error-help [ help ] [ "No help for this error. " print ] if*
167 : remove-article ( name -- )
168 dup articles get key? [
170 dup articles get delete-at
173 : add-article ( article name -- )
174 [ remove-article ] keep
175 [ articles get set-at ] keep
178 : remove-word-help ( word -- )
179 dup word-help [ dup unxref-article ] when
180 f "help" set-word-prop ;
182 : set-word-help ( content word -- )
183 [ remove-word-help ] keep
184 [ swap "help" set-word-prop ] keep