diff --git a/src/Revise.jl b/src/Revise.jl index 4b1fbf73..d8cd3008 100644 --- a/src/Revise.jl +++ b/src/Revise.jl @@ -655,11 +655,16 @@ end includet(file::AbstractString) = includet(Main, file) """ - entr(f, files) - entr(f, files, modules) + entr(f, files; postpone=false, pause=0.02) + entr(f, files, modules; postpone=false, pause=0.02) Execute `f()` whenever files listed in `files`, or code in `modules`, updates. `entr` will process updates (and block your command line) until you press Ctrl-C. +Unless `postpone` is `true`, `f()` will be executed also when calling `entr`, +regardless of file changes. The `pause` is the period (in seconds) that `entr` +will wait between being triggered and actually calling `f()`, to handle +clusters of modifications, such as those produced by saving files in certain +text editors. # Example @@ -671,7 +676,7 @@ end This will print "update" every time `"/tmp/watched.txt"` or any of the code defining `Pkg1` or `Pkg2` gets updated. """ -function entr(f::Function, files, modules=nothing) +function entr(f::Function, files, modules=nothing; postpone=false, pause=0.02) files = collect(files) # because we may add to this list if modules !== nothing for mod in modules @@ -685,12 +690,13 @@ function entr(f::Function, files, modules=nothing) active = true try @sync begin + postpone || f() for file in files waitfor = isdir(file) ? watch_folder : watch_file @async while active ret = waitfor(file, 1) - ret.renamed && break - if active && ret.changed + if active && (ret.changed || ret.renamed) + sleep(pause) revise() f() end