script: Improve dirty propagation and fix script-layout synchronization.

This fixes race conditions whereby layout and script could be running
simultaneously.

r? @jdm 
cc @cgaebel 
I like the distinction between flowing incrementally and non-incrementally. Can we use this to only check for the `-i` option only in this function, and then remove the checks in layout?