Guest User

Touch a file whenever defn is called. Useful with LiveReload

a guest
Mar 4th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def reload-trigger-file "reload.trigger")
  2.  
  3. (defn- touch-reload-trigger
  4.   "Called on defn invocation; updates the mod time on the reload trigger
  5.   file so LiveReload will reload the web page."
  6.   []
  7.   (with-open [w (io/writer (var-get #'reload-trigger-file))]
  8.     (.write w "x")))
  9.  
  10. (defn- trigger-on-defn [f & args]
  11.   (touch-reload-trigger)
  12.   (apply f args))
  13.  
  14. (defn start-reloading-on-defn []
  15.   (add-hook #'defn #'trigger-on-defn))
Add Comment
Please, Sign In to add comment