More help documentation
parent
10af34de4d
commit
aec1590ff7
|
@ -99,10 +99,10 @@ vectors words ;
|
||||||
"/library/tools/debugger.factor"
|
"/library/tools/debugger.factor"
|
||||||
|
|
||||||
"/library/help/stylesheet.factor"
|
"/library/help/stylesheet.factor"
|
||||||
"/library/help/help.factor"
|
"/library/help/topics.factor"
|
||||||
"/library/help/markup.factor"
|
"/library/help/markup.factor"
|
||||||
"/library/help/word-help.factor"
|
|
||||||
"/library/help/crossref.factor"
|
"/library/help/crossref.factor"
|
||||||
|
"/library/help/help.factor"
|
||||||
"/library/help/porter-stemmer.factor"
|
"/library/help/porter-stemmer.factor"
|
||||||
"/library/help/search.factor"
|
"/library/help/search.factor"
|
||||||
"/library/help/syntax.factor"
|
"/library/help/syntax.factor"
|
||||||
|
@ -247,6 +247,9 @@ vectors words ;
|
||||||
"/library/help/crossref.facts"
|
"/library/help/crossref.facts"
|
||||||
"/library/help/help.facts"
|
"/library/help/help.facts"
|
||||||
"/library/help/markup.facts"
|
"/library/help/markup.facts"
|
||||||
|
"/library/help/search.facts"
|
||||||
|
"/library/help/syntax.facts"
|
||||||
|
"/library/help/topics.facts"
|
||||||
"/library/io/binary.facts"
|
"/library/io/binary.facts"
|
||||||
"/library/io/buffer.facts"
|
"/library/io/buffer.facts"
|
||||||
"/library/io/c-streams.facts"
|
"/library/io/c-streams.facts"
|
||||||
|
|
|
@ -9,7 +9,8 @@ parser sequences sequences-internals words ;
|
||||||
[
|
[
|
||||||
"Cross-referencing..." print flush
|
"Cross-referencing..." print flush
|
||||||
H{ } clone crossref set-global xref-words
|
H{ } clone crossref set-global xref-words
|
||||||
H{ } clone help-graph set-global xref-articles
|
H{ } clone link-graph set-global
|
||||||
|
H{ } clone parent-graph set-global xref-articles
|
||||||
|
|
||||||
"compile" get [
|
"compile" get [
|
||||||
"native-io" get [
|
"native-io" get [
|
||||||
|
|
|
@ -291,7 +291,7 @@ M: hashtable ' ( hashtable -- pointer )
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
vocabularies typemap builtins c-types crossref
|
vocabularies typemap builtins c-types crossref
|
||||||
articles help-graph
|
articles link-graph parent-graph
|
||||||
} [ dup get swap bootstrap-word set ] each
|
} [ dup get swap bootstrap-word set ] each
|
||||||
] make-hash '
|
] make-hash '
|
||||||
global-offset fixup ;
|
global-offset fixup ;
|
||||||
|
|
|
@ -21,7 +21,8 @@ H{ } clone vocabularies set
|
||||||
vocabularies get [ "syntax" set ] bind
|
vocabularies get [ "syntax" set ] bind
|
||||||
|
|
||||||
H{ } clone articles set
|
H{ } clone articles set
|
||||||
help-graph off
|
link-graph off
|
||||||
|
parent-graph off
|
||||||
crossref off
|
crossref off
|
||||||
|
|
||||||
! Call the quotation parsed from primitive-types.factor
|
! Call the quotation parsed from primitive-types.factor
|
||||||
|
|
|
@ -5,10 +5,7 @@ USING: arrays generic graphs hashtables io kernel
|
||||||
namespaces sequences strings words ;
|
namespaces sequences strings words ;
|
||||||
|
|
||||||
: all-articles ( -- seq )
|
: all-articles ( -- seq )
|
||||||
[
|
articles get hash-keys all-words append ;
|
||||||
articles get hash-keys %
|
|
||||||
[ word-article ] word-subset %
|
|
||||||
] { } make ;
|
|
||||||
|
|
||||||
GENERIC: elements* ( elt-type element -- )
|
GENERIC: elements* ( elt-type element -- )
|
||||||
|
|
||||||
|
@ -22,29 +19,55 @@ M: array elements*
|
||||||
|
|
||||||
: elements ( elt-type element -- seq ) [ elements* ] { } make ;
|
: elements ( elt-type element -- seq ) [ elements* ] { } make ;
|
||||||
|
|
||||||
: collect-elements ( elt-type article -- )
|
: collect-elements ( element seq -- )
|
||||||
elements [ 1 swap tail [ dup set ] each ] each ;
|
[
|
||||||
|
[
|
||||||
: links-out ( article -- seq )
|
swap elements [
|
||||||
article-content [
|
1 swap tail [ dup set ] each
|
||||||
\ $link over collect-elements
|
] each
|
||||||
\ $see-also over collect-elements
|
] each-with
|
||||||
\ $subsection swap collect-elements
|
|
||||||
] make-hash hash-keys ;
|
] make-hash hash-keys ;
|
||||||
|
|
||||||
SYMBOL: help-graph
|
SYMBOL: link-graph
|
||||||
|
|
||||||
|
: links-out ( article -- seq )
|
||||||
|
article-content { $link $see-also } collect-elements ;
|
||||||
|
|
||||||
|
: ?link dup link? [ link-name ] when ;
|
||||||
|
|
||||||
: links-in ( article -- seq )
|
: links-in ( article -- seq )
|
||||||
dup link? [ link-name ] when help-graph get in-edges ;
|
?link link-graph get in-edges ;
|
||||||
|
|
||||||
|
SYMBOL: parent-graph
|
||||||
|
|
||||||
|
: children ( article -- seq )
|
||||||
|
article-content { $subsection } collect-elements ;
|
||||||
|
|
||||||
|
: ?link dup link? [ link-name ] when ;
|
||||||
|
|
||||||
|
: parents ( article -- seq )
|
||||||
|
?link parent-graph get in-edges ;
|
||||||
|
|
||||||
|
: (where) ( article -- )
|
||||||
|
dup , parents [ word? not ] subset dup empty?
|
||||||
|
[ drop ] [ [ (where) ] each ] if ;
|
||||||
|
|
||||||
|
: where ( article -- seq )
|
||||||
|
[ (where) ] { } make 1 swap tail ;
|
||||||
|
|
||||||
: xref-article ( article -- )
|
: xref-article ( article -- )
|
||||||
[ links-out ] help-graph get add-vertex ;
|
dup
|
||||||
|
[ links-out ] link-graph get add-vertex
|
||||||
|
[ children ] parent-graph get add-vertex ;
|
||||||
|
|
||||||
: unxref-article ( article -- )
|
: unxref-article ( article -- )
|
||||||
[ links-out ] help-graph get remove-vertex ;
|
dup [ links-out ] link-graph get remove-vertex
|
||||||
|
[ children ] parent-graph get remove-vertex ;
|
||||||
|
|
||||||
: xref-articles ( -- )
|
: xref-articles ( -- )
|
||||||
all-articles [ links-out ] help-graph get build-graph ;
|
all-articles dup
|
||||||
|
[ links-out ] link-graph get build-graph
|
||||||
|
[ children ] parent-graph get build-graph ;
|
||||||
|
|
||||||
: links-in. ( article -- )
|
: links-in. ( article -- )
|
||||||
links-in [ links-in. ] help-outliner ;
|
links-in [ links-in. ] help-outliner ;
|
||||||
|
|
|
@ -1,43 +1,32 @@
|
||||||
! Copyright (C) 2005, 2006 Slava Pestov.
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: help
|
IN: help
|
||||||
USING: arrays errors hashtables io kernel namespaces sequences
|
USING: arrays io kernel namespaces prettyprint sequences words ;
|
||||||
strings ;
|
|
||||||
|
|
||||||
! Markup
|
M: word article-title
|
||||||
GENERIC: print-element
|
dup word-name swap stack-effect [ " " swap append3 ] when* ;
|
||||||
|
|
||||||
DEFER: $title
|
M: word article-content
|
||||||
|
[
|
||||||
! Help articles
|
\ $synopsis over 2array ,
|
||||||
SYMBOL: articles
|
dup "help" word-prop [
|
||||||
|
%
|
||||||
TUPLE: article title content ;
|
] [
|
||||||
|
"predicating" word-prop [
|
||||||
: article ( name -- article )
|
\ $predicate swap 2array ,
|
||||||
dup articles get hash
|
] when*
|
||||||
[ ] [ "No such article: " swap append throw ] ?if ;
|
] ?if
|
||||||
|
] { } make ;
|
||||||
: add-article ( name title element -- )
|
|
||||||
<article> swap articles get set-hash ;
|
|
||||||
|
|
||||||
M: string article-title article article-title ;
|
|
||||||
M: string article-content article article-content ;
|
|
||||||
|
|
||||||
! Special case: f help
|
|
||||||
M: f article-title drop \ f article-title ;
|
|
||||||
M: f article-content drop \ f article-content ;
|
|
||||||
|
|
||||||
SYMBOL: last-block
|
|
||||||
|
|
||||||
: print-title ( article -- )
|
|
||||||
article-title $title ;
|
|
||||||
|
|
||||||
: with-default-style ( quot -- )
|
: with-default-style ( quot -- )
|
||||||
default-char-style [
|
default-char-style [
|
||||||
default-para-style [ last-block on call ] with-nesting
|
default-para-style [ last-block on call ] with-nesting
|
||||||
] with-style ; inline
|
] with-style ; inline
|
||||||
|
|
||||||
|
: print-title ( article -- )
|
||||||
|
[ dup article-title $title $where ] with-default-style
|
||||||
|
terpri ;
|
||||||
|
|
||||||
: print-content ( element -- )
|
: print-content ( element -- )
|
||||||
[ print-element ] with-default-style ;
|
[ print-element ] with-default-style ;
|
||||||
|
|
||||||
|
@ -45,4 +34,20 @@ SYMBOL: last-block
|
||||||
|
|
||||||
: help ( topic -- ) dup print-title (help) ;
|
: help ( topic -- ) dup print-title (help) ;
|
||||||
|
|
||||||
|
: see-help ( word -- )
|
||||||
|
dup help [ $definition terpri ] with-default-style ;
|
||||||
|
|
||||||
: handbook ( -- ) "handbook" help ;
|
: handbook ( -- ) "handbook" help ;
|
||||||
|
|
||||||
|
: $subtopic ( object -- )
|
||||||
|
[
|
||||||
|
subtopic-style [
|
||||||
|
unclip f rot [ print-content ] curry write-outliner
|
||||||
|
] with-style
|
||||||
|
] ($block) ;
|
||||||
|
|
||||||
|
: $subsection ( object -- )
|
||||||
|
[ first [ (help) ] swap ($subsection) ] ($block) ;
|
||||||
|
|
||||||
|
: $outliner ( content -- )
|
||||||
|
first call [ (help) ] help-outliner ;
|
||||||
|
|
|
@ -1,32 +1,9 @@
|
||||||
IN: help
|
IN: help
|
||||||
USING: io ;
|
USING: io prettyprint ;
|
||||||
|
|
||||||
HELP: print-element "( element -- )"
|
HELP: print-title "( topic -- )"
|
||||||
{ $values { "element" "a markup element" } }
|
{ $values { "topic" "a help article name or a word" } }
|
||||||
{ $description "Prints a markup element to the " { $link stdio } " stream." } ;
|
{ $description "Prints a help article's title, or a word's " { $link synopsis } ", depending on the type of " { $snippet "topic" } "." } ;
|
||||||
|
|
||||||
HELP: articles f
|
|
||||||
{ $description "Variable. Hashtable mapping article names to " { $link article } " instances." } ;
|
|
||||||
|
|
||||||
HELP: article "( name -- article )"
|
|
||||||
{ $values { "name" "an article name" } { "article" "an " { $link article } " object" } }
|
|
||||||
{ $description "Outputs a named " { $link article } " object." } ;
|
|
||||||
|
|
||||||
HELP: article-title "( topic -- string )"
|
|
||||||
{ $values { "topic" "an article name or a word" } { "string" "a string" } }
|
|
||||||
{ $description "Outputs the title of a specific help article." } ;
|
|
||||||
|
|
||||||
HELP: article-content "( topic -- element )"
|
|
||||||
{ $values { "topic" "an article name or a word" } { "element" "a markup element" } }
|
|
||||||
{ $description "Outputs the content of a specific help article." } ;
|
|
||||||
|
|
||||||
HELP: add-article "( name title element -- )"
|
|
||||||
{ $values { "name" "a string" } { "title" "a string" } { "element" "a markup element" } }
|
|
||||||
{ $description "Adds a help article to the " { $link articles } " hashtable." }
|
|
||||||
{ $notes "This word is used to implement " { $link POSTPONE: ARTICLE: } "." } ;
|
|
||||||
|
|
||||||
HELP: last-block f
|
|
||||||
{ $description "Variable. Set by " { $link print-element } " if the last element output was a block element, thus if the next element is a block element no newline needs to be output." } ;
|
|
||||||
|
|
||||||
HELP: print-content "( element -- )"
|
HELP: print-content "( element -- )"
|
||||||
{ $values { "element" "a markup element" } }
|
{ $values { "element" "a markup element" } }
|
||||||
|
@ -37,15 +14,43 @@ HELP: (help) "( topic -- )"
|
||||||
{ $description
|
{ $description
|
||||||
"Displays a help article or documentation associated to a word on the " { $link stdio } " stream. This word does not print the article title, so it is intended for use by outliners and in other contexts where the title is already visible to the user."
|
"Displays a help article or documentation associated to a word on the " { $link stdio } " stream. This word does not print the article title, so it is intended for use by outliners and in other contexts where the title is already visible to the user."
|
||||||
}
|
}
|
||||||
{ $see-also help } ;
|
{ $see-also help see-help } ;
|
||||||
|
|
||||||
HELP: help "( topic -- )"
|
HELP: help "( topic -- )"
|
||||||
{ $values { "topic" "an article name or a word" } }
|
{ $values { "topic" "an article name or a word" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Displays a help article or documentation associated to a word on the " { $link stdio } " stream."
|
"Displays a help article or documentation associated to a word on the " { $link stdio } " stream."
|
||||||
}
|
}
|
||||||
{ $see-also (help) } ;
|
{ $see-also (help) see-help } ;
|
||||||
|
|
||||||
|
HELP: see-help "( word -- )"
|
||||||
|
{ $values { "word" "a word" } }
|
||||||
|
{ $description
|
||||||
|
"Display the documentation and definition of a word on the " { $link stdio } " stream."
|
||||||
|
}
|
||||||
|
{ $see-also (help) help see } ;
|
||||||
|
|
||||||
HELP: handbook "( -- )"
|
HELP: handbook "( -- )"
|
||||||
{ $description "Displays the Factor developer's handbook." }
|
{ $description "Displays the Factor developer's handbook." }
|
||||||
{ $see-also help } ;
|
{ $see-also help } ;
|
||||||
|
|
||||||
|
HELP: $subsection "( element -- )"
|
||||||
|
{ $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
|
||||||
|
{ $description "Prints an expandable outliner containing the body of the help topic named by the first string element of " { $snippet "element" } "." }
|
||||||
|
{ $examples
|
||||||
|
{ $markup-example { $subsection "sequences" } }
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: $subtopic "( element -- )"
|
||||||
|
{ $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
|
||||||
|
{ $description "Prints an expandable outliner with the given title containing an arbitrary markup element." }
|
||||||
|
{ $examples
|
||||||
|
{ $markup-example { $subtopic "Subtopic example"
|
||||||
|
"Subtopics are useful for short notes, sidebars "
|
||||||
|
"and other bits of info which don't really deserve "
|
||||||
|
"their own help article." } }
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: $outliner "( element -- )"
|
||||||
|
{ $values { "element" "a markup element of the form " { $snippet "( quot -- )" } } }
|
||||||
|
{ $description "Calls the quotation to generate a sequence of help topics, and outputs an outliner for each one. Expanding a help topic shows the article body." } ;
|
||||||
|
|
|
@ -57,27 +57,9 @@ M: word print-element { } swap execute ;
|
||||||
: $code ( content -- )
|
: $code ( content -- )
|
||||||
"\n" join dup <input> [ write ] ($code) ;
|
"\n" join dup <input> [ write ] ($code) ;
|
||||||
|
|
||||||
: $syntax ( word -- )
|
|
||||||
dup stack-effect [
|
|
||||||
"Syntax" $heading
|
|
||||||
>r word-name $snippet " " $snippet r> $snippet
|
|
||||||
] [
|
|
||||||
drop
|
|
||||||
] if* ;
|
|
||||||
|
|
||||||
: $stack-effect ( word -- )
|
|
||||||
stack-effect [
|
|
||||||
"Stack effect" $heading $snippet
|
|
||||||
] when* ;
|
|
||||||
|
|
||||||
: $vocabulary ( content -- )
|
: $vocabulary ( content -- )
|
||||||
first word-vocabulary [
|
first word-vocabulary
|
||||||
"Vocabulary" $heading $snippet
|
[ "Vocabulary" $heading $snippet ] when* ;
|
||||||
] when* ;
|
|
||||||
|
|
||||||
: $synopsis ( content -- )
|
|
||||||
dup $vocabulary
|
|
||||||
first dup parsing? [ $syntax ] [ $stack-effect ] if ;
|
|
||||||
|
|
||||||
: $description ( content -- )
|
: $description ( content -- )
|
||||||
"Description" $heading print-element ;
|
"Description" $heading print-element ;
|
||||||
|
@ -109,9 +91,7 @@ TUPLE: link name ;
|
||||||
|
|
||||||
M: link article-title link-name article-title ;
|
M: link article-title link-name article-title ;
|
||||||
M: link article-content link-name article-content ;
|
M: link article-content link-name article-content ;
|
||||||
M: link summary
|
M: link summary "Link: " swap link-name append ;
|
||||||
link-name dup word?
|
|
||||||
[ synopsis ] [ "Link to " swap unparse append ] if ;
|
|
||||||
|
|
||||||
: ($subsection) ( quot object -- )
|
: ($subsection) ( quot object -- )
|
||||||
subsection-style [
|
subsection-style [
|
||||||
|
@ -119,19 +99,11 @@ M: link summary
|
||||||
rot write-outliner
|
rot write-outliner
|
||||||
] with-style ;
|
] with-style ;
|
||||||
|
|
||||||
: $subsection ( object -- )
|
: >link ( obj -- obj ) dup word? [ <link> ] unless ;
|
||||||
[ first [ (help) ] swap ($subsection) ] ($block) ;
|
|
||||||
|
|
||||||
: $subtopic ( object -- )
|
|
||||||
[
|
|
||||||
subtopic-style [
|
|
||||||
unclip f rot [ print-content ] curry write-outliner
|
|
||||||
] with-style
|
|
||||||
] ($block) ;
|
|
||||||
|
|
||||||
: $link ( article -- )
|
: $link ( article -- )
|
||||||
last-block off first link-style
|
last-block off first link-style
|
||||||
[ dup article-title swap <link> write-object ] with-style ;
|
[ dup article-title swap >link write-object ] with-style ;
|
||||||
|
|
||||||
: textual-list ( seq quot -- )
|
: textual-list ( seq quot -- )
|
||||||
[ ", " print-element ] interleave ; inline
|
[ ", " print-element ] interleave ; inline
|
||||||
|
@ -139,6 +111,15 @@ M: link summary
|
||||||
: $links ( content -- )
|
: $links ( content -- )
|
||||||
[ 1array $link ] textual-list ;
|
[ 1array $link ] textual-list ;
|
||||||
|
|
||||||
|
: $where ( article -- )
|
||||||
|
where dup empty? [
|
||||||
|
drop
|
||||||
|
] [
|
||||||
|
where-style [
|
||||||
|
[ "Parent topics: " write $links ] ($block)
|
||||||
|
] with-style
|
||||||
|
] if ;
|
||||||
|
|
||||||
: $see-also ( content -- )
|
: $see-also ( content -- )
|
||||||
"See also" $heading $links ;
|
"See also" $heading $links ;
|
||||||
|
|
||||||
|
@ -207,6 +188,3 @@ M: link summary
|
||||||
|
|
||||||
: help-outliner ( seq quot -- | quot: obj -- )
|
: help-outliner ( seq quot -- | quot: obj -- )
|
||||||
swap sort-articles [ ($subsection) terpri ] each-with ;
|
swap sort-articles [ ($subsection) terpri ] each-with ;
|
||||||
|
|
||||||
: $outliner ( content -- )
|
|
||||||
first call [ (help) ] help-outliner ;
|
|
||||||
|
|
|
@ -41,22 +41,10 @@ HELP: $code "( element -- )"
|
||||||
{ $markup-example { $code "2 2 + ." } }
|
{ $markup-example { $code "2 2 + ." } }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: $syntax "( word -- )"
|
HELP: $vocabulary "( word -- )"
|
||||||
{ $values { "word" "a word" } }
|
{ $values { "word" "a markup element of the form " { $snippet "{ word }" } } }
|
||||||
{ $description "Prints a description of a parsing word's syntax. This element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
|
|
||||||
|
|
||||||
HELP: $stack-effect "( word -- )"
|
|
||||||
{ $values { "word" "a word" } }
|
|
||||||
{ $description "Prints a description of a word's stack effect. This element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
|
|
||||||
|
|
||||||
HELP: $vocabulary "( element -- )"
|
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
|
|
||||||
{ $description "Prints a word's vocabulary. This markup element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
|
{ $description "Prints a word's vocabulary. This markup element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
|
||||||
|
|
||||||
HELP: $synopsis "( element -- )"
|
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
|
|
||||||
{ $description "Prints a the header material found on every word help page -- the word's vocabulary, stack effect and syntax, printing the latter only for parsing words. This markup element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
|
|
||||||
|
|
||||||
HELP: $description "( element -- )"
|
HELP: $description "( element -- )"
|
||||||
{ $values { "element" "a markup element" } }
|
{ $values { "element" "a markup element" } }
|
||||||
{ $description "Prints the description subheading found on the help page of most words." } ;
|
{ $description "Prints the description subheading found on the help page of most words." } ;
|
||||||
|
@ -100,23 +88,6 @@ HELP: $warning "( element -- )"
|
||||||
{ $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
|
{ $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: $subsection "( element -- )"
|
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
|
|
||||||
{ $description "Prints an expandable outliner containing the body of the help topic named by the first string element of " { $snippet "element" } "." }
|
|
||||||
{ $examples
|
|
||||||
{ $markup-example { $subsection "sequences" } }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
HELP: $subtopic "( element -- )"
|
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
|
|
||||||
{ $description "Prints an expandable outliner with the given title containing an arbitrary markup element." }
|
|
||||||
{ $examples
|
|
||||||
{ $markup-example { $subtopic "Subtopic example"
|
|
||||||
"Subtopics are useful for short notes, sidebars "
|
|
||||||
"and other bits of info which don't really deserve "
|
|
||||||
"their own help article." } }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
HELP: $link "( element -- )"
|
HELP: $link "( element -- )"
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
|
{ $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
|
||||||
{ $description "Prints a link to a help article or word." }
|
{ $description "Prints a link to a help article or word." }
|
||||||
|
@ -215,10 +186,10 @@ HELP: $see "( element -- )"
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: $definition "( word -- )"
|
HELP: $definition "( word -- )"
|
||||||
{ $values { "word" "a word" } } }
|
{ $values { "word" "a word" } }
|
||||||
{ $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." }
|
{ $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." }
|
||||||
{ $notes
|
{ $notes
|
||||||
"This markup element is output by " { $link show } " but not " { $link help } "."
|
"This markup element is output by " { $link see-help } " but not " { $link help } "."
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: $curious "( element -- )"
|
HELP: $curious "( element -- )"
|
||||||
|
@ -238,7 +209,3 @@ HELP: sort-articles "( seq -- assoc )"
|
||||||
HELP: help-outliner "( seq quot -- )"
|
HELP: help-outliner "( seq quot -- )"
|
||||||
{ $values { "seq" "a sequence of help article names and words" } { "quot" "a quotation with stack effect " { $snippet "( topic -- )" } } }
|
{ $values { "seq" "a sequence of help article names and words" } { "quot" "a quotation with stack effect " { $snippet "( topic -- )" } } }
|
||||||
{ $description "Writes an outliner of help topics to the " { $link stdio } " stream. Expanding a help topic calls " { $snippet "quot" } " with the topic on the data stack." } ;
|
{ $description "Writes an outliner of help topics to the " { $link stdio } " stream. Expanding a help topic calls " { $snippet "quot" } " with the topic on the data stack." } ;
|
||||||
|
|
||||||
HELP: $outliner "( element -- )"
|
|
||||||
{ $values { "element" "a markup element of the form " { $snippet "( quot -- )" } } }
|
|
||||||
{ $description "Calls the quotation to generate a sequence of help topics, and outputs an outliner for each one. Expanding a help topic shows the article body." } ;
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ SYMBOL: term-index
|
||||||
|
|
||||||
: count-occurrences ( seq -- hash )
|
: count-occurrences ( seq -- hash )
|
||||||
[
|
[
|
||||||
dup [ hash-keys [ off ] each ] each
|
dup [ [ drop off ] hash-each ] each
|
||||||
[ [ swap +@ ] hash-each ] each
|
[ [ swap +@ ] hash-each ] each
|
||||||
] make-hash ;
|
] make-hash ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
IN: help
|
||||||
|
USING: namespaces ;
|
||||||
|
|
||||||
|
HELP: ignored-word? "( string -- ? )"
|
||||||
|
{ $values { "string" "a string" } } { $description "Tests for English stop words." } ;
|
||||||
|
|
||||||
|
HELP: tokenize "( string -- seq )"
|
||||||
|
{ $values { "string" "a string" } { "seq" "a sequence of strings" } }
|
||||||
|
{ $description "Split a string along whitespace boundaries, convert all tokens to lower case, and stem all tokens." } ;
|
||||||
|
|
||||||
|
HELP: index-text "( score topic string -- )"
|
||||||
|
{ $values { "score" "a relevance score" } { "topic" "a help article name or a word" } { "string" "a string" } }
|
||||||
|
{ $description "Tokenizes the string and adds each token to the term index, with the specified score placed on the topic." }
|
||||||
|
{ $notes "This word operates on the current namespace, and so must be wrapped in a " { $link bind } " to specify the term index hashtable." } ;
|
||||||
|
|
||||||
|
HELP: index-article-title "( topic -- )"
|
||||||
|
{ $values { "topic" "a help article name or a word" } }
|
||||||
|
{ $description "Adds the tokens making up the article's title to the term index with a high relevancy score." } ;
|
||||||
|
|
||||||
|
HELP: index-article-content "( topic -- )"
|
||||||
|
{ $values { "topic" "a help article name or a word" } }
|
||||||
|
{ $description "Adds the tokens making up the article's content to the term index with a regular relevancy score." } ;
|
||||||
|
|
||||||
|
HELP: index-article "( topic -- )"
|
||||||
|
{ $values { "topic" "a help article name or a word" } }
|
||||||
|
{ $description "Adds the tokens making up the article's title and content to the term index, with the title terms having a higher relevancy score." } ;
|
||||||
|
|
||||||
|
HELP: term-index f
|
||||||
|
{ $description "Variable. A hashtable mapping stemmed search terms to hashtables mapping help topics to relevancy scores."
|
||||||
|
$terpri
|
||||||
|
"The " { $link search-help } " word searches the term index and the " { $link index-help } " word updates it." }
|
||||||
|
{ $see-also help } ;
|
||||||
|
|
||||||
|
HELP: discard-irrelevant "( results -- results )"
|
||||||
|
{ $values }
|
||||||
|
{ $description "Discard search results which rank in the lower 33% compared to the top scoring result, since they are most likely irrelevant." } ;
|
||||||
|
|
||||||
|
HELP: count-occurrences "( seq -- hash )"
|
||||||
|
{ $values { "seq" "a sequence of hashtables" } { "hash" "a hashtable" } }
|
||||||
|
{ $description "Collates all keys from the hashtables in " { $snippet "seq" } " and sums their values, which must be numbers." } ;
|
||||||
|
|
||||||
|
HELP: search-help "( phrase -- assoc )"
|
||||||
|
{ $values { "phrase" "a string" } { "assoc" "a sequence of pairs" } }
|
||||||
|
{ $description "Performs a full-text search in the term index for help topics relating to " { $snippet "phrase" } ". The result is an association list of topic names paired with scores, sorted by decreasing score." } ;
|
||||||
|
|
||||||
|
HELP: index-help "( -- )"
|
||||||
|
{ $description "Updates the full-text search term index for use by " { $link search-help } " and " { $link search-help. } "." } ;
|
||||||
|
|
||||||
|
HELP: search-help. "( phrase -- )"
|
||||||
|
{ $values { "phrase" "a string" } }
|
||||||
|
{ $description "Performs a full-text search in the term index for help topics relating to " { $snippet "phrase" } ", and prints an outliner with the results." } ;
|
|
@ -5,7 +5,7 @@ USING: styles ;
|
||||||
|
|
||||||
: default-char-style
|
: default-char-style
|
||||||
H{
|
H{
|
||||||
{ font "sans-serif" }
|
{ font "serif" }
|
||||||
{ font-size 12 }
|
{ font-size 12 }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -22,14 +22,20 @@ USING: styles ;
|
||||||
|
|
||||||
: title-style
|
: title-style
|
||||||
H{
|
H{
|
||||||
{ font "sans-serif" }
|
{ font "serif" }
|
||||||
{ font-size 16 }
|
{ font-size 16 }
|
||||||
{ font-style bold }
|
{ font-style bold }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
: where-style
|
||||||
|
H{
|
||||||
|
{ font "serif" }
|
||||||
|
{ font-size 10 }
|
||||||
|
} ;
|
||||||
|
|
||||||
: heading-style
|
: heading-style
|
||||||
H{
|
H{
|
||||||
{ font "sans-serif" }
|
{ font "serif" }
|
||||||
{ font-size 14 }
|
{ font-size 14 }
|
||||||
{ font-style bold }
|
{ font-style bold }
|
||||||
{ foreground { 0.2 0.2 0.4 1 } }
|
{ foreground { 0.2 0.2 0.4 1 } }
|
||||||
|
@ -37,7 +43,7 @@ USING: styles ;
|
||||||
|
|
||||||
: subsection-style
|
: subsection-style
|
||||||
H{
|
H{
|
||||||
{ font "sans-serif" }
|
{ font "serif" }
|
||||||
{ font-size 14 }
|
{ font-size 14 }
|
||||||
{ font-style bold }
|
{ font-style bold }
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
IN: help
|
||||||
|
USING: arrays errors hashtables io kernel namespaces sequences
|
||||||
|
strings ;
|
||||||
|
|
||||||
|
! Markup
|
||||||
|
GENERIC: print-element
|
||||||
|
|
||||||
|
! Help articles
|
||||||
|
SYMBOL: articles
|
||||||
|
|
||||||
|
TUPLE: article title content ;
|
||||||
|
|
||||||
|
: article ( name -- article )
|
||||||
|
dup articles get hash
|
||||||
|
[ ] [ "No such article: " swap append throw ] ?if ;
|
||||||
|
|
||||||
|
: add-article ( name title element -- )
|
||||||
|
<article> swap articles get set-hash ;
|
||||||
|
|
||||||
|
M: string article-title article article-title ;
|
||||||
|
M: string article-content article article-content ;
|
||||||
|
|
||||||
|
! Special case: f help
|
||||||
|
M: f article-title drop \ f article-title ;
|
||||||
|
M: f article-content drop \ f article-content ;
|
||||||
|
|
||||||
|
SYMBOL: last-block
|
|
@ -0,0 +1,29 @@
|
||||||
|
IN: help
|
||||||
|
USING: io ;
|
||||||
|
|
||||||
|
HELP: print-element "( element -- )"
|
||||||
|
{ $values { "element" "a markup element" } }
|
||||||
|
{ $description "Prints a markup element to the " { $link stdio } " stream." } ;
|
||||||
|
|
||||||
|
HELP: articles f
|
||||||
|
{ $description "Variable. Hashtable mapping article names to " { $link article } " instances." } ;
|
||||||
|
|
||||||
|
HELP: article "( name -- article )"
|
||||||
|
{ $values { "name" "an article name" } { "article" "an " { $link article } " object" } }
|
||||||
|
{ $description "Outputs a named " { $link article } " object." } ;
|
||||||
|
|
||||||
|
HELP: article-title "( topic -- string )"
|
||||||
|
{ $values { "topic" "an article name or a word" } { "string" "a string" } }
|
||||||
|
{ $description "Outputs the title of a specific help article." } ;
|
||||||
|
|
||||||
|
HELP: article-content "( topic -- element )"
|
||||||
|
{ $values { "topic" "an article name or a word" } { "element" "a markup element" } }
|
||||||
|
{ $description "Outputs the content of a specific help article." } ;
|
||||||
|
|
||||||
|
HELP: add-article "( name title element -- )"
|
||||||
|
{ $values { "name" "a string" } { "title" "a string" } { "element" "a markup element" } }
|
||||||
|
{ $description "Adds a help article to the " { $link articles } " hashtable." }
|
||||||
|
{ $notes "This word is used to implement " { $link POSTPONE: ARTICLE: } "." } ;
|
||||||
|
|
||||||
|
HELP: last-block f
|
||||||
|
{ $description "Variable. Set by " { $link print-element } " if the last element output was a block element, thus if the next element is a block element no newline needs to be output." } ;
|
|
@ -1,23 +0,0 @@
|
||||||
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
|
||||||
IN: help
|
|
||||||
USING: arrays io kernel namespaces prettyprint sequences words ;
|
|
||||||
|
|
||||||
M: word article-title
|
|
||||||
dup word-name swap stack-effect [ " " swap append3 ] when* ;
|
|
||||||
|
|
||||||
: word-article ( word -- article ) "help" word-prop ;
|
|
||||||
|
|
||||||
M: word article-content
|
|
||||||
[
|
|
||||||
\ $synopsis over 2array ,
|
|
||||||
dup word-article [
|
|
||||||
%
|
|
||||||
] [
|
|
||||||
"predicating" word-prop [
|
|
||||||
\ $predicate swap 2array ,
|
|
||||||
] when*
|
|
||||||
] ?if
|
|
||||||
] { } make ;
|
|
||||||
|
|
||||||
: show ( word -- ) dup help $definition terpri ;
|
|
|
@ -52,14 +52,14 @@ DEFER: show-vocab
|
||||||
: <word-pages> ( word -- tabs )
|
: <word-pages> ( word -- tabs )
|
||||||
{
|
{
|
||||||
{ "Definition" [ see ] }
|
{ "Definition" [ see ] }
|
||||||
{ "Documentation" [ (help) ] }
|
{ "Documentation" [ help ] }
|
||||||
{ "Calls in" [ usage. ] }
|
{ "Calls in" [ usage. ] }
|
||||||
{ "Links in" [ links-in. ] }
|
{ "Links in" [ links-in. ] }
|
||||||
{ "Properties" [ word-props describe ] }
|
{ "Properties" [ word-props describe ] }
|
||||||
} <pages> ;
|
} <pages> ;
|
||||||
|
|
||||||
: <word-view> ( word -- gadget )
|
: <word-view> ( word -- gadget )
|
||||||
[ <word-pages> ] keep article-title <browser-tile> ;
|
[ <word-pages> ] keep word-name <browser-tile> ;
|
||||||
|
|
||||||
: show-word ( word browser -- )
|
: show-word ( word browser -- )
|
||||||
over word-vocabulary over show-vocab
|
over word-vocabulary over show-vocab
|
||||||
|
|
|
@ -50,7 +50,7 @@ M: help-gadget focusable-child*
|
||||||
[ over history-seq push-new update-history ] [ 2drop ] if ;
|
[ over history-seq push-new update-history ] [ 2drop ] if ;
|
||||||
|
|
||||||
: fancy-help ( obj -- )
|
: fancy-help ( obj -- )
|
||||||
link-name dup word? [ show ] [ help ] if ;
|
link-name dup word? [ see-help ] [ help ] if ;
|
||||||
|
|
||||||
: show-help ( link help -- )
|
: show-help ( link help -- )
|
||||||
dup add-history [ set-help-gadget-showing ] 2keep
|
dup add-history [ set-help-gadget-showing ] 2keep
|
||||||
|
|
Loading…
Reference in New Issue