1 ! Copyright (C) 2008, 2009 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: accessors assocs command-line concurrency.messaging
\r
4 continuations init io.backend io.files io.monitors io.pathnames
\r
5 kernel namespaces sequences sets splitting threads
\r
6 tr vocabs vocabs.loader vocabs.refresh vocabs.cache ;
\r
7 IN: vocabs.refresh.monitor
\r
9 TR: convert-separators "/\\" ".." ;
\r
11 : vocab-dir>vocab-name ( path -- vocab )
\r
12 trim-head-separators
\r
13 trim-tail-separators
\r
14 convert-separators ;
\r
16 : path>vocab-name ( path -- vocab )
\r
17 dup ".factor" tail? [ parent-directory ] when ;
\r
19 : chop-vocab-root ( path -- path' )
\r
20 "resource:" prepend-path normalize-path
\r
22 [ normalize-path ] map
\r
23 [ head? ] with find nip
\r
26 : path>vocab ( path -- vocab )
\r
27 chop-vocab-root path>vocab-name vocab-dir>vocab-name ;
\r
29 : monitor-loop ( -- )
\r
30 #! On OS X, monitors give us the full path, so we chop it
\r
31 #! off if its there.
\r
32 receive path>> path>vocab changed-vocab
\r
36 : add-monitor-for-path ( path -- )
\r
37 dup exists? [ t my-mailbox (monitor) ] when drop ;
\r
39 : monitor-thread ( -- )
\r
42 vocab-roots get prune [ add-monitor-for-path ] each
\r
44 H{ } clone changed-vocabs set-global
\r
45 vocabs [ changed-vocab ] each
\r
51 : start-monitor-thread ( -- )
\r
52 #! Silently ignore errors during monitor creation since
\r
53 #! monitors are not supported on all platforms.
\r
54 [ monitor-thread ] "Vocabulary monitor" spawn drop ;
\r
57 "-no-monitors" (command-line) member?
\r
58 [ start-monitor-thread ] unless
\r
59 ] "vocabs.refresh.monitor" add-startup-hook
\r