1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs command-line concurrency.messaging
4 continuations init io.backend io.files io.monitors io.pathnames
5 kernel libc namespaces sequences sets splitting threads fry
6 tr vocabs vocabs.loader vocabs.refresh vocabs.cache
8 IN: vocabs.refresh.monitor
10 TR: convert-separators "/\\" ".." ;
12 : vocab-dir>vocab-name ( path -- vocab )
17 : path>vocab-name ( path -- vocab )
18 dup ".factor" tail? [ parent-directory ] when ;
20 : chop-vocab-root ( path -- path' )
21 "resource:" prepend-path normalize-path
23 [ [ normalize-path ] map ]
24 [ [ resolve-symlinks ] map ] bi append
25 [ head? ] with find nip
28 : path>vocab ( path -- vocab )
29 chop-vocab-root path>vocab-name vocab-dir>vocab-name ;
31 : monitor-loop ( monitor -- )
32 ! On OS X, monitors give us the full path, so we chop it
35 next-change path>> path>vocab
36 [ changed-vocab ] [ reset-cache ] bi
41 : (start-vocab-monitor) ( vocab-root -- )
43 [ [ t <monitor> monitor-loop ] with-monitors ] [ drop ] if ;
45 : start-vocab-monitor ( vocab-root -- )
46 [ '[ [ _ (start-vocab-monitor) ] ignore-errors ] ]
47 [ "Root monitor: " prepend ]
50 : init-vocab-monitor ( -- )
51 H{ } clone changed-vocabs set-global
52 loaded-vocab-names [ changed-vocab ] each ;
55 "-no-monitors" (command-line) member? [
56 [ drop ] add-vocab-root-hook set-global
57 f changed-vocabs set-global
60 vocab-roots get [ start-vocab-monitor ] each
61 [ start-vocab-monitor ] add-vocab-root-hook set-global
63 ] "vocabs.refresh.monitor" add-startup-hook