"Application vocabularies can define a main entry point, giving the user a convenient way to run the application:"
{ $subsection POSTPONE: MAIN: }
{ $subsection run }
-"Reloading source files changed on disk:"
-{ $subsection refresh }
-{ $subsection refresh-all }
{ $see-also "vocabularies" "parser-files" "source-files" } ;
ABOUT: "vocabs.loader"
HELP: require
{ $values { "vocab" "a vocabulary specifier" } }
{ $description "Loads a vocabulary if it has not already been loaded." }
-{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files, use " { $link refresh } " or " { $link refresh-all } "." } ;
+{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "tools.vocabs" } "." } ;
HELP: run
{ $values { "vocab" "a vocabulary specifier" } }
HELP: vocab-docs-path
{ $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string or " { $link f } } }
{ $description "Outputs a pathname where the documentation for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a directory on disk." } ;
-
-HELP: refresh
-{ $values { "prefix" string } }
-{ $description "Reloads source files and documentation belonging to loaded vocabularies whose names are prefixed by " { $snippet "prefix" } " which have been modified on disk." } ;
-
-HELP: refresh-all
-{ $description "Reloads source files and documentation for all loaded vocabularies which have been modified on disk." } ;
-
-{ refresh refresh-all } related-words
"To define one, refer to \\ MAIN: help" print
] ?if ;
-: modified ( seq quot -- seq )
- [ dup ] swap compose { } map>assoc
- [ nip ] assoc-subset
- [ nip source-modified? ] assoc-subset keys ; inline
-
-: modified-sources ( vocabs -- seq )
- [ vocab-source-path ] modified ;
-
-: modified-docs ( vocabs -- seq )
- [ vocab-docs-path ] modified ;
-
-: update-roots ( vocabs -- )
- [ dup find-vocab-root swap vocab set-vocab-root ] each ;
-
-: to-refresh ( prefix -- modified-sources modified-docs )
- child-vocabs
- dup update-roots
- dup modified-sources swap modified-docs ;
-
-: vocab-heading. ( vocab -- )
- nl
- "==== " write
- dup vocab-name swap vocab write-object ":" print
- nl ;
-
-: load-error. ( triple -- )
- dup first vocab-heading.
- dup second print-error
- drop ;
-
-: load-failures. ( failures -- )
- [ load-error. nl ] each ;
-
SYMBOL: blacklist
-SYMBOL: failures
-
-: require-all ( vocabs -- failures )
- [
- V{ } clone blacklist set
- V{ } clone failures set
- [
- [ require ]
- [ swap vocab-name failures get set-at ]
- recover
- ] each
- failures get
- ] with-compiler-errors ;
-
-: do-refresh ( modified-sources modified-docs -- )
- 2dup
- [ f swap set-vocab-docs-loaded? ] each
- [ f swap set-vocab-source-loaded? ] each
- append prune require-all load-failures. ;
-
-: refresh ( prefix -- ) to-refresh do-refresh ;
-
-SYMBOL: sources-changed?
-
-[ t sources-changed? set-global ] "vocabs.loader" add-init-hook
-
-: refresh-all ( -- )
- "" refresh f sources-changed? set-global ;
GENERIC: (load-vocab) ( name -- vocab )
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel vocabs vocabs.loader tools.time tools.browser
+USING: kernel vocabs vocabs.loader tools.time tools.vocabs
arrays assocs io.styles io help.markup prettyprint sequences
continuations debugger ;
IN: benchmark
"tools.test"
"tools.time"
"tools.threads"
+ "tools.vocabs"
"editors"
} [ require ] each
! Copyright (C) 2005, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: parser kernel namespaces sequences definitions io.files
-inspector continuations tuples tools.crossref tools.browser
+inspector continuations tuples tools.crossref tools.vocabs
io prettyprint source-files assocs vocabs vocabs.loader ;
IN: editors
{ $subsection "io.timeouts" } ;
ARTICLE: "tools" "Developer tools"
+{ $subsection "tools.vocabs" }
"Exploratory tools:"
{ $subsection "editor" }
{ $subsection "tools.crossref" }
! Copyright (C) 2006, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: sequences parser kernel help help.markup help.topics
-words strings classes tools.browser namespaces io
+words strings classes tools.vocabs namespaces io
io.streams.string prettyprint definitions arrays vectors
combinators splitting debugger hashtables sorting effects vocabs
vocabs.loader assocs editors continuations classes.predicate
TUPLE: link name ;
+MIXIN: topic
+INSTANCE: link topic
+INSTANCE: word topic
+
GENERIC: >link ( obj -- obj )
M: link >link ;
M: vocab-spec >link ;
"io.unix." os append require
-"vocabs.monitor" require
+"tools.vocabs.monitor" require
T{ windows-nt-io } set-io-backend
-"vocabs.monitor" require
+"tools.vocabs.monitor" require
+++ /dev/null
-Slava Pestov
+++ /dev/null
-USING: help.markup help.syntax io strings ;
-IN: tools.browser
-
-ARTICLE: "vocab-index" "Vocabulary index"
-{ $tags }
-{ $authors }
-{ $describe-vocab "" } ;
-
-ARTICLE: "tools.browser" "Vocabulary browser"
-"Getting and setting vocabulary meta-data:"
-{ $subsection vocab-file-contents }
-{ $subsection set-vocab-file-contents }
-{ $subsection vocab-summary }
-{ $subsection set-vocab-summary }
-{ $subsection vocab-tags }
-{ $subsection set-vocab-tags }
-{ $subsection add-vocab-tags }
-"Global meta-data:"
-{ $subsection all-vocabs }
-{ $subsection all-vocabs-seq }
-{ $subsection all-tags }
-{ $subsection all-authors }
-"Because loading the above data is expensive, it is cached. The cache is flushed by the " { $vocab-link "vocabs.monitor" } " vocabulary. It can also be flushed manually when file system change monitors are not available:"
-{ $subsection reset-cache } ;
-
-HELP: vocab-file-contents
-{ $values { "vocab" "a vocabulary specifier" } { "name" string } { "seq" "a sequence of lines, or " { $link f } } }
-{ $description "Outputs the contents of the file named " { $snippet "name" } " from the vocabulary's directory, or " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-file-contents
-{ $values { "seq" "a sequence of lines" } { "vocab" "a vocabulary specifier" } { "name" string } }
-{ $description "Stores a sequence of lines to the file named " { $snippet "name" } " from the vocabulary's directory." } ;
-
-HELP: vocab-summary
-{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }
-{ $description "Outputs a one-line string description of the vocabulary's intended purpose from the " { $snippet "summary.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-summary
-{ $values { "string" "a string or " { $link f } } { "vocab" "a vocabulary specifier" } }
-{ $description "Stores a one-line string description of the vocabulary to the " { $snippet "summary.txt" } " file in the vocabulary's directory." } ;
-
-HELP: vocab-tags
-{ $values { "vocab" "a vocabulary specifier" } { "tags" "a sequence of strings" } }
-{ $description "Outputs a list of short tags classifying the vocabulary from the " { $snippet "tags.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-tags
-{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }
-{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;
-
-HELP: all-vocabs
-{ $values { "assoc" "an association list mapping vocabulary roots to sequences of vocabulary specifiers" } }
-{ $description "Outputs an association list of all vocabularies which have been loaded or are available for loading." } ;
+++ /dev/null
-IN: tools.browser.tests
-USING: tools.browser tools.test help.markup ;
-
-[ ] [ { $describe-vocab "scratchpad" } print-content ] unit-test
+++ /dev/null
-! Copyright (C) 2007, 2008 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces splitting sequences io.files kernel assocs
-words vocabs vocabs.loader definitions parser continuations
-inspector debugger io io.styles hashtables
-sorting prettyprint source-files arrays combinators strings
-system math.parser help.markup help.topics help.syntax
-help.stylesheet memoize io.encodings.utf8 ;
-IN: tools.browser
-
-MEMO: (vocab-file-contents) ( path -- lines )
- ?resource-path dup exists?
- [ utf8 file-lines ] [ drop f ] if ;
-
-: vocab-file-contents ( vocab name -- seq )
- vocab-path+ dup [ (vocab-file-contents) ] when ;
-
-: set-vocab-file-contents ( seq vocab name -- )
- dupd vocab-path+ [
- ?resource-path utf8 set-file-lines
- ] [
- "The " swap vocab-name
- " vocabulary was not loaded from the file system"
- 3append throw
- ] ?if ;
-
-: vocab-summary-path ( vocab -- string )
- vocab-dir "summary.txt" path+ ;
-
-: vocab-summary ( vocab -- summary )
- dup dup vocab-summary-path vocab-file-contents
- dup empty? [
- drop vocab-name " vocabulary" append
- ] [
- nip first
- ] if ;
-
-M: vocab summary
- [
- dup vocab-summary %
- " (" %
- vocab-words assoc-size #
- " words)" %
- ] "" make ;
-
-M: vocab-link summary vocab-summary ;
-
-: set-vocab-summary ( string vocab -- )
- >r 1array r>
- dup vocab-summary-path
- set-vocab-file-contents ;
-
-: vocab-tags-path ( vocab -- string )
- vocab-dir "tags.txt" path+ ;
-
-: vocab-tags ( vocab -- tags )
- dup vocab-tags-path vocab-file-contents ;
-
-: set-vocab-tags ( tags vocab -- )
- dup vocab-tags-path set-vocab-file-contents ;
-
-: add-vocab-tags ( tags vocab -- )
- [ vocab-tags append prune ] keep set-vocab-tags ;
-
-: vocab-authors-path ( vocab -- string )
- vocab-dir "authors.txt" path+ ;
-
-: vocab-authors ( vocab -- authors )
- dup vocab-authors-path vocab-file-contents ;
-
-: set-vocab-authors ( authors vocab -- )
- dup vocab-authors-path set-vocab-file-contents ;
-
-: subdirs ( dir -- dirs )
- directory [ second ] subset keys natural-sort ;
-
-: (all-child-vocabs) ( root name -- vocabs )
- [ vocab-dir path+ ?resource-path subdirs ] keep
- dup empty? [
- drop
- ] [
- swap [ "." swap 3append ] with map
- ] if ;
-
-: vocabs-in-dir ( root name -- )
- dupd (all-child-vocabs) [
- 2dup vocab-dir? [ 2dup swap >vocab-link , ] when
- vocabs-in-dir
- ] with each ;
-
-: all-vocabs ( -- assoc )
- vocab-roots get [
- dup [ "" vocabs-in-dir ] { } make
- ] { } map>assoc ;
-
-MEMO: all-vocabs-seq ( -- seq )
- all-vocabs values concat ;
-
-: dangerous? ( name -- ? )
- #! Hack
- {
- { [ "cpu." ?head ] [ t ] }
- { [ "io.unix" ?head ] [ t ] }
- { [ "io.windows" ?head ] [ t ] }
- { [ "ui.x11" ?head ] [ t ] }
- { [ "ui.windows" ?head ] [ t ] }
- { [ "ui.cocoa" ?head ] [ t ] }
- { [ "cocoa" ?head ] [ t ] }
- { [ "core-foundation" ?head ] [ t ] }
- { [ "vocabs.loader.test" ?head ] [ t ] }
- { [ "editors." ?head ] [ t ] }
- { [ ".windows" ?tail ] [ t ] }
- { [ ".unix" ?tail ] [ t ] }
- { [ "unix." ?head ] [ t ] }
- { [ ".linux" ?tail ] [ t ] }
- { [ ".bsd" ?tail ] [ t ] }
- { [ ".macosx" ?tail ] [ t ] }
- { [ "windows." ?head ] [ t ] }
- { [ "cocoa" ?head ] [ t ] }
- { [ ".test" ?tail ] [ t ] }
- { [ "raptor" ?head ] [ t ] }
- { [ dup "tools.deploy.app" = ] [ t ] }
- { [ t ] [ f ] }
- } cond nip ;
-
-: filter-dangerous ( seq -- seq' )
- [ vocab-name dangerous? not ] subset ;
-
-: try-everything ( -- failures )
- all-vocabs-seq
- filter-dangerous
- require-all ;
-
-: load-everything ( -- )
- try-everything load-failures. ;
-
-: unrooted-child-vocabs ( prefix -- seq )
- dup empty? [ CHAR: . add ] unless
- vocabs
- [ vocab-root not ] subset
- [
- vocab-name swap ?head CHAR: . rot member? not and
- ] with subset
- [ vocab ] map ;
-
-: all-child-vocabs ( prefix -- assoc )
- vocab-roots get [
- over dupd dupd (all-child-vocabs)
- swap [ >vocab-link ] curry map
- ] { } map>assoc
- f rot unrooted-child-vocabs 2array add ;
-
-: load-children ( prefix -- )
- all-child-vocabs values concat
- filter-dangerous
- require-all
- load-failures. ;
-
-: vocab-status-string ( vocab -- string )
- {
- { [ dup not ] [ drop "" ] }
- { [ dup vocab-main ] [ drop "[Runnable]" ] }
- { [ t ] [ drop "[Loaded]" ] }
- } cond ;
-
-: write-status ( vocab -- )
- vocab vocab-status-string write ;
-
-: vocab. ( vocab -- )
- [
- dup [ write-status ] with-cell
- dup [ ($link) ] with-cell
- [ vocab-summary write ] with-cell
- ] with-row ;
-
-: vocab-headings. ( -- )
- [
- [ "State" write ] with-cell
- [ "Vocabulary" write ] with-cell
- [ "Summary" write ] with-cell
- ] with-row ;
-
-: root-heading. ( root -- )
- [ "Children from " swap append ] [ "Children" ] if*
- $heading ;
-
-: vocabs. ( assoc -- )
- [
- dup empty? [
- 2drop
- ] [
- swap root-heading.
- standard-table-style [
- vocab-headings. [ vocab. ] each
- ] ($grid)
- ] if
- ] assoc-each ;
-
-: describe-summary ( vocab -- )
- vocab-summary [
- "Summary" $heading print-element
- ] when* ;
-
-TUPLE: vocab-tag name ;
-
-C: <vocab-tag> vocab-tag
-
-: tags. ( seq -- ) [ <vocab-tag> ] map $links ;
-
-: describe-tags ( vocab -- )
- vocab-tags f like [
- "Tags" $heading tags.
- ] when* ;
-
-TUPLE: vocab-author name ;
-
-C: <vocab-author> vocab-author
-
-: authors. ( seq -- ) [ <vocab-author> ] map $links ;
-
-: describe-authors ( vocab -- )
- vocab-authors f like [
- "Authors" $heading authors.
- ] when* ;
-
-: describe-help ( vocab -- )
- vocab-help [
- "Documentation" $heading nl ($link)
- ] when* ;
-
-: describe-children ( vocab -- )
- vocab-name all-child-vocabs vocabs. ;
-
-: describe-files ( vocab -- )
- vocab-files [ <pathname> ] map [
- "Files" $heading
- [
- snippet-style get [
- code-style get [
- stack.
- ] with-nesting
- ] with-style
- ] ($block)
- ] when* ;
-
-: describe-words ( vocab -- )
- words dup empty? [
- "Words" $heading
- dup natural-sort $links
- ] unless drop ;
-
-: map>set ( seq quot -- )
- map concat prune natural-sort ; inline
-
-: vocab-xref ( vocab quot -- vocabs )
- >r dup vocab-name swap words r> map
- [ [ word? ] subset [ word-vocabulary ] map ] map>set
- remove [ ] subset [ vocab ] map ; inline
-
-: vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
-
-: vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
-
-: describe-uses ( vocab -- )
- vocab-uses dup empty? [
- "Uses" $heading
- dup $links
- ] unless drop ;
-
-: describe-usage ( vocab -- )
- vocab-usage dup empty? [
- "Used by" $heading
- dup $links
- ] unless drop ;
-
-: $describe-vocab ( element -- )
- first
- dup describe-children
- dup vocab-root over vocab-dir? [
- dup describe-summary
- dup describe-tags
- dup describe-authors
- dup describe-files
- ] when
- dup vocab [
- dup describe-help
- dup describe-words
- dup describe-uses
- dup describe-usage
- ] when drop ;
-
-: keyed-vocabs ( str quot -- seq )
- all-vocabs [
- swap >r
- [ >r 2dup r> swap call member? ] subset
- r> swap
- ] assoc-map 2nip ; inline
-
-: tagged ( tag -- assoc )
- [ vocab-tags ] keyed-vocabs ;
-
-: authored ( author -- assoc )
- [ vocab-authors ] keyed-vocabs ;
-
-: $tagged-vocabs ( element -- )
- first tagged vocabs. ;
-
-MEMO: all-tags ( -- seq )
- all-vocabs-seq [ vocab-tags ] map>set ;
-
-: $authored-vocabs ( element -- )
- first authored vocabs. ;
-
-MEMO: all-authors ( -- seq )
- all-vocabs-seq [ vocab-authors ] map>set ;
-
-: $tags ( element -- )
- drop "Tags" $heading all-tags tags. ;
-
-: $authors ( element -- )
- drop "Authors" $heading all-authors authors. ;
-
-M: vocab-spec article-title vocab-name " vocabulary" append ;
-
-M: vocab-spec article-name vocab-name ;
-
-M: vocab-spec article-content
- vocab-name \ $describe-vocab swap 2array ;
-
-M: vocab-spec article-parent drop "vocab-index" ;
-
-M: vocab-tag >link ;
-
-M: vocab-tag article-title
- vocab-tag-name "Vocabularies tagged ``" swap "''" 3append ;
-
-M: vocab-tag article-name vocab-tag-name ;
-
-M: vocab-tag article-content
- \ $tagged-vocabs swap vocab-tag-name 2array ;
-
-M: vocab-tag article-parent drop "vocab-index" ;
-
-M: vocab-tag summary article-title ;
-
-M: vocab-author >link ;
-
-M: vocab-author article-title
- vocab-author-name "Vocabularies by " swap append ;
-
-M: vocab-author article-name vocab-author-name ;
-
-M: vocab-author article-content
- \ $authored-vocabs swap vocab-author-name 2array ;
-
-M: vocab-author article-parent drop "vocab-index" ;
-
-M: vocab-author summary article-title ;
-
-: reset-cache ( -- )
- \ (vocab-file-contents) reset-memoized
- \ all-vocabs-seq reset-memoized
- \ all-authors reset-memoized
- \ all-tags reset-memoized ;
--- /dev/null
+Slava Pestov
--- /dev/null
+USING: help.markup help.syntax io strings ;
+IN: tools.vocabs.browser
+
+ARTICLE: "vocab-index" "Vocabulary index"
+{ $tags }
+{ $authors }
+{ $describe-vocab "" } ;
--- /dev/null
+IN: tools.vocabs.browser.tests
+USING: tools.vocabs.browser tools.test help.markup ;
+
+[ ] [ { $describe-vocab "scratchpad" } print-content ] unit-test
--- /dev/null
+! Copyright (C) 2007, 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel combinators vocabs vocabs.loader tools.vocabs io
+io.files io.styles help.markup help.stylesheet sequences assocs
+help.topics namespaces prettyprint words sorting definitions
+arrays inspector ;
+IN: tools.vocabs.browser
+
+: vocab-status-string ( vocab -- string )
+ {
+ { [ dup not ] [ drop "" ] }
+ { [ dup vocab-main ] [ drop "[Runnable]" ] }
+ { [ t ] [ drop "[Loaded]" ] }
+ } cond ;
+
+: write-status ( vocab -- )
+ vocab vocab-status-string write ;
+
+: vocab. ( vocab -- )
+ [
+ dup [ write-status ] with-cell
+ dup [ ($link) ] with-cell
+ [ vocab-summary write ] with-cell
+ ] with-row ;
+
+: vocab-headings. ( -- )
+ [
+ [ "State" write ] with-cell
+ [ "Vocabulary" write ] with-cell
+ [ "Summary" write ] with-cell
+ ] with-row ;
+
+: root-heading. ( root -- )
+ [ "Children from " swap append ] [ "Children" ] if*
+ $heading ;
+
+: vocabs. ( assoc -- )
+ [
+ dup empty? [
+ 2drop
+ ] [
+ swap root-heading.
+ standard-table-style [
+ vocab-headings. [ vocab. ] each
+ ] ($grid)
+ ] if
+ ] assoc-each ;
+
+: describe-summary ( vocab -- )
+ vocab-summary [
+ "Summary" $heading print-element
+ ] when* ;
+
+TUPLE: vocab-tag name ;
+
+INSTANCE: vocab-tag topic
+
+C: <vocab-tag> vocab-tag
+
+: tags. ( seq -- ) [ <vocab-tag> ] map $links ;
+
+: describe-tags ( vocab -- )
+ vocab-tags f like [
+ "Tags" $heading tags.
+ ] when* ;
+
+TUPLE: vocab-author name ;
+
+INSTANCE: vocab-author topic
+
+C: <vocab-author> vocab-author
+
+: authors. ( seq -- ) [ <vocab-author> ] map $links ;
+
+: describe-authors ( vocab -- )
+ vocab-authors f like [
+ "Authors" $heading authors.
+ ] when* ;
+
+: describe-help ( vocab -- )
+ vocab-help [
+ "Documentation" $heading nl ($link)
+ ] when* ;
+
+: describe-children ( vocab -- )
+ vocab-name all-child-vocabs vocabs. ;
+
+: describe-files ( vocab -- )
+ vocab-files [ <pathname> ] map [
+ "Files" $heading
+ [
+ snippet-style get [
+ code-style get [
+ stack.
+ ] with-nesting
+ ] with-style
+ ] ($block)
+ ] when* ;
+
+: describe-words ( vocab -- )
+ words dup empty? [
+ "Words" $heading
+ dup natural-sort $links
+ ] unless drop ;
+
+: vocab-xref ( vocab quot -- vocabs )
+ >r dup vocab-name swap words r> map
+ [ [ word? ] subset [ word-vocabulary ] map ] map>set
+ remove [ ] subset [ vocab ] map ; inline
+
+: vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
+
+: vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
+
+: describe-uses ( vocab -- )
+ vocab-uses dup empty? [
+ "Uses" $heading
+ dup $links
+ ] unless drop ;
+
+: describe-usage ( vocab -- )
+ vocab-usage dup empty? [
+ "Used by" $heading
+ dup $links
+ ] unless drop ;
+
+: $describe-vocab ( element -- )
+ first
+ dup describe-children
+ dup vocab-root over vocab-dir? [
+ dup describe-summary
+ dup describe-tags
+ dup describe-authors
+ dup describe-files
+ ] when
+ dup vocab [
+ dup describe-help
+ dup describe-words
+ dup describe-uses
+ dup describe-usage
+ ] when drop ;
+
+: keyed-vocabs ( str quot -- seq )
+ all-vocabs [
+ swap >r
+ [ >r 2dup r> swap call member? ] subset
+ r> swap
+ ] assoc-map 2nip ; inline
+
+: tagged ( tag -- assoc )
+ [ vocab-tags ] keyed-vocabs ;
+
+: authored ( author -- assoc )
+ [ vocab-authors ] keyed-vocabs ;
+
+: $tagged-vocabs ( element -- )
+ first tagged vocabs. ;
+
+: $authored-vocabs ( element -- )
+ first authored vocabs. ;
+
+: $tags ( element -- )
+ drop "Tags" $heading all-tags tags. ;
+
+: $authors ( element -- )
+ drop "Authors" $heading all-authors authors. ;
+
+INSTANCE: vocab topic
+
+INSTANCE: vocab-link topic
+
+M: vocab-spec article-title vocab-name " vocabulary" append ;
+
+M: vocab-spec article-name vocab-name ;
+
+M: vocab-spec article-content
+ vocab-name \ $describe-vocab swap 2array ;
+
+M: vocab-spec article-parent drop "vocab-index" ;
+
+M: vocab-tag >link ;
+
+M: vocab-tag article-title
+ vocab-tag-name "Vocabularies tagged ``" swap "''" 3append ;
+
+M: vocab-tag article-name vocab-tag-name ;
+
+M: vocab-tag article-content
+ \ $tagged-vocabs swap vocab-tag-name 2array ;
+
+M: vocab-tag article-parent drop "vocab-index" ;
+
+M: vocab-tag summary article-title ;
+
+M: vocab-author >link ;
+
+M: vocab-author article-title
+ vocab-author-name "Vocabularies by " swap append ;
+
+M: vocab-author article-name vocab-author-name ;
+
+M: vocab-author article-content
+ \ $authored-vocabs swap vocab-author-name 2array ;
+
+M: vocab-author article-parent drop "vocab-index" ;
+
+M: vocab-author summary article-title ;
--- /dev/null
+Slava Pestov
--- /dev/null
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: threads io.files io.monitors init kernel\r
+vocabs.loader tools.vocabs namespaces continuations ;\r
+IN: tools.vocabs.monitor\r
+\r
+! Use file system change monitoring to flush the tags/authors\r
+! cache\r
+SYMBOL: vocab-monitor\r
+\r
+: monitor-thread ( -- )\r
+ vocab-monitor get-global\r
+ next-change 2drop\r
+ t sources-changed? set-global reset-cache ;\r
+\r
+: start-monitor-thread\r
+ #! Silently ignore errors during monitor creation since\r
+ #! monitors are not supported on all platforms.\r
+ [\r
+ "" resource-path t <monitor> vocab-monitor set-global\r
+ [ monitor-thread t ] "Vocabulary monitor" spawn-server drop\r
+ ] ignore-errors ;\r
+\r
+[ start-monitor-thread ] "tools.vocabs.monitor" add-init-hook\r
--- /dev/null
+Use io.monitors to clear tools.browser authors/tags/summary cache
--- /dev/null
+USING: help.markup help.syntax strings ;\r
+IN: tools.vocabs\r
+\r
+ARTICLE: "tools.vocabs" "Vocabulary tools"\r
+"Reloading source files changed on disk:"\r
+{ $subsection refresh }\r
+{ $subsection refresh-all }\r
+"Vocabulary summaries:"\r
+{ $subsection vocab-summary }\r
+{ $subsection set-vocab-summary }\r
+"Vocabulary tags:"\r
+{ $subsection vocab-tags }\r
+{ $subsection set-vocab-tags }\r
+{ $subsection add-vocab-tags }\r
+"Getting and setting vocabulary meta-data:"\r
+{ $subsection vocab-file-contents }\r
+{ $subsection set-vocab-file-contents }\r
+"Global meta-data:"\r
+{ $subsection all-vocabs }\r
+{ $subsection all-vocabs-seq }\r
+{ $subsection all-tags }\r
+{ $subsection all-authors }\r
+"Because loading the above data is expensive, it is cached. The cache is flushed by the " { $vocab-link "tools.vocabs.monitor" } " vocabulary. It can also be flushed manually when file system change monitors are not available:"\r
+{ $subsection reset-cache } ;\r
+\r
+ABOUT: "tools.vocabs"\r
+\r
+HELP: refresh\r
+{ $values { "prefix" string } }\r
+{ $description "Reloads source files and documentation belonging to loaded vocabularies whose names are prefixed by " { $snippet "prefix" } " which have been modified on disk." } ;\r
+\r
+HELP: refresh-all\r
+{ $description "Reloads source files and documentation for all loaded vocabularies which have been modified on disk." } ;\r
+\r
+{ refresh refresh-all } related-words\r
+\r
+HELP: vocab-file-contents\r
+{ $values { "vocab" "a vocabulary specifier" } { "name" string } { "seq" "a sequence of lines, or " { $link f } } }\r
+{ $description "Outputs the contents of the file named " { $snippet "name" } " from the vocabulary's directory, or " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-file-contents\r
+{ $values { "seq" "a sequence of lines" } { "vocab" "a vocabulary specifier" } { "name" string } }\r
+{ $description "Stores a sequence of lines to the file named " { $snippet "name" } " from the vocabulary's directory." } ;\r
+\r
+HELP: vocab-summary\r
+{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }\r
+{ $description "Outputs a one-line string description of the vocabulary's intended purpose from the " { $snippet "summary.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-summary\r
+{ $values { "string" "a string or " { $link f } } { "vocab" "a vocabulary specifier" } }\r
+{ $description "Stores a one-line string description of the vocabulary to the " { $snippet "summary.txt" } " file in the vocabulary's directory." } ;\r
+\r
+HELP: vocab-tags\r
+{ $values { "vocab" "a vocabulary specifier" } { "tags" "a sequence of strings" } }\r
+{ $description "Outputs a list of short tags classifying the vocabulary from the " { $snippet "tags.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-tags\r
+{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }\r
+{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;\r
+\r
+HELP: all-vocabs\r
+{ $values { "assoc" "an association list mapping vocabulary roots to sequences of vocabulary specifiers" } }\r
+{ $description "Outputs an association list of all vocabularies which have been loaded or are available for loading." } ;\r
--- /dev/null
+! Copyright (C) 2007, 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: io.files kernel io.encodings.utf8 vocabs.loader vocabs\r
+sequences namespaces math.parser arrays hashtables assocs\r
+memoize inspector sorting splitting combinators source-files\r
+io debugger continuations compiler.errors init ;\r
+IN: tools.vocabs\r
+\r
+: modified ( seq quot -- seq )\r
+ [ dup ] swap compose { } map>assoc\r
+ [ nip ] assoc-subset\r
+ [ nip source-modified? ] assoc-subset keys ; inline\r
+\r
+: modified-sources ( vocabs -- seq )\r
+ [ vocab-source-path ] modified ;\r
+\r
+: modified-docs ( vocabs -- seq )\r
+ [ vocab-docs-path ] modified ;\r
+\r
+: update-roots ( vocabs -- )\r
+ [ dup find-vocab-root swap vocab set-vocab-root ] each ;\r
+\r
+: to-refresh ( prefix -- modified-sources modified-docs )\r
+ child-vocabs\r
+ dup update-roots\r
+ dup modified-sources swap modified-docs ;\r
+\r
+: vocab-heading. ( vocab -- )\r
+ nl\r
+ "==== " write\r
+ dup vocab-name swap vocab write-object ":" print\r
+ nl ;\r
+\r
+: load-error. ( triple -- )\r
+ dup first vocab-heading.\r
+ dup second print-error\r
+ drop ;\r
+\r
+: load-failures. ( failures -- )\r
+ [ load-error. nl ] each ;\r
+\r
+SYMBOL: failures\r
+\r
+: require-all ( vocabs -- failures )\r
+ [\r
+ V{ } clone blacklist set\r
+ V{ } clone failures set\r
+ [\r
+ [ require ]\r
+ [ swap vocab-name failures get set-at ]\r
+ recover\r
+ ] each\r
+ failures get\r
+ ] with-compiler-errors ;\r
+\r
+: do-refresh ( modified-sources modified-docs -- )\r
+ 2dup\r
+ [ f swap set-vocab-docs-loaded? ] each\r
+ [ f swap set-vocab-source-loaded? ] each\r
+ append prune require-all load-failures. ;\r
+\r
+: refresh ( prefix -- ) to-refresh do-refresh ;\r
+\r
+SYMBOL: sources-changed?\r
+\r
+[ t sources-changed? set-global ] "tools.vocabs" add-init-hook\r
+\r
+: refresh-all ( -- )\r
+ "" refresh f sources-changed? set-global ;\r
+\r
+MEMO: (vocab-file-contents) ( path -- lines )\r
+ ?resource-path dup exists?\r
+ [ utf8 file-lines ] [ drop f ] if ;\r
+\r
+: vocab-file-contents ( vocab name -- seq )\r
+ vocab-path+ dup [ (vocab-file-contents) ] when ;\r
+\r
+: set-vocab-file-contents ( seq vocab name -- )\r
+ dupd vocab-path+ [\r
+ ?resource-path utf8 set-file-lines\r
+ ] [\r
+ "The " swap vocab-name\r
+ " vocabulary was not loaded from the file system"\r
+ 3append throw\r
+ ] ?if ;\r
+\r
+: vocab-summary-path ( vocab -- string )\r
+ vocab-dir "summary.txt" path+ ;\r
+\r
+: vocab-summary ( vocab -- summary )\r
+ dup dup vocab-summary-path vocab-file-contents\r
+ dup empty? [\r
+ drop vocab-name " vocabulary" append\r
+ ] [\r
+ nip first\r
+ ] if ;\r
+\r
+M: vocab summary\r
+ [\r
+ dup vocab-summary %\r
+ " (" %\r
+ vocab-words assoc-size #\r
+ " words)" %\r
+ ] "" make ;\r
+\r
+M: vocab-link summary vocab-summary ;\r
+\r
+: set-vocab-summary ( string vocab -- )\r
+ >r 1array r>\r
+ dup vocab-summary-path\r
+ set-vocab-file-contents ;\r
+\r
+: vocab-tags-path ( vocab -- string )\r
+ vocab-dir "tags.txt" path+ ;\r
+\r
+: vocab-tags ( vocab -- tags )\r
+ dup vocab-tags-path vocab-file-contents ;\r
+\r
+: set-vocab-tags ( tags vocab -- )\r
+ dup vocab-tags-path set-vocab-file-contents ;\r
+\r
+: add-vocab-tags ( tags vocab -- )\r
+ [ vocab-tags append prune ] keep set-vocab-tags ;\r
+\r
+: vocab-authors-path ( vocab -- string )\r
+ vocab-dir "authors.txt" path+ ;\r
+\r
+: vocab-authors ( vocab -- authors )\r
+ dup vocab-authors-path vocab-file-contents ;\r
+\r
+: set-vocab-authors ( authors vocab -- )\r
+ dup vocab-authors-path set-vocab-file-contents ;\r
+\r
+: subdirs ( dir -- dirs )\r
+ directory [ second ] subset keys natural-sort ;\r
+\r
+: (all-child-vocabs) ( root name -- vocabs )\r
+ [ vocab-dir path+ ?resource-path subdirs ] keep\r
+ dup empty? [\r
+ drop\r
+ ] [\r
+ swap [ "." swap 3append ] with map\r
+ ] if ;\r
+\r
+: vocabs-in-dir ( root name -- )\r
+ dupd (all-child-vocabs) [\r
+ 2dup vocab-dir? [ 2dup swap >vocab-link , ] when\r
+ vocabs-in-dir\r
+ ] with each ;\r
+\r
+: all-vocabs ( -- assoc )\r
+ vocab-roots get [\r
+ dup [ "" vocabs-in-dir ] { } make\r
+ ] { } map>assoc ;\r
+\r
+MEMO: all-vocabs-seq ( -- seq )\r
+ all-vocabs values concat ;\r
+\r
+: dangerous? ( name -- ? )\r
+ #! Hack\r
+ {\r
+ { [ "cpu." ?head ] [ t ] }\r
+ { [ "io.unix" ?head ] [ t ] }\r
+ { [ "io.windows" ?head ] [ t ] }\r
+ { [ "ui.x11" ?head ] [ t ] }\r
+ { [ "ui.windows" ?head ] [ t ] }\r
+ { [ "ui.cocoa" ?head ] [ t ] }\r
+ { [ "cocoa" ?head ] [ t ] }\r
+ { [ "core-foundation" ?head ] [ t ] }\r
+ { [ "vocabs.loader.test" ?head ] [ t ] }\r
+ { [ "editors." ?head ] [ t ] }\r
+ { [ ".windows" ?tail ] [ t ] }\r
+ { [ ".unix" ?tail ] [ t ] }\r
+ { [ "unix." ?head ] [ t ] }\r
+ { [ ".linux" ?tail ] [ t ] }\r
+ { [ ".bsd" ?tail ] [ t ] }\r
+ { [ ".macosx" ?tail ] [ t ] }\r
+ { [ "windows." ?head ] [ t ] }\r
+ { [ "cocoa" ?head ] [ t ] }\r
+ { [ ".test" ?tail ] [ t ] }\r
+ { [ "raptor" ?head ] [ t ] }\r
+ { [ dup "tools.deploy.app" = ] [ t ] }\r
+ { [ t ] [ f ] }\r
+ } cond nip ;\r
+\r
+: filter-dangerous ( seq -- seq' )\r
+ [ vocab-name dangerous? not ] subset ;\r
+\r
+: try-everything ( -- failures )\r
+ all-vocabs-seq\r
+ filter-dangerous\r
+ require-all ;\r
+\r
+: load-everything ( -- )\r
+ try-everything load-failures. ;\r
+\r
+: unrooted-child-vocabs ( prefix -- seq )\r
+ dup empty? [ CHAR: . add ] unless\r
+ vocabs\r
+ [ vocab-root not ] subset\r
+ [\r
+ vocab-name swap ?head CHAR: . rot member? not and\r
+ ] with subset\r
+ [ vocab ] map ;\r
+\r
+: all-child-vocabs ( prefix -- assoc )\r
+ vocab-roots get [\r
+ over dupd dupd (all-child-vocabs)\r
+ swap [ >vocab-link ] curry map\r
+ ] { } map>assoc\r
+ f rot unrooted-child-vocabs 2array add ;\r
+\r
+: load-children ( prefix -- )\r
+ all-child-vocabs values concat\r
+ filter-dangerous\r
+ require-all\r
+ load-failures. ;\r
+\r
+: map>set ( seq quot -- )\r
+ map concat prune natural-sort ; inline\r
+\r
+MEMO: all-tags ( -- seq )\r
+ all-vocabs-seq [ vocab-tags ] map>set ;\r
+\r
+MEMO: all-authors ( -- seq )\r
+ all-vocabs-seq [ vocab-authors ] map>set ;\r
+\r
+: reset-cache ( -- )\r
+ \ (vocab-file-contents) reset-memoized\r
+ \ all-vocabs-seq reset-memoized\r
+ \ all-authors reset-memoized\r
+ \ all-tags reset-memoized ;\r
editors tools.profiler tools.test tools.time tools.walker
ui.commands ui.gadgets.editors ui.gestures ui.operations
ui.tools.deploy vocabs vocabs.loader words sequences
-tools.browser classes compiler.units ;
+tools.vocabs classes compiler.units ;
IN: ui.tools.operations
V{ } clone operations set-global
{ +secondary+ t }
} define-operation
-[
- class
- { link word vocab vocab-link vocab-tag vocab-author }
- memq?
-] \ com-follow H{
+[ topic? ] \ com-follow H{
{ +keyboard+ T{ key-down f { C+ } "H" } }
{ +primary+ t }
} define-operation
tuples ui.commands ui.gadgets ui.gadgets.editors
ui.gadgets.lists ui.gadgets.scrollers ui.gadgets.tracks
ui.gestures ui.operations vocabs words vocabs.loader
-tools.browser unicode.case calendar ui ;
+tools.vocabs unicode.case calendar ui ;
IN: ui.tools.search
TUPLE: live-search field list ;
+++ /dev/null
-Slava Pestov
+++ /dev/null
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: threads io.files io.monitors init kernel\r
-tools.browser namespaces continuations vocabs.loader ;\r
-IN: vocabs.monitor\r
-\r
-! Use file system change monitoring to flush the tags/authors\r
-! cache\r
-SYMBOL: vocab-monitor\r
-\r
-: monitor-thread ( -- )\r
- vocab-monitor get-global\r
- next-change 2drop\r
- t sources-changed? set-global reset-cache ;\r
-\r
-: start-monitor-thread\r
- #! Silently ignore errors during monitor creation since\r
- #! monitors are not supported on all platforms.\r
- [\r
- "" resource-path t <monitor> vocab-monitor set-global\r
- [ monitor-thread t ] "Vocabulary monitor" spawn-server drop\r
- ] ignore-errors ;\r
-\r
-[ start-monitor-thread ] "vocabs.monitor" add-init-hook\r
+++ /dev/null
-Use io.monitors to clear tools.browser authors/tags/summary cache