View difference between Paste ID: Bc8DpDiE and 6QZZLH2a
SHOW: | | - or go back to the newest paste.
1
(ns toucher.core
2
  (:require [clojure.java.io :as io]
3
            [robert.hooke :as rh :only [append]]))
4
5
(defn- touch-file
6
  "Called on defn invocation; updates the mod time on the reload trigger
7
   file so LiveReload will reload the web page."
8
  [file-to-touch]
9
  (let [f (java.io.File. file-to-touch)]
10
    (if (.exists f)
11
      (.setLastModified f (System/currentTimeMillis))
12-
      (with-open [w (io/writer f)]
12+
      (with-open [w (io/writer f)]))))
13-
          (comment .write w "x")))))
13+
14
(defn touch-file-on-defn
15
  "Starts touching the specified file every time a function is defined.
16
17
   In your startup code, call
18
19
      (toucher.core/touch-file-on-defn \"some-filename.trigger\")
20
21
   and configure LiveReload to watch for changes to .trigger files in your
22
   directory. (Use whatever extension you want; .trigger has no special
23
   meaning.) Now when you send a function definition to the REPL either
24
   directly from the REPL prompt or remotely from vim-fireplace or another
25
   tool, LiveReload will see the update of the trigger file and automatically
26
   reload the web page so you don't have to remove focus from your terminal
27
   window."
28
  [file-to-touch]
29
  (rh/append defn (touch-file file-to-touch)))