help.crossref, tools.crossref: improved help cross-referencing

db4
Slava Pestov 2010-01-26 01:18:10 +13:00
parent 13e2de5cae
commit 6306d58f77
2 changed files with 26 additions and 14 deletions

View File

@ -7,10 +7,10 @@ IN: help.crossref
: article-links ( topic elements -- seq ) : article-links ( topic elements -- seq )
[ article-content ] dip [ article-content ] dip
collect-elements [ >link ] map ; collect-elements ;
: article-children ( topic -- seq ) : article-children ( topic -- seq )
{ $subsection $subsections } article-links ; { $subsection $subsections } article-links [ >link ] map ;
: help-path ( topic -- seq ) : help-path ( topic -- seq )
[ article-parent ] follow rest ; [ article-parent ] follow rest ;

View File

@ -1,9 +1,10 @@
! Copyright (C) 2005, 2009 Slava Pestov. ! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: words assocs definitions io io.pathnames io.styles kernel USING: words assocs definitions io io.pathnames io.styles kernel
prettyprint sorting see sets sequences arrays hashtables help.crossref prettyprint sorting see sets sequences arrays hashtables help
help.topics help.markup quotations accessors source-files namespaces help.crossref help.topics help.markup quotations accessors
graphs vocabs generic generic.single threads compiler.units init ; source-files namespaces graphs vocabs generic generic.single
threads compiler.units init combinators.smart ;
IN: tools.crossref IN: tools.crossref
SYMBOL: crossref SYMBOL: crossref
@ -50,10 +51,16 @@ M: callable uses ( quot -- assoc )
M: word uses def>> uses ; M: word uses def>> uses ;
M: link uses { $subsection $subsections $link $see-also } article-links ; M: link uses
[ { $subsection $subsections $link $see-also } article-links [ >link ] map ]
[ { $vocab-link } article-links [ >vocab-link ] map ]
bi append ;
M: pathname uses string>> source-file top-level-form>> [ uses ] [ { } ] if* ; M: pathname uses string>> source-file top-level-form>> [ uses ] [ { } ] if* ;
! To make UI browser happy
M: vocab uses drop f ;
GENERIC: crossref-def ( defspec -- ) GENERIC: crossref-def ( defspec -- )
M: object crossref-def M: object crossref-def
@ -62,18 +69,23 @@ M: object crossref-def
M: word crossref-def M: word crossref-def
[ call-next-method ] [ subwords [ crossref-def ] each ] bi ; [ call-next-method ] [ subwords [ crossref-def ] each ] bi ;
: defs-to-crossref ( -- seq )
[
all-words
all-articles [ >link ] map
source-files get keys [ <pathname> ] map
] append-outputs ;
: build-crossref ( -- crossref ) : build-crossref ( -- crossref )
"Computing usage index... " write flush yield "Computing usage index... " write flush yield
H{ } clone crossref [ H{ } clone [
all-words crossref set-global
source-files get keys [ <pathname> ] map defs-to-crossref [ crossref-def ] each
[ [ crossref-def ] each ] bi@ ] keep
crossref get
] with-variable
"done" print flush ; "done" print flush ;
: get-crossref ( -- crossref ) : get-crossref ( -- crossref )
crossref global [ drop build-crossref ] cache ; crossref get-global [ build-crossref ] unless* ;
GENERIC: irrelevant? ( defspec -- ? ) GENERIC: irrelevant? ( defspec -- ? )