    (set-status {:type :clear})
    (.clearGutter @editor "CodeMirror-lint-markers")
    (c/run code (fn [res]
+                 (save-code update-url)
                  (cond (:error res) (set-status {:type :errors})
                        (not (empty? (:warnings res))) (set-status {:type :warnings})
                        :default (set-status {:type :ok}))

                                            (.popover (j/$ "#share") "destroy")))
  (.on js/CodeMirror @editor "touchstart" #(do
                                            (hide-result-pane)
                                            (.popover (j/$ "#share") "destroy"))))


(j/$ init)

      :no-code (set "alert-warning" "no form found under cursor")
      :clear (set "" ""))))

(defn save-code [cb]
  (let [code (.getValue @editor)]
   (j/ajax
    {:url "/sketches/create"
     :method "POST"
     :data (.stringify js/JSON #js {:cljs code})
     :contentType "application/json"
     :success (fn [resp]
                (let [resp (js->clj resp :keywordize-keys true)]
                  (cb resp)))})))

(defn show-share-dialog [resp]
  (let [path (str "/sketches/show/" (:id resp))
        url (str (.-protocol js/location) "//" (.-host js/location) path)]
    (j/val (j/$ "#share-dialog input") url)
    (.modal (j/$ "#share-dialog") "show")))

(defn update-url [resp]
  (let [path (str "/sketches/show/" (:id resp))]
    (when (not= path (.-pathname js/location))
      (.pushState js/history
                  #js {:source (:cljs resp)} "" path))))

(defn share []
  (save-code
   #(do (update-url %)
        (show-share-dialog %))))

(defn compile
  ([] (compile (.getValue @editor)))
  ([code]
