1 ! Copyright (C) 2005, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays io kernel namespaces parser prettyprint sequences
4 words assocs definitions generic quotations effects
5 slots continuations tuples debugger combinators
6 vocabs help.stylesheet help.topics help.crossref help.markup
10 GENERIC: word-help* ( word -- content )
12 : word-help ( word -- content )
13 dup "help" word-prop [ ] [
15 [ swap 2array 1array ] [ 2drop f ] if
18 M: word word-help* drop f ;
20 M: slot-reader word-help* drop \ $slot-reader ;
22 M: slot-writer word-help* drop \ $slot-writer ;
24 : all-articles ( -- seq )
26 all-words [ word-help ] subset append ;
29 all-articles [ xref-article ] each ;
31 : error? ( word -- ? )
32 \ $error-description swap word-help elements empty? not ;
34 : sort-articles ( seq -- newseq )
35 [ dup article-title ] { } map>assoc sort-values 0 <column> ;
37 : all-errors ( -- seq )
38 all-words [ error? ] subset sort-articles ;
40 M: word article-name word-name ;
43 dup parsing? over symbol? or [
48 [ effect>string " " swap 3append ] when*
51 M: word article-content
53 \ $vocabulary over 2array ,
55 \ $related over 2array ,
56 dup get-global [ \ $value swap 2array , ] when*
57 \ $definition swap 2array ,
60 M: word article-parent "help-parent" word-prop ;
62 M: word set-article-parent swap "help-parent" set-word-prop ;
64 : $doc-path ( article -- )
65 help-path dup empty? [
70 "Parent topics: " write $links
79 dup article-title swap >link write-object
85 last-element off dup $title
86 article-content print-content nl ;
92 "The " write vocab-name write
93 " vocabulary does not define a main help article." print
94 "To define one, refer to \\ ABOUT: help" print
97 : ($index) ( articles -- )
98 subsection-style get [
99 sort-articles [ nl ] [ ($subsection) ] interleave
102 : $index ( element -- )
103 first call dup empty?
104 [ drop ] [ [ ($index) ] ($block) ] if ;
106 : $about ( element -- )
107 first vocab-help [ 1array $subsection ] when* ;
110 "This error has multiple delegates:" print
114 drop "No help for this error. " print ;
117 error get delegates [ error-help ] map [ ] subset
119 { [ dup empty? ] [ (:help-none) ] }
120 { [ dup length 1 = ] [ first help ] }
121 { [ t ] [ (:help-multi) ] }
124 : remove-article ( name -- )
125 dup articles get key? [
127 dup articles get delete-at
130 : add-article ( article name -- )
131 [ remove-article ] keep
132 [ articles get set-at ] keep
135 : remove-word-help ( word -- )
136 dup word-help [ dup unxref-article ] when
137 f "help" set-word-prop ;
139 : set-word-help ( content word -- )
140 [ remove-word-help ] keep
141 [ swap "help" set-word-prop ] keep